Help in image processing - how to count the number of black shapes on white image

14 views (last 30 days)
I have a fractography image. It consists of many black spots.. Black spots are of different shapes. I want to count the number of black spots...
Please find the attachment.
Please anyone suggest the code/command for this.. Any help is much appreciated..
  2 Comments
David K.
David K. on 26 Aug 2019
First you need to make this greyscale image fully black white. This can be done with a simple threshold with
threshold = 0.5; % fiddle with this
BW = im2bw(yourImage, threshold);
BW = ~BW; % the following code needs white spots black background
Then you can use regionprops to identify every spot
stats = regionprops('table',bw,'Centroid','MajorAxisLength','MinorAxisLength')
test if everything was found with
imshow(yourImage)
centers = stats.Centroid;
diameters = mean([stats.MajorAxisLength stats.MinorAxisLength],2);
radii = diameters/2;
hold on
viscircles(centers,radii);
hold off
Most likely, due to the complexity of your image you will need to look into adaptive thresholding as well as some image processing to clean it up such as imfill. Hope this gets you on your way.
UMANG NAGPAL
UMANG NAGPAL on 5 May 2020
@David K
The above written has been done but How should I count the number of pores now?
I have got a plot , with circles covering the black regions/pores , but how should I count them?

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 26 Aug 2019
Edited: KALYAN ACHARJYA on 26 Aug 2019
gray_image=imread('3.bmp');
% Improve the Thresholding to get more accurate answer
% Here I have used Global image threshold using Otsu's method
[T sm]=graythresh(gray_image);
bw_image=im2bw(gray_image,T);
[L hole_counts]=bwlabel(~bw_image);
fprintf('The Black holes counts: %d',hole_counts-1);
% 1 Minus for lower balck strips

Community Treasure Hunt

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

Start Hunting!