Thanks, that works. I hadn’t realised that Analyzer was always available, and when I did try it I spelled it the UK way (Analy s er) and so it threw an error.
For reference, I am now using this to get the size, grey level and position of the blob in my image, where img1 is the original greyscale image and img2 is the thresholded image:
ImagePlus img1 = WindowManager.getCurrentImage();
ImagePlus img2 = new Duplicator().run(img1);
IJ.setAutoThreshold(img2, "Yen dark");
IJ.run(img2, "Convert to Mask", "");
int opts = PA_EXCLUDE_EDGE_PARTICLES | PA_SHOW_PROGRESS | PA_CLEAR_WORKSHEET | PA_INCLUDE_HOLES;
int meas = MEAS_AREA | MEAS_MEAN | MEAS_CENTER_OF_MASS;
double minSize = Math.PI*Math.pow((10.0/2),2.0);
double maxSize = Math.PI*Math.pow((150.0/2),2.0);
ResultsTable rt1 = new ResultsTable();
ParticleAnalyzer pa = new ParticleAnalyzer(opts, meas, rt1, minSize, maxSize);
//code to set i to the blob of interest
double dot_area=-1, dot_x=-1, dot_y=-1, dot_mean=-1;
dot_area = rt1.getValueAsDouble(rt1.getColumnIndex("Area"), i);
dot_mean = rt1.getValueAsDouble(rt1.getColumnIndex("Mean"), i);
dot_x = rt1.getValueAsDouble(rt1.getColumnIndex("XM"), i);
dot_y = rt1.getValueAsDouble(rt1.getColumnIndex("YM"), i);
If there are any gotchas I have missed in this code, please let me know.
I want to change the IJ.setAutoThreshold and IJ.run(img2, “Convert to Mask”, “”) to direct Java calls as well, but that hasn’t happened yet.