Apply a recorded marco to multiple images. Help!

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Apply a recorded marco to multiple images. Help!

meiemi2000
Dear ImageJ gurus,

I am new to imageJ and would appreciate your help. I have been searching for a week and played with multiple code pieces without much success, so I think its time to ask.

I have images in RGB, where Red is for nuclear membrane, green is for channel of interest and blue is for DNA(not used in this macro). I want to use red to define the nuclear space (ROIs) and measure both red and green channels in these ROIs. Then I want to resize all ROIs to X% of the original ROIs and measure both red and green channels again. I recorded the macro and it runs fine, and it outputs four excel files.

Here is an example image.



Now, I want to apply the macro to a folder of images and have the output excel files titled with the original image file name (so I know which four files belong together). Can you help me to add the code to run this macro on multiple images? Or any pointer is highly appreciated!

Thanks a lot!

Here is the macro

//open RGB image first//

selectWindow("WT-0018.tif");

//split RGB channel//
run("Split Channels");

//slecte red channel (nuclear membrane) to defind the nuclear space, rename red channge as "red", green channel as "green"//
selectWindow("WT-0018.tif (red)");
run("Duplicate...", "title=red");
selectWindow("red");
selectWindow("WT-0018.tif (green)");
rename("green");
selectWindow("red");
run("Subtract Background...", "rolling=50");
setAutoThreshold("Default dark");
//run("Threshold...");
setAutoThreshold("Default dark");
setThreshold(21, 255);
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
run("Convert to Mask");
run("Analyze Particles...", "size=5-500 circularity=0.70-1.00 show=Outlines add");

//measure ROIs in the red channel and save as an excel file//
selectWindow("WT-0018.tif (red)");
roiManager("Measure");
saveAs("Results", "/Users/hueimeichen/Desktop/red100.xls");
run("Close");

//measure ROIs in the green channel and save as an excel file//
selectWindow("green");
roiManager("Measure");
saveAs("Results", "/Users/hueimeichen/Desktop/green100.xls");
run("Close");

//resize all ROIs to 80% with ROI centered//

count = roiManager("count");
current = roiManager("index");
for (i = 0; i < count; i++) {
 roiManager("select", i);

run("Scale... ", "x=0.8 y=0.8 centered");

roiManager("update")
}
selectWindow("WT-0018.tif (red)");
roiManager("select all")
roiManager("Measure");
saveAs("Results", "/Users/hueimeichen/Desktop/red80.xls");
run("Close");
selectWindow("green");
roiManager("select all")
roiManager("Measure");
saveAs("Results", "/Users/hueimeichen/Desktop/green80.xls");
run("Close");

//close all window//
selectWindow("green");
run("Close");
selectWindow("WT-0018.tif (red)");
run("Close");
selectWindow("red");
run("Close");
selectWindow("WT-0018.tif (blue)");
run("Close");
Reply | Threaded
Open this post in threaded view
|

Re: Apply a recorded marco to multiple images. Help!

ctrueden
Hi Huei Mei,

> I want to apply the macro to a folder of images

Have you looked at this page?
http://imagej.net/Batch_Processing

The Script Editor's "Process Folder" template (Templates > IJ1 Macro >
Process Folder) might be a good starting point for you.

Regards,
Curtis


On Mon, Sep 22, 2014 at 11:40 AM, meiemi2000 <[hidden email]>
wrote:

> Dear ImageJ gurus,
>
> I am new to imageJ and would appreciate your help. I have been searching
> for
> a week and played with multiple code pieces without much success, so I
> think
> its time to ask.
>
> I have images in RGB, where Red is for nuclear membrane, green is for
> channel of interest and blue is for DNA(not used in this macro). I want to
> use red to define the nuclear space (ROIs) and measure both red and green
> channels in these ROIs. Then I want to resize all ROIs to X% of the
> original
> ROIs and measure both red and green channels again. I recorded the macro
> and
> it runs fine, and it outputs four excel files.
>
> Here is an example image.
> <http://imagej.1557.x6.nabble.com/file/n5009711/WT-0016.jpg>
>
>
> Now, I want to apply the macro to a folder of images and have the output
> excel files titled with the original image file name (so I know which four
> files belong together). Can you help me to add the code to run this macro
> on
> multiple images? Or any pointer is highly appreciated!
>
> Thanks a lot!
>
> Here is the macro
>
> //open RGB image first//
>
> selectWindow("WT-0018.tif");
>
> //split RGB channel//
> run("Split Channels");
>
> //slecte red channel (nuclear membrane) to defind the nuclear space, rename
> red channge as "red", green channel as "green"//
> selectWindow("WT-0018.tif (red)");
> run("Duplicate...", "title=red");
> selectWindow("red");
> selectWindow("WT-0018.tif (green)");
> rename("green");
> selectWindow("red");
> run("Subtract Background...", "rolling=50");
> setAutoThreshold("Default dark");
> //run("Threshold...");
> setAutoThreshold("Default dark");
> setThreshold(21, 255);
> setOption("BlackBackground", true);
> run("Convert to Mask");
> run("Fill Holes");
> run("Convert to Mask");
> run("Analyze Particles...", "size=5-500 circularity=0.70-1.00 show=Outlines
> add");
>
> //measure ROIs in the red channel and save as an excel file//
> selectWindow("WT-0018.tif (red)");
> roiManager("Measure");
> saveAs("Results", "/Users/hueimeichen/Desktop/red100.xls");
> run("Close");
>
> //measure ROIs in the green channel and save as an excel file//
> selectWindow("green");
> roiManager("Measure");
> saveAs("Results", "/Users/hueimeichen/Desktop/green100.xls");
> run("Close");
>
> //resize all ROIs to 80% with ROI centered//
>
> count = roiManager("count");
> current = roiManager("index");
> for (i = 0; i < count; i++) {
>  roiManager("select", i);
>
> run("Scale... ", "x=0.8 y=0.8 centered");
>
> roiManager("update")
> }
> selectWindow("WT-0018.tif (red)");
> roiManager("select all")
> roiManager("Measure");
> saveAs("Results", "/Users/hueimeichen/Desktop/red80.xls");
> run("Close");
> selectWindow("green");
> roiManager("select all")
> roiManager("Measure");
> saveAs("Results", "/Users/hueimeichen/Desktop/green80.xls");
> run("Close");
>
> //close all window//
> selectWindow("green");
> run("Close");
> selectWindow("WT-0018.tif (red)");
> run("Close");
> selectWindow("red");
> run("Close");
> selectWindow("WT-0018.tif (blue)");
> run("Close");
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Apply-a-recorded-marco-to-multiple-images-Help-tp5009711.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Apply a recorded marco to multiple images. Help!

Reisak
In reply to this post by meiemi2000