Posted by
Krs5 on
May 22, 2020; 1:04pm
URL: http://imagej.273.s1.nabble.com/Macro-to-split-images-and-save-as-title-tp5023353p5023360.html
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&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C1bf036ad2d3146009bb008d7fde02622%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637257011478467046&sdata=TZn0Nvdg2%2FHYJ9jnvzZpEtYu%2FTPbbDKaa0dVUi%2FVP2Y%3D&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&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C1bf036ad2d3146009bb008d7fde02622%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637257011478467046&sdata=8ZTsHBsJKoq%2FOVV6%2B4wg%2FqNfmL14%2B4t5UTfa%2BjPJaZA%3D&reserved=0--
ImageJ mailing list:
https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C1bf036ad2d3146009bb008d7fde02622%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637257011478467046&sdata=bPblPoCkf2dfpLdMZH8Tx3PxlJ09GRWCdHKapSYyON0%3D&reserved=0--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html