필터 지우기
필터 지우기

Filling ellipse fit with white, and making the rest of the image black

조회 수: 1 (최근 30일)
med-sweng
med-sweng 2014년 11월 24일
답변: DGM 2023년 4월 30일
If you run the code here, you will get a best ellipse fit with green borders.
I know how to fill the ellipse with white for instance, but, I have some white pixels coming out off the ellipse best fit. How can I get rid of those small white pixels appearing outside the ellipse, and make the rest of the image black?
It seems if we use im2bw, some information will be lost.
Thanks.

답변 (2개)

Image Analyst
Image Analyst 2014년 11월 24일
Get a binary image (mask) of where the ellipse is. So it's true inside the ellipse and false outside. Then to zero out the pixels in the gray scale image outside the ellipse mask, simply do:
grayImage(~binaryEllipseMask) = 0;
  댓글 수: 2
med-sweng
med-sweng 2014년 11월 24일
Thanks for your kind reply.
Can you just kindly clarify your point:
Get a binary image (mask) of where the ellipse is
I don't think this will be done with im2bw? Right? Should I here explicitly determine the location of the ellipse?
med-sweng
med-sweng 2014년 11월 24일
Also, would that be a manual process? Not an automatic one then?

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


DGM
DGM 2023년 4월 30일
See the attached function conic2mask(). The only effective difference between conic2mask() and DrawConic() is the change of a single line. Other than that, I replaced the synopsis since the original was simultaneously undescriptive and wrong. Everything else in the package needs documentation and cleanup.
img = imread('rice.png');
E = FindEllipses(img);
outsize = size(img);
mask = false(outsize(1:2));
for k = 1:size(E,1)
thismask = conic2mask(E(k,:),outsize);
mask = mask | thismask; % the union of masks
end
imshow(mask,'border','tight')

태그

Community Treasure Hunt

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

Start Hunting!

Translated by