Skip to content
Snippets Groups Projects
Commit a4371edc authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Merged in smoothing operation that supports binary masks

parent 653252ba
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,7 @@ def is_mask(img): ...@@ -18,7 +18,7 @@ def is_mask(img):
return True return True
elif img.dtype == 'uint8': elif img.dtype == 'uint8':
unique = np.unique(img) unique = np.unique(img)
if unique.shape[0] == 2 and np.all(unique == [0, 255]): if unique.shape[0] <= 2 and np.all(unique == [0, 255]):
return True return True
return False return False
...@@ -136,7 +136,14 @@ def smooth(img: np.ndarray, sig: float) -> np.ndarray: ...@@ -136,7 +136,14 @@ def smooth(img: np.ndarray, sig: float) -> np.ndarray:
:param sig: threshold parameter :param sig: threshold parameter
:return: smoothed image :return: smoothed image
""" """
return gaussian(img, sig) ga = gaussian(img, sig, preserve_range=True)
if is_mask(img):
if img.dtype == 'bool':
return ga > ga.mean()
elif img.dtype == 'uint8':
return (255 * (ga > ga.mean())).astype('uint8')
else:
return ga
class Error(Exception): class Error(Exception):
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment