Clear Filters
Clear Filters

Extraction of the region of interest in MATLAB

3 views (last 30 days)
I have this binary image as my input and I want to extract the region marked in red automatically without manually providing any coordinates Any help will be appreciated
  3 Comments
anshumala rakesh
anshumala rakesh on 5 Oct 2018
Actually I was given a gray-scale image in .TIF format and I had to extract this A type region.so I binarized it and since it was the largest area so I extracted it using the bwareafilt but now I have to extract that particular region
anshumala rakesh
anshumala rakesh on 5 Oct 2018
This is the original image which I have converted in .BMP for uploading purpose

Sign in to comment.

Accepted Answer

JSC
JSC on 5 Oct 2018
Here is some code which should work for this task:
Read in the image:
Image=imread('input.bmp');
figure
imshow(Image)
Get the red and green channel of the rgb-image:
RedChannel=Image(:,:,1);
GreenChannel=Image(:,:,2);
Convert red areas to 1 and others to 0:
Image_BW = (RedChannel>200).* (GreenChannel<100);
figure(1)
clf
imshow(Image_BW)
Get the boundaries:
B=bwboundaries(Image_BW);
Get and plot inner boundary
Bound=B{2};
hold on
plot(Bound(:,2),Bound(:,1),'g-')
Get minimal and maximal x-position of roi
min_x=min(Bound(:,2));
max_x=max(Bound(:,2));
Image2=zeros(size(Image));
%loop over columns intersecting roi
for i=min_x:max_x
%get logical vector with 1s for roi-boundary-pixels in ith line
x=Bound(:,2)==i;
%get minimal and maximal y-value of roi in ith column
min_y=min(Bound(x,1));
max_y=max(Bound(x,1));
%write ith column of roi to Image2
Image2(min_y:max_y,i,:)=Image(min_y:max_y,i,:);
end
Plot the result
figure(2)
imshow(Image2);
  5 Comments
JSC
JSC on 5 Oct 2018
So is the answer what you imagined? Can you run the code for the bmp-image?

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!