Saving all open images with sequential numbering

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

Saving all open images with sequential numbering

sam
Hi there,

Apologies for the basic question but I'm new to ImageJ macros.

I am trying to write a macro to save all open images with a single prefix, followed by a sequential number.

e.g. Image1, Image2.tif, image3.tif, Image4.tif etc

I can't get the sequential numbering right.  The best I can get is uging their unique Image ID, which isn't quite what I want:



// get image IDs of all open images
dir = getDirectory("Choose a Directory");
ids=newArray(nImages);
for (i=0;i<nImages;i++) {
        selectImage(i+1);
        ids[i]=getImageID;

// save the images based on their inique ID

saveAs("Tiff", dir+"sd2"+ids[i]);


}


Can anyone help?  Many thanks in advance,
Reply | Threaded
Open this post in threaded view
|

Re: Saving all open images with sequential numbering

Aryeh Weiss
On 1/26/14, 1:09 PM, sam wrote:

> Hi there,
>
> Apologies for the basic question but I'm new to ImageJ macros.
>
> I am trying to write a macro to save all open images with a single prefix,
> followed by a sequential number.
>
> e.g. Image1, Image2.tif, image3.tif, Image4.tif etc
>
> I can't get the sequential numbering right.  The best I can get is uging
> their unique Image ID, which isn't quite what I want:
>
>
>
> // get image IDs of all open images
> dir = getDirectory("Choose a Directory");
> ids=newArray(nImages);
> for (i=0;i<nImages;i++) {
>          selectImage(i+1);
>          ids[i]=getImageID;
>
> // save the images based on their inique ID
>
> saveAs("Tiff", dir+"sd2"+ids[i]);
>
>
> }

How about;

saveAs("Tiff", dir+"sd2"+d2s(i,0));

where i is your loop counter.

If you may have lots of images:

saveAs("Tiff", dir+"sd2"+IJ.pad(d2s(i,0), 3) );

IJ.pad will make sure that your images list in the correct order.

--aryeh

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

Re: Saving all open images with sequential numbering

sam
Thank you - that worked extremely well!