0

I'm trying to write a code in Image J that will:

  1. Open all images in separate windows that end in " - GFP.vsi" within a folder
  2. Use look up tables to convert images to green and RGB color From ImageJ, the commands are: run("Green"); and run("RGB Color");
  3. Save each image in the same, original folder with the same name and as a .tif Would be ok if images overwrite original, but would also be ok if they had a new name. From ImageJ, to save as .tif file: saveAs("Tiff", "Filepath");

I have no experience with Java and just a little experience with coding. I tried to piece something together using code I found on stackoverflow and on the ImageJ website, but kept getting error codes. Any help is much appreciated!

Cam
  • 1
  • 1

1 Answers1

0

This is the way I would approach this task:

macro "Change and Resave" {
    dir1 = getDirectory("Choose Source Directory ");
    dir2 = getDirectory("Choose Destination Directory ");
    list = getFileList(dir1);

    // Make an array of files ending " - GFP.vsi"
    nd2list = newArray(0);
    for (i=0; i<list.length; i++) {
        if (endsWith(list[i], " - GFP.vsi")) {
            vsilist = append(vsilist, list[i]);
        }
    }

    setBatchMode(true);
    // loop through files
    for (i=0; i<vsilist.length; i++) {
        showProgress(i+1, vsilist.length);
        // open file using Bio-Formats, you may need to edit these two lines
        s = "open=["+dir1+vsilist[i]+"] autoscale color_mode=Composite rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT";
        run("Bio-Formats Importer", s);
        // your commands from your question
        run("Green");
        run("RGB Color");
        saveAs("tiff", dir2+replace(vsilist[i],".vsi",".tif"));
        close();
    }
    setBatchMode(false);
}

function append(arr, value) {
    arr2 = newArray(arr.length+1);
    for (i=0; i<arr.length; i++)
        arr2[i] = arr[i];
        arr2[arr.length] = value;
    return arr2;
}
quantixed
  • 287
  • 3
  • 12