Reshaping Blobs in a Binary
6 views (last 30 days)
Show older comments
When processing an image with low contrast, I inevitably will distort some of the shapes when I threshold the grayscale image and convert it to binary.
Is there any way to reshape blobs after I have done the conversion to binary? I know the shapes should all be circular, but most have tails or look elongated.
1 Comment
Accepted Answer
Image Analyst
on 20 Jun 2012
Regarding your latest comment...For each blob, get the EquivDiameter and the centroid, then call rectangle() to display a circle in the overlay at the centroid location with a diameter of EquivDiameter.
2 Comments
Ryan
on 20 Jun 2012
I = imread('TestImage.jpg');
BW = im2bw(I,graythresh(I));
[ai,bi] = size(BW);
figure,imshow(BW), hold on
props = regionprops(logical(BW),'Centroid','EquivDiameter');
centroids = cat(1,props.Centroid);
diams = cat(1,props.EquivDiameter);
for m = 1:length(centroids(:,1))
rectangle('Position',[centroids(m,1)-diams(m)/2,centroids(m,2)-
diams(m)/2,diams(m),diams(m)],'Curvature',[1,1],'FaceColor','r')
end
hold off
Where this is the "TestImage.jpg" that I used:
http://i.imgur.com/Q5C6j.jpg
This is the result:
http://i.imgur.com/kRz8m.jpg
More Answers (2)
Image Analyst
on 20 Jun 2012
Perhaps, but it's not easy. Let's say you have a comet-shaped blob - pointier at one end than the other. Use bwboundaries() to get all the boundary coordinates. Use regionprops to get the equation of the major axis, using orientation and centroid. Then take the coordinate from each half of the blob. Half will come from the pointy side and half from the larger, rounder size. Scan each set of coordinates to find the minimum curvature over a range of pixels, say 10 or 20 pixels. The side with the larger minimum radius of curvature will be the circular side and the side with the smaller minimum radius of curvature will be the pointy side.
Alternatively you can use bwmorph('skel') to get the skeleton. Then, perhaps you can use bwmorph('endpoints') to get the ends of the skeleton and see which is closer to a boundary point. The endpoint at the pointy tail end will be closer to the nearest boundary point than the endpoint at the larger round head end. The circle would then be placed at the round head end with a radius equal to, say, the average distance of the closest 10 boundary points. Good luck.
0 Comments
Ryan
on 20 Jun 2012
use region props area measurements and dilate the centroid points with a disk structuring element with the appropriate radius (assume circle and use A = pi*r^2). I have also read some academic papers in the past where they filled areas with the largest circle possible, but I am not sure how to program that.
For area of the circle, you could also use "EquivDiameter" from the regionprops.
5 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!