0

So this is the second time I've posted a question like this. Last time I got so much help from a user called @quantixed but I need help again.

My code isn't working, but it's something to do with me trying to isolate images from a stack because I need to analyse each layer separately and look for over lap (double positive and triple positive cells). It runs up until I try to name each layer. I've tried adding "startsWith" because each layer regardless of stack starts with c:1/3, c:2/3 or c:3. This is the code:

macro "Process My Files" {
    dir1 = getDirectory("C:/Users/laure/OneDrive/Documents/MSc Molecular Biology & Biotechnology/Masters Project - Dombrowski Lab/Project Data/LD005 CX5/CellHealthProfiling.V4_03-06-20_09;46;02/CEM-133432_200229080001/");
    dir2 = getDirectory("C:/Users/laure/OneDrive/Documents/MSc Molecular Biology & Biotechnology/Masters Project - Dombrowski Lab/Project Data/LD005 CX5/CellHealthProfiling.V4_03-06-20_09;46;02/CEM-133432_200229080001/ImageJ Macro Batch Results");
    list = getFileList(dir1);

    // Make an array of C01 files only
    C01list = newArray(0);
    for (i=0; i<list.length; i++) {
        if (endsWith(list[i], ".C01")) {
            C01list = append(C01list, list[i]);
        }
    }
    
x=startsWith("c:1/3")
y=startsWith("c:2/3")
a=startsWith("c:3/3")
b="Result of" + x
c="Result of" + b
d="Drawing of" + x
e="Drawing of" + y
f="Drawing of" + a
g="Drawing of" + b
h="Drawing of" + g

function DAPI() {
    selectWindow(x);
    run("8-bit");
    setThreshold(45, 255);
    run("Convert to Mask");
    run("Analyze Particles...", "size=30-350 show=Outlines clear summarize add");
}

function OLIG2() {
    selectWindow(y);
    run("8-bit");
    setThreshold(25, 255);
    run("Conert to Mask");
    run("Analyze Particles...", "size=30-250 show=Outlines clear summarize add");
}

function MBP() {
    selectWindow(a);
    run("8-bit");
    setThreshold(52, 255);
    run("Convert to Mask");
    run("Analyze Particles...", "size=30.00-250.0 show=Outlines clear summarize add");  
}

function DAPI_Olig2_overlay() {
    imageCalculator("AND create", x, y);
    selectWindow(b);
    run("Analyze Particles...", "size=30-250 show=Outlines clear summarize add");
}

function DAPI_Olig2_MBP_overlay() {
    imageCalculator("AND create", b, a); //overlay DAPI, Olig2 and Ki-67
    selectWindow(d);
    run("Analyze Particles...", "size=30-250 show=Outlines clear summarize add");   
}


    setBatchMode(true);
    for (i=0; i<C01list.length; i++) {
        showProgress(i+1, C01list.length);
        // your code goes here - an example is shown
        s = "open=["+dir1+C01list[i]+"] autoscale color_mode=Composite rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT";
         DAPI();
        OLIG2();
        Ki67orMBP();
        DAPI_Olig2_overlay();
        DAPI_Olig2_Ki67_overlay();
        saveAs("tiff", dir2+replace(C01list[i],".C01",".tif"));
        close();
        // and ends here
    }
    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;
}

The problem I'm having is that it reaches x=startsWith("c:1/3"), it can't go any further. I know the rest of the code works, its just having an issue selecting which layer of the stack I want it to analyse. Whenever I hit run I get this error back:

Error:      Number or numeric function expected in line 14:
        x = startsWith ( "c:1/3" <)>

Any ideas?

  • Stackoverflow is not the optimal place to ask ImageJ-related questions. I recommend asking on https://forum.image.sc, the official forum for ImageJ and other scientific image processing. In case you cross-post there, please link here so that the discussion stays transparent. – Jan Eglinger Jun 29 '20 at 12:24
  • I think Jan is right. SO is meant to catalogue answers to specific issues in coding. The forum is much better for "how can I get this code working?".There's two issues I see with your code as it is. The syntax in your string declarations is not right (hence the error). Second, you are trying to use these local variables in functions. The functions do not know about those variables. You need to pass them to the function as an argument. Anyway, I'd encourage you to ask this over at the forum. – quantixed Jun 29 '20 at 20:43

0 Answers0