Getting color statistics from multiple ROI in an image

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

Getting color statistics from multiple ROI in an image

Cmhulbert
Hey all,

I have an image that I have segmented and it now is an RGB tiff image with overlayed ROIs. Most images have around 50 ROIs. I know how to get color statistics using the Color Histogram tool, but I have had little luck writing a script to utilize this. Namely, I don't know how to save the table you get after clicking "list" on the Color Histogram window within a script. I can run Color Histogram from the script, but am having a hard time getting the Color Histogram jar to import directly, so I could access its showList command.

Anyway, I'm not sure that is even the best way to go about it. I know there is a Color processor class, but I'm not sure how to use it from an irregular shaped ROI.

I should note that I don't just want RGB mean values, but the RGB values in each area, such as Color Histogram provides if you click "list" in the window. Any help would be great!

Sincerely,
Caleb
Reply | Threaded
Open this post in threaded view
|

Re: Getting color statistics from multiple ROI in an image

Peter Haub
Hi Caleb,

- iterate over the Rois ()
    -- iterate over the pixels in a Roi (check topic "Iterator over Roi
points anywhere?" in the mailing list)
       --- convert integer values to RGB values (and calculate whatever
you need)

Peter


On 06.05.2016 17:30, Cmhulbert wrote:

> Hey all,
>
> I have an image that I have segmented and it now is an RGB tiff image with
> overlayed ROIs. Most images have around 50 ROIs. I know how to get color
> statistics using the Color Histogram tool, but I have had little luck
> writing a script to utilize this. Namely, I don't know how to save the table
> you get after clicking "list" on the Color Histogram window within a script.
> I can run Color Histogram from the script, but am having a hard time getting
> the Color Histogram jar to import directly, so I could access its showList
> command.
>
> Anyway, I'm not sure that is even the best way to go about it. I know there
> is a Color processor class, but I'm not sure how to use it from an irregular
> shaped ROI.
>
> I should note that I don't just want RGB mean values, but the RGB values in
> each area, such as Color Histogram provides if you click "list" in the
> window. Any help would be great!
>
> Sincerely,
> Caleb
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Getting-color-statistics-from-multiple-ROI-in-an-image-tp5016337.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
Reply | Threaded
Open this post in threaded view
|

Re: Getting color statistics from multiple ROI in an image

Cmhulbert
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
Reply | Threaded
Open this post in threaded view
|

Re: Getting color statistics from multiple ROI in an image

Krs5
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
Reply | Threaded
Open this post in threaded view
|

Re: Getting color statistics from multiple ROI in an image

Cmhulbert
That's much quicker, thanks Kees!

The issue here is that it seems to be measuring the roi by its bounding box, not the bounds of the irregular roi I have. I think it shouldn't be too hard to merge the two scripts I have now (the two in this thread) but I'm having trouble converting your .ijm macro to a java script (which is what the previous one is in, and also where my experience lies. Do you have any advice for checking whether the bin I'm measuring with your script is within the bounds of the irregular rois im using?

Caleb
Reply | Threaded
Open this post in threaded view
|

Re: Getting color statistics from multiple ROI in an image

Krs5
Dear Caleb,

Sorry I am afraid I cannot help you with the java code. However, I have updated the code so it can deal with irregular roi's. As before, not fully tested but it is fast.

// Macro code to measure RGB bins in ROIs including irregular shaped ROIs
// 12 May 2016, Kees Straatman, University of Leicester

setBatchMode(true);
for(r=0;r<roiManager("count");r++){
        roiManager("Select", r);
        name = Roi.getName;
        nBins = 256;
        run("Duplicate...", "title="+name);
        run("Split Channels");

        // Get number of black pixels in ROI
        selectWindow(name+" (red)");
        OutsideWhite();
        getHistogram(values, countsRed, nBins);
       
        selectWindow(name+" (green)");
        OutsideWhite();
        getHistogram(values, countsGreen, nBins);
       
        selectWindow(name+" (blue)");
        OutsideWhite();
        getHistogram(values, countsBlue, nBins);
       
  row = nResults;
  setResult("Label", row, name);
        setResult("Value", row, values[0]);
        setResult("Red", row, countsRed[0]);
        setResult("Green", row, countsGreen[0]);
        setResult("Blue", row, countsBlue[0]);
        row++;

        // Get pixels for all other bins in ROI
        selectWindow(name+" (red)");
        OutsideBlack();
        getHistogram(values, countsRed, nBins);
               
        selectWindow(name+" (green)");
        OutsideBlack();
        getHistogram(values, countsGreen, nBins);
       
        selectWindow(name+" (blue)");
        OutsideBlack();
        getHistogram(values, countsBlue, nBins);
       
    for (i=1; 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;


function OutsideWhite(){
        setBackgroundColor(255, 255, 255);
        clear();
}

function OutsideBlack(){
        setBackgroundColor(0, 0, 0);
        clear();
}

function clear(){
        roiManager("Select", r);
        run("Clear Outside");
}

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: 11 May 2016 18:37
To: [hidden email]
Subject: Re: Getting color statistics from multiple ROI in an image

That's much quicker, thanks Kees!

The issue here is that it seems to be measuring the roi by its bounding box, not the bounds of the irregular roi I have. I think it shouldn't be too hard to merge the two scripts I have now (the two in this thread) but I'm having trouble converting your .ijm macro to a java script (which is what the previous one is in, and also where my experience lies. Do you have any advice for checking whether the bin I'm measuring with your script is within the bounds of the irregular rois im using?

Caleb




--
View this message in context: http://imagej.1557.x6.nabble.com/Getting-color-statistics-from-multiple-ROI-in-an-image-tp5016337p5016407.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