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=sharing I 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 |
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=sharing I 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 |
Dear Andrew,
Is the ring more or less in the same place on all the images or does it move around? Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Anderson, Charles (DNR) Sent: 08 June 2015 23:31 To: [hidden email] Subject: Re: Automate circular ROI selection 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=sharing I 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Kees,
Yes the rings are more or less in the same place. Thank you for your comments, Charles. Am I supposed to draw the circle on the last black and white image that pops up, titled "Results of a (green) (25%)? or on the original image? |
Dear Andrew,
The attached code assumes the ring is more or less in the centre and will try to find the best fitting circle. It also uses the Color Threshold to find the green areas but you probably have already better code to collect this info but maybe the first part is useful to find the ring in the image. At the moment you manually have to open an image. Best wishes Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Andrew Sanchez Sent: 11 June 2015 20:15 To: [hidden email] Subject: Re: Automate circular ROI selection Dear Kees, Yes the rings are more or less in the same place. Thank you for your comments, Charles. Am I supposed to draw the circle on the last black and white image that pops up, titled "Results of a (green) (25%)? or on the original image? -- View this message in context: http://imagej.1557.x6.nabble.com/Automate-circular-ROI-selection-tp5013060p5013133.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 Macro_test.txt (5K) Download Attachment |
Thanks for your suggestion, Kees. I guess saying that the rings are more or less in the same place was a bit of a stretch. Unfortunately, I don't think my images are consistent enough for this macro to work. Back to searching the archives! The circle selection needs to be precise but I think it can be done!
|
Free forum by Nabble | Edit this page |