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

code refactoring

code clean up
parent f9e9e63d
No related branches found
No related tags found
1 merge request!20Version for release
......@@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import static fr.pasteur.ida.zellige.jzy3D.LocalMaximumsDisplay.displayMaximums;
import static fr.pasteur.ida.zellige.steps.pixelSelection.util.Derivative.CENTRAL;
......@@ -90,6 +91,7 @@ public class ReferenceSurfaceExtraction< T extends RealType< T > & NativeType< T
/* First step : Pixel selection */
LOGGER.info( "Running selection..." );
maximums = PixelSelection.run( input, pretreatmentParameters, pixelClassificationParameters, postTreatmentParameters );
displayMaximums( maximums );
}
public void construct() throws NoSurfaceFoundException
......
......@@ -20,27 +20,25 @@ import java.util.List;
public class LocalOtsuClassification< T extends RealType< T > & NativeType< T > >
{
private final RandomAccessibleInterval< T > source;
private final ImgFactory< T > factory;
private final RandomAccessibleInterval< T > grid;
private final RandomAccessibleInterval< T > input;
private final RandomAccessibleInterval< T > output;
private final Img< BitType > binary;
private final double percent;
private final double userThreshold;
private static long processingTime;
private final static Logger LOGGER = LoggerFactory.getLogger( LocalOtsuClassification.class );
/**
* @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
* @param input the input {@link Img}
* @param binary the resulting binary image as a {@link Img<BitType> }
* @param userThreshold the percentage of global otsu value
*/
private LocalOtsuClassification( final RandomAccessibleInterval< T > source, final ImgFactory< T > factory, final Img< BitType > binary, double percent )
private LocalOtsuClassification( final RandomAccessibleInterval< T > input, final ImgFactory< T > factory, final Img< BitType > binary, double userThreshold )
{
this.source = source;
this.factory = factory;
this.input = input;
this.binary = binary;
this.percent = percent;
this.grid = factory.create( source );
this.userThreshold = userThreshold;
this.output = factory.create( input );
}
/**
......@@ -49,7 +47,7 @@ public class LocalOtsuClassification< T extends RealType< T > & NativeType< T >
* @param <T> the type on the input
* @return a 3D binary {@link Img<BitType>}
*/
public static < T extends RealType< T > & NativeType< T > > Img< BitType > runOtsuClassification( final RandomAccessibleInterval< T > input, ImgFactory< T > factory, double percent )
public static < T extends RealType< T > & NativeType< T > > Img< BitType > run( final RandomAccessibleInterval< T > input, ImgFactory< T > factory, double percent )
{
if ( percent > 0 )
{
......@@ -61,7 +59,7 @@ public class LocalOtsuClassification< T extends RealType< T > & NativeType< T >
classification.run();
long stop = System.currentTimeMillis();
classification.setProcessingTime( stop - start );
return classification.getGrid();
return classification.getOutput();
}
else
{
......@@ -97,7 +95,7 @@ public class LocalOtsuClassification< T extends RealType< T > & NativeType< T >
}
}
}
LOGGER.info( "Local thresholds applied." );
LOGGER.debug( "Local thresholds applied." );
}
/**
......@@ -105,7 +103,7 @@ public class LocalOtsuClassification< T extends RealType< T > & NativeType< T >
* @param grid the image containing the grid of local thresholds
*/
private void
computeLocalThreshold( RandomAccessibleInterval< T > input, ImgFactory< T > factory, RandomAccessibleInterval< T > grid )
computeLocalThreshold( RandomAccessibleInterval< T > input, RandomAccessibleInterval< T > grid )
{
long width = input.dimension( 0 );
long height = input.dimension( 1 );
......@@ -117,9 +115,9 @@ public class LocalOtsuClassification< T extends RealType< T > & NativeType< T >
{
computeLocalThreshold( input, grid, interval );
}
grid = Utils.gaussConvolution( grid, factory, new double[]{ 5, 5, 1 } );
Utils.gaussianConvolution( grid, grid, new double[]{ 5, 5, 1 } );
// ImageJFunctions.show(grid, "grid ");
LOGGER.info( "Local thresholds computed with user value = {}.", this.percent );
LOGGER.info( "Local thresholds computed with user value = {}.", this.userThreshold );
}
private void
......@@ -137,14 +135,14 @@ public class LocalOtsuClassification< T extends RealType< T > & NativeType< T >
*/
private void run()
{
computeLocalThreshold( source, factory, grid );
applyLocalThreshold( Views.iterable( source ), Views.iterable( grid ), binary, percent );
computeLocalThreshold( input, output );
applyLocalThreshold( Views.iterable( input ), Views.iterable( output ), binary, userThreshold );
}
/**
* @return the image containing the grid of local thresholds
*/
public Img< BitType > getGrid()
public Img< BitType > getOutput()
{
return binary;
}
......
......@@ -26,7 +26,7 @@ public class MaximumAmplitudeClassification< T extends RealType< T > & NativeTyp
private final RandomAccessibleInterval< T > input;
private final ImgFactory< T > factory;
private final double userAmplitudeThreshold;
private final double userThreshold;
private Img< BitType > output;
private static long processingTime;
......@@ -34,13 +34,13 @@ public class MaximumAmplitudeClassification< T extends RealType< T > & NativeTyp
public MaximumAmplitudeClassification( RandomAccessibleInterval< T > input,
ImgFactory< T > factory, Img< BitType > amplitude,
double userAmplitudeThreshold )
double userThreshold )
{
this.input = input;
this.factory = factory;
this.output = amplitude;
this.userAmplitudeThreshold = userAmplitudeThreshold;
LOGGER.info( "User input = {}", userAmplitudeThreshold );
this.userThreshold = userThreshold;
LOGGER.info( "User input = {}", userThreshold );
LOGGER.info( "Derivative method used : {}", ReferenceSurfaceExtraction.getDerivativeMethod() );
}
......@@ -167,7 +167,7 @@ public class MaximumAmplitudeClassification< T extends RealType< T > & NativeTyp
Img< T > amp = getAmplitude( maximums, factory, minimums );
T TMax = Threshold.getFirstMaxValue( maximums, false );
LOGGER.debug( "threshold value before user = {} ", TMax );
TMax.mul( userAmplitudeThreshold );
TMax.mul( userThreshold );
LOGGER.debug( "Threshold value after user = {}", TMax );
output = Thresholder.threshold( amp, TMax, true, 5 );
}
......
......@@ -80,22 +80,22 @@ public class PixelClassification< T extends RealType< T > & NativeType< T > >
void processAmplitudeClassification( RandomAccessibleInterval< T > input, ImgFactory< T > factory, double amplitudeThreshold ) throws EmptyOutputException, DataValidationException
{
/* Classification according to maximum amplitude */
output = MaximumAmplitudeClassification.runAmplitudeClassification( input, factory, amplitudeThreshold );
output = MaximumAmplitudeClassification.run( input, factory, amplitudeThreshold );
}
void processOtsuClassification( RandomAccessibleInterval< T > input, ImgFactory< T > factory, double otsuThreshold )
{
/* Classification according to local intensity*/
output = LocalOtsuClassification.runOtsuClassification( input, factory, otsuThreshold );
output = LocalOtsuClassification.run( input, factory, otsuThreshold );
}
void processBothClassification( RandomAccessibleInterval< T > input, ImgFactory< T > factory, double amplitudeThreshold, double otsuThreshold ) throws EmptyOutputException, DataValidationException
{
/* Classification according to maximum amplitude */
Img< BitType > amplitudeImg = MaximumAmplitudeClassification.runAmplitudeClassification( input, factory, amplitudeThreshold );
Img< BitType > amplitudeImg = MaximumAmplitudeClassification.run( input, factory, amplitudeThreshold );
/* Classification according to local intensity*/
Img< BitType > otsuImg = LocalOtsuClassification.runOtsuClassification( input, factory, otsuThreshold );
Img< BitType > otsuImg = LocalOtsuClassification.run( input, factory, otsuThreshold );
/* Intersection of both classification */
this.output = classification( amplitudeImg, amplitudeImg.factory(), otsuImg );
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment