Login  Register

Re: Macro to split images and save as title

Posted by CARL Philippe (LBP) on May 26, 2020; 4:45pm
URL: http://imagej.273.s1.nabble.com/Macro-to-split-images-and-save-as-title-tp5023353p5023404.html

Dear Kees,
Then just use something like:
save(dir2+substring(getTitle(),0,lastIndexOf(getTitle(),"."))+".tif");
And you are all set...
My best regards,
Philippe

----- Le 26 Mai 20, à 18:38, Straatman, Kees (Dr.) [hidden email] a écrit :

Dear Carl

Is correct, but with getTitle() you get the ".nd2" extension included in the new name. I normally try to replace it with ".tif", but I agree, that is just cosmetic.

Kees

________________________________


Dear Kees and Marc,
To answer your question, the generated picture names are in the form of "C1-imageName".
But reading your previous macro code, I found it quite strange on the first hand that you use the line:
title = File.getNameWithoutExtension(path);
on first hand.
Why don't you just use:
title = getTitle();
for each split picture?
I would even push it further by including directly the getTitle() inside the saveAs method.
And given that your path ends with ".tif", you can even simplify your code further by using the save method instead of the saveAs ending up by having:
dir1 = getDirectory("Select folder with images");
list = getFileList(dir1);
dir2 = getDirectory("Select folder to save the results");
for (i=0; i<list.length; i++){
    path = dir1 + list[i];
    run("Viewer", "open=[path]");
    getDimensions(width, height, channels, slices, frames);
    run("Split Channels");
    for (j=0; j<channels;j++){
        save(dir2+getTitle()+".tif");
        close();
    }
}
Take care,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 42 89

----- Mail original -----
De: "Straatman, Kees (Dr.)" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Mardi 26 Mai 2020 17:51:16
Objet: Re: Macro to split images and save as title

Dear Marc,

OK, so ImageJ does not recognize the file name opened by the plugin. So we can use something like

title = File.getNameWithoutExtension(path);

But we still have to take care that each channel is saved correctly. If the channels are split is the naming like "C1-imageName" or "imageName (red)"?

Kees

________________________________


Deer Kees,

Thank you very much for helping! I copied the macro into the editor and
removed gremlins as you described and checked that the " look the same (it
doesn't appear to have been changed). When running the macro I get asked
first source then destination directory as expected. It then asks me to
select a file (but only a single one, if I run it as batch would it be able
to take a whole directory of files?). However, after opening the file and
splitting it I get the following error message:

Number or numeric function expected in line 10
title = File.getNameWithoutExtension();

And it stops there unable to save.

Marc



--
Sent from: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.1557.x6.nabble.com%2F&amp;data=02%7C01%7Ckrs5%40leicester.ac.uk%7Cf2cf5ebd82c0483e766b08d801913d77%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261070605209275&amp;sdata=zh7NrS1xtmd2ky1Kj6lVEmfoc7yqYy1pLrxvj4VXrCw%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Ckrs5%40leicester.ac.uk%7Cf2cf5ebd82c0483e766b08d801913d77%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261070605209275&amp;sdata=BrMczMzkkzNitlp%2Byp%2BoNhYilfKQSwFplqtFM9ooow0%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Ckrs5%40leicester.ac.uk%7Cf2cf5ebd82c0483e766b08d801913d77%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261070605209275&amp;sdata=BrMczMzkkzNitlp%2Byp%2BoNhYilfKQSwFplqtFM9ooow0%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Ckrs5%40leicester.ac.uk%7Cf2cf5ebd82c0483e766b08d801913d77%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261070605209275&amp;sdata=BrMczMzkkzNitlp%2Byp%2BoNhYilfKQSwFplqtFM9ooow0%3D&amp;reserved=0

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

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