I want to find out the region which has a white spot in the image, and how many white spots are available.
조회 수: 5 (최근 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162700/image.jpeg)
댓글 수: 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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!