Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
linshaova opened this issue Apr 28, 2021 · 3 comments

Comments

@linshaova
Copy link

linshaova commented Apr 28, 2021

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants