Run stack histogram null pointer exception

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

Run stack histogram null pointer exception

Josue Balandrano Coronel
Hi,
I’m trying to run a macro that extracts the histogram in csv and jpeg form. The jpeg form is the actual graph and it’s what I cannot do at the moment.
Here’s my macro:

args = getArgument();
args_arr = split(args, "&");

in_file="";
image_type="";
width=0;
height=0;
number=1;
offset=0;
gap=0;
byte_order="";

for (i=0; i<args_arr.length; i++) {
    arg = split(args_arr[i], '=');
    if (arg[0] == "in_file") {
        in_file=arg[1];
    } else if (arg[0] == "image_type") {
        image_type=arg[1];
    } else if (arg[0] == "width") {
        width=arg[1];
    } else if (arg[0] == "height") {
        height=arg[1];
    } else if (arg[0] == "number") {
        number=arg[1];
    } else if (arg[0] == "offset") {
        offset=arg[1];
    } else if (arg[0] == "gap") {
        gap=arg[1];
    } else if (arg[0] == "byte_order") {
        if (arg[1] == "little-endian") {
            byte_order=arg[1];
        }
    }
}

image_params = "open=[" + in_file + "] image=[" + image_type + "] width=" + width
                + " height=" + height + " offset=" + offset + " number=" + number
                + " gap=" + gap + " " + byte_order;
run("Raw...", image_params);

run("Histogram", "stack");

saveAs("Jpeg", in_file+".histogram.jpg");

if (image_type == "8-bit") {
    nBins = 256;
    totalcounts=newArray(nBins);

    for (m=0; m<nBins; m++) {
        totalcounts[m]=0;
    }

    for (k=1; k<=nSlices; k++) {
        setSlice(k);
        getHistogram(values, counts, nBins);
        for (m=0; m<nBins; m++) {
            totalcounts[m]+=counts[m];
        }
    }

} else {
    histMin=-1000;
    histMax=5000;
    nBins=256;
    totalcounts=newArray(nBins);

    for (m=0; m<nBins; m++) {
        totalcounts[m]=0;
    }

    for (k=1; k<=nSlices; k++) {
        setSlice(k);
        getHistogram(values, counts, nBins, histMin, histMax);
        for (m=0; m<nBins; m++) {
            totalcounts[m]+=counts[m];
        }
    }
}

run("Clear Results");

for (m=0; m<values.length; m++){
                setResult("Value", m, values[m]);
                setResult("Count", m, totalcounts[m]);
}

setOption("ShowRowNumbers", false);

updateResults();

saveAs("Results", in_file+".histogram.csv");

run("Close");

eval("script", "System.exit(0);");


The csv file is correct but the jpeg file is always just an all black image. This is a histogram from a stack.
Also when I run this I get a Null Pointer Exception.
This works when I do it through the GUI. Is there something else I can try to fix it?
I’m using the latest FIJI version.

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