Login  Register

Re: Macro to split images and save as title

Posted by bluebird-2 on Jun 18, 2020; 7:58pm
URL: http://imagej.273.s1.nabble.com/Macro-to-split-images-and-save-as-title-tp5023353p5023538.html

Solved:

Philippe Carl made some further adjustments to the macro and it works
beautifully now. Posting it below. Thank you everyone for your kind help!

Best,
Marc

Macro for importing, splitting and saving .vsi files:

        dir1 = getDirectory("Select folder with images");
        list = getFileList(dir1);
        dir2 = getDirectory("Select folder to save the results");
        for (i = 0; i < list.length; i++)
        {
                if(endsWith(list[i], ".vsi") || endsWith(list[i], ".ets"))
                {
                        path = dir1 + list[i];
                        ext = substring(path, lastIndexOf(path, "."), lengthOf(path));
                        run("Bio-Formats Macro Extensions");
                        Ext.setId(path);
                        Ext.getSeriesCount(seriesCount);
                        print("Number of pictures:     " + seriesCount);
                        for(n = 1; n <= seriesCount; n++)
                        {
                                run("Bio-Formats Importer", "open=[" + path + "] autoscale
color_mode=Composite view=Hyperstack stack_order=XYCZT series_" + n);
                                if(endsWith(getTitle(), "macro image"))
                                {
                                        close();
                                }
                                else
                                {
                                        getDimensions(width, height, channels, slices, frames);
                                        run("Split Channels");
                                        for (j = 0; j < channels; j++)
                                        {
                                                outpath = dir2 + replace(replace(getTitle(), replace(dir1, "\\", "/"),
""), ext, "") + ".tif";
                                                print(outpath);
                                                save (outpath);
                                                close();
                                        }
                                }
                        }
                }
        }



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

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