Image processing of a binary image
이전 댓글 표시
I made this binary image such that a bigger circle has non overlapping random smaller circles. How can I remove those circles those are not complete.

댓글 수: 5
KSSV
2023년 2월 21일
Show us your code which generates this image.
Shubham
2023년 2월 21일
A cheaper version of:
bigCircleImage = zeros(image_size, image_size, 'double');
[x, y] = meshgrid(1:image_size, 1:image_size);
bigCircleImage((x - image_size/2).^2 + (y - image_size/2).^2 <= bigCircleRadius.^2) = 1;
is
v = ((1:image_size) - image_size / 2).^2;
bigCircleImage = double(v + v.' <= bigCircleRadius.^2);
It would be easy to omit the small circles during the calculation of their centers: Simply keep only circles, whos center is inside the circle with the radius bigCircleRadius - smallCircleRadius.
Creating the image at first an removing the cropped circles afterwards is far too indirect. So insert the rejection inside the code for placing the small circles. It would be inefficient, if the readers rewrite this code just to insert one additional IF condition.
Shubham
2023년 2월 21일
Jan
2023년 2월 21일
"how to compare this using code" - You must have some code, which prevent overlapping between the small circles already. The code to include only small circles inside a radius minus the radius of the small circle is trivial.
It would include something like: vecnorm(c - C) < bigR - smallR. As soon as you show your code, it would be very easy to insert this condition. But for posting a working answer, we have to guess, what you code is at first and rewrite it. This is not an efficient way to search for a solution.
채택된 답변
추가 답변 (2개)
mask = imread('circles.png') > 128; % Get original binary image from a file.
subplot(1,2,1);
imshow(mask);
% Get mask
mask = ~bwconvhull(mask) | mask;
% Remove blobs at border
mask = imclearborder(mask);
subplot(1,2,2);
imshow(mask);
Note: some blobs are touching to form a dumbbell-shaped blob, and are not circular. If those touch the border, the whole irregular shape will get removed.
댓글 수: 1
Note: some blobs are touching to form a dumbbell-shaped blob, and are not circular. If those touch the border, the whole irregular shape will get removed.
Here's a refinement that can fix some of that.
mask = imread('circles.png') > 128; % Get original binary image from a file.
subplot(1,2,1);
imshow(mask);
% Get mask
circ=circMask(size(mask));
se=strel('disk',4);
mask=imerode(mask,se);
circ=imdilate(~circ,se);
mask = circ|mask;
% Remove blobs at border
mask = imdilate( imclearborder(mask),se);
subplot(1,2,2);
imshow(mask);
function c=circMask(sz)
[m,n]=deal(sz(1),sz(2));
R=min(sz)/2;
[x,y]=deal((1:m)',1:n);
c=(x-mean(x)).^2+(y-mean(y)).^2<=R^2;
end
load BWimage
BW0=BW;
BW=imerode(BW, strel('disk',3));
BW=bwpropfilt(BW,'Eccentricity',[0,0.3]);
BW=imdilate(BW, strel('disk',3));
immontage({BW0,BW},'Bord',[5,5],'Back','w')
카테고리
도움말 센터 및 File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



