Can u send me the code to this mail gundunavya35@gmail.com please
Image Prcoessing - Automatic Region of Interest Extraction - Help!!
4 次查看(过去 30 天)
显示 更早的评论
Hello,
I am working on a project where I have to calculate the relative area of a region of interest to the area of the whole object. Separating the whole object out is easy and done. I need help/example code on how to automatically separate out the region of interest (pictures below)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164235/image.png)
Green - Whole image, Red - Region of interest(drawn by hand). The region of interest has to automatically be extracted when the code is run.
I have already tried all the basic methods such as thresholding, pixel values of the ROI, boundary conditions, etc.
I will answer any questions if those arise.
Thank you!
采纳的回答
Ahmet Cecen
2016-5-14
编辑:Ahmet Cecen
2016-5-14
Ok here is what I could do in 5 mins with my above suggestions and a little more:
1. Get Blue channel with the green line on the image:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174304/image.png)
2. Convert to double, take square of the image, erode with a disk strel until satisfied:
XPX = double(blue);
XPX = XPX.^2;
se = strel('disk',3,0)'
XPX = imerode(XPX,se);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174305/image.png)
3. Threshold and find biggest connected component inside the green boundary, then fill holes:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174306/image.png)
4. Activecontour with the thresholded image as a mask, then imopen with a giant disk to round:
bw3 = activecontour(blue,BW2,300);
se3 = strel('disk',100,0);
BWXP3 = imopen(bw3,se3);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174307/image.png)
5. ROI Overlayed:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174308/image.png)
I am sure you can get better results with more fine tuning or maybe resizing to a smaller image, however this process makes some specific assumptions about the nature of your data, which may not be applicable for the rest of your images as Image Analyst mentioned. He would also have more experience with this stuff, I only do computer vision in a narrow field of study.
5 个评论
Image Analyst
2016-5-14
You can get the same effect with eroding just once with a larger structuring element.
Ahmet Cecen
2016-5-14
编辑:Ahmet Cecen
2016-5-14
Yeah pretty much, with the exception of the curvature effect, which shouldn't really matter here (radius 3 is pretty much a diamond with flat diagonal edges, whereas radius 50 is pretty circular). It is just unclear what size will do the trick, so you can either keep trying with different sizes and plot and check, or just erode with something smaller and plot and check. Both are for loops, pick a preference.
I have an irrational fear of the "disk" element in large radius, in small sizes when I look at the eroded image I can relate to the jagged diagonals of a diamond more easily. I can always use a large diamond, but then some guy asks me to justify why diamond and not circle, whereas in small sizes I don't have to answer. It's one of those convoluted habits you pickup when you start coding and didn't know better, then it just sticks with you.
更多回答(2 个)
Ahmet Cecen
2016-5-13
Since you didn't provide a clean image, I can only speculate. My strategy would be:
- The region of interest seems "bluer" than the rest. Pick out the blue channel out of the RGB matrix. Convert to double, maybe even take element-wise square for highlighting.
- Repeatedly erode with a small disk to eat off the bluer regions around the main object (the shines) as I erode, since that green line will become larger as you erode.
- After experimenting with the number of erosion steps, I would threshold out what I can, hoping that after the green line expands enough, the region of interest is the only "bluer" region remaining.
Image Analyst
2016-5-14
Please post the original image without annotation lines. The problem is you can't do it by color segmentation or morphology alone because the top of the seed, or whatever that is, is not well defined. Just use the Color Thresholder app and you'll see what I mean. And if you get something that works for that image, it might not work for other images.
4 个评论
Image Analyst
2016-5-14
Yes, for this particular image the top of the kernel is a problem. One approach is to use watershed to cut it off. See Steve's blog entry. Then use bwareafilt() to extract the largest blob. However if you do that on an image that does not exhibit that problem, it might just mess it up. My next thing to try or suggest was activecontour() - it looks like Ahmet gave you code for that. I'm also attaching my standard demo for that (not using your image).
One thing you've got to look out for in these kind of adaptive/automatic methods is that sometimes you will force them to find a blob when they shouldn't. What is there is no lighter stuff there and you did something foolhardy like used graythresh()? Well it would return a threshold. What if you had two well separated humps in the histogram. Well it would return a valid splitting level. However what if there was no brighter blob and you just had a single hump on the dark end of the histogram? Well it would find a threshold in the middle of the hump and tell you that half of your background is actually foreground, and that would be wrong. So in your situation, you don't want to be so locally adaptive that it's finding stuff it shouldn't. Often what is done in these situations is to calibrate the intensity by setting the lux level to a known value, using constant camera settings (no automatic anything in the camera), and image a known standard like the Color Checker Passport. Then you can use fixed threshold or color gamut segmenting values.
You may need a combination of fixed algorithms and adaptive algorithms. For example you may get an algorithm that works on all levels (from none there to 100% there) of white-ish in yellow-ish corn but then find that algorithm won't work for greenish or whitish kernels. So it might have to adjust for the color of the bulk kernel, then adapt and use "fixed" values determined from the bulk color. Like maybe you compute the bulk color, and say that the inside region is always 10 units of Delta E from the bulk. I attach a delta E demo.
See my File Exchange for more color segmentation demos. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Finally, I attach a visualization of the 3-D color gamut in CIE LAB color space:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/183020/image.png)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!