I want to find out the region which has a white spot in the image, and how many white spots are available.
6 次查看(过去 30 天)
显示 更早的评论
I want to have an output which displays the number of white spots in the image. Also How to define the region of white spot in the image.
0 个评论
回答(3 个)
Peter Bone
2014-5-15
You could use regionprops to find the area or bounding box of each region. Look for the region with the right size. That could work on most images. If you need to do it based on shape then you could use Hough transform for circle detection. See the File Exchange.
Image Analyst
2014-5-15
I'm going to assume that if it's some white area that's not a circle, then you don't want it. So the easiest way, assuming what you show is typical, is to just sum up the white pixels in a rectangular subimages - essentially a template. Let's say you know the starting and ending rows and columns for each rectangular location. Then just do
subimage = binaryImage(row1:row2, col1:col2)
areaFraction = sum(subimage(:)) / numel(subimage);
if areaFraction < someValue
% It's a circle
else
% It's a big mess.
end
If that doesn't work and you need to really go by the shape because you might have other subimages with, say, squares that have the same area fraction, then you need to use regionprops
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Area', 'Perimeter', 'EquivDiameter');
allAreas = [measurements.Area];
allPerimeters = [measurements.Perimeter];
allDiams = [measurements.EquivDiameter];
circularities = appPerimeters.^2 ./ (4*pi*allAreas);
circleIndexes = allDiams > minDiameter & allDiams < maxDiameter & circularities < 2; % Or whatever value works
numberOfCircles = sum(circleIndexes)
Or do it both ways and then resolve conflicts if they disagree.
Julien Moussou
2014-5-15
The question is not very specific : what is a white spot ?
If it is just a connex component, see
doc BWboundaries
If it is a somewhat round-shaped form, you need to have some criterion for what is and what is not a white spot, for instance size, ratio of height over length, etc.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!