How can I remove the background from a binarized image of which I selected a specific ROI?

4 views (last 30 days)
Hi everyone.
In order to conduct an Object analysis from a binary source image (white=main matrix, black=background and pores)
I had to inverse the colours of the image by applying the imcomplement function and then select a Region of Interest (ROI).
From that, as a final image I'd need a binary ROI image with: white=pores, black=main matrix and background, so basically I would like to remove the white background obtained with the imcomplement function.
NOTE: I already tried to select the ROI before and then imcomplement it but it doesn't work because once created, the ROI-image is imrect type instead of logical as it is required by imcomplement.
Attached there are: the source binarized image, an example of ROI-shaped image with inverted colours.
I hope someone can help me to sort this out ASAP. Thanks in advance.
Serena.

Accepted Answer

Image Analyst
Image Analyst on 25 Jul 2018
I'm confused. What is the "main matrix" part of the image? And what are pores and what is background? The images look the same, just cropped. I don't see any inverting nor do I see why it's needed.
I'll assume you want the white blobs but not the white circular surround. So simply use a circular template mask to get rid of it:
binaryImage(circularMask) = false;
or call imclearborder() to get rid of the circular surround
binaryImage = imclearborder(binaryImage);
imclearborder will also remove and partial blobs crossing the circular border, which is not a bad thing - just depends if you want area fraction and partial blobs are okay, or if you need complete blobs for your computations.
Then call imrect() or rbbox() to define the cropping rectangle, call imcrop() or use indexing to actually make the crop, and you're done.
  1 Comment
Serena Ditroia
Serena Ditroia on 25 Jul 2018
I'm sorry I haven't been clear but it was a bit difficult to extract the problem from the code and then explain it shortly and in a clear way. However, thank you very much, you helped me solving my problem. I indeed needed all the white blobs with a black background whichever ROI shape I choose. I had already created a mask with my ROI and cropped it to move forward in my study. The solution was achieved with: binaryImage(circularMask) = false;
Thank you,
Serena.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!