diff --git a/.gitignore b/.gitignore index cfc34f0a3b795e77e26409b41458bf46078fe736..0500cccbbbaea66d4d8a83a6d8635c74f8b7902a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ doc/ /**/*.plantuml uml/ target/ +*.iml diff --git a/src/main/java/StartingOSStats.java b/src/main/java/StartingOSStats.java index 1217020f467ce7d90a2e76a27056c09b44bac865..11bf1a4fc718480b2f0b2de5c3708fd9d1bc9dda 100644 --- a/src/main/java/StartingOSStats.java +++ b/src/main/java/StartingOSStats.java @@ -97,8 +97,8 @@ public class StartingOSStats if ( stackImage.numDimensions() == 3 )// Is it a stack ? { - ImageJFunctions.show( stackImage, "original" ); - ImageJFunctions.show( TestMIP.findMIP( stackImage, stackImage.factory() ), "MIP" ); +// ImageJFunctions.show( stackImage, "original" ); +// ImageJFunctions.show( TestMIP.findMIP( stackImage, stackImage.factory() ), "MIP" ); new ReferenceSurfaceExtraction<>( stackImage, stackImage.factory(),userParameters, advancedUserParameters ); } else diff --git a/src/main/java/fr/pasteur/ida/zellige/jzy3D/LocalExtremaDisplay.java b/src/main/java/fr/pasteur/ida/zellige/jzy3D/LocalExtremaDisplay.java new file mode 100644 index 0000000000000000000000000000000000000000..1da3556f38abd52c3221e65fc447d1ede296999b --- /dev/null +++ b/src/main/java/fr/pasteur/ida/zellige/jzy3D/LocalExtremaDisplay.java @@ -0,0 +1,87 @@ +package fr.pasteur.ida.zellige.jzy3D; + + +import fr.pasteur.ida.zellige.surfaceConstruction.element.Coordinate; +import fr.pasteur.ida.zellige.surfaceConstruction.element.Pixels; +import org.jzy3d.analysis.AbstractAnalysis; +import org.jzy3d.chart.factories.AWTChartComponentFactory; +import org.jzy3d.colors.Color; +import org.jzy3d.maths.Coord3d; +import org.jzy3d.plot3d.primitives.Scatter; +import org.jzy3d.plot3d.rendering.canvas.Quality; + + +public class LocalExtremaDisplay extends AbstractAnalysis +{ + private final Pixels[][] maximumCoordinates; + private final Color color; + private final String c; + + public LocalExtremaDisplay( Pixels[][] localMaximums, Color color, String c ) + { + this.maximumCoordinates = localMaximums; + this.color = color; + this.c = c; + init(); + } + + @Override + public void init( ) + { + if ( maximumCoordinates != null ) + { + int length = getNumberOfCoordinates(); + System.out.println("number of coordinates for " + c + " : " + length); + Coord3d[] points = new Coord3d[ length ]; + Color[] colors = new Color[ length ]; + + int x; + int y; + int z; + int index = 0; + for ( int i = 0; i <= this.maximumCoordinates.length - 1; i++ ) + { + for ( int j = 0; j <= this.maximumCoordinates[ 0 ].length - 1; j++ ) + { +// + Pixels pixels = maximumCoordinates[ i ][ j ]; + if ( pixels != null ) + { + { + for ( Coordinate coordinate : pixels .get() ) + { + z = coordinate.getZ(); + points[ index ] = new Coord3d( coordinate.getX(), coordinate.getY(), z ); + colors[ index ] = color; +// System.out.println( points[index]); + index++; + } + } + + } + } + } + + Scatter scatter = new Scatter( points, colors ); + scatter.setWidth( 1 ); + chart = AWTChartComponentFactory.chart( Quality.Advanced, "awt" ); + chart.getScene().add( scatter ); + } + } + + private int getNumberOfCoordinates() + { + int n = 0; + for ( int i = 0; i <= maximumCoordinates[0].length - 1; i++ ) + { + for ( int j = 0; j <= maximumCoordinates.length - 1 ; j++ ) + { + if( maximumCoordinates[j][i] != null) + { + n += maximumCoordinates[j][i].size(); + } + } + } + return n; + } +} diff --git a/src/main/java/fr/pasteur/ida/zellige/main/Main.java b/src/main/java/fr/pasteur/ida/zellige/main/Main.java index 0be1b5d25c4afe8e372632f074828b6f5cbc9675..aecee9f6a5ac04afc841ec8db7411048e798ca50 100644 --- a/src/main/java/fr/pasteur/ida/zellige/main/Main.java +++ b/src/main/java/fr/pasteur/ida/zellige/main/Main.java @@ -57,9 +57,9 @@ public class Main // Input of the image. final String imagePath = - "doc/STK.tif"; +// "doc/STK.tif"; // "C:\\Users\\ctrebeau\\Desktop\\MoucheAile\\STK\\STK_Mouche_c01_f0001_p005.tif"; -// "C:\\Users\\ctrebeau\\Downloads\\phantom3b_combined.tif"; + "C:\\Users\\ctrebeau\\Downloads\\phantom3b_combined.tif"; // "C:\\Users\\ctrebeau\\Desktop\\HighRes\\STK_170706_Vangl2-Lp-wt_E14.5_Phall_cochlea_01bHighRes_c01_f0001_p005.tif"; System.out.println(imagePath); // Creation of the image : version with unsigned type. */ @@ -95,8 +95,8 @@ public class Main if ( stackImage.numDimensions() == 3 )// Is it a stack ? { - ImageJFunctions.show( stackImage, "original" ); - ImageJFunctions.show( TestMIP.findMIP( stackImage, stackImage.factory() ), "MIP" ); +// ImageJFunctions.show( stackImage, "original" ); +// ImageJFunctions.show( TestMIP.findMIP( stackImage, stackImage.factory() ), "MIP" ); ReferenceSurfaceExtraction rse = new ReferenceSurfaceExtraction<>( stackImage, stackImage.factory(),userParameters, advancedUserParameters ); rse.extract(); rse.project(); diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/ReferenceSurfaceExtraction.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/ReferenceSurfaceExtraction.java index 3bd58de8119623e4ad034cd4a17295ae0c9cc090..366344fd78f3ffc975a7d55c6551e63574d4e85d 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/ReferenceSurfaceExtraction.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/ReferenceSurfaceExtraction.java @@ -22,6 +22,7 @@ import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.integer.UnsignedShortType; import org.jzy3d.analysis.AnalysisLauncher; +import org.jzy3d.colors.Color; import java.util.ArrayList; @@ -116,7 +117,7 @@ public class ReferenceSurfaceExtraction< T extends RealType< T > & NativeType< T } } } - displayMaximums( tempCoordinates ); +// displayMaximums( tempCoordinates ); return tempCoordinates; } @@ -162,7 +163,7 @@ public class ReferenceSurfaceExtraction< T extends RealType< T > & NativeType< T // First step : fill in the holes with linear interpolation. */ Img< UnsignedShortType > interpolated = Interpolation.run( surface.getZMap() ); Img< UnsignedShortType > smoothed = interpolated.copy(); - ImageJFunctions.show( smoothed, "smoothed" ); +// ImageJFunctions.show( smoothed, "smoothed" ); // Second step: smooth the elevation map with gaussian blur Utils.gaussConvolution( interpolated, smoothed, new double[]{ 1.0, 1.0 } ); return smoothed; @@ -221,7 +222,7 @@ public class ReferenceSurfaceExtraction< T extends RealType< T > & NativeType< T int index = 0; for( Surface surface : surfaces ) { - displaySurface( surface ); +// displaySurface( surface ); Img< UnsignedShortType > processedZMap = processedZMap( surface ); ReferenceSurface< T > referenceSurface = new ReferenceSurface<>( input, factory, processedZMap, index++ ); referenceSurfaces.add( referenceSurface ); @@ -233,8 +234,8 @@ public class ReferenceSurfaceExtraction< T extends RealType< T > & NativeType< T for(ReferenceSurface<T> referenceSurface : referenceSurfaces) { referenceSurface.setProjection( userParameters.getProjectionType(), userParameters.getDelta() ); - DisplayParameter displayParameter = new DisplayParameter( userParameters.getDelta(), true, - true, true, true ); + DisplayParameter displayParameter = new DisplayParameter( userParameters.getDelta(), false, + false, false, true ); referenceSurface.display( displayParameter ); } } diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacePixelSelection.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacePixelSelection.java index aa34c762171b31e780f748682c82a7d96833466b..217c89b22ee7a70522712ba19bac32669dad9f13 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacePixelSelection.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacePixelSelection.java @@ -1,5 +1,6 @@ package fr.pasteur.ida.zellige.surfaceConstruction.construction; +import fr.pasteur.ida.zellige.jzy3D.LocalExtremaDisplay; import fr.pasteur.ida.zellige.jzy3D.LocalMaximumsDisplay; import fr.pasteur.ida.zellige.surfaceConstruction.parameters.UserParameters; import fr.pasteur.ida.zellige.surfaceConstruction.element.Coordinate; @@ -18,6 +19,7 @@ import net.imglib2.type.logic.BitType; import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.real.FloatType; import org.jzy3d.analysis.AnalysisLauncher; +import org.jzy3d.colors.Color; public class SurfacePixelSelection { @@ -46,7 +48,7 @@ public class SurfacePixelSelection maximums = maximumSearch( normalized, factory ); /* Output */ - displayMaximums( maximums ); + displayExtrema( maximums, Color.BLACK, "Black total maximums"); } /** @@ -79,18 +81,18 @@ public class SurfacePixelSelection { /* Grid of amplitude thresholds */ Img< FloatType > amplitudeImg = MaximumAmplitudeClassification.find(input,factory,userParameters.getAmplitude() , 0.10); - ImageJFunctions.show( amplitudeImg," amplitude" ); - +// ImageJFunctions.show( amplitudeImg," amplitude" ); + displayExtrema( amplitudeImg, Color.GRAY, "Gray maxima amplitude" ); /* Grid of local thresholds*/ Img< BitType > thresholds = LocalOtsuClassification.find( input, factory, userParameters.getThreshold()); - + displayExtrema( thresholds, Color.BLUE , " Blue Otsu threshold"); /* Pixel selection */ Img<FloatType> finalList = Threshold.classification( amplitudeImg, amplitudeImg.factory(), thresholds ); - + displayExtrema( finalList, Color.RED, " Red otsu and amplitude intersection " ); /* Dilatation of the resulting image*/ double sigma = userParameters.getSigmas(); Utils.gaussConvolution( finalList.copy(), finalList, new double[]{ sigma, sigma, 1 } ); - ImageJFunctions.show(finalList, "blurred maximums" ); +// ImageJFunctions.show(finalList, "blurred maximums" ); /* Local maximum detection due to previous smoothing*/ finalList = LocalExtremaDetection.findMaxima( finalList.copy(), finalList.factory() ); @@ -102,7 +104,7 @@ public class SurfacePixelSelection * @param <T> * @return */ - public < T extends RealType< T > & NativeType< T > > Pixels[][] buildPixelArray( + public static < T extends RealType< T > & NativeType< T > > Pixels[][] buildPixelArray( final RandomAccessibleInterval< T > stack ) { RandomAccess< T > access = stack.randomAccess(); @@ -151,4 +153,24 @@ public class SurfacePixelSelection { return maximums; } + + + public static void displayExtrema(Pixels[][] extrema , Color color, String c) + { + try + { + LocalExtremaDisplay localExtremaDisplay = new LocalExtremaDisplay( extrema, color, c ); + AnalysisLauncher.open( localExtremaDisplay ); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + + public static < T extends RealType< T > & NativeType< T > > void displayExtrema(Img<T> img , Color color, String c) + { + Pixels[][] extrema = buildPixelArray( img ); + displayExtrema( extrema, color, c ); + } } diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/ReferenceSurface.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/ReferenceSurface.java index 0ab013ec3ae2e4f4b2526dd83bdb68afc13c165c..d2462d8b0646e05210f2e09c3e742db314a27bf8 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/ReferenceSurface.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/ReferenceSurface.java @@ -37,7 +37,7 @@ public class ReferenceSurface< T extends RealType< T > & NativeType< T > > { this.delta = delta; this.projectionType = projectionType; - ImageJFunctions.show( zMap, "input zMap" ); +// ImageJFunctions.show( zMap, "input zMap" ); extractedStack = StackProjection.getExtractedStack( input, factory, zMap, delta ); if ( projectionType.equals( "MIP" ) || diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/Surface.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/Surface.java index 9d460f5c639350e4d0552a7f9487f018e553c614..3c82ae97ce7279c05f922cf20ff59b6689f69cb3 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/Surface.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/Surface.java @@ -265,7 +265,7 @@ public class Surface } } } - ImageJFunctions.show( zMap, "after getzmap" ); +// ImageJFunctions.show( zMap, "after getzmap" ); System.out.println(" Thre count = " + count); return zMap; } diff --git a/src/main/java/fr/pasteur/ida/zellige/utils/Interpolation.java b/src/main/java/fr/pasteur/ida/zellige/utils/Interpolation.java index 76a1a0a6bcb10d75ee0f9d30a1abda5701cf368b..7e06b1c62f9e3b31238f7006a177d89eb55baf5b 100644 --- a/src/main/java/fr/pasteur/ida/zellige/utils/Interpolation.java +++ b/src/main/java/fr/pasteur/ida/zellige/utils/Interpolation.java @@ -21,7 +21,7 @@ public class Interpolation public static Img<UnsignedShortType> run( RandomAccessibleInterval< UnsignedShortType > input ) { InterpolationOperator operator = new InterpolationOperator( input ); - ImageJFunctions.show( operator.getOutput() ); +// ImageJFunctions.show( operator.getOutput() ); return operator.getOutput(); } @@ -43,11 +43,11 @@ public class Interpolation */ private void execute() { - ImageJFunctions.show( input, "zMap" ); +// ImageJFunctions.show( input, "zMap" ); Img< UnsignedShortType > interpolated0 = execute( input, 0 ); - ImageJFunctions.show( interpolated0, "interpolated 0" ); +// ImageJFunctions.show( interpolated0, "interpolated 0" ); Img< UnsignedShortType > interpolated1 = execute( input, 1 ); - ImageJFunctions.show( interpolated1, "interpolated 1" ); +// ImageJFunctions.show( interpolated1, "interpolated 1" ); Cursor< UnsignedShortType > cursor0 = interpolated0.cursor(); Cursor< UnsignedShortType > cursor1 = interpolated1.cursor(); diff --git a/src/main/java/fr/pasteur/ida/zellige/utils/LocalOtsuClassification.java b/src/main/java/fr/pasteur/ida/zellige/utils/LocalOtsuClassification.java index c7a4ecb329d9af6847222aaf45bad4fac5673e09..23d6fd1eba8cc4124e0239fe49f509e4d7cce0af 100644 --- a/src/main/java/fr/pasteur/ida/zellige/utils/LocalOtsuClassification.java +++ b/src/main/java/fr/pasteur/ida/zellige/utils/LocalOtsuClassification.java @@ -130,7 +130,7 @@ public class LocalOtsuClassification } } } - ImageJFunctions.show( binary, "binary" ); +// ImageJFunctions.show( binary, "binary" ); } diff --git a/src/main/java/fr/pasteur/ida/zellige/utils/MaximumAmplitudeClassification.java b/src/main/java/fr/pasteur/ida/zellige/utils/MaximumAmplitudeClassification.java index 88314c5a9b614b19cfbde095b8204463d0c1b1e8..78d30ea53b89b81aaea08f78c9779d10dcd817c0 100644 --- a/src/main/java/fr/pasteur/ida/zellige/utils/MaximumAmplitudeClassification.java +++ b/src/main/java/fr/pasteur/ida/zellige/utils/MaximumAmplitudeClassification.java @@ -1,5 +1,6 @@ package fr.pasteur.ida.zellige.utils; +import fr.pasteur.ida.zellige.surfaceConstruction.construction.SurfacePixelSelection; import net.imglib2.Cursor; import net.imglib2.Interval; import net.imglib2.RandomAccess; @@ -17,6 +18,7 @@ import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Util; import net.imglib2.view.IntervalView; import net.imglib2.view.Views; +import org.jzy3d.colors.Color; import java.util.List; @@ -45,7 +47,7 @@ public class MaximumAmplitudeClassification Img< FloatType > output = floatTypeImgFactory.create( input ); new BackgroundForegroundGrid( maximumAmplitude.getAmplitude(), output, sizePercent ); Utils.gaussConvolution( output.copy(), output, new double[]{ 0, 0, 0.5 } ); - ImageJFunctions.show( output, "new class amplitude" ); +// ImageJFunctions.show( output, "new class amplitude" ); return output; } @@ -172,9 +174,8 @@ public class MaximumAmplitudeClassification public void run() { -// Img< T > maximums = LocalMaximumDetection.findMaximums( input, factory ); Img< T > maximums = LocalExtremaDetection.findMaxima( input, factory ); -// Img< T > minimums = LocalMinimumDetection.findMinimums( input, factory ); + SurfacePixelSelection.displayExtrema( maximums, Color.MAGENTA, "Magenta total maximums" ); Img< T > minimums = LocalExtremaDetection.findMinima( input, factory ); Img< T > amp = getAmplitude( maximums, factory, minimums ); T TMax = Threshold.getFirstMaxValue( maximums, false );