Login  Register

Re: Can getDirectory() automatically select a predefined folder path?

Posted by George Patterson on Sep 15, 2014; 9:15pm
URL: http://imagej.273.s1.nabble.com/Can-getDirectory-automatically-select-a-predefined-folder-path-tp5009535p5009631.html

Hi Dave,
If I've understood what you need I don't think you need any other
functions.  Just a few small changes should be needed.
I've copied your macro below with those changes.
Best,
George


macro "Split channels then convert to 16-bit"

{
        {
        // Open and split channels then save to new folder...
                dir1 = getDirectory("Choose Original Images Directory");
                list = getFileList(dir1);
                setBatchMode(true);
                for (i=0; i<list.length; i++) {
                        path = dir1+list[i];
                        open(path);
                        run("Split Channels");
                        dir2 = dir1+"split"+File.separator;
                        File.makeDirectory(dir2);
                        path = dir2+list[i];
                        dotIndex = lastIndexOf(path, "."); path =
substring(path, 0, dotIndex);
// remove ext.
                //      save(path+"_blue.tif");
                        close();
                        save(path+"_green.tif");
                        close();
                        save(path+"_red.tif");
                        close();
                }
        }

        {
        // Open split channels and save as 16-bit then save to new folder...
                //dir1 = getDirectory("Choose Split Channels Directory");
                //list = getFileList(dir1);
                list = getFileList(dir2);
                setBatchMode(true);
                for (i=0; i<list.length; i++) {
                        //path = dir1+list[i];
                        path = dir2+list[i];
                        open(path);
                        run("16-bit");
                        //dir2 = dir1+"16-bit"+File.separator;
                        //File.makeDirectory(dir2);
                        //path = dir2+list[i];
                        dir3 = dir2+"16-bit"+File.separator;
                        File.makeDirectory(dir3);
                        path = dir3+list[i];
                        dotIndex = lastIndexOf(path, "."); path =
substring(path, 0, dotIndex);
// remove ext
                        save(path+"-16bit.tif");
                        close();
                }
        }

        {
                exit("Finished")
        }


On Fri, Sep 5, 2014 at 4:09 PM, DaveMc <[hidden email]> wrote:

> Hi All,
>
> I'm writing a macro for a user of our core facility and wondering if I can
> streamline it even more. What he wants to do is open large folders (~1500)
> of RGB images, split the channels saving only the red and green appending
> the file names in a new subfolder, then convert and save those as 16-bit in
> another new subfolder.
>
> The macro is working well but he has to wait until the split step is done
> then choose that folder to start the 16-bit step.
>
> The question is...can I use the getDirectory function, or another option,
> to
> get the macro to automatically select the subfolder the split channels are
> in by path and automatically start the 16-bit step without him having to
> choose it?
>
> Thanks!
> Dave
>
> Here's the code...
>
> ------------------
>
> macro "Split channels then convert to 16-bit"
>
> {
>         {
>         // Open and split channels then save to new folder...
>                 dir1 = getDirectory("Choose Original Images Directory");
>                 list = getFileList(dir1);
>                 setBatchMode(true);
>                 for (i=0; i<list.length; i++) {
>                         path = dir1+list[i];
>                         open(path);
>                         run("Split Channels");
>                         dir2 = dir1+"split"+File.separator;
>                         File.makeDirectory(dir2);
>                         path = dir2+list[i];
>                         dotIndex = lastIndexOf(path, "."); path =
> substring(path, 0, dotIndex);
> // remove ext.
>                 //      save(path+"_blue.tif");
>                         close();
>                         save(path+"_green.tif");
>                         close();
>                         save(path+"_red.tif");
>                         close();
>                 }
>         }
>
>         {
>         // Open split channels and save as 16-bit then save to new
> folder...
>                 dir1 = getDirectory("Choose Split Channels Directory");
>                 list = getFileList(dir1);
>                 setBatchMode(true);
>                 for (i=0; i<list.length; i++) {
>                         path = dir1+list[i];
>                         open(path);
>                         run("16-bit");
>                         dir2 = dir1+"16-bit"+File.separator;
>                         File.makeDirectory(dir2);
>                         path = dir2+list[i];
>                         dotIndex = lastIndexOf(path, "."); path =
> substring(path, 0, dotIndex);
> // remove ext
>                         save(path+"-16bit.tif");
>                         close();
>                 }
>         }
>
>         {
>                 exit("Finished")
>         }
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Can-getDirectory-automatically-select-a-predefined-folder-path-tp5009535.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