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

5 ビュー (過去 30 日間)
AMIT VERMA
AMIT VERMA 2015 年 1 月 19 日
回答済み: Image Analyst 2021 年 6 月 23 日
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 日
Is the expected answer "3" or is it "lots" ?
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