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