-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add multiple otsu as threshold method with selection range of components (Sourcery refactored) #713
feat: Add multiple otsu as threshold method with selection range of components (Sourcery refactored) #713
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -870,7 +870,7 @@ class PixelBrightnessSum(MeasurementMethodBase): | |
text_info = "Pixel brightness sum", "Sum of pixel brightness for current segmentation" | ||
|
||
@staticmethod | ||
def calculate_property(area_array: np.ndarray, channel: np.ndarray, **_): # pylint: disable=W0221 | ||
def calculate_property(area_array: np.ndarray, channel: np.ndarray, **_): # pylint: disable=W0221 | ||
""" | ||
:param area_array: mask for area | ||
:param channel: data. same shape like area_type | ||
|
@@ -879,11 +879,9 @@ def calculate_property(area_array: np.ndarray, channel: np.ndarray, **_): # pyl | |
if area_array.shape != channel.shape: | ||
if area_array.size == channel.size: | ||
channel = channel.reshape(area_array.shape) | ||
else: # pragma: no cover | ||
else: | ||
Czaki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise ValueError(f"channel ({channel.shape}) and mask ({area_array.shape}) do not fit each other") | ||
if np.any(area_array): | ||
return np.sum(channel[area_array > 0]) | ||
return 0 | ||
return np.sum(channel[area_array > 0]) if np.any(area_array) else 0 | ||
|
||
@classmethod | ||
def get_units(cls, ndim): | ||
|
@@ -913,9 +911,7 @@ class MaximumPixelBrightness(MeasurementMethodBase): | |
def calculate_property(area_array, channel, **_): # pylint: disable=W0221 | ||
if area_array.shape != channel.shape: # pragma: no cover | ||
raise ValueError(f"channel ({channel.shape}) and mask ({area_array.shape}) do not fit each other") | ||
if np.any(area_array): | ||
return np.max(channel[area_array > 0]) | ||
return 0 | ||
return np.max(channel[area_array > 0]) if np.any(area_array) else 0 | ||
Comment on lines
-916
to
+914
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@classmethod | ||
def get_units(cls, ndim): | ||
|
@@ -933,9 +929,7 @@ class MinimumPixelBrightness(MeasurementMethodBase): | |
def calculate_property(area_array, channel, **_): # pylint: disable=W0221 | ||
if area_array.shape != channel.shape: # pragma: no cover | ||
raise ValueError("channel and mask do not fit each other") | ||
if np.any(area_array): | ||
return np.min(channel[area_array > 0]) | ||
return 0 | ||
return np.min(channel[area_array > 0]) if np.any(area_array) else 0 | ||
Comment on lines
-936
to
+932
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@classmethod | ||
def get_units(cls, ndim): | ||
|
@@ -953,9 +947,7 @@ class MeanPixelBrightness(MeasurementMethodBase): | |
def calculate_property(area_array, channel, **_): # pylint: disable=W0221 | ||
if area_array.shape != channel.shape: # pragma: no cover | ||
raise ValueError("channel and mask do not fit each other") | ||
if np.any(area_array): | ||
return np.mean(channel[area_array > 0]) | ||
return 0 | ||
return np.mean(channel[area_array > 0]) if np.any(area_array) else 0 | ||
Comment on lines
-956
to
+950
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@classmethod | ||
def get_units(cls, ndim): | ||
|
@@ -973,9 +965,7 @@ class MedianPixelBrightness(MeasurementMethodBase): | |
def calculate_property(area_array, channel, **_): # pylint: disable=W0221 | ||
if area_array.shape != channel.shape: # pragma: no cover | ||
raise ValueError("channel and mask do not fit each other") | ||
if np.any(area_array): | ||
return np.median(channel[area_array > 0]) | ||
return 0 | ||
return np.median(channel[area_array > 0]) if np.any(area_array) else 0 | ||
Comment on lines
-976
to
+968
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@classmethod | ||
def get_units(cls, ndim): | ||
|
@@ -996,9 +986,7 @@ class StandardDeviationOfPixelBrightness(MeasurementMethodBase): | |
def calculate_property(area_array, channel, **_): # pylint: disable=W0221 | ||
if area_array.shape != channel.shape: # pragma: no cover | ||
raise ValueError("channel and mask do not fit each other") | ||
if np.any(area_array): | ||
return np.std(channel[area_array > 0]) | ||
return 0 | ||
return np.std(channel[area_array > 0]) if np.any(area_array) else 0 | ||
Comment on lines
-999
to
+989
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@classmethod | ||
def get_units(cls, ndim): | ||
|
@@ -1213,9 +1201,7 @@ def calculate_property(channel, area_array, **kwargs): # pylint: disable=W0221 | |
if border_mask_array is None: | ||
return None | ||
final_mask = np.array((border_mask_array > 0) * (area_array > 0)) | ||
if np.any(final_mask): | ||
return np.sum(channel[final_mask]) | ||
return 0 | ||
return np.sum(channel[final_mask]) if np.any(final_mask) else 0 | ||
Comment on lines
-1216
to
+1204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@classmethod | ||
def get_units(cls, ndim): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
PixelBrightnessSum.calculate_property
refactored with the following changes:swap-nested-ifs
)hoist-similar-statement-from-if
)reintroduce-else
)assign-if-exp
)This removes the following comments ( why? ):