How to find circles within a region of interest
조회 수: 10 (최근 30일)
이전 댓글 표시
We're trying to find circles within a freehand drawn boundary. The issue that we're running into is that the circle finder code is also finding the edges of the region of interest and calling them circles. This is our code:
%open your image
A = imread('sample.png');
%create mask%
h_im= imshow(A);
e = imfreehand
mask = createMask(e,h_im);
imshow(mask)
%overlay mask
[rows, columns, numberofcolorbands]= size(A);
if numberofcolorbands == 1
maskImage = A;
maskImage(~mask) = 0;
else
maskedImage = bsxfun(@times,A,cast(mask,class(A)));
end
%Find circles in masked region
[centers, radii] = imfindcircles(maskImage,[2 4],'ObjectPolarity','dark','Sensitivity',1,'Method','twostage','EdgeThreshold',0.25);
imshow(maskImage);
h = viscircles(centers, radii);
And here is our sample output:
How do we specify that we want only the code to look within the boundary to find the circles and ignore the edge?
Thanks, Jenna and Amy
댓글 수: 0
답변 (1개)
Spandan Tiwari
2016년 12월 20일
imfindcircles uses circular Hough transform underneath and detecting circles with small radius (usually < 5) is always challenging. I don't see a simple way to play with the parameters of imfindcircles to get rid of the boundary circles. There's a parameter called 'EdgeThreshold' that you can try but the idea there is to keep the strong edges in the image for circle detection and ignore the weak ones. But in this case I won't be surprised if the edges at the boundary of the region are the strongest, in which case this parameter won't be able to remove the ones at the edges (at least not in one call). This means that we need to do some post-processing to identify and eliminate the spurious circles at the edges. If you are using imfreehand to create the region you can get the binary mask of the region as follows:
h = imfreehand();
% Create a binary mask
binaryImage = h.createMask();
Now you can get a mask for the boundary of the region as follows:
rad = 5;
boundaryMask = imdilate(binaryImage, 5) - imerode(binaryImage, 5);
'boundaryMask' will highlight pixels that are within a 'rad' distance from the boundary, on either side. From this point on, it should be easy to check whether a circle (its center maybe) lies within this boundary region or not.
댓글 수: 2
Image Analyst
2016년 12월 20일
Maybe if they'd attached the input image, people could try things. With only the output image, I can't even see the circles they're trying to identify. Perhaps regionfill can be used to smear the blob outwards and reduce the strength of the signal near the boundary. But maybe just checking whether the circle is inside the ring of width 5 around the perimeter, like Spandan suggested, is better and/or simpler. It's just whether you want to avoid finding them in the first place versus finding them and then throwing them away if they're near the boundary.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!