How to isolate the circle from the shaded area?

조회 수: 3 (최근 30일)
Mahmoud
Mahmoud 2015년 2월 1일
편집: Matt J 2015년 2월 1일
I would like to have only a shaded area from the picture. I want to remove the circle from the binary image. Any idea?

답변 (1개)

Matt J
Matt J 2015년 2월 1일
How about
A=imread('http://www.mathworks.com/matlabcentral/answers/uploaded_files/24735/D1.png');
A=rgb2gray(A);
outer=~imfill(A,'holes');
outerd=imdilate(outer,ones(5));
newImage = A&~outerd;
  댓글 수: 2
Mahmoud
Mahmoud 2015년 2월 1일
Amazing!! That worked perfectly! Now, if I want to fill the isolated area to find the area in pixel using regionprops, how can I fill that region?
Matt J
Matt J 2015년 2월 1일
편집: Matt J 2015년 2월 1일
B=imerode(~A,ones(3));
S=regionprops(B,'PixelIdxList','Area');
[ar,idx]=sort([S.Area],'descend');
tofill=vertcat(S(idx(1:2)).PixelIdxList);
C=false(size(A));
C(tofill)=1;
result=~imdilate(C,ones(5));

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by