Calculating mean for lines generated from Hough Transform

3 ビュー (過去 30 日間)
Liz
Liz 2014 年 2 月 12 日
コメント済み: Liz 2014 年 2 月 18 日
Hello everyone,
I'm trying to determine the average RGB colour of lines detected in an image through a Hough transform. I have calcuated the mean of each individual line successful, but I want the mean of all of the lines that are found. The amount of lines could change each time.
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% find average road colour - get all co-ords between endpoints
[x, y]=bresenham(xy(1,1),xy(1,2),xy(2,1),xy(2,2));
LineCoOrds{k}=[x, y];
% Get RGB values for these points & their mean
P{k} = impixel(I,x,y);
Meanpix{k}=mean(P{k});
end
I have tried methods such as below, but havent got it quite right.
TotalMeanPixel=cellfun(@mean, Meanpix);
I'm fairly new to Matlab so any help is appreciated a lot.
EDIT - Just to clarify, I want the mean of each individual column, e.g. first column, for all the cells in Meanpix, so I ended up with one value for RGB. I need the average colour of all the lines detected.
Many thanks!
Liz

採用された回答

Paul
Paul 2014 年 2 月 12 日
編集済み: Paul 2014 年 2 月 12 日
Maybe something like this is what you need:
mean_vec=[];
for ii=1:length(Meanpix)
x=cell2mat(Meanpix{ii});
col1 = x(:,1);
mean_vec=[mean_vec; col1];
end
TotalMeanPixel=mean(mean_vec)
  4 件のコメント
Paul
Paul 2014 年 2 月 13 日
You can do this too which is easier:
mean_mat=[];
for ii=1:length(Meanpix)
x=cell2mat(Meanpix(ii));
mean_mat=[mean_mat; x];
end
TotalMeanPixel=mean(mean_mat);
R_mean=TotalMeanPixel(1);
G_mean=TotalMeanPixel(2);
B_mean=TotalMeanPixel(3);
Liz
Liz 2014 年 2 月 18 日
Even better, thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by