save all opened images and changing their name

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

save all opened images and changing their name

inesica
Hello everybody. I am new to ImageJ, so I would need your help. I want to save all my opened images that are called: Stack_Reg-0001, Stack_Reg-0002 etc. I used a macro from a previously asked question about this:  

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

        saveAs("tiff", dir+title);
}

However, since I am using a matlab program that needs the files with a certain name, I need to change their name. I would like to have them as: z0000_t0000, z0001_t0000, z0002_t0000 etc, until z0024_t0000. Is it possible to do this in the macro?
Thank you very much in advance.
Reply | Threaded
Open this post in threaded view
|

Re: save all opened images and changing their name

CARL Philippe (LBP)
Dear inesica,
You were not very far from the solution you are looking for since you just
need to replace the line "saveAs("tiff", dir+title);" with "saveAs("tiff",
dir + "z" + substring(title, 10, lengthOf(title)) +"_t0000");" or if you
want something "slightly" more complicated by "saveAs("tiff", dir + "z" +
substring(title, indexOf(title, "-") + 1, lengthOf(title)) +"_t0000");"
Nevertheless, I'm not really convinced that an ImageJ macro is the most
adapted tool for performing what you trying to do.
And for such a job (and if you are under Windows), I would rather recommend
you Total_Commander that can be found under the following link:
http://www.ghisler.com
They have a very powerful File->Multi-Rename_Tool with which what you are
looking for is done within seconds.
In parallel, Total_Commander has a File->Compare_by_content... tool which is
really cool in the case you have several versions of a given macro and you
want to know what differentiate them.
I hope I helped you to move further in your work and wish you a nice day.
My best regards,
Philippe

Philippe CARL
Laboratoire de Biophotonique et Pharmacologie
UMR 7213 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de
inesica
Envoyé : lundi 4 avril 2016 10:27
À : [hidden email]
Objet : save all opened images and changing their name

Hello everybody. I am new to ImageJ, so I would need your help. I want to
save all my opened images that are called: Stack_Reg-0001, Stack_Reg-0002
etc. I used a macro from a previously asked question about this:  

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

        saveAs("tiff", dir+title);
}

However, since I am using a matlab program that needs the files with a
certain name, I need to change their name. I would like to have them as:
z0000_t0000, z0001_t0000, z0002_t0000 etc, until z0024_t0000. Is it possible
to do this in the macro?
Thank you very much in advance.



--
View this message in context:
http://imagej.1557.x6.nabble.com/save-all-opened-images-and-changing-their-n
ame-tp5016055.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: save all opened images and changing their name

Herbie
In reply to this post by inesica
Inesica,

you may have a look at the text handling functions of the ImageJ macro
language:

<http://rsb.info.nih.gov/ij/developer/macro/functions.html>

Is this the desired text-translation?
Stack_Reg-0001 >  z0000_t0000
Stack_Reg-0002 >  z0001_t0000
...

Here is an example snippet:
name = "Stack_Reg-0002";
number = parseInt( replace( name, "Stack_Reg-", "" ) );
number--;
if ( number < 10 ) { name = "z000"; } else { name = "z00"; }
name += "" + number + "_t0000";
print( name );

HTH

Herbie

:::::::::::::::::::::::::::::::::::::
Am 04.04.16 um 10:26 schrieb inesica:

> Hello everybody. I am new to ImageJ, so I would need your help. I want to
> save all my opened images that are called: Stack_Reg-0001, Stack_Reg-0002
> etc. I used a macro from a previously asked question about this:
>
> // get image IDs of all open images
> dir = getDirectory("Choose a Directory");
> ids=newArray(nImages);
> for (i=0;i<nImages;i++) {
>          selectImage(i+1);
>          title = getTitle;
>          print(title);
>          ids[i]=getImageID;
>
>          saveAs("tiff", dir+title);
> }
>
> However, since I am using a matlab program that needs the files with a
> certain name, I need to change their name. I would like to have them as:
> z0000_t0000, z0001_t0000, z0002_t0000 etc, until z0024_t0000. Is it possible
> to do this in the macro?
> Thank you very much in advance.
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/save-all-opened-images-and-changing-their-name-tp5016055.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: save all opened images and changing their name

CARL Philippe (LBP)
Dear Herbie,
You can replace your:
If ( number < 10 ) { name = "z000"; } else { name = "z00"; }; name += "" +
number + "_t0000";
By:
name = "z" + IJ.pad(number, 4) + "_t0000"; print(name);
Kindest regards,
Philippe

Philippe CARL
Laboratoire de Biophotonique et Pharmacologie
UMR 7213 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84


-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Herbie
Envoyé : lundi 4 avril 2016 11:35
À : [hidden email]
Objet : Re: save all opened images and changing their name

Inesica,

you may have a look at the text handling functions of the ImageJ macro
language:

<http://rsb.info.nih.gov/ij/developer/macro/functions.html>

Is this the desired text-translation?
Stack_Reg-0001 >  z0000_t0000
Stack_Reg-0002 >  z0001_t0000
...

Here is an example snippet:
name = "Stack_Reg-0002";
number = parseInt( replace( name, "Stack_Reg-", "" ) ); number--; if (
number < 10 ) { name = "z000"; } else { name = "z00"; } name += "" + number
+ "_t0000"; print( name );

HTH

Herbie

:::::::::::::::::::::::::::::::::::::
Am 04.04.16 um 10:26 schrieb inesica:
> Hello everybody. I am new to ImageJ, so I would need your help. I want
> to save all my opened images that are called: Stack_Reg-0001,
> Stack_Reg-0002 etc. I used a macro from a previously asked question about
this:

>
> // get image IDs of all open images
> dir = getDirectory("Choose a Directory"); ids=newArray(nImages); for
> (i=0;i<nImages;i++) {
>          selectImage(i+1);
>          title = getTitle;
>          print(title);
>          ids[i]=getImageID;
>
>          saveAs("tiff", dir+title);
> }
>
> However, since I am using a matlab program that needs the files with a
> certain name, I need to change their name. I would like to have them as:
> z0000_t0000, z0001_t0000, z0002_t0000 etc, until z0024_t0000. Is it
> possible to do this in the macro?
> Thank you very much in advance.
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/save-all-opened-images-and-changing-t
> heir-name-tp5016055.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

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

Re: save all opened images and changing their name

inesica
In reply to this post by CARL Philippe (LBP)
Thank you very much!!! I will also take a look at Total Commander!
Reply | Threaded
Open this post in threaded view
|

Re: save all opened images and changing their name

inesica
In reply to this post by CARL Philippe (LBP)
Thank you very much!

However, when I convert my files, the first one is not z0000_t0000 but z0001_t0000. can the program be written otherwise? or how can i then convert all my files from z0001_t0000 to z0000_t0000; z0002_t0000 to z0001_t0000 etc?

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: save all opened images and changing their name

Herbie
Inesica,

evidently you didn't follow my suggestion.
Why?

Here is the example code again:
//----------------------------------------------------
name = "Stack_Reg-0002";
number = parseInt( replace( name, "Stack_Reg-", "" ) );
number--;
if ( number < 10 ) { name = "z000"; } else { name = "z00"; }
name += "" + number + "_t0000";
print( name );
//----------------------------------------------------

Best

Herbie

:::::::::::::::::::::::::::::::::::::
Am 20.04.16 um 14:52 schrieb inesica:

> Thank you very much!
>
> However, when I convert my files, the first one is not z0000_t0000
> but z0001_t0000. can the program be written otherwise? or how can i
> then convert all my files from z0001_t0000 to z0000_t0000;
> z0002_t0000 to z0001_t0000 etc?
>
> Thank you!
>
>
>
> -- View this message in context:
> http://imagej.1557.x6.nabble.com/save-all-opened-images-and-changing-their-name-tp5016055p5016193.html

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