Show the object in boundary box

5 ビュー (過去 30 日間)
Han
Han 2018 年 2 月 6 日
回答済み: Image Analyst 2018 年 2 月 6 日
I'm trying to use boundary box for each objects and then calculate color histogram for each object !
Here in my code, I tried to show the object which is "white square"
[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);
end
but the result isn't what I expected, see the image ! Any advice please :)

回答 (1 件)

Image Analyst
Image Analyst 2018 年 2 月 6 日
This is a very common beginner mistake.
You think arrays are indexed as OriginalImage(x, y). They ARE NOT. They are indexed as OriginalImage(row, column), which is OriginalImage(y, x). Reverse your indexes:
TestImage = OriginalImage(y:(y+h), x:(x+w), :);

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by