Posted by
Anderson, Charles (DNR) on
Jun 08, 2015; 10:28pm
URL: http://imagej.273.s1.nabble.com/Automate-circular-ROI-selection-tp5013060p5013083.html
Good day, Andrew,
The rim of your cylinder will be slightly elliptical because the camera is slightly off axis. It will be hard to identify automatically because it is partly occluded by soil and vegetation. Additionally, the white rim will be hard to distinguish from the interior walls. That said, I hope someone will show us a good automatic approximation method for your challenging circle!
The macro below will automate most of the process, though it still requires you to identify a circle as each image is processed. The results table reports the area (pixels) of the circle you choose and the mean gray level. The proportion of 'green' pixels can be found as the mean / 255. I have used only a very crude method to identify "green", but there are papers on identifying vegetation from images that might give better answers.
As a biologist, I'd be more willing to believe results if you place circular ROI than if it is done automatically. I think you can best place them so none of the shadow or reflection on the interior walls is miss-identified as 'green', yet nearly all the interior of your cylinder is within your ROI. Perhaps some effort with the Wiki segmentation plugin could allow you to distinguish green plants, dead grass, and soil. Dead grass occludes some of the greenery, so there are more questions to think about.
Charles
// CircleVeg.ijm
//run("Set Measurements...", "area mean centroid bounding shape feret's redirect=None decimal=2");
run("Set Measurements...", "area mean shape redirect=None decimal=2");
//setForegroundColor(255, 255, 255);
setForegroundColor(0, 0, 0);
dir1 = getDirectory("Choose Source Directory ");
list = getFileList(dir1);
//setBatchMode(true);
for (i = 0; i<list.length; i++) {
showProgress(i+1, list.length);
open(dir1+list[i]);
run("Duplicate...", "title=a");
selectWindow("a");
run("Split Channels");
selectWindow("a (blue)");
imageCalculator("Subtract create", "a (green)","a (red)");
selectWindow("Result of a (green)");
setAutoThreshold("Default dark");
//run("Threshold...");
setThreshold(1, 255);
run("Convert to Mask");
setTool("oval");
waitForUser("Select areas","Hold shift to draw circle, then click 'Ok'");
// Draw circle using oval tool holding shift down
run("Clear Outside");
run("Measure");
selectWindow("Result of a (green)");
close();
selectWindow("a (blue)");
close();
selectWindow("a (green)");
close();
selectWindow("a (red)");
close();
selectWindow(list[i]);
close();
}
-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of Andrew Sanchez
Sent: Friday, June 05, 2015 3:35 PM
To:
[hidden email]
Subject: Automate circular ROI selection
I am trying to automate the selection of a circular ROI. I have been exploring some suggested solutions like Hough transformation (
http://rsb.info.nih.gov/ij/plugins/hough-circles.html) and segmentation, including the Trainable Weka Segmentation tool, but have not had any so far, most likely due to my slow climb of the learning curve as a new user.
I am brand new to ImageJ, and am working my way through tutorials and documentation for a solution.
Here is a sample image:
https://drive.google.com/file/d/0B208tul7KbkbX2RYLXhDLXJlVFE/view?usp=sharingI need to select everything inside of the thick white circle, take the area of the circle in pixels, and then count the number of green pixels. Is there a way to do this without manually selecting the circle for every image?
--
Thank you,
Andrew Sanchez
Lab Assistant
Center for Ecosystem Science
Northern Arizona University
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html