Issues with presetting an array from a previous matrix, possibly an issue with impixel.

I would like to write a program that would detect a square image in a video and would measure the RGB values in the square. This works if I read the values in the D matrix and set them for x and y (like example 1 below). But what I would like to do is make the code select them from the D matrix. However, when I try to do this (in example 2 below) I get a different result, even though the values are the same. Does anyone understand why using name values in an array has this effect? Could it be something to do with impixel?
clear all
A = mmreader('video2.avi');
for t = 1:2;
B = read(A, t);
C = rgb2gray(B);
C = edge(C,'sobel');
C = bwareaopen(C,1000);
C = imfill(C,'holes');
C = bwlabel(C);
C = regionprops(C,'BoundingBox');
C = struct2cell(C);
C = cell2mat(C);
C = uint16(C);
if C > 0;
D(:,t) = C;
else
end
for x = 137:584;
for y = 94:416;
E(:,x-136,y-93) = impixel(B,x,y);
end
end
end
What I would like to do is:
clear all
A = mmreader('video2.avi');
for t = 1:2;
B = read(A, t);
C = rgb2gray(B);
C = edge(C,'sobel');
C = bwareaopen(C,1000);
C = imfill(C,'holes');
C = bwlabel(C);
C = regionprops(C,'BoundingBox');
C = struct2cell(C);
C = cell2mat(C);
C = uint16(C);
if C > 0;
D(:,t) = C;
else
end
XMIN = C(1,t);
YMIN = C(2,t);
XMAX = C(3,t)+XMIN;
YMAX = C(4,t)+YMIN;
for x = XMIN:XMAX;
for y = YMIN:YMAX;
E(:,x-136,y-93) = impixel(B,x,y);
end
end
end
I don't understand when XMIN, XMAX, YMIN and YMAX are the same as 137, 584, 94, 416 respectfully I get a different answer for the E matrix. Thanks
The output is as follows with the numbers:
E ( : , 137:147 , 94 ) =
45 .. .. ..
30 .. .. ..
18 .. .. ..
and so on, compared with the NAMED variables:
36 .. .. ..
26 .. .. ..
14 .. .. ..
I don't get it, I've checked and rechecked everything and it should work.

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 11 月 2 日
Your line
E(:,x-136,y-93) = impixel(B,x,y);
needs to be adjusted as well, to
E(:,x-XMIN+1,y-YMIN+1) = impixel(B,x,y);

1 件のコメント

David
David 2011 年 11 月 2 日
Yes I was going to do this, but I'm already having an issue with the impixel output. So didn't change it just left it as 136 and 93 for now.

この質問は閉じられています。

タグ

質問済み:

2011 年 11 月 2 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by