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

Fix incorrect segmenter object size thresholding calculations #50

Merged
merged 6 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ All dates in this file are given in the [UTC time zone](https://en.wikipedia.org
- (Hardware controller) The bitrate of the camera preview stream has been reduced slightly from ~8 Mbps to ~7 Mbps.
- (Hardware controller) The framerate of the camera preview stream is now explicitly limited to 25 fps.

### Fixed

- (Breaking change; segmenter) The previously incorrect method for filtering segmented objects by size has now been corrected to filter object sizes by filled area rather than bounding box area, and directly using the mesh size as the threshold for equivalent spherical diameter (ESD) instead of calculating a fictional ESD.

## v2024.0.0-beta.2 - 2024-08-19

### Changed
Expand Down
13 changes: 6 additions & 7 deletions processing/segmenter/planktoscope/segmenter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,16 @@ def __augment_slice(dim_slice, max_dims, size=10):
dim_slice = tuple(dim_slice)
return dim_slice

minMesh = self.__global_metadata.get("acq_minimum_mesh", 20) # microns
minESD = minMesh * 2
minArea = math.pi * (minESD / 2) * (minESD / 2)
pixel_size = self.__global_metadata.get("process_pixel", 1.0)
# minsizepix = minArea / pixel_size / pixel_size
minsizepix = (minESD / pixel_size) ** 2
min_mesh = self.__global_metadata.get("acq_minimum_mesh", 20) # microns
min_esd = min_mesh # or process_min_ESD in the future (microns)
pixel_size = self.__global_metadata["process_pixel"]
min_radius = min_esd / 2 / pixel_size # (pixels)
min_area = math.pi * min_radius * min_radius

labels, nlabels = skimage.measure.label(mask, return_num=True)
regionprops = skimage.measure.regionprops(labels)
regionprops_filtered = [
region for region in regionprops if region.bbox_area >= minsizepix
region for region in regionprops if region.filled_area >= min_area
]
object_number = len(regionprops_filtered)
logger.debug(f"Found {nlabels} labels, or {object_number} after size filtering")
Expand Down