Login  Register

Re: Help with macro

Posted by Aryeh Weiss on Dec 06, 2016; 6:44pm
URL: http://imagej.273.s1.nabble.com/Help-with-macro-tp5017698p5017700.html

Dear Pablo

The short answer to your question is that your filename is "hard-coded"
into the recorded commands, and therefore the code will not work on an
image with a different name.
So you need to do something like:
imageName = getTitle(); // assumes the image you want to process is
selected (active)
and then use imageName in place of the hard coded names.

However, what you really need to do is check out:
Macro Programming in ImageJ
http://wiki.cmci.info/documents/ijcourses

and particularly page 76, which will tell you how to read a list of
files and process them.

It will involve some learning curve on your part, but it will pay off.

God luck
--aryeh

On 06/12/2016 19:59, Pablo M wrote:

> Dear ImageJ community,
>
> I want to create  a macro  to analyse a complete folder of my images since
> I do not know how to write the macro I am using the macro record tool.
>
> This is the macro with my instructions,
>
>   selectWindow("1 control.lsm");
> run("Subtract Background...", "rolling=300 stack");
> run("Median...", "radius=1.2 stack");
> run("StackReg", "transformation=Translation disable_global");
> run("Split Channels");
> selectWindow("C1-1 control.lsm");
> run("Duplicate...", "title=CFP");
> setAutoThreshold("Default dark");
> //run("Threshold...");
> setOption("BlackBackground", false);
> run("Convert to Mask");
> run("Divide...", "value=255.000");
> imageCalculator("Divide create 32-bit", "C2-1 control.lsm","C1-1
> control.lsm");
> selectWindow("Result of C2-1 control.lsm");
> imageCalculator("Divide create 32-bit", "Result of C2-1 control.lsm","CFP");
> selectWindow("Result of Result of C2-1 control.lsm");
> run("16 colors");
> run("Scale Bar...", "width=30 height=8 font=28 color=White background=None
> location=[Lower Right] bold");
> run("Calibration Bar...", "location=[Upper Right] fill=White label=Black
> number=5 decimal=1 font=12 zoom=2");
>
> My problem is when I try to do this with another image with differents name
> (e.g 1 Treatment.lsm, 2 Treatment.lsm , etc) the macro does not work.
> I would like to do this process to a complete folder of images which the
> name of the images are different and save the result in another folder.
>
>   Furthermore, I would like that the macro asks me to adjust the Threshold.
>
> Any suggestion and help I will really appreciate and will save me a lot of
> hour behind the computer.
>
> Thanks in advance.
>
> Pablo M.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html