I do not know why your images get renamed, but I think the easiest way
to solve this is to use the getImageID() function, which returns a
unique ID for the active image, and then use the selectImage(id)
function to activate the image later. It has a few benefits: it's
faster, the IDs are unique, and the IDs don't change throughout macro
execution.
I think you can just replace the rename() and selectWindow()
statements you have now, and it should work. However, I believe
imageCalculator("or", img1, img2) does the same thing as all of those
select-copy-select-pastes, so you might use that in order to make the
code more succinct.
Justin
On 1/30/08, crieken <chris.rieken@gmail.com> wrote:
> 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 :confused:.
> 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");
>
> --
> View this message in context:
>
http://www.nabble.com/Help-with-ImageJ-macro-code-tp15195190p15195190.html> Sent from the ImageJ mailing list archive at Nabble.com.
>