MATLAB: Image Prcoessing – Automatic Region of Interest Extraction – Help!!

fruitim2bwimageimage processingregion of interestseedthresholding

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)
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!

Best Answer

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:
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);
3. Threshold and find biggest connected component inside the green boundary, then fill holes:
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);
5. ROI Overlayed:
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.