Skip to content

Commit ebfa6ff

Browse files
author
Stefan Hahmann
committed
Change way to determine whether an image is 3d or not for Cellpose3 and Cellpose4 Detectors
1 parent e2c8c00 commit ebfa6ff

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/main/java/org/mastodon/mamut/detection/Cellpose3Detector.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ public void compute( final List< SourceAndConverter< ? > > sources, final ModelG
163163
* will have a size of 1.
164164
*/
165165
double[] voxelDimensions = source.getVoxelDimensions().dimensionsAsDoubleArray();
166-
boolean is3D = voxelDimensions.length == 3;
167-
cellpose.set3D( is3D );
166+
cellpose.set3D( is3D( image ) );
168167
double anisotropy = respectAnisotropy ? getAnisotropy( voxelDimensions ) : 1.0;
169168
cellpose.setAnisotropy( ( float ) anisotropy );
170169
cellpose.setCellprobThreshold( cellProbabilityThreshold );
@@ -232,4 +231,21 @@ private double getAnisotropy( double[] voxelSizes )
232231
return highestValue / lowestValue;
233232
}
234233

234+
private boolean is3D( final RandomAccessibleInterval< ? > image )
235+
{
236+
long[] dimensions = image.dimensionsAsLongArray();
237+
if ( dimensions.length <= 2 )
238+
return false;
239+
else
240+
{
241+
int nonPlaneDimensionCount = 0;
242+
for ( final long dimension : dimensions )
243+
{
244+
if ( dimension > 1 )
245+
nonPlaneDimensionCount++;
246+
}
247+
return nonPlaneDimensionCount > 2;
248+
}
249+
}
250+
235251
}

src/main/java/org/mastodon/mamut/detection/Cellpose4Detector.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ public void compute( final List< SourceAndConverter< ? > > sources, final ModelG
155155
* channel. It is always 3D. If the source is 2D, the 3rd dimension
156156
* will have a size of 1.
157157
*/
158-
double[] voxelDimensions = source.getVoxelDimensions().dimensionsAsDoubleArray();
159-
boolean is3D = voxelDimensions.length == 3;
160-
cellpose.set3D( is3D );
158+
cellpose.set3D( is3D( image ) );
161159
cellpose.setCellprobThreshold( cellProbabilityThreshold );
162160
cellpose.setFlowThreshold( flowThreshold );
163161
Img< ? > segmentation = cellpose.segmentImage( Cast.unchecked( image ) );
@@ -196,4 +194,21 @@ public Map< String, Object > getDefaultSettings()
196194
defaultSettings.put( KEY_FLOW_THRESHOLD, Cellpose4.DEFAULT_FLOW_THRESHOLD );
197195
return defaultSettings;
198196
}
197+
198+
private boolean is3D( final RandomAccessibleInterval< ? > image )
199+
{
200+
long[] dimensions = image.dimensionsAsLongArray();
201+
if ( dimensions.length <= 2 )
202+
return false;
203+
else
204+
{
205+
int nonPlaneDimensionCount = 0;
206+
for ( final long dimension : dimensions )
207+
{
208+
if ( dimension > 1 )
209+
nonPlaneDimensionCount++;
210+
}
211+
return nonPlaneDimensionCount > 2;
212+
}
213+
}
199214
}

0 commit comments

Comments
 (0)