Skip to content
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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions package/PartSegCore/analysis/measurement_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

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:

This removes the following comments ( why? ):

# pragma: no cover

"""
:param area_array: mask for area
:param channel: data. same shape like area_type
Expand All @@ -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):
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MaximumPixelBrightness.calculate_property refactored with the following changes:


@classmethod
def get_units(cls, ndim):
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MinimumPixelBrightness.calculate_property refactored with the following changes:


@classmethod
def get_units(cls, ndim):
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MeanPixelBrightness.calculate_property refactored with the following changes:


@classmethod
def get_units(cls, ndim):
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MedianPixelBrightness.calculate_property refactored with the following changes:


@classmethod
def get_units(cls, ndim):
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function StandardDeviationOfPixelBrightness.calculate_property refactored with the following changes:


@classmethod
def get_units(cls, ndim):
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RimPixelBrightnessSum.calculate_property refactored with the following changes:


@classmethod
def get_units(cls, ndim):
Expand Down