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

documentation

parent df29f70a
Branches
Tags
1 merge request!10Surface reconstruction Refactoring
...@@ -16,76 +16,114 @@ import net.imglib2.view.Views; ...@@ -16,76 +16,114 @@ import net.imglib2.view.Views;
import java.util.List; import java.util.List;
/**
public class LocalOtsu *
*/
public class LocalOtsuClassification
{ {
/**
public static < T extends RealType< T > & NativeType< T > > Img< BitType > find( final Img< T > source , double percent) *
* @param input the input {@link Img}
* @param percent the percentage of global otsu value
* @param <T> the type on the input
* @return a 3D binary {@link Img<BitType>}
*/
public static < T extends RealType< T > & NativeType< T > > Img< BitType > find( final Img< T > input , double percent)
{ {
// Prepare output. // Prepare output.
final ImgFactory< BitType > factory = Util.getArrayOrCellImgFactory( source, new BitType() ); final ImgFactory< BitType > factory = Util.getArrayOrCellImgFactory( input, new BitType() );
Img< BitType > binary = factory.create( source ); Img< BitType > binary = factory.create( input );
new OtsuThreshold<>( source, binary, percent); new OtsuThreshold<>( input, binary, percent);
return binary; return binary;
} }
/**
*
* @param <T>
*/
private static final class OtsuThreshold< T extends RealType< T > & NativeType< T > > private static final class OtsuThreshold< T extends RealType< T > & NativeType< T > >
{ {
private final Img< T > source; private final Img< T > source;
private final Img< T > output; private final Img< T > grid;
private final Img< BitType > binary; private final Img< BitType > binary;
private final double percent; private final double percent;
/**
*
* @param source the input {@link Img}
* @param binary the resulting binary image as a {@link Img<BitType> }
* @param percent the percentage of global otsu value
*/
private OtsuThreshold( final Img< T > source, final Img< BitType > binary, double percent ) private OtsuThreshold( final Img< T > source, final Img< BitType > binary, double percent )
{ {
this.source = source; this.source = source;
this.binary = binary; this.binary = binary;
this.percent = percent; this.percent = percent;
final ImgFactory< T > factory = Util.getArrayOrCellImgFactory( source, Util.getTypeFromInterval( source ) ); final ImgFactory< T > factory = Util.getArrayOrCellImgFactory( source, Util.getTypeFromInterval( source ) );
this.output = factory.create( source ); this.grid = factory.create( source );
run(); run();
} }
/**
*
*/
public void run() public void run()
{ {
computeLocalThreshold( source, output ); computeLocalThreshold( source, grid);
applyLocalThreshold( source, output, binary, percent ); applyLocalThreshold( source, grid, binary, percent );
} }
public Img< BitType > getOutput() /**
*
* @return the image containing the grid of local thresholds
*/
public Img< BitType > getGrid()
{ {
return binary; return binary;
} }
/**
*
* @param input the input {@link Img}
* @param grid the image containing the grid of local thresholds
* @param <T> the type on the input
*/
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 > input, Img< T > grid )
{ {
long X = source.dimension( 0 ); long X = input.dimension( 0 );
long Y = source.dimension( 1 ); long Y = input.dimension( 1 );
long Z = source.dimension( 2 ); long Z = input.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, 3 } );//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 )
{ {
IntervalView< T > viewSource = Views.offsetInterval( source, interval ); IntervalView< T > viewSource = Views.offsetInterval( input, interval );
IntervalView< T > viewOutput = Views.offsetInterval( output, interval ); IntervalView< T > viewGrid = Views.offsetInterval( grid, interval );
T threshold = Otsu.getThreshold( viewSource ); T threshold = Otsu.getThreshold( viewSource );
viewOutput.forEach( pixel -> pixel.set( threshold ) ); viewGrid.forEach( pixel -> pixel.set( threshold ) );
} }
} }
/**
*
* @param input the input {@link Img}
* @param grid the image containing the grid of local thresholds
* @param binary the resulting binary image as a {@link Img<BitType> }
* @param percent the percentage of global otsu value
* @param <T> the input type
*/
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 > input, Img< T > grid, Img<BitType> binary , double percent)
{ {
double threshold = Threshold.getThreshold( source, percent ).getRealDouble(); double threshold = Threshold.getThreshold( input, percent ).getRealDouble();
Utils.gaussConvolution( output.copy(), output, new double[]{5, 5, 1} ); Utils.gaussConvolution( grid.copy(), grid, new double[]{5, 5, 1} );
ImageJFunctions.show( output.copy(), "grid" ); ImageJFunctions.show( grid.copy(), "grid" );
Cursor<T> sourceCursor = source.localizingCursor(); Cursor<T> sourceCursor = input.localizingCursor();
Cursor<T> outputCursor = output.cursor(); Cursor<T> outputCursor = grid.cursor();
RandomAccess< BitType > randomAccess = binary.randomAccess(); RandomAccess< BitType > randomAccess = binary.randomAccess();
while(sourceCursor.hasNext()) while(sourceCursor.hasNext())
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment