Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Oct 01, 2016; 3:46am
URL: http://imagej.273.s1.nabble.com/Launching-a-Histogram-from-the-roi-Manager-tp5017262p5017265.html
> On Sep 30, 2016, at 2:44 PM, Dan McDonald <
[hidden email]> wrote:
>
> Dear List,
>
> I am trying to write a macro to get a histogram of a selection via the
> roiManager.
>
> When I manually click through the steps I get what I expect. When I try to
> execute the same steps through a macro I get different results. I have
> included a snip of my code below.
>
> I think that when I select a selection through the roiManager in the macro
> and then execute run("Histogram") it is not running a histogram on the
> selected selection I think I've specified.
Remove the run("Histogram”) line, which is not needed and causes a lot histogram windows to open. You can also avoid using the ROI Manager and activate the selections directly from the overlay, as in this example:
run("Blobs (25K)");
setAutoThreshold("Default");
run("Analyze Particles...", " show=Overlay");
resetThreshold;
for (i=0; i<Overlay.size; i++) {
Overlay.activateSelection(i);
getHistogram(values, counts, 256);
print(i, counts[128]);
}
-wayne
> selectWindow("rootDiameterImage");
>
> // Transfer roi from roiManager to new file
>
> run("From ROI Manager");
>
> totalRootSegments=roiManager("count");
>
> for(k_rs=0; k_rs <totalRootSegments;k_rs++) {
>
> roiManager("Select", k_rs);
>
> run("Histogram");
>
> getHistogram(Values,Counts,256);
>
> for(i_Hist=1; i_Hist<Values.length; i_Hist++) {
>
> thisValue=Values[i_Hist];
>
> thisCount=Counts[i_Hist];
>
> thisProduct=thisValue*thisCount;
>
> sumOfValueTimesCount=sumOfValueTimesCount +thisProduct;
>
> sumOfCount=sumOfCount+thisCount;
>
> }
>
>
> Can anyone see what I am doing wrong?
>
> When I manually click in the roiManager for a selection and then run a
> histogram and examine the values under the histogram "list" I get what I was
> expecting.
>
> When I examine the values within the histogram from the macro I get values
> not associated with the "selection."
>
> Thanks for your assistance,
>
> Dan
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html