Blob analysis and thresholding
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Han
am 6 Feb. 2018
Kommentiert: Image Analyst
am 6 Feb. 2018
I have two white objects I detected by blob analysis the message should be "Alarm it is white !"
% Blob Analysis
BlobAnalysis = vision.BlobAnalysis('Connectivity',8);
[area,centroid,bbox] = step(BlobAnalysis,BW);
% Box
Ishape = insertShape(OriginalImage,'rectangle',bbox,'Linewidth',3);
subplot(2,2,2);
imshow(Ishape);
[row , col ] = size (bbox);
for i =1 : row
x = bbox(i,1);
y =bbox(i,2);
w=bbox(i,3);
h=bbox(i,4);
TestImage = OriginalImage(x:(x+w), y :(y+h),:);
r = TestImage(:,:,1);
g = TestImage(:,:,2);
b = TestImage(:,:,3);
subplot(2,2,3)
imshow(TestImage);
histogram2(r,g,'DisplayStyle','tile','ShowEmptyBins','on', ...
'XBinLimits',[0 255],'YBinLimits',[0 255]);
histogram(r,'BinMethod','integers','FaceColor','r','EdgeAlpha',0,'FaceAlpha',1)
hold on
histogram(g,'BinMethod','integers','FaceColor','g','EdgeAlpha',0,'FaceAlpha',0.7)
histogram(b,'BinMethod','integers','FaceColor','b','EdgeAlpha',0,'FaceAlpha',0.7)
xlabel('RGB value')
ylabel('Frequency')
title('Color Histogram')
xlim([0 257])
threshold =128;
a = r.*g .*b;
c = 128.*128.*128;
if a >= c
msgbox('Alarm it is white !');
else
msgbox('ok');
end
clear TestImage;
end
I have a threshold which is equal to 128 if the color histogram for each object is greater than threshold the the message "Alarm .." is displayed !!
I think my mistake is here I don't know how can I do it:
threshold =128;
a = r.*g .*b;
c = 128.*128.*128;
if a >= c
msgbox('Alarm it is white !');
else
msgbox('ok');
end
Also I get some errors:
Index exceeds matrix dimensions.
Error in Tracking(line 25)
TestImage = OriginalImage(x:(x+w), y :(y+h),:);
THANK YOU !
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 6 Feb. 2018
Make sure bbox is integers. Call round() if necessary. Often the bounding box is a half pixel outside of the pixel centers.
2 Kommentare
Image Analyst
am 6 Feb. 2018
x is NOT the first index. It is row, which is y, not x. To correct:
TestImage = OriginalImage(y :(y+h), x:(x+w), :);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!