Filling ellipse fit with white, and making the rest of the image black
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
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;
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')
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!