@@ -120,16 +120,17 @@ public static Client checkOMEROConnection(String hostname,
120120 }
121121
122122
123- private static void cropImageFromOMERO2 (Client client , ImageWrapper image , ImageWrapper imageToCrop ,
124- DatasetWrapper outputDataset , int c )
123+ private static void cropImageFromOMERO (Client client , ImageWrapper image ,
124+ ImageWrapper imageToCrop ,
125+ DatasetWrapper outputDataset , int c )
125126 throws AccessException , ServiceException , ExecutionException , IOException , OMEROServerError {
126- List <ROIWrapper > rois = image .getROIs (client );
127- List <ChannelWrapper > canaux = imageToCrop .getChannels (client );
128- if (c > canaux .size () - 1 ) {
127+ List <ROIWrapper > rois = image .getROIs (client );
128+ List <ChannelWrapper > channels = imageToCrop .getChannels (client );
129+ if (c > channels .size () - 1 ) {
129130 LOGGER .debug ("Channel doesn't exists, there are only {} channels, first channel index is 0 !" ,
130- canaux .size ());
131+ channels .size ());
131132 } else {
132- LOGGER .debug ("Number of channels detected : {}" , canaux .size ());
133+ LOGGER .debug ("Number of channels detected : {}" , channels .size ());
133134 for (ROIWrapper roi : rois ) {
134135 // Get the roi names
135136 String roiName = roi .getName ();
@@ -141,30 +142,32 @@ private static void cropImageFromOMERO2(Client client, ImageWrapper image, Image
141142 // Get the image to crop
142143 ImagePlus imp = imageToCrop .toImagePlus (client , roi );
143144 // Save Crop File
144- FileSaver fileSaver = new FileSaver (imp );
145- String sortie = fileSaver .toString ();
145+ FileSaver fileSaver = new FileSaver (imp );
146+ String resultPath = fileSaver .toString ();
146147 // Save the crop as TIF
147- fileSaver .saveAsTiff (sortie );
148+ fileSaver .saveAsTiff (resultPath );
148149 // generate a temporary file
149- String resultPath = sortie ;
150- File resultFile = new File (resultPath );
150+ File resultFile = new File (resultPath );
151151 // Remove file extension
152152 FilesNames outPutFilesNames = new FilesNames (imageToCropName );
153153 String prefix = outPutFilesNames .prefixNameFile ();
154154 // Rename the temporary file same as toCrop Image name
155155 File toCropNewName = new File (prefix + "_" + roiName + "_C" + c );
156- resultFile .renameTo (toCropNewName );
157- String toCropFile = toCropNewName .toString ();
158- // Import Cropped Image to the Dataset
159- outputDataset .importImages (client , toCropFile );
160- // Delete temp file
161- Files .deleteIfExists (toCropNewName .toPath ());
156+ if (resultFile .renameTo (toCropNewName )) {
157+ String toCropFile = toCropNewName .toString ();
158+ // Import Cropped Image to the Dataset
159+ outputDataset .importImages (client , toCropFile );
160+ // Delete temp file
161+ Files .deleteIfExists (toCropNewName .toPath ());
162+ }
162163 }
163164 }
164165 }
165166
166167
167- private static void cropImageFromOMERO (Client client , ImageWrapper image , ImageWrapper imageToCrop ,
168+ private static void cropImageFromOMERO (Client client ,
169+ ImageWrapper image ,
170+ ImageWrapper imageToCrop ,
168171 DatasetWrapper outputDataset )
169172 throws AccessException , ServiceException , ExecutionException , IOException , OMEROServerError {
170173 List <ROIWrapper > rois = image .getROIs (client );
@@ -176,24 +179,24 @@ private static void cropImageFromOMERO(Client client, ImageWrapper image, ImageW
176179 // Get the image to crop
177180 ImagePlus imp = imageToCrop .toImagePlus (client , roi );
178181 // Save Crop File
179- FileSaver fileSaver = new FileSaver (imp );
180- String sortie = fileSaver .toString ();
182+ FileSaver fileSaver = new FileSaver (imp );
183+ String resultPath = fileSaver .toString ();
181184 // Save the crop as TIF
182- fileSaver .saveAsTiff (sortie );
185+ fileSaver .saveAsTiff (resultPath );
183186 // generate a temporary file
184- String resultPath = sortie ;
185- File resultFile = new File (resultPath );
187+ File resultFile = new File (resultPath );
186188 // Remove file extension
187189 FilesNames outPutFilesNames = new FilesNames (imageToCropName );
188190 String prefix = outPutFilesNames .prefixNameFile ();
189191 // Rename the temporary file same as toCrop Image name
190192 File toCropNewName = new File (prefix + "_" + roiName );
191- resultFile .renameTo (toCropNewName );
192- String toCropFile = toCropNewName .toString ();
193- // Import Cropped Image to the Dataset
194- outputDataset .importImages (client , toCropFile );
195- // Delete temp file
196- Files .deleteIfExists (toCropNewName .toPath ());
193+ if (resultFile .renameTo (toCropNewName )) {
194+ String toCropFile = toCropNewName .toString ();
195+ // Import Cropped Image to the Dataset
196+ outputDataset .importImages (client , toCropFile );
197+ // Delete temp file
198+ Files .deleteIfExists (toCropNewName .toPath ());
199+ }
197200 }
198201 }
199202
@@ -228,7 +231,7 @@ public void runOMERO() throws AccessException, ServiceException, ExecutionExcept
228231
229232 try {
230233 LOGGER .info ("Begin Autocrop from coordinate process " );
231- cropImageFromOMERO2 (client , image , imageToCrop , outputds , channel ); // Ru
234+ cropImageFromOMERO (client , image , imageToCrop , outputds , channel ); // Ru
232235 } catch (AccessException | OMEROServerError | ServiceException | IOException | ExecutionException e ) {
233236 LOGGER .info ("Autocrop from coordinate process has failed" );
234237 LOGGER .error ("An error occurred." , e );
0 commit comments