Getting measures from some ares in an image by a mask
Posted by luckyluke on Nov 19, 2014; 9:48am
URL: http://imagej.273.s1.nabble.com/Getting-measures-from-some-ares-in-an-image-by-a-mask-tp5010537.html
Hi ImageJ developers,
I am trying to get some measures ( as specified and set measurements) on an color image however on its specific area defined by another mask images.
I am trying to do that by java codes..actually, i try to do this in image J by doing particle analyzer on my mask image then adding this to ROI manger and then do measures in ROI manger when set measure are redirected to my main image.
I have written a piece of code but the counter below returns me 0..I am new to imageJ so I appreciate any help so I can write this program..
This is the piece of my code but i don't get any result
==========
File f = new File(Test.class.getResource("/IMD002.bmp").toURI());
File f1 = new File(Test.class.getResource("/IMD002_R1_Label4.bmp").toURI());
ColorProcessor image = new ColorProcessor(ImageIO.read(f));
//ByteProcessor mask = new ByteProcessor(ImageIO.read(f1));
ColorProcessor maskI=new ColorProcessor(ImageIO.read(f1));
ImagePlus imP=new ImagePlus("tt",maskI);
IJ.run(imP,"8-bit", "");//conveting the mask ti 8 bit image
ResultsTable rt=new ResultsTable();
ParticleAnalyzer pt=new ParticleAnalyzer
(ParticleAnalyzer.ADD_TO_MANAGER+ParticleAnalyzer.CLEAR_WORKSHEET,
ij.measure.Measurements.AREA+ij.measure.Measurements.MEAN,
rt, 1, 1000, 1, 1000);
ImagePlus img=new ImagePlus();
img.setProcessor(image);
RoiManager roi=RoiManager.getInstance();
pt.setRoiManager(roi);
ij.plugin.filter.Analyzer.setRedirectImage(img);
pt.analyze(imP);
ResultsTable rt1 = ij.plugin.filter.Analyzer.getResultsTable();
int counter = rt1.getCounter(); //number of results
System.out.println(counter);
//if (counter==0)
//no results, handle that error here
int col = rt1.getColumnIndex("Area");
for (int row=0; row<counter; row++)
{
double value = rt1.getValueAsDouble(col, row);
System.out.println(value);
}
======
Thanks any one if has any tip?
Regards