mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-14 11:18:06 +08:00
@@ -8,14 +8,14 @@ def test_int_cast_not_possible():
|
||||
np.testing.assert_raises(ValueError, safe_as_int, np.r_[7.1, 0.9])
|
||||
np.testing.assert_raises(ValueError, safe_as_int, (7.1, 0.9))
|
||||
np.testing.assert_raises(ValueError, safe_as_int, ((3, 4, 1),
|
||||
(2, 7.6, 289)))
|
||||
(2, 7.6, 289)))
|
||||
|
||||
np.testing.assert_raises(ValueError, safe_as_int, 7.1, 0.09)
|
||||
np.testing.assert_raises(ValueError, safe_as_int, [7.1, 0.9], 0.09)
|
||||
np.testing.assert_raises(ValueError, safe_as_int, np.r_[7.1, 0.9], 0.09)
|
||||
np.testing.assert_raises(ValueError, safe_as_int, (7.1, 0.9), 0.09)
|
||||
np.testing.assert_raises(ValueError, safe_as_int, ((3, 4, 1),
|
||||
(2, 7.6, 289)), 0.25)
|
||||
(2, 7.6, 289)), 0.25)
|
||||
|
||||
|
||||
def test_int_cast_possible():
|
||||
@@ -25,8 +25,8 @@ def test_int_cast_possible():
|
||||
np.testing.assert_array_equal(safe_as_int([2, 42, 5789234.0, 87, 4]),
|
||||
np.r_[2, 42, 5789234, 87, 4])
|
||||
np.testing.assert_array_equal(safe_as_int(np.r_[[[3, 4, 1.000000001],
|
||||
[7, 2, -8.999999999],
|
||||
[6, 9, -4234918347.]]]),
|
||||
[7, 2, -8.999999999],
|
||||
[6, 9, -4234918347.]]]),
|
||||
np.r_[[[3, 4, 1],
|
||||
[7, 2, -9],
|
||||
[6, 9, -4234918347]]])
|
||||
|
||||
@@ -11,6 +11,7 @@ def test_skipper():
|
||||
pass
|
||||
|
||||
class c():
|
||||
|
||||
def __init__(self):
|
||||
self.me = "I think, therefore..."
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ class deprecated(object):
|
||||
func_code = six.get_function_code(func)
|
||||
warnings.simplefilter('always', skimage_deprecation)
|
||||
warnings.warn_explicit(msg,
|
||||
category=skimage_deprecation,
|
||||
filename=func_code.co_filename,
|
||||
lineno=func_code.co_firstlineno + 1)
|
||||
category=skimage_deprecation,
|
||||
filename=func_code.co_filename,
|
||||
lineno=func_code.co_firstlineno + 1)
|
||||
elif self.behavior == 'raise':
|
||||
raise skimage_deprecation(msg)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
+16
-16
@@ -299,8 +299,8 @@ sb_primaries = np.array([1. / 155, 1. / 190, 1. / 225]) * 1e5
|
||||
|
||||
# From sRGB specification
|
||||
xyz_from_rgb = np.array([[0.412453, 0.357580, 0.180423],
|
||||
[0.212671, 0.715160, 0.072169],
|
||||
[0.019334, 0.119193, 0.950227]])
|
||||
[0.212671, 0.715160, 0.072169],
|
||||
[0.019334, 0.119193, 0.950227]])
|
||||
|
||||
rgb_from_xyz = linalg.inv(xyz_from_rgb)
|
||||
|
||||
@@ -978,19 +978,19 @@ def xyz2luv(xyz, illuminant="D65", observer="2"):
|
||||
L[mask] = 116. * np.power(L[mask], 1. / 3.) - 16.
|
||||
L[~mask] = 903.3 * L[~mask]
|
||||
|
||||
u0 = 4*xyz_ref_white[0] / np.dot([1, 15, 3], xyz_ref_white)
|
||||
v0 = 9*xyz_ref_white[1] / np.dot([1, 15, 3], xyz_ref_white)
|
||||
u0 = 4 * xyz_ref_white[0] / np.dot([1, 15, 3], xyz_ref_white)
|
||||
v0 = 9 * xyz_ref_white[1] / np.dot([1, 15, 3], xyz_ref_white)
|
||||
|
||||
# u' and v' helper functions
|
||||
def fu(X, Y, Z):
|
||||
return (4.*X) / (X + 15.*Y + 3.*Z + eps)
|
||||
return (4. * X) / (X + 15. * Y + 3. * Z + eps)
|
||||
|
||||
def fv(X, Y, Z):
|
||||
return (9.*Y) / (X + 15.*Y + 3.*Z + eps)
|
||||
return (9. * Y) / (X + 15. * Y + 3. * Z + eps)
|
||||
|
||||
# compute u and v using helper functions
|
||||
u = 13.*L * (fu(x, y, z) - u0)
|
||||
v = 13.*L * (fv(x, y, z) - v0)
|
||||
u = 13. * L * (fu(x, y, z) - u0)
|
||||
v = 13. * L * (fv(x, y, z) - v0)
|
||||
|
||||
return np.concatenate([q[..., np.newaxis] for q in [L, u, v]], axis=-1)
|
||||
|
||||
@@ -1043,24 +1043,24 @@ def luv2xyz(luv, illuminant="D65", observer="2"):
|
||||
# compute y
|
||||
y = L.copy()
|
||||
mask = y > 7.999625
|
||||
y[mask] = np.power((y[mask]+16.) / 116., 3.)
|
||||
y[mask] = np.power((y[mask] + 16.) / 116., 3.)
|
||||
y[~mask] = y[~mask] / 903.3
|
||||
xyz_ref_white = get_xyz_coords(illuminant, observer)
|
||||
y *= xyz_ref_white[1]
|
||||
|
||||
# reference white x,z
|
||||
uv_weights = [1, 15, 3]
|
||||
u0 = 4*xyz_ref_white[0] / np.dot(uv_weights, xyz_ref_white)
|
||||
v0 = 9*xyz_ref_white[1] / np.dot(uv_weights, xyz_ref_white)
|
||||
u0 = 4 * xyz_ref_white[0] / np.dot(uv_weights, xyz_ref_white)
|
||||
v0 = 9 * xyz_ref_white[1] / np.dot(uv_weights, xyz_ref_white)
|
||||
|
||||
# compute intermediate values
|
||||
a = u0 + u / (13.*L + eps)
|
||||
b = v0 + v / (13.*L + eps)
|
||||
c = 3*y * (5*b-3)
|
||||
a = u0 + u / (13. * L + eps)
|
||||
b = v0 + v / (13. * L + eps)
|
||||
c = 3 * y * (5 * b - 3)
|
||||
|
||||
# compute x and z
|
||||
z = ((a-4)*c - 15*a*b*y) / (12*b)
|
||||
x = -(c/b + 3.*z)
|
||||
z = ((a - 4) * c - 15 * a * b * y) / (12 * b)
|
||||
x = -(c / b + 3. * z)
|
||||
|
||||
return np.concatenate([q[..., np.newaxis] for q in [x, y, z]], axis=-1)
|
||||
|
||||
|
||||
@@ -336,4 +336,4 @@ def get_dH2(lab1, lab2):
|
||||
C2 = np.hypot(a2, b2)
|
||||
|
||||
term = (C1 * C2) - (a1 * a2 + b1 * b2)
|
||||
return 2*term
|
||||
return 2 * term
|
||||
|
||||
@@ -65,18 +65,19 @@ def lena():
|
||||
"""
|
||||
return load("lena.png")
|
||||
|
||||
|
||||
def astronaut():
|
||||
"""Colour image of the astronaut Eileen Collins.
|
||||
|
||||
Photograph of Eileen Collins, an American astronaut. She was selected
|
||||
Photograph of Eileen Collins, an American astronaut. She was selected
|
||||
as an astronaut in 1992 and first piloted the space shuttle STS-63 in
|
||||
1995. She retired in 2006 after spending a total of 38 days, 8 hours
|
||||
1995. She retired in 2006 after spending a total of 38 days, 8 hours
|
||||
and 10 minutes in outer space.
|
||||
|
||||
This image was downloaded from the NASA Great Images database
|
||||
<http://grin.hq.nasa.gov/ABSTRACTS/GPN-2000-001177.html>`__.
|
||||
|
||||
No known copyright restrictions, released into the public domain.
|
||||
No known copyright restrictions, released into the public domain.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ from skimage.util import view_as_blocks, pad
|
||||
|
||||
MAX_REG_X = 16 # max. # contextual regions in x-direction */
|
||||
MAX_REG_Y = 16 # max. # contextual regions in y-direction */
|
||||
NR_OF_GREY = 2**14 # number of grayscale levels to use in CLAHE algorithm
|
||||
NR_OF_GREY = 2 ** 14 # number of grayscale levels to use in CLAHE algorithm
|
||||
|
||||
|
||||
@adapt_rgb(hsv_value)
|
||||
|
||||
@@ -11,9 +11,9 @@ __all__ = ['histogram', 'cumulative_distribution', 'equalize_hist',
|
||||
|
||||
DTYPE_RANGE = dtype_range.copy()
|
||||
DTYPE_RANGE.update((d.__name__, limits) for d, limits in dtype_range.items())
|
||||
DTYPE_RANGE.update({'uint10': (0, 2**10 - 1),
|
||||
'uint12': (0, 2**12 - 1),
|
||||
'uint14': (0, 2**14 - 1),
|
||||
DTYPE_RANGE.update({'uint10': (0, 2 ** 10 - 1),
|
||||
'uint12': (0, 2 ** 12 - 1),
|
||||
'uint14': (0, 2 ** 14 - 1),
|
||||
'bool': dtype_range[np.bool_],
|
||||
'float': dtype_range[np.float64]})
|
||||
|
||||
@@ -457,8 +457,8 @@ def adjust_sigmoid(image, cutoff=0.5, gain=10, inv=False):
|
||||
scale = float(dtype_limits(image, True)[1] - dtype_limits(image, True)[0])
|
||||
|
||||
if inv:
|
||||
out = (1 - 1 / (1 + np.exp(gain * (cutoff - image/scale)))) * scale
|
||||
out = (1 - 1 / (1 + np.exp(gain * (cutoff - image / scale)))) * scale
|
||||
return dtype(out)
|
||||
|
||||
out = (1 / (1 + np.exp(gain * (cutoff - image/scale)))) * scale
|
||||
out = (1 / (1 + np.exp(gain * (cutoff - image / scale)))) * scale
|
||||
return dtype(out)
|
||||
|
||||
@@ -104,7 +104,7 @@ def hog(image, orientations=9, pixels_per_cell=(8, 8),
|
||||
cell are used to vote into the orientation histogram.
|
||||
"""
|
||||
|
||||
magnitude = sqrt(gx**2 + gy**2)
|
||||
magnitude = sqrt(gx ** 2 + gy ** 2)
|
||||
orientation = arctan2(gy, gx) * (180 / pi) % 180
|
||||
|
||||
sy, sx = image.shape
|
||||
@@ -119,7 +119,7 @@ def hog(image, orientations=9, pixels_per_cell=(8, 8),
|
||||
subsample = np.index_exp[cy // 2:cy * n_cellsy:cy,
|
||||
cx // 2:cx * n_cellsx:cx]
|
||||
for i in range(orientations):
|
||||
#create new integral image for this orientation
|
||||
# create new integral image for this orientation
|
||||
# isolate orientations in this range
|
||||
|
||||
temp_ori = np.where(orientation < 180.0 / orientations * (i + 1),
|
||||
@@ -177,7 +177,7 @@ def hog(image, orientations=9, pixels_per_cell=(8, 8),
|
||||
for y in range(n_blocksy):
|
||||
block = orientation_histogram[y:y + by, x:x + bx, :]
|
||||
eps = 1e-5
|
||||
normalised_blocks[y, x, :] = block / sqrt(block.sum()**2 + eps)
|
||||
normalised_blocks[y, x, :] = block / sqrt(block.sum() ** 2 + eps)
|
||||
|
||||
"""
|
||||
The final step collects the HOG descriptors from all blocks of a dense
|
||||
|
||||
@@ -185,7 +185,7 @@ def blob_dog(image, min_sigma=1, max_sigma=50, sigma_ratio=1.6, threshold=2.0,
|
||||
|
||||
# a geometric progression of standard deviations for gaussian kernels
|
||||
sigma_list = np.array([min_sigma * (sigma_ratio ** i)
|
||||
for i in range(k + 1)])
|
||||
for i in range(k + 1)])
|
||||
|
||||
gaussian_images = [gaussian_filter(image, s) for s in sigma_list]
|
||||
|
||||
|
||||
@@ -171,13 +171,13 @@ class BRIEF(DescriptorExtractor):
|
||||
# Removing keypoints that are within (patch_size / 2) distance from the
|
||||
# image border
|
||||
self.mask = _mask_border_keypoints(image.shape, keypoints,
|
||||
patch_size // 2)
|
||||
patch_size // 2)
|
||||
|
||||
keypoints = np.array(keypoints[self.mask, :], dtype=np.intp,
|
||||
order='C', copy=False)
|
||||
|
||||
self.descriptors = np.zeros((keypoints.shape[0], desc_size),
|
||||
dtype=bool, order='C')
|
||||
dtype=bool, order='C')
|
||||
|
||||
_brief_loop(image, self.descriptors.view(np.uint8), keypoints,
|
||||
pos1, pos2)
|
||||
|
||||
@@ -31,7 +31,7 @@ STAR_FILTER_SHAPE = [(1, 0), (3, 1), (4, 2), (5, 3), (7, 4), (8, 5),
|
||||
def _filter_image(image, min_scale, max_scale, mode):
|
||||
|
||||
response = np.zeros((image.shape[0], image.shape[1],
|
||||
max_scale - min_scale + 1), dtype=np.double)
|
||||
max_scale - min_scale + 1), dtype=np.double)
|
||||
|
||||
if mode == 'dob':
|
||||
|
||||
@@ -48,8 +48,8 @@ def _filter_image(image, min_scale, max_scale, mode):
|
||||
# Constant multipliers for the outer region and the inner region
|
||||
# of the bi-level filters with the constraint of keeping the
|
||||
# DC bias 0.
|
||||
inner_weight = (1.0 / (2 * n + 1)**2)
|
||||
outer_weight = (1.0 / (12 * n**2 + 4 * n))
|
||||
inner_weight = (1.0 / (2 * n + 1) ** 2)
|
||||
outer_weight = (1.0 / (12 * n ** 2 + 4 * n))
|
||||
|
||||
_censure_dob_loop(n, integral_img, response[:, :, i],
|
||||
inner_weight, outer_weight)
|
||||
@@ -79,8 +79,8 @@ def _filter_image(image, min_scale, max_scale, mode):
|
||||
|
||||
|
||||
def _octagon_kernel(mo, no, mi, ni):
|
||||
outer = (mo + 2 * no)**2 - 2 * no * (no + 1)
|
||||
inner = (mi + 2 * ni)**2 - 2 * ni * (ni + 1)
|
||||
outer = (mo + 2 * no) ** 2 - 2 * no * (no + 1)
|
||||
inner = (mi + 2 * ni) ** 2 - 2 * ni * (ni + 1)
|
||||
outer_weight = 1.0 / (outer - inner)
|
||||
inner_weight = 1.0 / inner
|
||||
c = ((mo + 2 * no) - (mi + 2 * ni)) // 2
|
||||
@@ -110,7 +110,6 @@ def _suppress_lines(feature_mask, image, sigma, line_threshold):
|
||||
> line_threshold * (Axx * Ayy - Axy ** 2)] = False
|
||||
|
||||
|
||||
|
||||
class CENSURE(FeatureDetector):
|
||||
|
||||
"""CENSURE keypoint detector.
|
||||
|
||||
@@ -323,8 +323,8 @@ def corner_kitchen_rosenfeld(image, mode='constant', cval=0):
|
||||
imxx, imxy = _compute_derivatives(imx, mode=mode, cval=cval)
|
||||
imyx, imyy = _compute_derivatives(imy, mode=mode, cval=cval)
|
||||
|
||||
numerator = (imxx * imy**2 + imyy * imx**2 - 2 * imxy * imx * imy)
|
||||
denominator = (imx**2 + imy**2)
|
||||
numerator = (imxx * imy ** 2 + imyy * imx ** 2 - 2 * imxy * imx * imy)
|
||||
denominator = (imx ** 2 + imy ** 2)
|
||||
|
||||
response = np.zeros_like(image, dtype=np.double)
|
||||
|
||||
@@ -403,12 +403,12 @@ def corner_harris(image, method='k', k=0.05, eps=1e-6, sigma=1):
|
||||
Axx, Axy, Ayy = structure_tensor(image, sigma)
|
||||
|
||||
# determinant
|
||||
detA = Axx * Ayy - Axy**2
|
||||
detA = Axx * Ayy - Axy ** 2
|
||||
# trace
|
||||
traceA = Axx + Ayy
|
||||
|
||||
if method == 'k':
|
||||
response = detA - k * traceA**2
|
||||
response = detA - k * traceA ** 2
|
||||
else:
|
||||
response = 2 * detA / (traceA + eps)
|
||||
|
||||
@@ -473,7 +473,7 @@ def corner_shi_tomasi(image, sigma=1):
|
||||
Axx, Axy, Ayy = structure_tensor(image, sigma)
|
||||
|
||||
# minimum eigenvalue of A
|
||||
response = ((Axx + Ayy) - np.sqrt((Axx - Ayy)**2 + 4 * Axy**2)) / 2
|
||||
response = ((Axx + Ayy) - np.sqrt((Axx - Ayy) ** 2 + 4 * Axy ** 2)) / 2
|
||||
|
||||
return response
|
||||
|
||||
@@ -543,7 +543,7 @@ def corner_foerstner(image, sigma=1):
|
||||
Axx, Axy, Ayy = structure_tensor(image, sigma)
|
||||
|
||||
# determinant
|
||||
detA = Axx * Ayy - Axy**2
|
||||
detA = Axx * Ayy - Axy ** 2
|
||||
# trace
|
||||
traceA = Axx + Ayy
|
||||
|
||||
@@ -553,7 +553,7 @@ def corner_foerstner(image, sigma=1):
|
||||
mask = traceA != 0
|
||||
|
||||
w[mask] = detA[mask] / traceA[mask]
|
||||
q[mask] = 4 * detA[mask] / traceA[mask]**2
|
||||
q[mask] = 4 * detA[mask] / traceA[mask] ** 2
|
||||
|
||||
return w, q
|
||||
|
||||
@@ -692,7 +692,7 @@ def corner_subpix(image, corners, window_size=11, alpha=0.99):
|
||||
b_edge = np.zeros((2, ), dtype=np.double)
|
||||
|
||||
# critical statistical test values
|
||||
redundancy = window_size**2 - 2
|
||||
redundancy = window_size ** 2 - 2
|
||||
t_crit_dot = stats.f.isf(1 - alpha, redundancy, redundancy)
|
||||
t_crit_edge = stats.f.isf(alpha, redundancy, redundancy)
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ OFAST_MASK = np.zeros((31, 31))
|
||||
OFAST_UMAX = [15, 15, 15, 15, 14, 14, 14, 13, 13, 12, 11, 10, 9, 8, 6, 3]
|
||||
for i in range(-15, 16):
|
||||
for j in range(-OFAST_UMAX[abs(i)], OFAST_UMAX[abs(i)] + 1):
|
||||
OFAST_MASK[15 + j, 15 + i] = 1
|
||||
OFAST_MASK[15 + j, 15 + i] = 1
|
||||
|
||||
|
||||
class ORB(FeatureDetector, DescriptorExtractor):
|
||||
@@ -185,7 +185,7 @@ class ORB(FeatureDetector, DescriptorExtractor):
|
||||
|
||||
keypoints_list.append(keypoints * self.downscale ** octave)
|
||||
orientations_list.append(orientations)
|
||||
scales_list.append(self.downscale ** octave
|
||||
scales_list.append(self.downscale ** octave
|
||||
* np.ones(keypoints.shape[0], dtype=np.intp))
|
||||
responses_list.append(responses)
|
||||
|
||||
@@ -314,7 +314,7 @@ class ORB(FeatureDetector, DescriptorExtractor):
|
||||
keypoints_list.append(keypoints[mask] * self.downscale ** octave)
|
||||
responses_list.append(responses[mask])
|
||||
orientations_list.append(orientations[mask])
|
||||
scales_list.append(self.downscale ** octave
|
||||
scales_list.append(self.downscale ** octave
|
||||
* np.ones(keypoints.shape[0], dtype=np.intp))
|
||||
descriptors_list.append(descriptors)
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ def _window_sum_2d(image, window_shape):
|
||||
|
||||
window_sum = np.cumsum(image, axis=0)
|
||||
window_sum = (window_sum[window_shape[0]:-1]
|
||||
- window_sum[:-window_shape[0]-1])
|
||||
- window_sum[:-window_shape[0] - 1])
|
||||
|
||||
window_sum = np.cumsum(window_sum, axis=1)
|
||||
window_sum = (window_sum[:, window_shape[1]:-1]
|
||||
- window_sum[:, :-window_shape[1]-1])
|
||||
- window_sum[:, :-window_shape[1] - 1])
|
||||
|
||||
return window_sum
|
||||
|
||||
@@ -24,7 +24,7 @@ def _window_sum_3d(image, window_shape):
|
||||
|
||||
window_sum = np.cumsum(window_sum, axis=2)
|
||||
window_sum = (window_sum[:, :, window_shape[2]:-1]
|
||||
- window_sum[:, :, :-window_shape[2]-1])
|
||||
- window_sum[:, :, :-window_shape[2] - 1])
|
||||
|
||||
return window_sum
|
||||
|
||||
@@ -126,13 +126,13 @@ def match_template(image, template, pad_input=False, mode='constant',
|
||||
# computation of integral images
|
||||
if image.ndim == 2:
|
||||
image_window_sum = _window_sum_2d(image, template.shape)
|
||||
image_window_sum2 = _window_sum_2d(image**2, template.shape)
|
||||
image_window_sum2 = _window_sum_2d(image ** 2, template.shape)
|
||||
elif image.ndim == 3:
|
||||
image_window_sum = _window_sum_3d(image, template.shape)
|
||||
image_window_sum2 = _window_sum_3d(image**2, template.shape)
|
||||
image_window_sum2 = _window_sum_3d(image ** 2, template.shape)
|
||||
|
||||
template_volume = np.prod(template.shape)
|
||||
template_ssd = np.sum((template - template.mean())**2)
|
||||
template_ssd = np.sum((template - template.mean()) ** 2)
|
||||
|
||||
if image.ndim == 2:
|
||||
xcorr = fftconvolve(image, template[::-1, ::-1],
|
||||
|
||||
@@ -9,7 +9,8 @@ __all__ = ['gabor_kernel', 'gabor_filter']
|
||||
def _sigma_prefactor(bandwidth):
|
||||
b = bandwidth
|
||||
# See http://www.cs.rug.nl/~imaging/simplecell.html
|
||||
return 1.0 / np.pi * np.sqrt(np.log(2)/2.0) * (2.0**b + 1) / (2.0**b - 1)
|
||||
return 1.0 / np.pi * np.sqrt(np.log(2) / 2.0) * \
|
||||
(2.0 ** b + 1) / (2.0 ** b - 1)
|
||||
|
||||
|
||||
def gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None,
|
||||
@@ -80,13 +81,13 @@ def gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None,
|
||||
np.abs(n_stds * sigma_y * np.sin(theta)), 1))
|
||||
y0 = np.ceil(max(np.abs(n_stds * sigma_y * np.cos(theta)),
|
||||
np.abs(n_stds * sigma_x * np.sin(theta)), 1))
|
||||
y, x = np.mgrid[-y0:y0+1, -x0:x0+1]
|
||||
y, x = np.mgrid[-y0:y0 + 1, -x0:x0 + 1]
|
||||
|
||||
rotx = x * np.cos(theta) + y * np.sin(theta)
|
||||
roty = -x * np.sin(theta) + y * np.cos(theta)
|
||||
|
||||
g = np.zeros(y.shape, dtype=np.complex)
|
||||
g[:] = np.exp(-0.5 * (rotx**2 / sigma_x**2 + roty**2 / sigma_y**2))
|
||||
g[:] = np.exp(-0.5 * (rotx ** 2 / sigma_x ** 2 + roty ** 2 / sigma_y ** 2))
|
||||
g /= 2 * np.pi * sigma_x * sigma_y
|
||||
g *= np.exp(1j * (2 * np.pi * frequency * rotx + offset))
|
||||
|
||||
|
||||
@@ -11,12 +11,10 @@ __all__ = ['gaussian_filter']
|
||||
|
||||
def gaussian_filter(image, sigma, output=None, mode='nearest', cval=0,
|
||||
multichannel=None):
|
||||
"""
|
||||
Multi-dimensional Gaussian filter
|
||||
"""Multi-dimensional Gaussian filter
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
image : array-like
|
||||
input image (grayscale or color) to filter.
|
||||
sigma : scalar or sequence of scalars
|
||||
@@ -43,13 +41,11 @@ def gaussian_filter(image, sigma, output=None, mode='nearest', cval=0,
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
||||
filtered_image : ndarray
|
||||
the filtered array
|
||||
|
||||
Notes
|
||||
-----
|
||||
|
||||
This function is a wrapper around :func:`scipy.ndimage.gaussian_filter`.
|
||||
|
||||
Integer arrays are converted to float.
|
||||
@@ -87,12 +83,14 @@ def gaussian_filter(image, sigma, output=None, mode='nearest', cval=0,
|
||||
>>> from skimage.data import astronaut
|
||||
>>> image = astronaut()
|
||||
>>> filtered_img = gaussian_filter(image, sigma=1, multichannel=True)
|
||||
|
||||
"""
|
||||
|
||||
spatial_dims = guess_spatial_dimensions(image)
|
||||
if spatial_dims is None and multichannel is None:
|
||||
msg = ("Images with dimensions (M, N, 3) are interpreted as 2D+RGB" +
|
||||
" by default. Use `multichannel=False` to interpret as " +
|
||||
" 3D image with last dimension of length 3.")
|
||||
msg = ("Images with dimensions (M, N, 3) are interpreted as 2D+RGB "
|
||||
"by default. Use `multichannel=False` to interpret as "
|
||||
"3D image with last dimension of length 3.")
|
||||
warnings.warn(RuntimeWarning(msg))
|
||||
multichannel = True
|
||||
if multichannel:
|
||||
|
||||
@@ -28,7 +28,7 @@ def rank_order(image):
|
||||
n - 1, where n is the number of distinct unique values in
|
||||
`image`.
|
||||
|
||||
original_values: 1-d ndarray
|
||||
original_values: 1-D ndarray
|
||||
Unique original values of `image`
|
||||
|
||||
Examples
|
||||
|
||||
@@ -43,6 +43,7 @@ class LPIFilter2D(object):
|
||||
"""Linear Position-Invariant Filter (2-dimensional)
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, impulse_response, **filter_params):
|
||||
"""
|
||||
Parameters
|
||||
@@ -239,7 +240,7 @@ def wiener(data, impulse_response=None, filter_params={}, K=0.25,
|
||||
F, G = filt._prepare(data)
|
||||
_min_limit(F)
|
||||
|
||||
H_mag_sqr = np.abs(F)**2
|
||||
H_mag_sqr = np.abs(F) ** 2
|
||||
F = 1 / F * H_mag_sqr / (H_mag_sqr + K)
|
||||
|
||||
return _centre(np.abs(ifftshift(np.dual.ifftn(G * F))), data.shape)
|
||||
|
||||
@@ -73,8 +73,8 @@ def shortest_path(arr, reach=1, axis=-1, output_indexlist=False):
|
||||
|
||||
if not output_indexlist:
|
||||
traceback = np.array(traceback)
|
||||
traceback = np.concatenate([traceback[:, :axis], traceback[:, axis + 1:]],
|
||||
axis=1)
|
||||
traceback = np.concatenate([traceback[:, :axis],
|
||||
traceback[:, axis + 1:]], axis=1)
|
||||
traceback = np.squeeze(traceback)
|
||||
|
||||
return traceback, cost
|
||||
|
||||
@@ -36,7 +36,6 @@ def _update_doc(doc):
|
||||
"""
|
||||
from textwrap import wrap
|
||||
|
||||
|
||||
info_table = [(p, plugin_info(p).get('description', 'no description'))
|
||||
for p in available_plugins if not p == 'test']
|
||||
|
||||
|
||||
@@ -206,7 +206,8 @@ class ImageCollection(object):
|
||||
im.getdata()[0]
|
||||
except IOError:
|
||||
site = "http://pillow.readthedocs.org/en/latest/installation.html#external-libraries"
|
||||
raise ValueError('Could not load "%s"\nPlease see documentation at: %s' % (fname, site))
|
||||
raise ValueError(
|
||||
'Could not load "%s"\nPlease see documentation at: %s' % (fname, site))
|
||||
else:
|
||||
i = 0
|
||||
while True:
|
||||
|
||||
@@ -119,7 +119,7 @@ def _scan_plugins():
|
||||
|
||||
for p in provides:
|
||||
if not p in plugin_store:
|
||||
print("Plugin `%s` wants to provide non-existent `%s`." \
|
||||
print("Plugin `%s` wants to provide non-existent `%s`."
|
||||
" Ignoring." % (name, p))
|
||||
|
||||
# Add plugins that provide 'imread' as provider of 'imread_collection'.
|
||||
@@ -201,7 +201,7 @@ def call_plugin(kind, *args, **kwargs):
|
||||
try:
|
||||
func = [f for (p, f) in plugin_funcs if p == plugin][0]
|
||||
except IndexError:
|
||||
raise RuntimeError('Could not find the plugin "%s" for %s.' % \
|
||||
raise RuntimeError('Could not find the plugin "%s" for %s.' %
|
||||
(plugin, kind))
|
||||
|
||||
return func(*args, **kwargs)
|
||||
@@ -240,7 +240,7 @@ def use_plugin(name, kind=None):
|
||||
kind = plugin_store.keys()
|
||||
else:
|
||||
if not kind in plugin_provides[name]:
|
||||
raise RuntimeError("Plugin %s does not support `%s`." % \
|
||||
raise RuntimeError("Plugin %s does not support `%s`." %
|
||||
(name, kind))
|
||||
|
||||
if kind == 'imshow':
|
||||
@@ -299,7 +299,7 @@ def _load(plugin):
|
||||
if p == 'imread_collection':
|
||||
_inject_imread_collection_if_needed(plugin_module)
|
||||
elif not hasattr(plugin_module, p):
|
||||
print("Plugin %s does not provide %s as advertised. Ignoring." % \
|
||||
print("Plugin %s does not provide %s as advertised. Ignoring." %
|
||||
(plugin, p))
|
||||
continue
|
||||
|
||||
|
||||
+4
-4
@@ -42,15 +42,15 @@ def _sift_read(f, mode='SIFT'):
|
||||
if mode == 'SIFT':
|
||||
nr_features, feature_len = map(int, f.readline().split())
|
||||
datatype = np.dtype([('row', float), ('column', float),
|
||||
('scale', float), ('orientation', float),
|
||||
('data', (float, feature_len))])
|
||||
('scale', float), ('orientation', float),
|
||||
('data', (float, feature_len))])
|
||||
else:
|
||||
mode = 'SURF'
|
||||
feature_len = int(f.readline()) - 1
|
||||
nr_features = int(f.readline())
|
||||
datatype = np.dtype([('column', float), ('row', float),
|
||||
('second_moment', (float, 3)),
|
||||
('sign', float), ('data', (float, feature_len))])
|
||||
('second_moment', (float, 3)),
|
||||
('sign', float), ('data', (float, feature_len))])
|
||||
data = np.fromfile(f, sep=' ')
|
||||
if data.size != nr_features * datatype.itemsize / np.dtype(float).itemsize:
|
||||
raise IOError("Invalid %s feature file." % mode)
|
||||
|
||||
@@ -7,6 +7,7 @@ import numpy as np
|
||||
from ..util.dtype import dtype_range
|
||||
from ..util.shape import view_as_windows
|
||||
|
||||
|
||||
def structural_similarity(X, Y, win_size=7,
|
||||
gradient=False, dynamic_range=None):
|
||||
"""Compute the mean structural similarity index between two images.
|
||||
@@ -64,34 +65,32 @@ def structural_similarity(X, Y, win_size=7,
|
||||
uy = np.mean(np.mean(YW, axis=2), axis=2)
|
||||
|
||||
# Compute variances var(X), var(Y) and var(X, Y)
|
||||
cov_norm = 1 / (win_size**2 - 1)
|
||||
cov_norm = 1 / (win_size ** 2 - 1)
|
||||
XWM = XW - ux[..., None, None]
|
||||
YWM = YW - uy[..., None, None]
|
||||
vx = cov_norm * np.sum(np.sum(XWM**2, axis=2), axis=2)
|
||||
vy = cov_norm * np.sum(np.sum(YWM**2, axis=2), axis=2)
|
||||
vx = cov_norm * np.sum(np.sum(XWM ** 2, axis=2), axis=2)
|
||||
vy = cov_norm * np.sum(np.sum(YWM ** 2, axis=2), axis=2)
|
||||
vxy = cov_norm * np.sum(np.sum(XWM * YWM, axis=2), axis=2)
|
||||
|
||||
R = dynamic_range
|
||||
K1 = 0.01
|
||||
K2 = 0.03
|
||||
C1 = (K1 * R)**2
|
||||
C2 = (K2 * R)**2
|
||||
C1 = (K1 * R) ** 2
|
||||
C2 = (K2 * R) ** 2
|
||||
|
||||
A1, A2, B1, B2 = (v[..., None, None] for v in
|
||||
(2 * ux * uy + C1,
|
||||
2 * vxy + C2,
|
||||
ux**2 + uy**2 + C1,
|
||||
ux ** 2 + uy ** 2 + C1,
|
||||
vx + vy + C2))
|
||||
|
||||
S = np.mean((A1 * A2) / (B1 * B2))
|
||||
|
||||
if gradient:
|
||||
local_grad = 2 / (NP * B1**2 * B2**2) * \
|
||||
(
|
||||
A1 * B1 * (B2 * XW - A2 * YW) - \
|
||||
B1 * B2 * (A2 - A1) * ux[..., None, None] + \
|
||||
A1 * A2 * (B1 - B2) * uy[..., None, None]
|
||||
)
|
||||
local_grad = 2 / (NP * B1 ** 2 * B2 ** 2) * \
|
||||
(A1 * B1 * (B2 * XW - A2 * YW) -
|
||||
B1 * B2 * (A2 - A1) * ux[..., None, None] +
|
||||
A1 * A2 * (B1 - B2) * uy[..., None, None])
|
||||
|
||||
grad = np.zeros_like(X, dtype=float)
|
||||
OW = view_as_windows(grad, (win_size, win_size))
|
||||
|
||||
@@ -9,7 +9,7 @@ def profile_line(img, src, dst, linewidth=1,
|
||||
Parameters
|
||||
----------
|
||||
img : numeric array, shape (M, N[, C])
|
||||
The image, either grayscale (2D array) or multichannel
|
||||
The image, either grayscale (2D array) or multichannel
|
||||
(3D array, where the final axis contains the channel
|
||||
information).
|
||||
src : 2-tuple of numeric scalar (float or int)
|
||||
@@ -109,4 +109,3 @@ def _line_profile_coordinates(src, dst, linewidth=1):
|
||||
perp_cols = np.array([np.linspace(col_i - col_width, col_i + col_width,
|
||||
linewidth) for col_i in line_col])
|
||||
return np.array([perp_rows, perp_cols])
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ def default_fallback(func):
|
||||
Returns
|
||||
-------
|
||||
func_out : function
|
||||
If the image dimentionality is greater than 2D, the ndimage
|
||||
If the image dimensionality is greater than 2D, the ndimage
|
||||
function is returned, otherwise skimage function is used.
|
||||
"""
|
||||
@functools.wraps(func)
|
||||
|
||||
@@ -171,9 +171,9 @@ def octahedron(radius, dtype=np.uint8):
|
||||
"""
|
||||
# note that in contrast to diamond(), this method allows non-integer radii
|
||||
n = 2 * radius + 1
|
||||
Z, Y, X = np.mgrid[-radius:radius:n*1j,
|
||||
-radius:radius:n*1j,
|
||||
-radius:radius:n*1j]
|
||||
Z, Y, X = np.mgrid[-radius:radius:n * 1j,
|
||||
-radius:radius:n * 1j,
|
||||
-radius:radius:n * 1j]
|
||||
s = np.abs(X) + np.abs(Y) + np.abs(Z)
|
||||
return np.array(s <= radius, dtype=dtype)
|
||||
|
||||
@@ -202,10 +202,10 @@ def ball(radius, dtype=np.uint8):
|
||||
are 1 and 0 otherwise.
|
||||
"""
|
||||
n = 2 * radius + 1
|
||||
Z, Y, X = np.mgrid[-radius:radius:n*1j,
|
||||
-radius:radius:n*1j,
|
||||
-radius:radius:n*1j]
|
||||
s = X**2 + Y**2 + Z**2
|
||||
Z, Y, X = np.mgrid[-radius:radius:n * 1j,
|
||||
-radius:radius:n * 1j,
|
||||
-radius:radius:n * 1j]
|
||||
s = X ** 2 + Y ** 2 + Z ** 2
|
||||
return np.array(s <= radius * radius, dtype=dtype)
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ def octagon(m, n, dtype=np.uint8):
|
||||
|
||||
"""
|
||||
from . import convex_hull_image
|
||||
selem = np.zeros((m + 2*n, m + 2*n))
|
||||
selem = np.zeros((m + 2 * n, m + 2 * n))
|
||||
selem[0, n] = 1
|
||||
selem[n, 0] = 1
|
||||
selem[0, m + n - 1] = 1
|
||||
@@ -274,20 +274,26 @@ def star(a, dtype=np.uint8):
|
||||
|
||||
"""
|
||||
from . import convex_hull_image
|
||||
|
||||
if a == 1:
|
||||
bfilter = np.zeros((3, 3), dtype)
|
||||
bfilter[:] = 1
|
||||
return bfilter
|
||||
|
||||
m = 2 * a + 1
|
||||
n = a // 2
|
||||
selem_square = np.zeros((m + 2 * n, m + 2 * n))
|
||||
selem_square[n: m + n, n: m + n] = 1
|
||||
|
||||
c = (m + 2 * n - 1) // 2
|
||||
selem_rotated = np.zeros((m + 2 * n, m + 2 * n))
|
||||
selem_rotated[0, c] = selem_rotated[-1, c] = selem_rotated[c, 0] = selem_rotated[c, -1] = 1
|
||||
selem_rotated[0, c] = selem_rotated[-1, c] = 1
|
||||
selem_rotated[c, 0] = selem_rotated[c, -1] = 1
|
||||
selem_rotated = convex_hull_image(selem_rotated).astype(int)
|
||||
|
||||
selem = selem_square + selem_rotated
|
||||
selem[selem > 0] = 1
|
||||
|
||||
return selem.astype(dtype)
|
||||
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ def watershed(image, markers, connectivity=None, offset=None, mask=None):
|
||||
if offset is None:
|
||||
if any([x % 2 == 0 for x in c_connectivity.shape]):
|
||||
raise ValueError("Connectivity array must have an unambiguous "
|
||||
"center")
|
||||
"center")
|
||||
#
|
||||
# offset to center of connectivity array
|
||||
#
|
||||
@@ -147,7 +147,8 @@ def watershed(image, markers, connectivity=None, offset=None, mask=None):
|
||||
pads = offset
|
||||
|
||||
def pad(im):
|
||||
new_im = np.zeros([i + 2 * p for i, p in zip(im.shape, pads)], im.dtype)
|
||||
new_im = np.zeros(
|
||||
[i + 2 * p for i, p in zip(im.shape, pads)], im.dtype)
|
||||
new_im[[slice(p, -p, None) for p in pads]] = im
|
||||
return new_im
|
||||
|
||||
@@ -220,7 +221,7 @@ def watershed(image, markers, connectivity=None, offset=None, mask=None):
|
||||
c_mask,
|
||||
c_output)
|
||||
c_output = c_output.reshape(c_image.shape)[[slice(1, -1, None)] *
|
||||
image.ndim]
|
||||
image.ndim]
|
||||
try:
|
||||
return c_output.astype(markers.dtype)
|
||||
except:
|
||||
|
||||
@@ -80,6 +80,7 @@ class Pixel(object):
|
||||
Transparency component (0-255), 255 (opaque) by default
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, pic, array, x, y, rgb, alpha=255):
|
||||
self._picture = pic
|
||||
self._x = x
|
||||
@@ -239,6 +240,7 @@ class Picture(object):
|
||||
>>> pic[:, pic.height-1] = (255, 0, 0)
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, path=None, array=None, xy_array=None):
|
||||
self._modified = False
|
||||
self.scale = 1
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# coding: utf-8
|
||||
import numpy as np
|
||||
from skimage import img_as_float
|
||||
from skimage.restoration._denoise_cy import _denoise_bilateral, \
|
||||
_denoise_tv_bregman
|
||||
from skimage.restoration._denoise_cy import (_denoise_bilateral,
|
||||
_denoise_tv_bregman)
|
||||
|
||||
|
||||
def denoise_bilateral(image, win_size=5, sigma_range=None, sigma_spatial=1,
|
||||
@@ -151,12 +151,12 @@ def _denoise_tv_chambolle_3d(im, weight=100, eps=2.e-4, n_iter_max=200):
|
||||
d[:, :, 1:] += pz[:, :, :-1]
|
||||
|
||||
out = im + d
|
||||
E = (d**2).sum()
|
||||
E = (d ** 2).sum()
|
||||
|
||||
gx[:-1] = np.diff(out, axis=0)
|
||||
gy[:, :-1] = np.diff(out, axis=1)
|
||||
gz[:, :, :-1] = np.diff(out, axis=2)
|
||||
norm = np.sqrt(gx**2 + gy**2 + gz**2)
|
||||
norm = np.sqrt(gx ** 2 + gy ** 2 + gz ** 2)
|
||||
E += weight * norm.sum()
|
||||
norm *= 0.5 / weight
|
||||
norm += 1.
|
||||
@@ -231,10 +231,10 @@ def _denoise_tv_chambolle_2d(im, weight=50, eps=2.e-4, n_iter_max=200):
|
||||
d[:, 1:] += py[:, :-1]
|
||||
|
||||
out = im + d
|
||||
E = (d**2).sum()
|
||||
E = (d ** 2).sum()
|
||||
gx[:-1] = np.diff(out, axis=0)
|
||||
gy[:, :-1] = np.diff(out, axis=1)
|
||||
norm = np.sqrt(gx**2 + gy**2)
|
||||
norm = np.sqrt(gx ** 2 + gy ** 2)
|
||||
E += weight * norm.sum()
|
||||
norm *= 0.5 / weight
|
||||
norm += 1
|
||||
|
||||
@@ -126,8 +126,8 @@ def wiener(image, psf, balance, reg=None, is_real=True, clip=True):
|
||||
else:
|
||||
trans_func = psf
|
||||
|
||||
wiener_filter = np.conj(trans_func) / (np.abs(trans_func)**2 +
|
||||
balance * np.abs(reg)**2)
|
||||
wiener_filter = np.conj(trans_func) / (np.abs(trans_func) ** 2 +
|
||||
balance * np.abs(reg) ** 2)
|
||||
if is_real:
|
||||
deconv = uft.uirfft2(wiener_filter * uft.urfft2(image),
|
||||
shape=image.shape)
|
||||
@@ -261,8 +261,8 @@ def unsupervised_wiener(image, psf, reg=None, user_params=None, is_real=True,
|
||||
|
||||
# The correlation of the object in Fourier space (if size is big,
|
||||
# this can reduce computation time in the loop)
|
||||
areg2 = np.abs(reg)**2
|
||||
atf2 = np.abs(trans_fct)**2
|
||||
areg2 = np.abs(reg) ** 2
|
||||
atf2 = np.abs(trans_fct) ** 2
|
||||
|
||||
# The Fourier transfrom may change the image.size attribut, so we
|
||||
# store it.
|
||||
|
||||
@@ -333,10 +333,10 @@ def image_quad_norm(inarray):
|
||||
"""
|
||||
# If there is a Hermitian symmetry
|
||||
if inarray.shape[-1] != inarray.shape[-2]:
|
||||
return (2 * np.sum(np.sum(np.abs(inarray)**2, axis=-1), axis=-1) -
|
||||
np.sum(np.abs(inarray[..., 0])**2, axis=-1))
|
||||
return (2 * np.sum(np.sum(np.abs(inarray) ** 2, axis=-1), axis=-1) -
|
||||
np.sum(np.abs(inarray[..., 0]) ** 2, axis=-1))
|
||||
else:
|
||||
return np.sum(np.sum(np.abs(inarray)**2, axis=-1), axis=-1)
|
||||
return np.sum(np.sum(np.abs(inarray) ** 2, axis=-1), axis=-1)
|
||||
|
||||
|
||||
def ir2tf(imp_resp, shape, dim=None, is_real=True):
|
||||
|
||||
@@ -45,7 +45,8 @@ def felzenszwalb(image, scale=1, sigma=0.8, min_size=20):
|
||||
|
||||
if image.ndim == 2:
|
||||
# assume single channel image
|
||||
return _felzenszwalb_grey(image, scale=scale, sigma=sigma, min_size=min_size)
|
||||
return _felzenszwalb_grey(image, scale=scale, sigma=sigma,
|
||||
min_size=min_size)
|
||||
|
||||
elif image.ndim != 3:
|
||||
raise ValueError("Felzenswalb segmentation can only operate on RGB and"
|
||||
|
||||
@@ -13,7 +13,8 @@ def find_boundaries(label_img):
|
||||
return boundaries
|
||||
|
||||
|
||||
def mark_boundaries(image, label_img, color=(1, 1, 0), outline_color=(0, 0, 0)):
|
||||
def mark_boundaries(image, label_img, color=(1, 1, 0),
|
||||
outline_color=(0, 0, 0)):
|
||||
"""Return image with boundaries between labeled regions highlighted.
|
||||
|
||||
Parameters
|
||||
|
||||
@@ -454,8 +454,8 @@ def random_walker(data, labels, beta=130, mode='bf', tol=1.e-3, copy=True,
|
||||
# Clean up results
|
||||
if return_full_prob:
|
||||
labels = labels.astype(np.float)
|
||||
X = np.array([_clean_labels_ar(Xline, labels,
|
||||
copy=True).reshape(dims) for Xline in X])
|
||||
X = np.array([_clean_labels_ar(Xline, labels, copy=True).reshape(dims)
|
||||
for Xline in X])
|
||||
for i in range(1, int(labels.max()) + 1):
|
||||
mask_i = np.squeeze(labels == i)
|
||||
X[:, mask_i] = 0
|
||||
|
||||
@@ -6,7 +6,8 @@ from scipy import ndimage
|
||||
import warnings
|
||||
|
||||
from skimage.util import img_as_float, regular_grid
|
||||
from skimage.segmentation._slic import _slic_cython, _enforce_label_connectivity_cython
|
||||
from skimage.segmentation._slic import (_slic_cython,
|
||||
_enforce_label_connectivity_cython)
|
||||
from skimage.color import rgb2lab
|
||||
|
||||
|
||||
|
||||
@@ -284,8 +284,8 @@ def _swirl_mapping(xy, center, rotation, strength, radius):
|
||||
radius = radius / 5 * np.log(2)
|
||||
|
||||
theta = rotation + strength * \
|
||||
np.exp(-rho / radius) + \
|
||||
np.arctan2(y - y0, x - x0)
|
||||
np.exp(-rho / radius) + \
|
||||
np.arctan2(y - y0, x - x0)
|
||||
|
||||
xy[..., 0] = x0 + rho * np.cos(theta)
|
||||
xy[..., 1] = y0 + rho * np.sin(theta)
|
||||
|
||||
@@ -10,7 +10,8 @@ def _smooth(image, sigma, mode, cval):
|
||||
|
||||
smoothed = np.empty(image.shape, dtype=np.double)
|
||||
|
||||
if image.ndim == 3: # apply Gaussian filter to all dimensions independently
|
||||
# apply Gaussian filter to all dimensions independently
|
||||
if image.ndim == 3:
|
||||
for dim in range(image.shape[2]):
|
||||
ndimage.gaussian_filter(image[..., dim], sigma,
|
||||
output=smoothed[..., dim],
|
||||
|
||||
@@ -63,8 +63,9 @@ def radon(image, theta=None, circle=False):
|
||||
if circle:
|
||||
radius = min(image.shape) // 2
|
||||
c0, c1 = np.ogrid[0:image.shape[0], 0:image.shape[1]]
|
||||
reconstruction_circle = ((c0 - image.shape[0] // 2)**2
|
||||
+ (c1 - image.shape[1] // 2)**2) <= radius**2
|
||||
reconstruction_circle = ((c0 - image.shape[0] // 2) ** 2
|
||||
+ (c1 - image.shape[1] // 2) ** 2)
|
||||
reconstruction_circle = reconstruction_circle <= radius ** 2
|
||||
if not np.all(reconstruction_circle | (image == 0)):
|
||||
raise ValueError('Image must be zero outside the reconstruction'
|
||||
' circle')
|
||||
@@ -189,7 +190,7 @@ def iradon(radon_image, theta=None, output_size=None,
|
||||
if circle:
|
||||
output_size = radon_image.shape[0]
|
||||
else:
|
||||
output_size = int(np.floor(np.sqrt((radon_image.shape[0])**2
|
||||
output_size = int(np.floor(np.sqrt((radon_image.shape[0]) ** 2
|
||||
/ 2.0)))
|
||||
if circle:
|
||||
radon_image = _sinogram_circle_to_square(radon_image)
|
||||
@@ -198,7 +199,7 @@ def iradon(radon_image, theta=None, output_size=None,
|
||||
# resize image to next power of two (but no less than 64) for
|
||||
# Fourier analysis; speeds up Fourier and lessens artifacts
|
||||
projection_size_padded = \
|
||||
max(64, int(2**np.ceil(np.log2(2 * radon_image.shape[0]))))
|
||||
max(64, int(2 ** np.ceil(np.log2(2 * radon_image.shape[0]))))
|
||||
pad_width = ((0, projection_size_padded - radon_image.shape[0]), (0, 0))
|
||||
img = util.pad(radon_image, pad_width, mode='constant', constant_values=0)
|
||||
|
||||
@@ -249,7 +250,7 @@ def iradon(radon_image, theta=None, output_size=None,
|
||||
reconstructed += backprojected
|
||||
if circle:
|
||||
radius = output_size // 2
|
||||
reconstruction_circle = (xpr**2 + ypr**2) <= radius**2
|
||||
reconstruction_circle = (xpr ** 2 + ypr ** 2) <= radius ** 2
|
||||
reconstructed[~reconstruction_circle] = 0.
|
||||
|
||||
return reconstructed * np.pi / (2 * len(th))
|
||||
|
||||
@@ -59,9 +59,9 @@ def regular_grid(ar_shape, n_points):
|
||||
if (sorted_dims < stepsizes).any():
|
||||
for dim in range(ndim):
|
||||
stepsizes[dim] = sorted_dims[dim]
|
||||
space_size = float(np.prod(sorted_dims[dim+1:]))
|
||||
stepsizes[dim+1:] = ((space_size / n_points) **
|
||||
(1.0 / (ndim - dim - 1)))
|
||||
space_size = float(np.prod(sorted_dims[dim + 1:]))
|
||||
stepsizes[dim + 1:] = ((space_size / n_points) **
|
||||
(1.0 / (ndim - dim - 1)))
|
||||
if (sorted_dims >= stepsizes).all():
|
||||
break
|
||||
starts = (stepsizes // 2).astype(int)
|
||||
|
||||
@@ -304,7 +304,7 @@ def img_as_uint(image, force_copy=False):
|
||||
|
||||
Notes
|
||||
-----
|
||||
Negative input values will be clipped.
|
||||
Negative input values will be clipped.
|
||||
Positive values are scaled between 0 and 65535.
|
||||
|
||||
"""
|
||||
@@ -353,7 +353,7 @@ def img_as_ubyte(image, force_copy=False):
|
||||
|
||||
Notes
|
||||
-----
|
||||
Negative input values will be clipped.
|
||||
Negative input values will be clipped.
|
||||
Positive values are scaled between 0 and 255.
|
||||
|
||||
"""
|
||||
|
||||
@@ -98,7 +98,7 @@ def montage2d(arr_in, fill='mean', rescale_intensity=False, grid_shape=None):
|
||||
if fill == 'mean':
|
||||
fill = arr_in.mean()
|
||||
|
||||
n_missing = int((alpha_y * alpha_x) - n_images)
|
||||
n_missing = int((alpha_y * alpha_x) - n_images)
|
||||
missing = np.ones((n_missing, height, width), dtype=arr_in.dtype) * fill
|
||||
arr_out = np.vstack((arr_in, missing))
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ def view_as_windows(arr_in, window_shape, step=1):
|
||||
arr_in = np.ascontiguousarray(arr_in)
|
||||
|
||||
new_shape = tuple((arr_shape - window_shape) // step + 1) + \
|
||||
tuple(window_shape)
|
||||
tuple(window_shape)
|
||||
|
||||
arr_strides = np.array(arr_in.strides)
|
||||
new_strides = np.concatenate((arr_strides * step, arr_strides))
|
||||
|
||||
Reference in New Issue
Block a user