@@ -113,12 +113,12 @@ def neighbors_in_radius(table: pd.DataFrame, radius: float = 15) -> np.ndarray:
113113#
114114
115115
116- # FIXME: this computes the distance in pixels, but the MoBIE table contains it in physical units (=nm)
117- # This is inconsistent.
118- def _compute_table (segmentation ):
116+ def _compute_table (segmentation , resolution ):
119117 props = measure .regionprops (segmentation )
120118 label_ids = np .array ([prop .label for prop in props ])
121119 coordinates = np .array ([prop .centroid for prop in props ])
120+ # transform pixel distance to physical units
121+ coordinates = coordinates * resolution
122122 sizes = np .array ([prop .area for prop in props ])
123123 table = pd .DataFrame ({
124124 "label_id" : label_ids ,
@@ -137,6 +137,7 @@ def filter_segmentation(
137137 threshold : float ,
138138 min_size : int = 1000 ,
139139 table : Optional [pd .DataFrame ] = None ,
140+ resolution : float = 0.38 ,
140141 output_key : str = "segmentation_postprocessed" ,
141142 ** spatial_statistics_kwargs ,
142143) -> Tuple [int , int ]:
@@ -152,6 +153,7 @@ def filter_segmentation(
152153 threshold: Distance in micrometer to check for neighbors
153154 min_size: Minimal number of pixels for filtering small instances
154155 table: Dataframe of segmentation table
156+ resolution: Resolution of segmentation in micrometer
155157 output_key: Output key for postprocessed segmentation
156158 spatial_statistics_kwargs: Arguments for spatial statistics function
157159
@@ -162,7 +164,7 @@ def filter_segmentation(
162164 # Compute the table on the fly.
163165 # NOTE: this currently doesn't work for large segmentations.
164166 if table is None :
165- table = _compute_table (segmentation )
167+ table = _compute_table (segmentation , resolution = resolution )
166168 n_ids = len (table )
167169
168170 # First apply the size filter.
0 commit comments