Standard bin size using the HistogramLister macro

Hi everyone,

I’m running into an issue when trying to standardize my histogram lists.
What we’re doing is creating a distance map and measuring the values of ROIs on it. This creates a list of results which we want to create a histogram of. What we want to save is the bin values, not the image. We’ve found the HistogramLister macro which does the job.

The problem: Some images have the values going from 0 to 255 but others go from 0 to 200, for example. We want every histogram to start at 0 and end at 255 so that the bins will always be the same size.

Currently the relevant part of my macro looks like this:

//Creates an image from the results
n = nResults;
newImage(“Mean”, “32-bit”, n, 1, 1);
for (i=0; i<n; i++)
setPixel(i, 0, getResult(“Mean”, i));

//Creates histogram data from said image
nBins = 25
run(“Clear Results”);
row = 0;
getHistogram(values, counts, nBins)
for (i=0; i<nBins; i++) {
setResult(“Value”, row, values[i]);
setResult(“Count”, row, counts[i]);
row++;
}
updateResults();

I’ve tried a lot of variations of a potential solution, but always get the following error:

Number or numeric function expected in line 11
getHistogram (values , counts , nBins [ <,> histMin, histMax]);

The same thing happens if I replace histMin and histMax by numbers, if I define them as variables first, if I remove that comma, etc.

If anyone knows how to get it to work, or knows another solution, your help would be much appreciated.

Thank you,
Emma

Hi @Emma,

It looks like you’re including the brackets in the code. Those just indicate that the rest of the parameters ( histMin and histMax) are optional, and are not meant to be included in the code:

getHistogram (values , counts , nBins , histMin, histMax);

Is this the case, or am I just misunderstanding?

Cheers!
Nico

1 Like

You’re right, it works now!
Thank you for explaining why the brackets are there, I had no idea.

1 Like