Help with macro

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

Help with macro

Pablo Munoz-2
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
Reply | Threaded
Open this post in threaded view
|

Re: Help with macro

Aryeh Weiss
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
Reply | Threaded
Open this post in threaded view
|

Re: Help with macro

Miguel Tapia R.
In reply to this post by Pablo Munoz-2
hi Pablo,

You could try to add the following lines to the beginning of your macro:

dir=getDirectory("Choose a Directory");
print(dir);
splitDir=dir + "\Treatments\\";
print(splitDir);
File.makeDirectory(splitDir);
list = getFileList(dir);

for (i=0; i<list.length; i++) {
     if (endsWith(list[i], ".lsm")){
               print(i + ": " + dir+list[i]);
             open(dir+list[i]);
             imgName=getTitle();
         baseNameEnd=indexOf(imgName, ".lsm");
         baseName=substring(imgName, 0, baseNameEnd);


and at the end the following:

saveAs("Tiff", splitDir+baseName + "-new.tif");
         
         close();
         close();
     }
     }


hope it helps, i'm new to the macro writing too


Miguel

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

Re: Help with macro

jerie
In reply to this post by Pablo Munoz-2
Dear Pablo,

a viable option to apply recorded macros to a number of files in a set
directory is by using http://imagej.net/Batch_Processing.

Hope that helps,

Abraços, Jens

Dr. Jens Rietdorf, visiting scientist @ center for technological
development in health CDTS, Oswaldo Cruz Foundation Fiocruz, Rio de Janeiro
Brasil.

On Tue, Dec 6, 2016 at 3:59 PM, Pablo M <[hidden email]> 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
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Jens Rietdorf Visiting Scientist Fundação Oswaldo Cruz - Ministério da Saúde, Centro de Desenvolvimento Tecnológico em Saúde (CDTS), Rio de Janeiro, Brasil.
Reply | Threaded
Open this post in threaded view
|

Re: Help with macro

Pablo Munoz-2
thank you all for the answers.e
I could manage to call a directory
Although now my biggest problem is how to solve this part of my macro

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");

I still do not know what to write in the name of the images (red) so my
macro can be more generic




On Tue, Dec 6, 2016 at 2:25 PM jens rietdorf <[hidden email]> wrote:

> Dear Pablo,
>
> a viable option to apply recorded macros to a number of files in a set
> directory is by using http://imagej.net/Batch_Processing.
>
> Hope that helps,
>
> Abraços, Jens
>
> Dr. Jens Rietdorf, visiting scientist @ center for technological
> development in health CDTS, Oswaldo Cruz Foundation Fiocruz, Rio de Janeiro
> Brasil.
>
> On Tue, Dec 6, 2016 at 3:59 PM, Pablo M <[hidden email]> 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
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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