Login  Register

Help with ImageJ macro code

Posted by crieken on Jan 31, 2008; 12:24am
URL: http://imagej.273.s1.nabble.com/Help-with-ImageJ-macro-code-tp3697312.html

Hi all, I hope this is an appropriate place for this question.  I'm writing a macro to put together a mask from three images with multiple channels.  I am making progress on the macro, but as I test it, I'm running into a problem.  When the 402nm image is opened, the windows "Z" and "W" are named properly.  When the 488nm image is opened, the windows "A", "C", and "D" are named fine, but the "Z" and "W" windows are renamed to "1".  This messes up the creation of the mask and will mess up the analysis that will come further down the line.  I have even tried saving each image individually, but the names still get reset.  This only occurs occasionally, though.  Does anyone have any ideas?  I can email the original images if it would help.  Thanks in advance!  BTW, this may not be the most elegant code, but go easy, I'm a beginner .
Chris

//Selects directory to save files to
dir = getDirectory("Select save directory");

//Prompt for 402nm image
var violet = "Open a 402nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("402nm");
  Dialog.addMessage(violet);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Closes 402 unassigned, 402 background, and renames channel 2 as "Z" and channel 1 as "W"
close();
close();
rename("Z");
run("Put Behind [tab]");
rename("W");

//Prompt for 488nm image
var blue = "Open a 488nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("488nm");
  Dialog.addMessage(blue);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Converts stack to images
run("Convert Stack to Images");

//Closes 488 unassigned, 488 background, E_488 and renames channel 3 as "D", channel 2 as "C", and channel 1 as "A"
close();
close();
close();
rename("D");
run("Put Behind [tab]");
rename("C");
run("Put Behind [tab]");
rename("A");

//Prompt for 561nm image
var green = "Open a 561nm image";  
requires("1.34m");
  title = "Untitled";
  width=512; height=512;
  Dialog.create("561nm");
  Dialog.addMessage(green);
  Dialog.show();

//Run ICS opener
run("ICS/IDS... ");

//Converts stack to images
run("Convert Stack to Images");

//Closes 561 unassigned, 561 background, and renames channel 3 as "gamma", channel 2 as "F", and channel 1 as "E"
close();
close();
rename("gamma");
run("Put Behind [tab]");
rename("F");
run("Put Behind [tab]");
rename("E");

//Create a mask
run("Duplicate...", "title=Mask");
run("Paste Control...");
setPasteMode("OR");
selectWindow("F");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("gamma");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("D");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("C");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("A");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("Z");
run("Copy");
selectWindow("Mask");
run("Paste");
selectWindow("W");
run("Copy");
selectWindow("Mask");
run("Paste");