Login  Register

Re: Getting color statistics from multiple ROI in an image

Posted by Krs5 on May 11, 2016; 4:37pm
URL: http://imagej.273.s1.nabble.com/Getting-color-statistics-from-multiple-ROI-in-an-image-tp5016337p5016406.html

Dear Caleb,

The code below might do what you want. At the moment all ROI results are in one table with the name of the ROI included.

for(r=0;r<roiManager("count");r++){
        roiManager("Select", r);
        name = Roi.getName;
        nBins = 256;
        run("Duplicate...", "title="+name);
        run("Split Channels");
        selectWindow(name+" (red)");
        getHistogram(values, countsRed, nBins);
        selectWindow(name+" (green)");
        getHistogram(values, countsGreen, nBins);
        selectWindow(name+" (blue)");
        getHistogram(values, countsBlue, nBins);
  row = nResults;
    for (i=0; i<nBins; i++) {
                setResult("Label", row, name);
                setResult("Value", row, values[i]);
                setResult("Red", row, countsRed[i]);
                setResult("Green", row, countsGreen[i]);
                setResult("Blue", row, countsBlue[i]);
                row++;
        }
        selectWindow(name+" (red)"); close;
        selectWindow(name+" (green)"); close;
        selectWindow(name+" (blue)"); close;
       
} updateResults;

Be aware, not fully tested!

Best wishes

Kees


Dr Ir K.R. Straatman
Senior Experimental Officer
Advanced Imaging Facility
Centre for Core Biotechnology Services
University of Leicester
http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Cmhulbert
Sent: 10 May 2016 16:12
To: [hidden email]
Subject: Re: Getting color statistics from multiple ROI in an image

Wow, I hadn't seen that method of looping over the ROI pixels, that's really useful! thanks!

My only issue with this method is that it is extremely slow (with the size/resolution of my roi's it takes about 30 seconds to process a single roi, of which i have sometimes as much as 80 per image). Comparatively, the color histogram seems to happen extremely quickly. Is there a quicker way I could measure the color, or is iterating over the pixels in the roi in this manner going to be the best method?

Best,
Caleb



--
View this message in context: http://imagej.1557.x6.nabble.com/Getting-color-statistics-from-multiple-ROI-in-an-image-tp5016337p5016387.html
Sent from the ImageJ mailing list archive at Nabble.com.

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

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