Posted by
Krs5 on
May 13, 2016; 11:30am
URL: http://imagej.273.s1.nabble.com/Getting-color-statistics-from-multiple-ROI-in-an-image-tp5016337p5016422.html
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.htmlSent 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