Calculating mean for lines generated from Hough Transform
10 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Paul
on 12 Feb 2014
Edited: Paul
on 12 Feb 2014
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 Comments
Paul
on 13 Feb 2014
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);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!