Login  Register

Re: Saving all open images with sequential numbering

Posted by Aryeh Weiss on Jan 26, 2014; 11:52am
URL: http://imagej.273.s1.nabble.com/Saving-all-open-images-with-sequential-numbering-tp5006281p5006282.html

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