Show the object in boundary box

5 Ansichten (letzte 30 Tage)
Han
Han am 6 Feb. 2018
Beantwortet: Image Analyst am 6 Feb. 2018
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 :)

Antworten (1)

Image Analyst
Image Analyst am 6 Feb. 2018
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), :);

Community Treasure Hunt

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

Start Hunting!

Translated by