diff --git a/src/main/java/StartingOSStats.java b/src/main/java/StartingOSStats.java index 82b35fef20e0a1bb6cc3fd84d780f6a4cc925e0b..58d764cd52eb5b39a55bc6918e7dfc23b5286b31 100644 --- a/src/main/java/StartingOSStats.java +++ b/src/main/java/StartingOSStats.java @@ -95,8 +95,7 @@ public class StartingOSStats ImageJFunctions.show( stackImage, "original" ); ImageJFunctions.show( TestMIP.findMIP( stackImage, stackImage.factory() ), "MIP" ); - SurfacesExtraction.setX( ( int ) stackImage.dimension( 0 ));// dimension X - SurfacesExtraction.setY(( int ) stackImage.dimension( 1 ));// dimension Y + SurfacesExtraction.extract(stackImage,amplitude, otsu, sigmas, false, delta, false, false, true, "MIP"); } diff --git a/src/main/java/fr/pasteur/ida/zellige/gui/ZelligeController.java b/src/main/java/fr/pasteur/ida/zellige/gui/ZelligeController.java index 2204bb6df86fdbadd2c154ab04a58019498150d0..fbcb55ca25aa185c012a915e1c764fed26036934 100644 --- a/src/main/java/fr/pasteur/ida/zellige/gui/ZelligeController.java +++ b/src/main/java/fr/pasteur/ida/zellige/gui/ZelligeController.java @@ -170,9 +170,8 @@ public class ZelligeController implements ChangeListener, ActionListener IJ.log( " - dimension " + d + ": [" + stackImage.axis( d ).type() + "], 1 unit = " + stackImage.averageScale( d ) + " " + stackImage.axis( d ).unit() ); if ( stackImage.numDimensions() == 3 )// Is it a stack ? { - SurfacesExtraction.setX( ( int ) stackImage.dimension( 0 ));// dimension X - SurfacesExtraction.setY( ( int ) stackImage.dimension( 1 ));// dimension Y - Pixels[][] maximums = new Pixels[SurfacesExtraction.getY()][SurfacesExtraction.getX()]; + + int localThreshold = localThresholdSpinner.getTextValue(); int globalThreshold = globalThresholdSpinner.getTextValue(); int sigma = blurSpinner.getTextValue(); 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 029a897b1000209c76bdf4b81ce13a7ed9dc1d34..0061e6ebb7fab96c083fd0737ce85b8b3c59c3dc 100644 --- a/src/main/java/fr/pasteur/ida/zellige/main/Main.java +++ b/src/main/java/fr/pasteur/ida/zellige/main/Main.java @@ -98,9 +98,6 @@ public class Main ImageJFunctions.show( stackImage, "original" ); ImageJFunctions.show( TestMIP.findMIP( stackImage, stackImage.factory() ), "MIP" ); - SurfacesExtraction.setX( ( int ) stackImage.dimension( 0 ));// dimension X - SurfacesExtraction.setY(( int ) stackImage.dimension( 1 ));// dimension Y - SurfacesExtraction.setZ(( int ) stackImage.dimension( 2 ));// dimension Z SurfacesExtraction.extract(stackImage,amplitude,otsu, sigmas, false, delta, false, false, true, "MIP"); } diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacesExtraction.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacesExtraction.java index 7f52d087b67eb18e3735c37c538ea4792c3bf525..bc77c2d680d4f35daa911600ba03c99b75557d11 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacesExtraction.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacesExtraction.java @@ -28,9 +28,7 @@ import java.util.TreeSet; public class SurfacesExtraction { - private static int X; - private static int Y; - private static int Z; + public static TreeSet<Integer> list; public static < T extends RealType< T > & NativeType< T > > void extract( @@ -43,18 +41,19 @@ public class SurfacesExtraction { /* First step : Pixel selection */ Pixels[][] maximums = SurfacePixelSelection.run(input, amplitude,threshold, sigmas); - + int X = (int) input.dimension( 0 ); + int Y = (int) input.dimension( 1 ); try { /* First round construction*/ - ArrayList< Surface > surfaces = firstRoundConstruction( maximums ); + ArrayList< Surface > surfaces = firstRoundConstruction( maximums , X, Y); System.out.println( "first round surfaces = " + surfaces.size() ); // // for (Surface surface : surfaces) { // displaySurface(surface); // } // Second round construction - ArrayList< Surface > finalSurfaces = secondRoundConstruction( surfaces ); + ArrayList< Surface > finalSurfaces = secondRoundConstruction( surfaces, X, Y ); // if ( !finalSurfaces.isEmpty() ) // { int index = 0; @@ -136,7 +135,7 @@ public class SurfacesExtraction } /* ----- First and second round construction methods. ----- */ - private static ArrayList< Surface > firstRoundConstruction( Pixels[][] maximums ) throws NoSurfaceFoundException + private static ArrayList< Surface > firstRoundConstruction( Pixels[][] maximums, int X, int Y ) throws NoSurfaceFoundException { int dimension = 0; // Setting and storage of the OS build in the X dimension according to the user thresholds settings. @@ -147,7 +146,7 @@ public class SurfacesExtraction System.out.println( "OS.count = " + OSE.getCount() ); /* Construction of the tempSurfaces*/ ArrayList< Surface > surfaces = - SurfacesReconstruction.buildSurfaces( 0, osListsArrayX ); + SurfacesReconstruction.buildSurfaces( 0, osListsArrayX, X, Y ); if ( ! surfaces.isEmpty() ) { mergeReferenceSurface( surfaces ); @@ -167,7 +166,7 @@ public class SurfacesExtraction * @param surface - the {@link SurfaceLine} array of a {@link Surface} * @return a {@link Surface} specific double pixel array. */ - private static Pixels[][] rebuildPixelsArray( Surface surface ) + private static Pixels[][] rebuildPixelsArray( Surface surface, int X, int Y ) { Pixels[][] tempCoordinates = new Pixels[ X ][ Y ]; // Transposed array for ( int i = 0; i <= Y - 1; i++ ) @@ -189,10 +188,10 @@ public class SurfacesExtraction * @param surface - the Surface object to process * @param osListsArrayY -the output OSList array */ - private static void transposeSurfaceLines( Surface surface, OSList[] osListsArrayY ) + private static void transposeSurfaceLines( Surface surface, OSList[] osListsArrayY, int X, int Y ) { int dimension = 1; - Pixels[][] pixels = rebuildPixelsArray( surface ); + Pixels[][] pixels = rebuildPixelsArray( surface, X, Y ); /* OS construction in dimension Y.*/ OSEStartingStatus startingStatus = new OSEStartingStatus( dimension ); set( pixels, osListsArrayY, dimension, startingStatus ); @@ -207,7 +206,7 @@ public class SurfacesExtraction * @param surfaces - the list of TempSurface objects. * @return a list of reconstructed Tempsurface objects */ - private static ArrayList< Surface > secondRoundConstruction( ArrayList< Surface > surfaces ) throws NoSurfaceFoundException + private static ArrayList< Surface > secondRoundConstruction( ArrayList< Surface > surfaces, int X, int Y ) throws NoSurfaceFoundException { System.out.println( "========================================" ); ArrayList< Surface > finalSurfaces = new ArrayList<>(); @@ -218,12 +217,12 @@ public class SurfacesExtraction { OSList[] osListsArrayY = new OSList[ X ]; - transposeSurfaceLines( surface, osListsArrayY ); + transposeSurfaceLines( surface, osListsArrayY, X, Y ); OSE.setStartingStatus( 1 ); System.out.println( "OS.count = " + OSE.getCount() ); // displayOS( osListsArrayY ); - ArrayList< Surface > temps = SurfacesReconstruction.buildSurfaces( 1, osListsArrayY ); + ArrayList< Surface > temps = SurfacesReconstruction.buildSurfaces( 1, osListsArrayY, X, Y ); if ( temps.isEmpty() ) { System.out.println( "small surface in second round" ); @@ -328,35 +327,35 @@ public class SurfacesExtraction } - public static int getX() - { - return X; - } - - public static void setX( int x ) - { - X = x; - } - - public static int getY() - { - return Y; - } - - public static void setY( int y ) - { - Y = y; - } - - public static int getZ() - { - return Z; - } - - public static void setZ( int z ) - { - Z = z; - } +// public static int getX() +// { +// return X; +// } +// +// public static void setX( int x ) +// { +// X = x; +// } +// +// public static int getY() +// { +// return Y; +// } +// +// public static void setY( int y ) +// { +// Y = y; +// } +// +// public static int getZ() +// { +// return Z; +// } +// +// public static void setZ( int z ) +// { +// Z = z; +// } /** * Displays the local maximums found using jzy3D package. diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacesReconstruction.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacesReconstruction.java index a10484615519ee6bf01a7563f95e4eb454195fae..ba1082294d0c738485f3182e08988866718cbb83 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacesReconstruction.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/construction/SurfacesReconstruction.java @@ -25,12 +25,12 @@ public class SurfacesReconstruction * @param osLists - the array of OSList * @return a list of TempSurface */ - public static ArrayList< Surface > buildSurfaces( int dimension, OSList[] osLists ) + public static ArrayList< Surface > buildSurfaces( int dimension, OSList[] osLists, int X, int Y ) { // Construction of the list of output TempSurface. ArrayList< Surface > surfaces = new ArrayList<>(); smallSurfaceCount = 0; - int finalIndex = findIndexValue( osLists, 0, dimension ); + int finalIndex = findIndexValue( osLists, 0, dimension, X, Y ); do { // All the OSLists are set to "not visited". @@ -40,10 +40,10 @@ public class SurfacesReconstruction // osLists[finalIndex].remove( firstOS );//TODO remove or not if ( firstOSE != null ) { - Surface surface = createSurface( firstOSE, dimension ); - buildSurface( osLists, surface, finalIndex ); + Surface surface = createSurface( firstOSE, dimension, X, Y); + buildSurface( osLists, surface, finalIndex, X, Y ); //it is really a reference surface ? - if ( surface.getSize() >= SurfacesExtraction.getX() * SurfacesExtraction.getY() * 0.01 ) + if ( surface.getSize() >= X * Y * 0.01 ) { surfaces.add( surface ); } @@ -52,7 +52,7 @@ public class SurfacesReconstruction smallSurfaceCount++; System.out.println( "searching.....from " ); } - finalIndex = findIndexValue( osLists, startingIndex, dimension ); + finalIndex = findIndexValue( osLists, startingIndex, dimension, X, Y ); } } while ( finalIndex <= osLists.length - 2 @@ -71,14 +71,14 @@ public class SurfacesReconstruction * @param surface - the TempSurface to construct * @param index - the position in the TempSurface */ - private static void buildSurface( OSList[] osLists, Surface surface, int index ) + private static void buildSurface( OSList[] osLists, Surface surface, int index, int X, int Y ) { /* First round of the construction -> top to bottom in the dimension.*/ SurfaceLine current = surface.get( index ); SurfaceLine next; while ( current != null ) { - next = searchForward( osLists, current ); + next = searchForward( osLists, current, X, Y ); if ( next != null ) { surface.set( next.getLine(), next ); @@ -113,7 +113,7 @@ public class SurfacesReconstruction { if ( surface.get( i ) != null ) { - next = searchForward( osLists, surface.get( i ) ); + next = searchForward( osLists, surface.get( i ), X, Y ); if ( next != null ) { if ( surface.get( i + 1 ) != null ) @@ -136,20 +136,20 @@ public class SurfacesReconstruction * @param dimension - the construction dimension * @return a surface as a {@link Surface} */ - private static Surface createSurface( OSE firstOSE, int dimension ) + private static Surface createSurface( OSE firstOSE, int dimension, int X, int Y) { - Surface surface = new Surface( dimension ); + Surface surface = new Surface( dimension, X, Y ); int i; if ( dimension == 0 ) { i = firstOSE.get( 0 ).getY(); - surface.set( i, new SurfaceLineX( firstOSE ) ); + surface.set( i, new SurfaceLineX( X, firstOSE ) ); } else { i = firstOSE.get( 0 ).getX(); - surface.set( i, new SurfaceLineY( firstOSE ) ); + surface.set( i, new SurfaceLineY(Y, firstOSE ) ); } return surface; } @@ -162,17 +162,17 @@ public class SurfacesReconstruction * @param dimension - the dimension in which the construction has to occur * @return the value of the first OSList containing a starting OS */ - private static int findIndexValue( OSList[] osLists, int index, int dimension ) + private static int findIndexValue( OSList[] osLists, int index, int dimension, int X, int Y ) { int i = index; int limitValue; if ( dimension == 0 ) { - limitValue = SurfacesExtraction.getY() - 1; + limitValue = Y - 1; } else { - limitValue = SurfacesExtraction.getX() - 1; + limitValue = X - 1; } while ( i <= limitValue - 2 ) { @@ -261,16 +261,16 @@ public class SurfacesReconstruction * @param current - the {@link SurfaceLine } to match * @return the SurfaceLine generated from the specified OSList array matching the current SurfaceLine */ - private static SurfaceLine searchForward( OSList[] osLists, SurfaceLine current ) + private static SurfaceLine searchForward( OSList[] osLists, SurfaceLine current , int X, int Y) { int length; if ( current instanceof SurfaceLineX ) { - length = SurfacesExtraction.getY(); + length = Y; } else { - length = SurfacesExtraction.getX(); + length = X; } if ( current.getLine() + 1 <= length - 1 ) 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 9c40147c6c7fd10f695c1d66f44b0ae8f913c9bd..5b3d3020ce65c995e99a33cf4716a919f1935878 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 @@ -19,18 +19,22 @@ public class Surface private final SurfaceLine[] surfaceLines; private final int dimension; + private final int X; + private final int Y; - public Surface( int dimension ) + public Surface( int dimension, int X, int Y ) { + this.X = X; + this.Y = Y; int length; if ( dimension == 0 ) { - length = SurfacesExtraction.getY(); + length = Y; } else { - length = SurfacesExtraction.getX(); + length = X; } this.dimension = dimension; this.surfaceLines = new SurfaceLine[ length ]; @@ -157,7 +161,7 @@ public class Surface */ public Surface transpose() { - Surface surface = new Surface( Math.abs( this.dimension - 1 ) ); + Surface surface = new Surface( Math.abs( this.dimension - 1 ), X, Y ); Class< ? > theClass; if ( this.dimension == 0 ) { @@ -236,7 +240,7 @@ public class Surface public Img< UnsignedShortType > getZMap() { - Dimensions dim = FinalDimensions.wrap( new long[]{SurfacesExtraction.getX(),SurfacesExtraction.getY() }); + Dimensions dim = FinalDimensions.wrap( new long[]{X,Y }); ImgFactory< UnsignedShortType > factory = Util.getArrayOrCellImgFactory(dim, new UnsignedShortType()); Img< UnsignedShortType > zMap = factory.create(dim); RandomAccess< UnsignedShortType > randomAccess = zMap.randomAccess(); diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLine.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLine.java index 8b09c05c6dcd7f7cb1fadae26a44ee5ab0e13d95..c6f098045f624414a96eefdef2f22cb0a8de77ba 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLine.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLine.java @@ -27,9 +27,9 @@ public abstract class SurfaceLine * * @param line - the position on the stack. */ - public SurfaceLine( int line ) + public SurfaceLine( int length, int line ) { - this.dimension = new Pixels[ this.getLength()] ; + this.dimension = new Pixels[ length ] ; this.line = line; } @@ -38,10 +38,10 @@ public abstract class SurfaceLine * * @param os - a list of Coordinates to fill the pixel array. */ - public SurfaceLine( OSE os ) + public SurfaceLine(int length , OSE os) { - this.dimension = new Pixels[ this.getLength()] ; - set( os ); + this.dimension = new Pixels[ length ] ; + set( os ); } public SurfaceLine( OSE os, int size ) @@ -215,14 +215,7 @@ public abstract class SurfaceLine public int getLength( ) { - if ( this instanceof SurfaceLineX ) - { - return SurfacesExtraction.getX(); - } - else - { - return SurfacesExtraction.getY(); - } + return this.dimension.length; } diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLineX.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLineX.java index 459ebb39043c8c88ba6bc7ffe159c414f531891f..1fa11ca2cefd0c6d4625e836d85344c35649e4c1 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLineX.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLineX.java @@ -12,9 +12,9 @@ public class SurfaceLineX extends SurfaceLine * * @param os - a list of Coordinates to fill the pixel array. */ - public SurfaceLineX( OSE os ) + public SurfaceLineX( int length, OSE os ) { - super( os ); + super( length, os ); this.setLine( os.get( 0 ).getY() ); } @@ -23,9 +23,9 @@ public class SurfaceLineX extends SurfaceLine * * @param line - the position on the stack. */ - public SurfaceLineX( int line ) + public SurfaceLineX( int length, int line ) { - super( line ); + super(length, line ); } public SurfaceLineX( OSE os, int size ) @@ -44,7 +44,7 @@ public class SurfaceLineX extends SurfaceLine */ public SurfaceLine match( OSE os, int j, double percent, int matched ) { - SurfaceLineX surfaceLine = new SurfaceLineX( this.getLine() + j ); + SurfaceLineX surfaceLine = new SurfaceLineX(this.getLength(), this.getLine() + j ); int match = 0; int k = 0; for ( int i = 0; i <= os.size() - 1; i++ ) diff --git a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLineY.java b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLineY.java index 25a5efea9bddd3d4362fda7bc2af81d8eda8bbaa..834d760d815a7973f6f74d5454ac5b44479681d7 100644 --- a/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLineY.java +++ b/src/main/java/fr/pasteur/ida/zellige/surfaceConstruction/element/surfaceLine/SurfaceLineY.java @@ -11,9 +11,9 @@ public class SurfaceLineY extends SurfaceLine * * @param os - a list of Coordinates to fill the pixel array. */ - public SurfaceLineY( OSE os ) + public SurfaceLineY( int length, OSE os ) { - super( os ); + super(length, os ); this.setLine( os.get( 0 ).getX() ); } @@ -22,9 +22,9 @@ public class SurfaceLineY extends SurfaceLine * * @param line - the position on the stack. */ - public SurfaceLineY( int line ) + public SurfaceLineY( int length, int line ) { - super( line ); + super(length, line ); } @@ -39,7 +39,7 @@ public class SurfaceLineY extends SurfaceLine */ public SurfaceLine match( OSE os, int j, double percent, int matched ) { - SurfaceLineY surfaceLine = new SurfaceLineY( this.getLine() + j ); + SurfaceLineY surfaceLine = new SurfaceLineY(this.getLength(), this.getLine() + j ); int match = 0; int k = 0; for ( int i = 0; i <= os.size() - 1; i++ ) 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 c88407aec5e9d71aa9d9064943cc49fe2110e254..02f4131066f150ab5b4e28f9f088fbd532e40d30 100644 --- a/src/main/java/fr/pasteur/ida/zellige/utils/MaximumAmplitudeClassification.java +++ b/src/main/java/fr/pasteur/ida/zellige/utils/MaximumAmplitudeClassification.java @@ -81,13 +81,13 @@ public class MaximumAmplitudeClassification RandomAccess< T > maxAccess = max.randomAccess(); RandomAccess< T > minAccess = min.randomAccess(); RandomAccess< T > ampAccess = amp.randomAccess(); - for ( int x = 0; x <= SurfacesExtraction.getX() - 1; x++ ) + for ( int x = 0; x <= max.dimension( 0 ) - 1; x++ ) { maxAccess.setPosition( x, 0 ); - for ( int y = 0; y <= SurfacesExtraction.getY() - 1; y++ ) + for ( int y = 0; y <= max.dimension( 1 ) - 1; y++ ) { maxAccess.setPosition( y, 1 ); - for ( int z = 0; z <= SurfacesExtraction.getZ() - 1; z++ ) + for ( int z = 0; z <= max.dimension( 2 ) - 1; z++ ) { maxAccess.setPosition( z, 2 ); @@ -95,7 +95,7 @@ public class MaximumAmplitudeClassification if ( maxValue != 0 ) { minAccess.setPosition( maxAccess ); - double amplitude = getAmplitude( maxValue, minAccess ); + double amplitude = getAmplitude( maxValue, minAccess, (int) max.dimension( 2 ) ); ampAccess.setPosition( maxAccess ); ampAccess.get().setReal( amplitude ); } @@ -112,10 +112,10 @@ public class MaximumAmplitudeClassification * @param <T> the type of the {@link RandomAccess} * @return the chosen amplitude value of the local maximum positioned at minAccess location */ - private static < T extends RealType< T > & NativeType< T > > double getAmplitude( float maxValue, RandomAccess< T > minAccess ) + private static < T extends RealType< T > & NativeType< T > > double getAmplitude( float maxValue, RandomAccess< T > minAccess , int Z) { double up = findValueUp( minAccess, maxValue ); - double down = findValueDown( minAccess, maxValue ); + double down = findValueDown( minAccess, maxValue , Z); double result = Math.max( Math.abs( maxValue - up ), Math.abs( maxValue - down ) ); if ( result == 0 ) { @@ -156,10 +156,10 @@ public class MaximumAmplitudeClassification * @return the amplitude value below the local maximum location in the Z dimension */ private static < T extends RealType< T > & NativeType< T > > double findValueDown( - RandomAccess< T > minAccess, float maxValue ) + RandomAccess< T > minAccess, float maxValue, int Z ) { int start = minAccess.getIntPosition( 2 ); - for ( int z = start + 1; z <= SurfacesExtraction.getZ() - 1; z++ ) + for ( int z = start + 1; z <= Z - 1; z++ ) { minAccess.setPosition( z, 2 ); double value = minAccess.get().getRealDouble();