Skip to content
Snippets Groups Projects
Commit 3f484077 authored by Céline  TREBEAU's avatar Céline TREBEAU
Browse files

Use of multithreaded Otsu (ImgLib2 histogram) instead of JBM Otsu

parent 6c18d45c
No related branches found
No related tags found
1 merge request!10Surface reconstruction Refactoring
...@@ -37,7 +37,7 @@ public class LocalOtsu ...@@ -37,7 +37,7 @@ public class LocalOtsu
private final Img< T > source; private final Img< T > source;
private final Img< T > output; private final Img< T > output;
private final Img< BitType > binary; private final Img< BitType > binary;
private double percent; private final double percent;
private OtsuThreshold( final Img< T > source, final Img< BitType > binary, double percent ) private OtsuThreshold( final Img< T > source, final Img< BitType > binary, double percent )
{ {
...@@ -64,12 +64,11 @@ public class LocalOtsu ...@@ -64,12 +64,11 @@ public class LocalOtsu
public static < T extends RealType< T > & NativeType< T > > void public static < T extends RealType< T > & NativeType< T > > void
computeLocalThreshold( Img< T > source, Img< T > output ) computeLocalThreshold( Img< T > source, Img< T > output )
{ {
long X = source.dimension( 0 ); long X = source.dimension( 0 );
long Y = source.dimension( 1 ); long Y = source.dimension( 1 );
long Z = source.dimension( 2 ); long Z = source.dimension( 2 );
List< Interval > intervals = Grids.collectAllContainedIntervals( new long[]{ X, Y, Z }, List< Interval > intervals = Grids.collectAllContainedIntervals( new long[]{ X, Y, Z },
new int[]{ 50, 50, 5 } );//TODO Size of a grid cube ? new int[]{ 50, 50, 3 } );//TODO Size of a grid cube ?
for ( Interval interval : intervals ) for ( Interval interval : intervals )
{ {
...@@ -82,9 +81,9 @@ public class LocalOtsu ...@@ -82,9 +81,9 @@ public class LocalOtsu
public static < T extends RealType< T > & NativeType< T > > void public static < T extends RealType< T > & NativeType< T > > void
applyLocalThreshold( Img< T > source, Img< T > output, Img<BitType> binary , double percent) applyLocalThreshold( Img< T > source, Img< T > output, Img<BitType> binary , double percent)
{ {
ImageJFunctions.show( output, "grid" ); double threshold = Threshold.getThreshold( source, percent ).getRealDouble();
double threshold = Otsu.getThreshold( source ).getRealDouble();
Utils.gaussConvolution( output.copy(), output, new double[]{5, 5, 1} ); Utils.gaussConvolution( output.copy(), output, new double[]{5, 5, 1} );
ImageJFunctions.show( output.copy(), "grid" );
Cursor<T> sourceCursor = source.localizingCursor(); Cursor<T> sourceCursor = source.localizingCursor();
Cursor<T> outputCursor = output.cursor(); Cursor<T> outputCursor = output.cursor();
RandomAccess< BitType > randomAccess = binary.randomAccess(); RandomAccess< BitType > randomAccess = binary.randomAccess();
...@@ -94,12 +93,15 @@ public class LocalOtsu ...@@ -94,12 +93,15 @@ public class LocalOtsu
outputCursor.fwd(); outputCursor.fwd();
final float s = sourceCursor.get().getRealFloat(); final float s = sourceCursor.get().getRealFloat();
final float o = outputCursor.get().getRealFloat(); final float o = outputCursor.get().getRealFloat();
if (s >= Math.max( o, threshold* percent))// background substraction
{ {
randomAccess.setPosition( sourceCursor ); if (s >= Math.max( o, threshold))// background subtraction
randomAccess.get().set(true); {
randomAccess.setPosition( sourceCursor );
randomAccess.get().set( true );
}
} }
} }
ImageJFunctions.show( binary, "binary" );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment