1515 * You should have received a copy of the GNU General Public License
1616 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1717 */
18- package fr .igred .nucleus .core ;
18+ package fr .igred .nucleus .segmentation ;
1919
20+ import fr .igred .nucleus .core .Measure3D ;
21+ import fr .igred .nucleus .utils .ConvexHullDetection ;
22+ import fr .igred .nucleus .utils .ConvexHullSegmentation ;
23+ import fr .igred .nucleus .utils .FillingHoles ;
2024import fr .igred .omero .Client ;
2125import fr .igred .omero .annotations .TagAnnotationWrapper ;
2226import fr .igred .omero .exception .AccessException ;
2832import fr .igred .omero .roi .RectangleWrapper ;
2933import fr .igred .nucleus .io .Directory ;
3034import fr .igred .nucleus .imageprocessing .Thresholding ;
31- import fr .igred .nucleus .segmentation .SegmentationParameters ;
32- import fr .igred .nucleus .utils .FillingHoles ;
3335import fr .igred .nucleus .utils .Gradient ;
3436import fr .igred .nucleus .utils .Histogram ;
3537import ij .ImagePlus ;
6971 * @author Tristan Dubos and Axel Poulet
7072 */
7173public class NucleusSegmentation {
72- /** Currently used algorithm to calculate nuclei convex hull */
73- public static final String CONVEX_HULL_ALGORITHM = "GRAHAM" ;
7474
7575 /** Logger */
7676 private static final Logger LOGGER = LoggerFactory .getLogger (MethodHandles .lookup ().lookupClass ());
7777
7878 /** Segmentation parameters for the analysis */
7979 private final SegmentationParameters segmentationParameters ;
8080 /** ImagePlus input to process */
81- private final ImagePlus imgRawTransformed ;
82- /** List of the 3D parameters computed associated to the segmented image */
83- private Measure3D measure3D ;
84- /* String stocking the file name if any nucleus is detected*/
81+ private final ImagePlus imgRawTransformed ;
8582 /** Threshold detected by the Otsu modified method */
8683 private int bestThreshold = -1 ;
87- /** volume min of the detected object */
88- private int vMin ;
89- /** volume max of the detected object */
90- private int vMax ;
9184 /** ImagePlus input to process */
9285 private ImagePlus imgRaw ;
9386 /** Check if the segmentation is not in border */
9487 private boolean badCrop ;
95- /** Current image analysed */
96- private File currentFile ;
97- /** String containing the output prefix */
98- private String outputFilesPrefix ;
9988 /** Segmented image */
10089 private ImagePlus [] imageSeg ;
10190
@@ -104,36 +93,32 @@ public class NucleusSegmentation {
10493 * Constructor for the segmentation analysis for a folder containing images.
10594 *
10695 * @param imageFile Current image analysed
107- * @param outputFilesPrefix prefix for the output file
108- * @param segmentationParameters list the parameters for the analyse
96+ * @param params list the parameters for the analyse
10997 *
11098 * @throws IOException
11199 * @throws FormatException
112100 */
113- public NucleusSegmentation (File imageFile ,
114- String outputFilesPrefix ,
115- SegmentationParameters segmentationParameters )
101+ public NucleusSegmentation (File imageFile , SegmentationParameters params )
116102 throws IOException , FormatException {
117- this .segmentationParameters = segmentationParameters ;
118- this .currentFile = imageFile ;
119- this .imgRaw = getImageChannel (0 );
103+ this .segmentationParameters = params ;
120104 // TODO ADD CHANNEL PARAMETERS (CASE OF CHANNELS UNSPLITED)
105+ this .imgRaw = getImageChannel (imageFile , 0 );
121106 imgRaw .setTitle (imageFile .getName ());
122107 this .imgRawTransformed = imgRaw .duplicate ();
123108 imgRawTransformed .setTitle (imageFile .getName ());
124- Directory dirOutputOTSU = new Directory (segmentationParameters .getOutputFolder () + "OTSU" );
109+ Directory dirOutputOTSU = new Directory (params .getOutputFolder () + "OTSU" );
125110 dirOutputOTSU .checkAndCreateDir ();
126- if (segmentationParameters .getConvexHullDetection ()) {
127- Directory dirOutputConvexHull = new Directory (segmentationParameters .getOutputFolder () +
128- CONVEX_HULL_ALGORITHM );
111+ if (params .getConvexHullDetection ()) {
112+ Directory dirOutputConvexHull = new Directory (params .getOutputFolder () +
113+ ConvexHullDetection . CONVEX_HULL_ALGORITHM );
129114 dirOutputConvexHull .checkAndCreateDir ();
130115 }
131116 }
132117
133118
134- public NucleusSegmentation (ImageWrapper image , SegmentationParameters segmentationParameters , Client client )
119+ public NucleusSegmentation (ImageWrapper image , SegmentationParameters params , Client client )
135120 throws ServiceException , AccessException , ExecutionException {
136- this .segmentationParameters = segmentationParameters ;
121+ this .segmentationParameters = params ;
137122
138123 int [] cBound = {0 , 0 };
139124 this .imgRaw = image .toImagePlus (client , null , null , cBound , null , null );
@@ -145,9 +130,8 @@ public NucleusSegmentation(ImageWrapper image, SegmentationParameters segmentati
145130
146131
147132 // Changed HERE TO RETRIEVE ONLY ID, ALLOWING MULTI THREADING DOWNLOAD
148- public NucleusSegmentation (ImageWrapper image , ImagePlus imp , SegmentationParameters segmentationParameters ,
149- Client client ) {
150- this .segmentationParameters = segmentationParameters ;
133+ public NucleusSegmentation (ImageWrapper image , ImagePlus imp , SegmentationParameters params ) {
134+ this .segmentationParameters = params ;
151135
152136 this .imgRaw = imp ;
153137 // TODO ADD CHANNEL PARAMETERS (CASE OF CHANNELS UNSPLITED)
@@ -160,10 +144,10 @@ public NucleusSegmentation(ImageWrapper image, ImagePlus imp, SegmentationParame
160144 public NucleusSegmentation (ImageWrapper image ,
161145 ROIWrapper roi ,
162146 int i ,
163- SegmentationParameters segmentationParameters ,
147+ SegmentationParameters params ,
164148 Client client )
165149 throws ServiceException , AccessException , ExecutionException {
166- this .segmentationParameters = segmentationParameters ;
150+ this .segmentationParameters = params ;
167151
168152 List <RectangleWrapper > rectangles = roi .getShapes ().getElementsOf (RectangleWrapper .class );
169153
@@ -195,16 +179,17 @@ public NucleusSegmentation(ImageWrapper image,
195179 /**
196180 * Method to set a specific channel image
197181 *
198- * @param channelNumber channel number of the current image to analyse
182+ * @param imageFile
183+ * @param channel channel number of the current image to analyse
199184 *
200185 * @return channel image
201186 *
202187 * @throws IOException
203188 * @throws FormatException
204189 */
205- public ImagePlus getImageChannel (int channelNumber ) throws IOException , FormatException {
206- ImagePlus [] currentImage = BF .openImagePlus (currentFile .getAbsolutePath ());
207- currentImage = ChannelSplitter .split (currentImage [channelNumber ]);
190+ public static ImagePlus getImageChannel (File imageFile , int channel ) throws IOException , FormatException {
191+ ImagePlus [] currentImage = BF .openImagePlus (imageFile .getAbsolutePath ());
192+ currentImage = ChannelSplitter .split (currentImage [channel ]);
208193 return currentImage [0 ];
209194 }
210195
@@ -217,7 +202,8 @@ public ImagePlus getImageChannel(int channelNumber) throws IOException, FormatEx
217202 * @return
218203 */
219204 public String saveImageResult (ImagePlus [] segmentedImage ) {
220- this .measure3D = new Measure3D (segmentedImage , imgRaw , getXCalibration (), getYCalibration (), getZCalibration ());
205+ Measure3D measure3D = new Measure3D (segmentedImage , imgRaw ,
206+ getXCalibration (), getYCalibration (), getZCalibration ());
221207 return measure3D .nucleusParameter3D ();
222208 }
223209
@@ -294,7 +280,7 @@ public void findOTSUMaximisingSphericity() {
294280 }
295281
296282 if (bestThreshold != -1 ) {
297- morphologicalCorrection (imageSeg [0 ]);
283+ imageSeg [ 0 ] = morphologicalCorrection (imageSeg [0 ]);
298284 checkBorder (imageSeg [0 ]);
299285 }
300286 }
@@ -424,7 +410,7 @@ public boolean isBadCrop() {
424410 * @return array lis which contain at the index 0 the min valu and index 1 the max value
425411 */
426412 private static List <Integer > computeMinMaxThreshold (ImagePlus imagePlusInput ) {
427- List <Integer > arrayListMinMaxThreshold = new ArrayList <>();
413+ List <Integer > minMaxThreshold = new ArrayList <>(2 );
428414
429415 int threshold = Thresholding .computeOTSUThreshold (imagePlusInput );
430416 StackStatistics stackStatistics = new StackStatistics (imagePlusInput );
@@ -433,12 +419,12 @@ private static List<Integer> computeMinMaxThreshold(ImagePlus imagePlusInput) {
433419 double max = threshold + stdDev / 2 ;
434420
435421 if (min < 0 ) {
436- arrayListMinMaxThreshold .add (6 );
422+ minMaxThreshold .add (6 );
437423 } else {
438- arrayListMinMaxThreshold .add ((int ) min );
424+ minMaxThreshold .add ((int ) min );
439425 }
440- arrayListMinMaxThreshold .add ((int ) max );
441- return arrayListMinMaxThreshold ;
426+ minMaxThreshold .add ((int ) max );
427+ return minMaxThreshold ;
442428 }
443429
444430
@@ -476,11 +462,11 @@ private static boolean isVoxelThresholded(ImagePlus imagePlusSegmented,
476462 *
477463 * @param imagePlusSegmented image to be correct
478464 */
479- private static void morphologicalCorrection (ImagePlus imagePlusSegmented ) {
465+ private static ImagePlus morphologicalCorrection (ImagePlus imagePlusSegmented ) {
480466 computeOpening (imagePlusSegmented );
481467 computeClosing (imagePlusSegmented );
482468 // TODO FIX?
483- imagePlusSegmented = FillingHoles .apply2D (imagePlusSegmented );
469+ return FillingHoles .apply2D (imagePlusSegmented );
484470 }
485471
486472
@@ -780,9 +766,9 @@ public void saveOTSUSegmentedOMERO(Client client, Long output)
780766 public void saveConvexHullSeg () {
781767 LOGGER .info ("Computing and saving Convex Hull segmentation." );
782768 if (!badCrop && bestThreshold != -1 && segmentationParameters .getConvexHullDetection ()) {
783- imageSeg [0 ] = ConvexHullSegmentation .convexHullDetection (imageSeg [0 ], segmentationParameters );
769+ imageSeg [0 ] = ConvexHullSegmentation .convexHullDetection (imageSeg [0 ]);
784770 String pathConvexHullSeg = segmentationParameters .getOutputFolder () +
785- CONVEX_HULL_ALGORITHM + File .separator + imageSeg [0 ].getTitle ();
771+ ConvexHullDetection . CONVEX_HULL_ALGORITHM + File .separator + imageSeg [0 ].getTitle ();
786772 imageSeg [0 ].setTitle (pathConvexHullSeg );
787773 saveFile (imageSeg [0 ], pathConvexHullSeg );
788774 }
@@ -797,7 +783,7 @@ public void saveConvexHullSegOMERO(Client client, Long output)
797783 throws IOException , AccessException , ServiceException , ExecutionException , OMEROServerError {
798784 LOGGER .info ("Computing and saving Convex Hull segmentation." );
799785 if (!badCrop && bestThreshold != -1 && segmentationParameters .getConvexHullDetection ()) {
800- imageSeg [0 ] = ConvexHullSegmentation .convexHullDetection (imageSeg [0 ], segmentationParameters );
786+ imageSeg [0 ] = ConvexHullSegmentation .convexHullDetection (imageSeg [0 ]);
801787
802788 String path = new java .io .File ("." ).getCanonicalPath () //+ File.separator + CONVEX_HULL_ALGORITHM
803789 + File .separator + imageSeg [0 ].getTitle ();
0 commit comments