AW: run macro

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

AW: run macro

Helmut Bergen
Hello

I try to do this into 1 large macro. The problem is that the second macro
needs the original picture and there is coming up a problem report, because
the second macro don't select the original picture . My idea is:

1) Open a picture/ or batch macro with a folder of pictures
2) first macro and rename and save the ORIGINAL picture
3) second macro and rename and save the ORIGINAL picture
4) etc.

If I run the macros one after the other it is all ok. But to do this task in
one idea

Thanks
Helmut

-----Ursprüngliche Nachricht-----
Von: Senseney, Justin (NIH/CIT) [G] [mailto:[hidden email]]
Gesendet: Mittwoch, 24. April 2013 14:57
An: Helmut Bergen
Betreff: RE: run macro

Helmut,

Since the macros are just plain text, I would recommend copying and pasting
the 4 macros into 1 large macro and running that.  But maybe there is
another way.  Would you mind posting this question on the main ImageJ list?
It's [hidden email]  I will subscribe you to that list.

Thanks,
Justin Senseney
________________________________
From: Helmut Bergen [[hidden email]]
Sent: Wednesday, April 24, 2013 6:57 AM
To: [hidden email]
Subject: run macro

Hello

I want to run four recorded macros with one macro. I hope this is possible
and get some helps.

Thanks and best regards
Helmut

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

Re: AW: run macro

George Patterson-3
Hi Helmut,
I'm a little unclear about what you're trying to do.
If you just need to change the file names, there is a macro function File.rename that you can include to to this.
If you need to process the original in multiple ways, you could just Duplicate the original, process the copy and save it.  This should leave open the original for a second duplication and processing.
Here's a short example.

fileToOpen=File.openDialog("Pick an image to open");
open(fileToOpen);
fileLocation=File.directory;
originalImage=getImageID();
run("Duplicate...", "title=copiedimage");
copiedImage=getImageID;
run("Smooth");//some processing
saveAs("tiff", fileLocation+"SmoothProcessed.tif");
//alternatively use the following function to get a dialog for changing the filename
//saveAs("tiff");
close();
selectImage(originalImage);
run("Duplicate...", "title=copiedimage");
copiedImage=getImageID;
run("Sharpen");//some processing
saveAs("tiff", fileLocation+"SharpenProcessed.tif");
close();

If they are not too large, you could post your macros so we can see what you need to accomplish and someone might have a better suggestion to streamline your processing.
Best,
George


On Apr 24, 2013, at 10:17 AM, Helmut Bergen wrote:

> Hello
>
> I try to do this into 1 large macro. The problem is that the second macro
> needs the original picture and there is coming up a problem report, because
> the second macro don't select the original picture . My idea is:
>
> 1) Open a picture/ or batch macro with a folder of pictures
> 2) first macro and rename and save the ORIGINAL picture
> 3) second macro and rename and save the ORIGINAL picture
> 4) etc.
>
> If I run the macros one after the other it is all ok. But to do this task in
> one idea
>
> Thanks
> Helmut
>
> -----Ursprüngliche Nachricht-----
> Von: Senseney, Justin (NIH/CIT) [G] [mailto:[hidden email]]
> Gesendet: Mittwoch, 24. April 2013 14:57
> An: Helmut Bergen
> Betreff: RE: run macro
>
> Helmut,
>
> Since the macros are just plain text, I would recommend copying and pasting
> the 4 macros into 1 large macro and running that.  But maybe there is
> another way.  Would you mind posting this question on the main ImageJ list?
> It's [hidden email]  I will subscribe you to that list.
>
> Thanks,
> Justin Senseney
> ________________________________
> From: Helmut Bergen [[hidden email]]
> Sent: Wednesday, April 24, 2013 6:57 AM
> To: [hidden email]
> Subject: run macro
>
> Hello
>
> I want to run four recorded macros with one macro. I hope this is possible
> and get some helps.
>
> Thanks and best regards
> Helmut
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

George H. Patterson
Building 13 3E33
13 South Drive
Biophotonics Section
National Institute of Biomedical Imaging and Bioengineering
National Institutes of Health
Bethesda, MD 20892
Office: 301-443-0241
Fax: 301-496-6608
[hidden email]


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

AW: AW: run macro

Helmut Bergen
Thanks for helping.
It's not only rename.  Here is one macro. The second macro is even the same;
only some numbers in the threshold are changed (if two macros run; four is
not far away). Thank you very much


MACRO:

run("Set Scale...", "distance=473 known=1 pixel=1 unit=cm global");

 imgName=getTitle();
         baseNameEnd=indexOf(imgName, ".tif");
         baseName=substring(imgName, 0, baseNameEnd);
rename(baseName + "_gelb.tiff");

//run("Brightness/Contrast...");
setMinAndMax(123, 123);

run("Color Threshold...");
// Color Thresholder 1.47m
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("RGB Stack");
run("Convert Stack to Images");
selectWindow("Red");
rename("0");
selectWindow("Green");
rename("1");
selectWindow("Blue");
rename("2");
min[0]=255;
max[0]=255;
filter[0]="pass";
min[1]=255;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=0;
filter[2]="pass";
for (i=0;i<3;i++){
  selectWindow(""+i);
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
}
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
  selectWindow(""+i);
  close();
}
selectWindow("Result of 0");
close();
selectWindow("Result of Result of 0");
rename(a);
// Colour Thresholding-------------

run("Analyze Particles...", "size=0.00004-Infinity circularity=0.00-1.00
show=[Bare Outlines] display summarize");

-----Ursprüngliche Nachricht-----
Von: ImageJ Interest Group [mailto:[hidden email]] Im Auftrag von
George Patterson
Gesendet: Mittwoch, 24. April 2013 17:12
An: [hidden email]
Betreff: Re: AW: run macro

Hi Helmut,
I'm a little unclear about what you're trying to do.
If you just need to change the file names, there is a macro function
File.rename that you can include to to this.
If you need to process the original in multiple ways, you could just
Duplicate the original, process the copy and save it.  This should leave
open the original for a second duplication and processing.
Here's a short example.

fileToOpen=File.openDialog("Pick an image to open"); open(fileToOpen);
fileLocation=File.directory; originalImage=getImageID(); run("Duplicate...",
"title=copiedimage"); copiedImage=getImageID; run("Smooth");//some
processing saveAs("tiff", fileLocation+"SmoothProcessed.tif");
//alternatively use the following function to get a dialog for changing the
filename //saveAs("tiff"); close(); selectImage(originalImage);
run("Duplicate...", "title=copiedimage"); copiedImage=getImageID;
run("Sharpen");//some processing saveAs("tiff",
fileLocation+"SharpenProcessed.tif");
close();

If they are not too large, you could post your macros so we can see what you
need to accomplish and someone might have a better suggestion to streamline
your processing.
Best,
George


On Apr 24, 2013, at 10:17 AM, Helmut Bergen wrote:

> Hello
>
> I try to do this into 1 large macro. The problem is that the second
> macro needs the original picture and there is coming up a problem
> report, because the second macro don't select the original picture . My
idea is:

>
> 1) Open a picture/ or batch macro with a folder of pictures
> 2) first macro and rename and save the ORIGINAL picture
> 3) second macro and rename and save the ORIGINAL picture
> 4) etc.
>
> If I run the macros one after the other it is all ok. But to do this
> task in one idea
>
> Thanks
> Helmut
>
> -----Ursprüngliche Nachricht-----
> Von: Senseney, Justin (NIH/CIT) [G] [mailto:[hidden email]]
> Gesendet: Mittwoch, 24. April 2013 14:57
> An: Helmut Bergen
> Betreff: RE: run macro
>
> Helmut,
>
> Since the macros are just plain text, I would recommend copying and
> pasting the 4 macros into 1 large macro and running that.  But maybe
> there is another way.  Would you mind posting this question on the main
ImageJ list?

> It's [hidden email]  I will subscribe you to that list.
>
> Thanks,
> Justin Senseney
> ________________________________
> From: Helmut Bergen [[hidden email]]
> Sent: Wednesday, April 24, 2013 6:57 AM
> To: [hidden email]
> Subject: run macro
>
> Hello
>
> I want to run four recorded macros with one macro. I hope this is
> possible and get some helps.
>
> Thanks and best regards
> Helmut
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

George H. Patterson
Building 13 3E33
13 South Drive
Biophotonics Section
National Institute of Biomedical Imaging and Bioengineering National
Institutes of Health Bethesda, MD 20892
Office: 301-443-0241
Fax: 301-496-6608
[hidden email]


--
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: AW: AW: run macro

George Patterson-3
Hi Helmut,
I've made a few edits below and I hope this still does what you want.
You can input the thresholds you'd use for macro 2 or more depending on how many different thresholds you want to use for processing the original image into the minRed, maxRed, filterRed, etc. arrays at the beginning.
I set it to save just about everything with the file names containing the thresholds.  Kind of ugly, but works.
You can delete the commands for what you don't need.
If you've a file full of RGB images, I think this can probably be put in a loop to open and process the files automatically.
 Best,
George



run("Set Scale...", "distance=473 known=1 pixel=1 unit=cm global");

imgName=getTitle();
        baseNameEnd=indexOf(imgName, ".tif");
        baseName=substring(imgName, 0, baseNameEnd);
processedName=baseName + "_gelb";
fileLocation=getInfo("image.directory");

//add thresholds for subsequent processing in the arrays here
//then you can just loop through

minRed=newArray(255,128,200);
maxRed=newArray(255,128,200);
filterRed=newArray("pass","pass","stop");

minGreen=newArray(255,128,200);
maxGreen=newArray(255,128,200);
filterGreen=newArray("pass","pass","stop");

minBlue=newArray(0,0,100);
maxBlue=newArray(0,0,100);
filterBlue=newArray("pass","pass","stop");


for(j=0;j<minRed.length;j++){
selectWindow(imgName);
run("Duplicate...", "title=processedName");
copiedImage=getImageID();
//run("Brightness/Contrast...");
setMinAndMax(123, 123);

run("Color Threshold...");
// Color Thresholder 1.47m
// Autogenerated macro, single images only!

run("RGB Stack");
run("Convert Stack to Images");

selectWindow("Red");
setThreshold(minRed[j], maxRed[j]);
run("Convert to Mask");
if (filterRed[j]=="stop")  run("Invert");

selectWindow("Green");
setThreshold(minGreen[j], maxGreen[j]);
run("Convert to Mask");
if (filterGreen[j]=="stop")  run("Invert");

selectWindow("Blue");
setThreshold(minBlue[j], maxBlue[j]);
run("Convert to Mask");
if (filterBlue[j]=="stop")  run("Invert");

imageCalculator("AND", "Red","Green");
imageCalculator("AND", "Red","Blue");
selectWindow("Green");
close();
selectWindow("Blue");
close();

selectWindow("Red");
rename(processedName+"_Rmin"+minRed[j]+"_Rmax"+maxRed[j]+"_Rfilter"+filterRed[j]+"_Gmin"+minGreen[j]+"_Gmax"+maxGreen[j]+"_Gfilter"+filterGreen[j]+"_Bmin"+minBlue[j]+"_Bmax"+maxBlue[j]+"_Bfilter"+filterBlue[j]);
newName=getTitle();
saveAs("tiff",fileLocation+newName+".tif");


// Colour Thresholding-------------

run("Analyze Particles...", "size=0.00004-Infinity circularity=0.00-1.00 show=[Bare Outlines] display summarize");
partAnalysis=newName+"_ParticleAnalysis";
saveAs("tiff",fileLocation+partAnalysis+".tif");
close();
selectWindow(newName+".tif");
close();
selectWindow("Results");
saveAs("Measurements",fileLocation+partAnalysis+"_results.txt");
run("Clear Results");
}
selectWindow("Summary");
saveAs("txt",fileLocation+imgName+"_summary.txt");

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