Skip to content

Commit

Permalink
Fixed a deprecation warning regarding np.clip
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Dec 2, 2020
1 parent 9761c46 commit c6b01ba
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions skued/image/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ def nfold(im, mod, center=None, mask=None, fill_value=0.0):
# Data-type must be float because of use of NaN
im = np.array(im, dtype=np.float, copy=True)

if mask is not None:
im[np.logical_not(mask)] = np.nan
if mask is None:
mask = np.ones_like(im, dtype=np.uint8)

kwargs = {"center": center, "mode": "constant", "cval": 0, "preserve_range": True}

# Use weights because edges of the pictures, which might be cropped by the rotation
# should not count in the average
wt = np.ones_like(im, dtype=np.uint8)
wt = np.ones_like(mask, dtype=np.float)
wt[np.logical_not(mask)] = np.nan

weights = (rotate(wt, angle, **kwargs) for angle in angles)
rotated = (rotate(im, angle, **kwargs) for angle in angles)

Expand Down Expand Up @@ -98,19 +100,26 @@ def reflection(im, angle, center=None, mask=None, fill_value=0.0):
im = np.array(im, dtype=np.float, copy=True)
reflected = np.array(im, copy=True) # reflected image

if mask is not None:
invalid_pixels = np.logical_not(mask)
im[invalid_pixels] = np.nan
reflected[invalid_pixels] = np.nan
if mask is None:
mask = np.ones_like(im, dtype=np.bool)
invalid_pixels = np.logical_not(mask)

kwargs = {"center": center, "mode": "constant", "cval": 0, "preserve_range": True}

# Rotate the 'reflected' image so that the reflection line is the x-axis
# Flip the image along the y-axis
# Rotate back to original orientation
# FIXME: this will not work properly for images that are offcenter
reflected = rotate(reflected, -angle, **kwargs)
reflected = mirror(reflected, axes=0)
reflected = rotate(reflected, angle, **kwargs)

return nan_to_num(average([im, reflected]), fill_value, copy=False)
def refl(arr):
arr = rotate(arr, -angle, **kwargs)
arr = mirror(arr, axes=0)
arr = rotate(arr, angle, **kwargs)
return arr

reflected = refl(reflected)
invalid_pixels_r = refl(invalid_pixels).astype(np.bool)

result = average([im, reflected])
result[invalid_pixels_r] = fill_value

return result

0 comments on commit c6b01ba

Please sign in to comment.