Blob analysis and thresholding

2 vues (au cours des 30 derniers jours)
Han
Han le 6 Fév 2018
Commenté : Image Analyst le 6 Fév 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 !

Réponse acceptée

Image Analyst
Image Analyst le 6 Fév 2018
Make sure bbox is integers. Call round() if necessary. Often the bounding box is a half pixel outside of the pixel centers.
  2 commentaires
Han
Han le 6 Fév 2018
bbox =
2×4 int32 matrix
201 67 168 150
436 293 147 119
Image Analyst
Image Analyst le 6 Fév 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), :);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by