issues with 'flip vertically' and saving RGB files

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

issues with 'flip vertically' and saving RGB files

David Nicholson
Hi all,
I'm trying to batch process images taken with a widefield microscope that simply saves black and white TIFF files.
What I need to do is(1) "flip vertically" all the images in a directory(2) apply appropriate LUTs to images of the same specimen taken with different filters(3) merge those images taken with different filters, then convert to RGB so that I can view both channels at once e.g. when pasting the image into a Microsoft office document

The issues I'm having are that:--when I run "flip vertically" in batch mode, it doesn't actually flip the image--when I "merge" the images and then run "RGB color", the resulting RGB image only contains one of the "channels"

I will paste below the two macros I've written that should hopefully let someone else reproduce these issues. Please let me know if there is some mistake I'm making.
Thank you for your timeJose Pimienta Dolores

////////////// this is the first macro ////////////////////////////////
function flipVertApplyLUT(inputDir, outputDir, filename) {
    print("opening " + inputDir + filename);
    open(inputDir + "\\" + filename);
    fname = getInfo("image.filename");
   
    // image -> transform -> flip vertically
    run("Flip Vertically");
   
    // if filename contains "TRITC", apply "hot red" look up table
    ind = indexOf(fname,"TRITC");
    if (ind > -1)  {
       
        run("Magenta");
        setMinAndMax(13, 61);

        periodInd = indexOf(fname,".");
        newFilename = substring(filename,0,periodInd);
        newFilename = newFilename + "_MagentaLUT";
        saveAs("tiff",outputDir + "\\" + newFilename );
        close();
    } else {
        print("Finding index of TXRED");
        ind = indexOf(fname,"TXRED");
        if (ind > -1)  {
            print("found TXRED in " + fname + " at index " + ind);
            run("Red Hot");
            periodInd = indexOf(fname,".");
            newFilename = substring(filename,0,periodInd);
            newFilename = newFilename + "_RedHotLUT";
            saveAs("tiff",outputDir + "\\" + newFilename );
            close();
        } else {
            // if filename contains "FITC", apply "green" look up table
            print("Finding index of FITC");
            ind = indexOf(fname, "FITC");
            if (ind > -1)  {
                print("found FITC in " + fname + " at index " + ind);
               
                run("Green");
                setMinAndMax(13, 56);
               
                periodInd = indexOf(fname,".");
                newFilename = substring(filename,0,periodInd);
                newFilename = newFilename + "_GreenLUT";
                saveAs("tiff",outputDir + "\\" + newFilename );
                close();
            } else {
                print("Could not find filter used in filename");
            }
        }
    }
}

macro "flipVertApplyLUTs" {
    // main script
    // note you have to put double backslashes in any path because a single slash is interpreted as the escape character (double slash = "no I really mean backslash")
    inputDir = "F:\\cb_project_backedUp090515\\tracer injection results\\fluorescent\\injects_in_X\\gr37or7\\inject site";
    outputDir = "F:\\cb_project_backedUp090515\\tracer injection results\\fluorescent\\injects_in_X\\gr37or7\\inject site";

    list = getFileList(inputDir);
   
    for (i = 0; i < list.length; i++) {
        print("flipVertApplyLUT receiving " + list[i]);
        flipVertApplyLUT(inputDir, outputDir, list[i]);
    }
}
////////////////// this is the second macro ////////////////////////////////for (i = 0; i < list.length; i += 2) {
    open(inputDir + "\\" + list[i]);
    chan1filename = getInfo("image.filename");
    //print("opened " + list[i]);
   
    open(inputDir + "\\" + list[i+1]);
    chan2filename = getInfo("image.filename");
    print("opened " + list[i+1]);
   
    paramString = "c1=" + chan1filename + " c2=" + chan2filename + " create keep";
    run("Merge Channels...", paramString);
    underscoreInds = newArray();
    for (j=0; j < lengthOf(chan1filename); j++) {
        if(substring(chan1filename,j,j+1) == "_"){
            underscoreInds = Array.concat(underscoreInds,j);
        }
    }
    // converting to RGB makes it so both channels appear at once, otherwise they are saved as separate images in one TIFF file
    run("RGB Color");
   
    mergeFilename = substring(chan1filename,0,underscoreInds[2]) + "10x_DTZ_merged_RGB";
    saveAs("tiff", outputDir + "\\" + mergeFilename);
   
    close();
    close(list[i]);
    close(list[i+1]);
    }   
setBatchMode(false);

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