Process a set of directories in the same way

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Process a set of directories in the same way

Xeal
Dear ImageJ Experts,

I wrote a little macro for image preprocessing:

1. Open a couple of images.
2. Execute the menu item 'Image - Stack - Images to Stack'.
3. Extract the background by executing 'Image - Stack - ZProjection' and selecting 'Min Intensity' in the user dialog.
4. Substract the background using the command 'Process - Image Calculator'. Use 'Stack' as the source, 'Substract' as the operation and 'MIN_Stack' as the substrahend.
5. Dissolve your stack with 'Image - Stack - Stack to Images'.
6. Save the images.

Here is my code:
macro "Remove static background and save Action Tool - C000T2f20S" {

        run("Close All"); //No image must be opened !

        showMessage("Choose source directory for static background reduction")
        dir1 = getDirectory("Choose source directory for static background reduction");

  run("Image Sequence...", "open=[dir1] sort");

    rename("Stack");

        run("Z Project...", "start=1 stop=100 projection=[Min Intensity]"); //Generate a new image with the static background
        idz = getImageID();
        imageCalculator("Subtract stack", "Stack","MIN_Stack"); // Remove static background from all images in the stack
        selectImage(idz); // close image of static background
        close();

        //run("Enhance Contrast", "saturated=0.05 normalize_all"); // Enhance contrast of all images from stack

        chooseBatch=1;


    run("Stack to Images"); //disassemble the stack to get single images with reduced static background

                while(chooseBatch == 1) {

                        // get image IDs of all open images
                        ids=newArray(nImages); //new Array, containing the ids of all opened images
                        for (i=0;i<nImages;i++) {
                        selectImage(i+1);
                        rename(i+1);
                        ids[i]=getImageID;
                                        }

                        // process all open images
                        for (i=0;i<ids.length;i++) {
                        showProgress(i+1, ids.length);

                        // If all opened images from the input folder have been processed, the batch process is finished.
    if (i+1==ids.length) {chooseBatch = 0; }


            ///////////////////////////////////
                        //What will be done with each image
                        ///////////////////////////////////
                                setBatchMode(true);
                                selectImage(ids[i]);
                                if (i<10)
                                j="0"+i;
                                else j=i;


        saveAs("Tiff", dir2+j+"_processed");
                   close();
            setBatchMode(false);
                        ///////////////////////////////////
                        //What will be done with each image
            ///////////////////////////////////

                        }


                }

        staticBackgroundRemoved = true;
        print("Static background has been removed! Now you can run the batch process!");
}


How can I modify this code, to load a set of folders and treat the content of this folder the way my macro doe ?