Macro to split images and save as title

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro to split images and save as title

bluebird-2
Hi all,

I'm new to ImageJ macros and am usually happy to use the macro recorder.
However, I can't seem to find a way to automate splitting images containing
multiple colour layers and then saving them as tiffs with the filename as
the title of the image. Maybe it's not doable as the files are .vsi format
(I use Olympus Viewer plugin to open them), but even just automating the
saving process after opening the images manually would be very helpful. It
seems I need to use a function like getTitle() and I found a couple of
threads that discuss something similar
(http://imagej.1557.x6.nabble.com/Using-getTitle-td3687039.html) but I can't
seem to get it to work.

Any help would be appreciated!



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Macro to split images and save as title

Krs5
Dear bluebird,

I don't know the Olympus viewer plugin but according to https://imagej.net/OlympusImageJPlugin it works in macros as well

so something like this might do the job:


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++){
        title = File.getNameWithoutExtension();
        saveAs("tiff", dir2+title+".tif");
        close();
    }
}

It will ask you were the files are you want to open and where you want to save the resulting split images. I assumes for the moment that you want to save your images as *.tif files. It also assumes that the folder with your Olympus files only contains these files and no other files.

Be aware if you copy the code above into the macro editor some of the " might be changed into some unreadable characters (at least for ImageJ). You can check this by using in the editor Edit > Zap Gremlins and add the correct ".

Hope it works

Kees
________________________________

Hi all,

I'm new to ImageJ macros and am usually happy to use the macro recorder.
However, I can't seem to find a way to automate splitting images containing
multiple colour layers and then saving them as tiffs with the filename as
the title of the image. Maybe it's not doable as the files are .vsi format
(I use Olympus Viewer plugin to open them), but even just automating the
saving process after opening the images manually would be very helpful. It
seems I need to use a function like getTitle() and I found a couple of
threads that discuss something similar
(https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.1557.x6.nabble.com%2FUsing-getTitle-td3687039.html&amp;data=02%7C01%7Ckrs5%40leicester.ac.uk%7C1bf036ad2d3146009bb008d7fde02622%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637257011478467046&amp;sdata=TZn0Nvdg2%2FHYJ9jnvzZpEtYu%2FTPbbDKaa0dVUi%2FVP2Y%3D&amp;reserved=0) but I can't
seem to get it to work.

Any help would be appreciated!



--
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%7C1bf036ad2d3146009bb008d7fde02622%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637257011478467046&amp;sdata=8ZTsHBsJKoq%2FOVV6%2B4wg%2FqNfmL14%2B4t5UTfa%2BjPJaZA%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%7C1bf036ad2d3146009bb008d7fde02622%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637257011478467046&amp;sdata=bPblPoCkf2dfpLdMZH8Tx3PxlJ09GRWCdHKapSYyON0%3D&amp;reserved=0

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

Re: Macro to split images and save as title

bluebird-2
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: http://imagej.1557.x6.nabble.com/

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

Re: Macro to split images and save as title

Krs5
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%7C53b0809a43b241ee5a8508d8000946db%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637259387131383447&amp;sdata=Y16D%2F3g4ZBwAt3h2UuY6H1cK62UHvfTLiiKf06N6t7k%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%7C53b0809a43b241ee5a8508d8000946db%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637259387131383447&amp;sdata=GorCKFmH5IuAPZW07IkRAwM0hCZbLyiDiwm7XIEaBrU%3D&amp;reserved=0

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

Re: Macro to split images and save as title

CARL Philippe (LBP)
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%7C53b0809a43b241ee5a8508d8000946db%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637259387131383447&amp;sdata=Y16D%2F3g4ZBwAt3h2UuY6H1cK62UHvfTLiiKf06N6t7k%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%7C53b0809a43b241ee5a8508d8000946db%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637259387131383447&amp;sdata=GorCKFmH5IuAPZW07IkRAwM0hCZbLyiDiwm7XIEaBrU%3D&amp;reserved=0

--
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: Macro to split images and save as title

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

Re: Macro to split images and save as title

CARL Philippe (LBP)
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
Reply | Threaded
Open this post in threaded view
|

Re: Macro to split images and save as title

Cammer, Michael-3
In reply to this post by Krs5
I use these to strip extensions.

for instance,

rename(getTitleStripExtensions());


function getTitleStripExtensions() {
  t = getTitle();
  extensions = newArray(".tif", ".tiff", ".lif", ".lsm", ".czi", ".nd2", ".ND2");
  for(i=0; i<extensions.length; i++)
    t = replace(t, extensions[i], "");
  return t;
}  // end getTitleStripExtension()



function getTitleStripOneExtension() {
  t = getTitle();
  lastPeriod = lastIndexOf(t, ".")   // same as t.lastIndexOf(".");
  t = substring(t, 0, lastPeriod);
  return t;
}



Michael Cammer, Sr Research Scientist, DART Microscopy Laboratory

NYU Langone Health, 540 First Avenue, SK2 Microscopy Suite, New York, NY  10016

[hidden email]<mailto:[hidden email]>  http://nyulmc.org/micros  http://microscopynotes.com/

Voice direct only, no text or messages:  1-914-309-3270 and 1-646-501-0567



________________________________
From: Straatman, Kees (Dr.) <[hidden email]>
Sent: Tuesday, May 26, 2020 12:38:13 PM
To: [hidden email]
Subject: Re: Macro to split images and save as title

[EXTERNAL]

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://urldefense.proofpoint.com/v2/url?u=https-3A__eur03.safelinks.protection.outlook.com_-3Furl-3Dhttp-253A-252F-252Fimagej.1557.x6.nabble.com-252F-26amp-3Bdata-3D02-257C01-257Ckrs5-2540leicester.ac.uk-257Cf2cf5ebd82c0483e766b08d801913d77-257Caebecd6a31d44b0195ce8274afe853d9-257C0-257C0-257C637261070605209275-26amp-3Bsdata-3Dzh7NrS1xtmd2ky1Kj6lVEmfoc7yqYy1pLrxvj4VXrCw-253D-26amp-3Breserved-3D0&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=Caw6ccLYV77PTAEvtzWhc3thv5L_7LvjpONnKZKTT88&s=OtYozwtGf7UVmHuHZ-DzlN3-MQ7kNCJXNRSYcTgSwTM&e=

--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=https-3A__eur03.safelinks.protection.outlook.com_-3Furl-3Dhttp-253A-252F-252Fimagej.nih.gov-252Fij-252Flist.html-26amp-3Bdata-3D02-257C01-257Ckrs5-2540leicester.ac.uk-257Cf2cf5ebd82c0483e766b08d801913d77-257Caebecd6a31d44b0195ce8274afe853d9-257C0-257C0-257C637261070605209275-26amp-3Bsdata-3DBrMczMzkkzNitlp-252Byp-252BoNhYilfKQSwFplqtFM9ooow0-253D-26amp-3Breserved-3D0&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=Caw6ccLYV77PTAEvtzWhc3thv5L_7LvjpONnKZKTT88&s=sCbF7cQDKnTrMe7AI9Ii0nE66bqIF3aRPVcs-ldBGzM&e=

--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=https-3A__eur03.safelinks.protection.outlook.com_-3Furl-3Dhttp-253A-252F-252Fimagej.nih.gov-252Fij-252Flist.html-26amp-3Bdata-3D02-257C01-257Ckrs5-2540leicester.ac.uk-257Cf2cf5ebd82c0483e766b08d801913d77-257Caebecd6a31d44b0195ce8274afe853d9-257C0-257C0-257C637261070605209275-26amp-3Bsdata-3DBrMczMzkkzNitlp-252Byp-252BoNhYilfKQSwFplqtFM9ooow0-253D-26amp-3Breserved-3D0&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=Caw6ccLYV77PTAEvtzWhc3thv5L_7LvjpONnKZKTT88&s=sCbF7cQDKnTrMe7AI9Ii0nE66bqIF3aRPVcs-ldBGzM&e=

--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=https-3A__eur03.safelinks.protection.outlook.com_-3Furl-3Dhttp-253A-252F-252Fimagej.nih.gov-252Fij-252Flist.html-26amp-3Bdata-3D02-257C01-257Ckrs5-2540leicester.ac.uk-257Cf2cf5ebd82c0483e766b08d801913d77-257Caebecd6a31d44b0195ce8274afe853d9-257C0-257C0-257C637261070605209275-26amp-3Bsdata-3DBrMczMzkkzNitlp-252Byp-252BoNhYilfKQSwFplqtFM9ooow0-253D-26amp-3Breserved-3D0&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=Caw6ccLYV77PTAEvtzWhc3thv5L_7LvjpONnKZKTT88&s=sCbF7cQDKnTrMe7AI9Ii0nE66bqIF3aRPVcs-ldBGzM&e=

--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=hUBj2D5n6oKThx2L01qn8IORZb5f-ruLVXPmQ1zQNnM&m=Caw6ccLYV77PTAEvtzWhc3thv5L_7LvjpONnKZKTT88&s=YFdmSZiyBlO2iMnLDlUD7nI5yqAk06c6ehIHA1isA24&e=

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

Re: Macro to split images and save as title

Krs5
In reply to this post by CARL Philippe (LBP)
Dear Philippe and Michael,

OK, both will work. Many thanks.

However, I am plying around a little and now notice that if I have a nd2 file and just safe it as a tif file the extension seems automatically being replaced. Was not aware of this (or maybe had forgotten...).

Best wishes

Kees



________________________________
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%7Cd8833901b1ba4eeddc7908d801946801%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261084196528799&amp;sdata=e3Ri5OZQ41Q9t%2F9P8JgPN%2BILB8zpX93sdwNsEhpSkt8%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%7Cd8833901b1ba4eeddc7908d801946801%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261084196528799&amp;sdata=r0wwbfd%2BFwrhfv8l3%2FlY95yA%2Ft16Q4g1xA55YXe2JLk%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%7Cd8833901b1ba4eeddc7908d801946801%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261084196528799&amp;sdata=r0wwbfd%2BFwrhfv8l3%2FlY95yA%2Ft16Q4g1xA55YXe2JLk%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%7Cd8833901b1ba4eeddc7908d801946801%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261084196528799&amp;sdata=r0wwbfd%2BFwrhfv8l3%2FlY95yA%2Ft16Q4g1xA55YXe2JLk%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%7Cd8833901b1ba4eeddc7908d801946801%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261084196528799&amp;sdata=r0wwbfd%2BFwrhfv8l3%2FlY95yA%2Ft16Q4g1xA55YXe2JLk%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%7Cd8833901b1ba4eeddc7908d801946801%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637261084196538799&amp;sdata=irpae%2BqDlbtxRUJBpCe6WbS8vpa5QS43LZA8srJiicY%3D&amp;reserved=0

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