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

6 visualizzazioni (ultimi 30 giorni)
AMIT VERMA
AMIT VERMA il 19 Gen 2015
Risposto: Image Analyst il 23 Giu 2021
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 Commenti
Walter Roberson
Walter Roberson il 23 Giu 2021
Is the expected answer "3" or is it "lots" ?
Walter Roberson
Walter Roberson il 23 Giu 2021
imadjust() is only for grayscale images. Your I2 is RGB.

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 23 Giu 2021
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