How to count no of black spots in a image??

5 次查看(过去 30 天)
clc
A5=imread('C:\Users\AMIT\Desktop\CB\sulphur\4-1.jpg');
imshow(A5);
background = imopen(A5,strel('disk',15));
I2 = A5- background;
figure, imshow(I2)
I3 = imadjust(I2);
figure, imshow(I3);
level = graythresh(I3); %Threshold the Image
bw = im2bw(I3,level);
C = imcrop(bw);
bw2 = bwareaopen(C,2);
figure, imshow(bw2)
cc = bwconncomp(bw2,8) %Identify Objects in the Image
P=cc.NumObjects;
SP=0.64/4;
defectdata = regionprops(cc, 'basic') %Compute Area of Each Object
DA = SP*[defectdata.Area];
[min_area, idx] = min(DA) %Compute Area-based Statistics
[max_area, idx] = max(DA)
nbins = 20; %Create Histogram of the Area
figure, hist(DA,nbins)
title('Histogram of defect Area');
xlabel('Area of defect mm2');
ylabel('Number of defects')
Ylim ([0 50])
DA
  4 个评论
Walter Roberson
Walter Roberson 2021-6-23
imadjust() is only for grayscale images. Your I2 is RGB.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2021-6-23
You already compute it, in your "P" variable. You probably just didn't notice because of the poor choice of some of your variable names that are not descriptive at all.
See my Image Segmentation Tutorial:
You might need to define just how small of a spot do you want to find.

Community Treasure Hunt

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

Start Hunting!

Translated by