Open a series of images via macro

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

Open a series of images via macro

Goon
Hi,

that's maybe a stupid question.
I want to open a series of around 4000 images, make the same change to them and save them.
Since these are a lot of pictures, I want to write a macro to do it.
I can make the changes, but how do I open and save this series of pictures?
The files would be like NAMEx.
So they all have the same name with a number from 0 to 4000+.
I didn't find a solution here, so far.
But maybe I searched for the wrong things.
Can anybody help with this or has a link when it is already solved?
Thanks!

Goon
Reply | Threaded
Open this post in threaded view
|

Re: Open a series of images via macro

ctrueden
Hi Goon,

Please have a look at the batch processing guide here:

https://imagej.net/Batch

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Fri, May 12, 2017 at 8:54 AM, Goon <[hidden email]> wrote:

> Hi,
>
> that's maybe a stupid question.
> I want to open a series of around 4000 images, make the same change to them
> and save them.
> Since these are a lot of pictures, I want to write a macro to do it.
> I can make the changes, but how do I open and save this series of pictures?
> The files would be like NAMEx.
> So they all have the same name with a number from 0 to 4000+.
> I didn't find a solution here, so far.
> But maybe I searched for the wrong things.
> Can anybody help with this or has a link when it is already solved?
> Thanks!
>
> Goon
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.
> com/Open-a-series-of-images-via-macro-tp5018711.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: Open a series of images via macro

Michael Schmid
In reply to this post by Goon
Hi Stephan,

the easiest is Process>Batch>Macro. This applies a macro to all files of
a directory and (if desired) saves the results into another directory,
so your macro need not care about reading or writing the files:

 
https://imagej.nih.gov/ij/docs/guide/146-29.html#toc-Subsubsection-29.12.3

The alternative: Writing a macro that also reads and writes the files in
a loop:

   http://imagej.net/How_to_apply_a_common_operation_to_a_complete_directory

Michael
________________________________________________________________
On 12/05/2017 15:54, Goon wrote:

> Hi,
>
> that's maybe a stupid question.
> I want to open a series of around 4000 images, make the same change to them
> and save them.
> Since these are a lot of pictures, I want to write a macro to do it.
> I can make the changes, but how do I open and save this series of pictures?
> The files would be like NAMEx.
> So they all have the same name with a number from 0 to 4000+.
> I didn't find a solution here, so far.
> But maybe I searched for the wrong things.
> Can anybody help with this or has a link when it is already solved?
> Thanks!
>
> Goon
>

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

Re: Open a series of images via macro

robert atwood
Hi, Stephan,
Here's how I have done it in the past, supposing that the files to be used follow a numerical pattern, and you might want to scale it up to a larger number of images than fit in memory via 'stack' ,  or that the folder contains other files you are not interested in making the 'virtual stack' opening a bit complicated .. or if for some other reasons the builtin stack/batch procedure is not suitable this may help as an example.


In this macro, string functions are used to open one image at a time , generating the file name each time. The result image is saved to another generated filename and some analysis data is accumulated.

The drawback I have in using this approach  is in being sure to close the images that are not required any more; being sure which image is in focus and what it is called seems to be a bit tricky , not sure if that's a general feature of Windows or IJ specific because I am usually not programming multi-windowed applications.

Since writing it the IJ.pad() function has appeared and so the leftPad() function is no longer necessary ..






setBatchMode(true);
//run("Set Measurements...", "area mean standard min centroid center bounding feret's redirect=orig.png decimal=3");
run("Clear Results");
xm=0;
ym=0;
xb=0;
yb=0;
w=5;
h=5;

setForegroundColor(255, 0, 0);

//Set up a string containing the whole filename before the numbered part
basename="/home/inputfolder/calbrate_cam/scanpython/ff_"

//On a windows system the syntax for file location
//must follow Windows format, i.e.
//basename="D:\\inputfolder\test_"
//set up a string containing the remainder of the filename after the numbered part
filetype=".png"

//the correct commands for your analysis may best be found by using
//the Record macro feature, then pasting the commands you want into the macro
//set up the parameters that you wish to record from each feature


//for a test we just try to analyze 3 images,
for (i=70;i<=73;i++){
filename=basename + leftPad(i,3)+filetype;
open(filename);
thisimage=getTitle();
//at this point the ?selected window? is the one with the recently opened file

//run("View 100%");


run("Duplicate...", "title=orig.png");
origimage=getTitle();
//run("View 100%");

//print(thisimage,origimage);
run("Set Measurements...", "area mean standard min centroid center bounding feret's redirect=orig.png decimal=3");
selectWindow(thisimage);
//run("Median...", "radius=2");
setThreshold(1, 255);
run("Convert to Mask");
run("Options...", "iterations=1 edm=Overwrite count=7");
run("Open");
run("Options...", "iterations=3 edm=Overwrite count=1");
run("Close-");


run("Analyze Particles...", "size=200-Infinity circularity=0.00-1.00 show=Outlines display");
//run("View 100%");

print(thisimage,nResults() );
if (nResults != 0 ){
xm=getResult("XM");
ym=getResult("YM");
xb=getResult("BX");
yb=getResult("BY");
w=getResult("Width");
h=getResult("Height");
}
selectWindow(thisimage);
filename=basename + leftPad(i,3)+"_mask.png";
saveAs("png", filename);
close();
selectWindow("orig.png");

run("RGB Color");
makeRectangle(xb,yb,w,h);
run("Draw");

filename=basename + leftPad(i,3)+"_proc.jpg";
saveAs("Jpeg", filename);

close();
}

selectWindow("Results");
run("Text...", "save=/home/outputfolder/results-70-115-nomed.xls");
setBatchMode(false);

// this funciton just makes a string from a number and puts leading zeros on it.
function leftPad(n, width) {
s =""+n;
while (lengthOf(s)<width)
s = "0"+s;
return s;
}


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid
Sent: Monday, May 15, 2017 16:43
To: [hidden email]
Subject: Re: Open a series of images via macro

Hi Stephan,

the easiest is Process>Batch>Macro. This applies a macro to all files of a directory and (if desired) saves the results into another directory, so your macro need not care about reading or writing the files:

 
https://imagej.nih.gov/ij/docs/guide/146-29.html#toc-Subsubsection-29.12.3

The alternative: Writing a macro that also reads and writes the files in
a loop:

   http://imagej.net/How_to_apply_a_common_operation_to_a_complete_directory

Michael
________________________________________________________________
On 12/05/2017 15:54, Goon wrote:

> Hi,
>
> that's maybe a stupid question.
> I want to open a series of around 4000 images, make the same change to them
> and save them.
> Since these are a lot of pictures, I want to write a macro to do it.
> I can make the changes, but how do I open and save this series of pictures?
> The files would be like NAMEx.
> So they all have the same name with a number from 0 to 4000+.
> I didn't find a solution here, so far.
> But maybe I searched for the wrong things.
> Can anybody help with this or has a link when it is already solved?
> Thanks!
>
> Goon
>

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

--
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom

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