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.
0 个评论
回答(1 个)
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
2011-11-2
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!