# I want to find out the region which has a white spot in the image, and how many white spots are available.

5 views (last 30 days)
manpreet singh on 15 May 2014
Commented: manpreet singh on 15 May 2014
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.

Peter Bone on 15 May 2014
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.
manpreet singh on 15 May 2014
Thank you Peter, I will try it out and get back :).

Image Analyst on 15 May 2014
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.
manpreet singh on 15 May 2014
Yes, I am looking to detect the number of circles in the picture. Thank you for leading me.

Julien Moussou on 15 May 2014
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.
manpreet singh on 15 May 2014
Thank you pointing out to me, yes Julien, I want to detect the regions of the White circle in the picture, and I want to obtain a reading of the number of such circles in the picture.
I would appreciate if I can get a code for it.
Regards,

### Categories

Find more on Region and Image Properties in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!