ijpb / MorphoLibJ

Collection of mathematical morphology methods and plugins for ImageJ
http://imagej.net/MorphoLibJ
GNU Lesser General Public License v3.0
101 stars 48 forks source link

In macro going through slices, Geodesic Distance Map (2D) stops after the first slice #52

Open linshaova opened 3 years ago

linshaova commented 3 years ago

Hello MorphoLibJ developers,

I'm trying to generate Geodesic Distance Map (GDM) for a series of of 2D masks stored in a 3D stack, together with a marker stack of the same dimensions. What I noticed is that if I perform anything with the GDM output image before closing it, the for loop would just exit after the first slice. Here is my simple IJ macro script:

mask = "motion_compen_mask.tif";
marker = "Mask3d.tif";
selectWindow(mask);
print(nSlices);

for (i=0; i<nSlices; i++) {
  print(i);
  selectWindow(mask);
  setSlice(i+1);
  selectWindow(marker);
  setSlice(i+1);
  run("Geodesic Distance Map", "marker="+marker+" mask="+mask+" distances=[Chessknight (5,7,11)] output=[32 bits] 
  normalize");
  gdwindow = getTitle();
// If I do anything here before closing the GDM output window, the for loop would just exit after i=0
// For example, a simple duplication of the GDM output would make it exit after i=0:
  run("Duplicate...", "title=dup");
// If you comment out the above line, the for loop would run through
  print("here");
  close(gdwindow);
// If close() is not called here, the for loop would also exit after i=0, no matter if anything was done to gdwindow
}
print("loop exited");

Could this a be a bug or by design? I'm attaching a ZIP file with the two TIFF files used in this script. Thank you very much!

--lin

tiffs.zip

dlegland commented 3 years ago

Hi,

well, this seems to be strange... I do not have clear idea right now.

Just to clarify, what do you want as output? Another 3D stack containing the concatenation of each slice processing?

linshaova commented 3 years ago

Yes, exactly! My plan was to duplicate the GDM result into another window for the 1st slice, and then append the results from subsequent slices to this window to form a 3D stack of 2D-GDM results.

I found a work-around since the first posting: after each slice's processing, I could save the result into a TIFF (i.e., one TIFF per slice) without interrupting the for loop, and then import the 2D TIFFs as a sequence. But of course it'd be nicer to not have to have this intermediate step.

Thank you!

lin

linshaova commented 3 years ago

Forgot to mention that I have an almost identical experience with applying Marker-Controlled Watershed (MCW) on a series of 2D slices from 3D stacks input. And the same saving-result-into-one-TIFF-per-slice workaround works. The only difference is that for MCW to work in 2D mode with 3D stacks as inputs, I had to duplicate the slices of the same slice# from the input stacks and use the those slices as input to MCW; just setSlice(i+1) wouldn't be enough, which is fine.

lin