Skip to content

Commit c5b8f5f

Browse files
committed
Handle different possible divisions by zero and remove unused variables/methods
1 parent d153a15 commit c5b8f5f

16 files changed

Lines changed: 52 additions & 205 deletions

src/main/java/gred/nucleus/autocrop/AutoCrop.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ public class AutoCrop {
7878
/** The path of the image to be processed */
7979
private final String imageFilePath;
8080

81-
/** File to process (Image input) */
82-
private final File currentFile;
83-
8481
/** Raw image */
8582
private ImagePlus rawImg;
8683
/** Segmented image */
@@ -114,7 +111,6 @@ public class AutoCrop {
114111
public AutoCrop(File imageFile, String outputFilesPrefix, AutocropParameters autocropParametersAnalyse)
115112
throws IOException, FormatException {
116113
this.autocropParameters = autocropParametersAnalyse;
117-
this.currentFile = imageFile;
118114
this.imageFilePath = imageFile.getAbsolutePath();
119115
this.outputDirPath = autocropParameters.getOutputFolder();
120116
this.outputFilesPrefix = outputFilesPrefix;
@@ -130,7 +126,6 @@ public AutoCrop(File imageFile, String outputFilesPrefix, AutocropParameters aut
130126

131127
public AutoCrop(ImageWrapper image, AutocropParameters autocropParametersAnalyse, Client client)
132128
throws ServiceException, AccessException, ExecutionException {
133-
this.currentFile = new File(image.getName());
134129
this.autocropParameters = autocropParametersAnalyse;
135130
this.outputDirPath = autocropParameters.getOutputFolder();
136131
this.outputFilesPrefix = FilenameUtils.removeExtension(image.getName());
@@ -154,7 +149,6 @@ public AutoCrop(File imageFile,
154149
Map<Double, Box> boxes)
155150
throws IOException, FormatException {
156151
this.autocropParameters = autocropParametersAnalyse;
157-
this.currentFile = imageFile;
158152
this.imageFilePath = imageFile.getAbsolutePath();
159153
this.outputDirPath = autocropParameters.getOutputFolder();
160154
this.outputFilesPrefix = outputFilesPrefix;

src/main/java/gred/nucleus/autocrop/GenerateOverlay.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ private Map<File, File> gatherFilePairs() {
9292
private LUT getNucleiLUT() throws IOException {
9393
InputStream in = getClass().getResourceAsStream("/overlay/LUT.txt");
9494
BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
95-
BufferedWriter bw = new BufferedWriter(new FileWriter("./tmp-LUT.txt"));
96-
String l;
97-
while ((l = br.readLine()) != null) {
98-
bw.write(l + "\n");
95+
try (BufferedWriter bw = new BufferedWriter(new FileWriter("./tmp-LUT.txt"))) {
96+
String l = br.readLine();
97+
while(l != null) {
98+
bw.write(l);
99+
bw.newLine();
100+
l = br.readLine();
101+
}
99102
}
100-
bw.close();
101103
LUT fire = LutLoader.openLut("./tmp-LUT.txt");
102104
Files.delete(Paths.get("./tmp-LUT.txt"));
103105
return fire;

src/main/java/gred/nucleus/cli/CLIHelper.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ private static void specificAction(String action) {
244244
break;
245245

246246
default:
247-
exampleArgument = "-action segmentation " +
248-
"-input path/to/input/folder/ " +
249-
"-output path/to/output/folder/ ";
250-
exampleCMD = exampleArgument.split(" ");
251-
CLIActionOptions wrongAction = new CLIActionOptions(exampleCMD);
252247
System.console().writer().println("Invalid action \"" + action + "\" :\n");
253248
System.console().writer().println(CLIActionOptions.getHelperInfo());
254249
break;

src/main/java/gred/nucleus/core/ChromocentersEnhancement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static double[] computeContrast(ImagePlus imagePlusRaw, ImagePlus imageP
128128
neighborVolumeTotal += tRegionAdjacencyGraph[i][j];
129129
}
130130
}
131-
if (tContrast[i] <= 0) {
131+
if (tContrast[i] <= 0 || neighborVolumeTotal == 0) {
132132
tContrast[i] = 0;
133133
} else {
134134
tContrast[i] /= neighborVolumeTotal;

src/main/java/gred/nucleus/core/Measure3D.java

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -82,49 +82,6 @@ public Measure3D(ImagePlus[] imageSegs, ImagePlus rawImage, double xCal, double
8282
}
8383

8484

85-
/**
86-
* Scan of image and if the voxel belong to the object of interest, looking, if in his neighborhood there are voxel
87-
* value == 0 then it is a boundary voxel. Adding the surface of the face of the voxel frontier, which are in
88-
* contact with the background of the image, to the surface total.
89-
*
90-
* @param label label of the interest object
91-
*
92-
* @return the surface
93-
*/
94-
public double computeSurfaceObject(double label) {
95-
ImageStack imageStackInput = imageSegs[0].getStack();
96-
double surfaceArea = 0, voxelValue, neighborVoxelValue;
97-
for (int k = 1; k < imageSegs[0].getStackSize(); ++k) {
98-
for (int i = 1; i < imageSegs[0].getWidth(); ++i) {
99-
for (int j = 1; j < imageSegs[0].getHeight(); ++j) {
100-
voxelValue = imageStackInput.getVoxel(i, j, k);
101-
if (voxelValue == label) {
102-
for (int kk = k - 1; kk <= k + 1; kk += 2) {
103-
neighborVoxelValue = imageStackInput.getVoxel(i, j, kk);
104-
if (voxelValue != neighborVoxelValue) {
105-
surfaceArea += xCal * yCal;
106-
}
107-
}
108-
for (int ii = i - 1; ii <= i + 1; ii += 2) {
109-
neighborVoxelValue = imageStackInput.getVoxel(ii, j, k);
110-
if (voxelValue != neighborVoxelValue) {
111-
surfaceArea += yCal * zCal;
112-
}
113-
}
114-
for (int jj = j - 1; jj <= j + 1; jj += 2) {
115-
neighborVoxelValue = imageStackInput.getVoxel(i, jj, k);
116-
if (voxelValue != neighborVoxelValue) {
117-
surfaceArea += xCal * zCal;
118-
}
119-
}
120-
}
121-
}
122-
}
123-
}
124-
return surfaceArea;
125-
}
126-
127-
12885
/**
12986
* This Method compute the volume of each segmented objects in imagePlus
13087
*
@@ -474,7 +431,7 @@ public static double computeIntensityRHF(ImagePlus imagePlusInput
474431
}
475432
}
476433
}
477-
return chromocenterIntensity / nucleusIntensity;
434+
return nucleusIntensity != 0 ? chromocenterIntensity / nucleusIntensity : 0;
478435
}
479436

480437

@@ -716,7 +673,7 @@ private double meanIntensity() {
716673
numberOfVoxel += hist.getValue();
717674
mean += hist.getKey() * hist.getValue();
718675
}
719-
return mean / numberOfVoxel;
676+
return numberOfVoxel != 0 ? mean / numberOfVoxel : 0;
720677
}
721678

722679

@@ -740,8 +697,7 @@ private double meanIntensityBackground() {
740697
}
741698
}
742699
}
743-
meanIntensity /= voxelCounted;
744-
return meanIntensity;
700+
return voxelCounted != 0 ? meanIntensity / voxelCounted : 0;
745701
}
746702

747703

@@ -891,7 +847,6 @@ public String nucleusParameter3D() {
891847
histogramSegmentedNucleus();
892848

893849
double volume = computeVolumeObjectML();
894-
double surfaceArea = computeSurfaceObject(255);
895850
double surfaceAreaNew = computeComplexSurface();
896851
double[] tEigenValues = computeEigenValue3D(255);
897852
compute2dParameters();
@@ -912,9 +867,9 @@ public String nucleusParameter3D() {
912867
+ medianIntensityNucleus() + ","
913868
+ medianIntensityBackground() + ","
914869
+ rawImage.getHeight() * rawImage.getWidth() * rawImage.getNSlices() + ","
915-
+ computeEigenValue3D(255)[0] + ","
916-
+ computeEigenValue3D(255)[1] + ","
917-
+ computeEigenValue3D(255)[2] + ","
870+
+ tEigenValues[0] + ","
871+
+ tEigenValues[1] + ","
872+
+ tEigenValues[2] + ","
918873
+ getAspectRatio() + ","
919874
+ getCirculairty();
920875
return results;

src/main/java/gred/nucleus/core/NucleusSegmentation.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,6 @@ public class NucleusSegmentation {
8383
private ImagePlus[] imageSeg;
8484

8585

86-
/**
87-
* Constructor for the segmentation analysis for a single image.
88-
*
89-
* @param imgRaw raw image to analyse
90-
* @param vMin minimum volume of detected object
91-
* @param vMax maximum volume of detected object
92-
* @param segmentationParameters list the parameters for the analyse
93-
*
94-
* @throws IOException
95-
* @throws FormatException
96-
*/
97-
public NucleusSegmentation(ImagePlus imgRaw,
98-
int vMin,
99-
int vMax,
100-
SegmentationParameters segmentationParameters)
101-
throws IOException, FormatException {
102-
this.vMin = vMin;
103-
this.vMax = vMax;
104-
this.segmentationParameters = segmentationParameters;
105-
this.imgRaw = imgRaw;
106-
this.imgRaw = getImageChannel(0);
107-
this.imgRawTransformed = this.imgRaw;
108-
}
109-
110-
11186
/**
11287
* Constructor for the segmentation analysis for a folder containing images.
11388
*

src/main/java/gred/nucleus/dialogs/SegmentationConfigDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public boolean isCalibrationSelected() {
184184
@Override
185185
public void itemStateChanged(ItemEvent e) {
186186
if (e.getSource() == convexHullDetection) {
187-
Boolean isConvexHullDetection = convexHullDetection.isSelected();
187+
boolean isConvexHullDetection = convexHullDetection.isSelected();
188188
} else if (e.getSource() == addCalibrationBox) {
189189
if (addCalibrationBox.isSelected()) {
190190

src/main/java/gred/nucleus/process/ChromocenterCalling.java

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@
1717
import loci.common.DebugTools;
1818
import loci.formats.FormatException;
1919
import loci.plugins.BF;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
2022

2123
import java.io.File;
2224
import java.io.IOException;
25+
import java.lang.invoke.MethodHandles;
2326
import java.nio.file.Files;
2427
import java.util.List;
2528
import java.util.concurrent.ExecutionException;
2629

2730

2831
public class ChromocenterCalling {
32+
/** Logger */
33+
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
34+
2935
private final ChromocenterParameters chromocenterParameters;
3036

3137
private String prefix;
@@ -77,7 +83,7 @@ public void runSeveralImages2() throws IOException, FormatException {
7783
file.mkdir();
7884
}
7985
// TODO A REFAIRE C EST MOCHE !!!!
80-
System.out.println("size: " + directoryInput.getNumberFiles());
86+
LOGGER.info("size: {}", directoryInput.getNumberFiles());
8187

8288
if (isGui) {
8389
progress = new Progress("Images Analysis: ", directoryInput.getNumberFiles());
@@ -139,7 +145,7 @@ public void SegmentationOMERO(String inputDirectoryRaw,
139145
if ("Image".equals(param[0]) && "Image".equals(param1[0])) {
140146
runOneImageOMERO(imageID, maskID, outputDirectory, client);
141147
} else if ("Dataset".equals(param[0]) && "Dataset".equals(param1[0])) {
142-
String dataset_name = client.getDataset(imageID).getName();
148+
String datasetName = client.getDataset(imageID).getName();
143149
List<ImageWrapper> images;
144150
List<ImageWrapper> masks;
145151
/* get raw images and masks datasets*/
@@ -148,8 +154,8 @@ public void SegmentationOMERO(String inputDirectoryRaw,
148154
/* get images List */
149155
images = imageDataset.getImages(client);
150156
/* Create Dataset named NodeJOMERO */
151-
outDataset = new DatasetWrapper("NODeJ_" + dataset_name, "");
152-
DatasetWrapper outDatasetGradient = new DatasetWrapper("NODeJ_" + dataset_name + "_Gradient", "");
157+
outDataset = new DatasetWrapper("NODeJ_" + datasetName, "");
158+
DatasetWrapper outDatasetGradient = new DatasetWrapper("NODeJ_" + datasetName + "_Gradient", "");
153159
project = client.getProject(Long.parseLong(outputDirectory));
154160
/* Add Dataset To the Project */
155161
Long datasetId = project.addDataset(client, outDataset).getId();
@@ -164,7 +170,7 @@ public void SegmentationOMERO(String inputDirectoryRaw,
164170
/* Get the mask with the same name */
165171
masks = maskDataset.getImages(client, imageName);
166172
/* Run Segmentation */
167-
runSeveralImagesOMERO(image, masks.get(0), dataset_name, client);
173+
runSeveralImagesOMERO(image, masks.get(0), datasetName, client);
168174
/* Import Segmented cc to the Dataset*/
169175
outDataset.importImages(client, segImg);
170176
outDatasetGradient.importImages(client, gradImg);
@@ -218,8 +224,7 @@ public void runOneImageOMERO(Long inputDirectoryRaw, Long inputDirectorySeg, Str
218224
ImagePlus[] rawImage = {image.toImagePlus(client)};
219225
ImagePlus[] segImage = {mask.toImagePlus(client)};
220226

221-
String diffDir = chromocenterParameters.outputFolder + "gradientImage";
222-
String segCcDir = chromocenterParameters.outputFolder + "SegCC";
227+
String diffDir = chromocenterParameters.outputFolder + "gradientImage";
223228

224229
FilesNames outPutFilesNames = new FilesNames(imageName);
225230
this.prefix = outPutFilesNames.prefixNameFile();
@@ -283,8 +288,7 @@ public void runSeveralImagesOMERO(ImageWrapper image, ImageWrapper mask, String
283288
ImagePlus[] rawImage = {image.toImagePlus(client)};
284289
ImagePlus[] segImage = {mask.toImagePlus(client)};
285290

286-
String diffDir = chromocenterParameters.outputFolder + "gradientImage";
287-
String segCcDir = chromocenterParameters.outputFolder + "SegCC";
291+
String diffDir = chromocenterParameters.outputFolder + "gradientImage";
288292

289293
FilesNames outPutFilesNames = new FilesNames(imageName);
290294

@@ -318,45 +322,6 @@ public void runSeveralImagesOMERO(ImageWrapper image, ImageWrapper mask, String
318322
}
319323

320324

321-
/**
322-
* Run the Chromocenter segmentation on a single image
323-
*
324-
* @throws IOException
325-
* @throws FormatException
326-
*/
327-
public void just3D() throws IOException, FormatException {
328-
DebugTools.enableLogging("OFF");
329-
Directory directoryInput = new Directory(chromocenterParameters.getInputFolder());
330-
directoryInput.listImageFiles(chromocenterParameters.getInputFolder());
331-
directoryInput.checkIfEmpty();
332-
String rhfChoice = "Volume";
333-
String nameFileChromocenter = chromocenterParameters.outputFolder + "CcParameters.tab";
334-
335-
String segCcDir = chromocenterParameters.outputFolder;
336-
337-
// TODO A REFAIRE C EST MOCHE !!!!
338-
System.out.println("size: " + directoryInput.getNumberFiles());
339-
340-
for (short i = 0; i < directoryInput.getNumberFiles(); ++i) {
341-
File currentFile = directoryInput.getFile(i);
342-
String fileImg = currentFile.toString();
343-
344-
ImagePlus[] raw = BF.openImagePlus(currentFile.getAbsolutePath());
345-
imageType(raw[0]);
346-
String outputFileName = segCcDir + File.separator + currentFile.getName();
347-
ImagePlus[] segNuc = BF.openImagePlus(chromocenterParameters.segInputFolder +
348-
File.separator +
349-
currentFile.getName());
350-
351-
NucleusChromocentersAnalysis.compute3DParameters(rhfChoice,
352-
raw[0],
353-
segNuc[0],
354-
IJ.openImage(outputFileName),
355-
chromocenterParameters);
356-
}
357-
}
358-
359-
360325
/**
361326
* @param img
362327
*/

0 commit comments

Comments
 (0)