How to extract image region within boundary

Hi, I have to segment the LV from cardiac MRI. The output is an image with a boundary for the specified region (attached image). My question is how can i get only the region within the boundary. how to set the inside of the boundary to 1 and 0 for the rest for a binary image.
Thanks in advance.

 Accepted Answer

It sounds like you have already identified the blue boundary somehow, because your question does not ask how to get the boundary in the first place. So, having the boundary, you should have an ordered list of x,y coordinates for it. So then, to create a mask that is 1 inside of the boundary and 0 outside the boundary, use poly2mask():
[rows, columns, numberOfColorChannels] = size(grayImage);
mask = poly2mask(x, y, rows, columns);

10 Comments

Thank you for your propositions. the problem is with the blue boundary. Is there any solutions to extract its coordiantes from the image?
Starting with your RGB image with the blue circle in it, first get the individual color channels and see where it equals exactly [0,0,255]:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
blueCircle = redChannel == 0 & greenChannel == 0 & blueChannel == 255;
This should be an image of just the pure blue ring. Now to get the (x, y) coordinates, use find():
[y, x] = find(blueCircle);
How to find this boundary with the help of matlab (I mean how to draw this blue line with matlab) ?
Circles can be drawn with viscircles(), rectangle(), or plot().
But suppose i dont have a circular region. I have a irregular shape in the same image. How to find that region and male a boundary around it
Use bwboundaries() to get the boundary around your region in your binary image, then use plot() to plot it.
I want to make a boundary of this round object(shown in the image) and after that, I want to mask it. Right now, I am doing it manually for every image. I have tried using bwboundaries but it is not giving good results. Hope you can help.
bwboundaries is meant for binary images. You haven't even done the first step of segmentation yet. You need to do that first. It will take some time to develop a segmentation algorithm that works with images like this. Good luck.
But how to extract multiple regions with boundary on an image?
You use image segmentation. See my Image Segmentation Tutorial on my File Exchange https://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc

Sign in to comment.

More Answers (1)

If you complete the segmentation part probably you will have the information's of circular boundary Once you get the information you can do the remaining stuffs by referring here

Community Treasure Hunt

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

Start Hunting!