登录论坛

查看完整版本 : [问题] 如何指定画像范围


kkwu
2011-01-23, 21:25
小弟刚刚开始尝试着用matlab来解决画像识别的问题,同时也是小弟的毕业课题。
所以有很多东西求救无门,希望各位指教。
目前面临的问题是,如何使画面只显示需要的路面部分,其他全部涂黑
代码如下
clear all;
% 画像読み込み
I = imread('1.png');
figure, imshow(I/2);

% 画像の2値化 im2bw(x, 閾値)
BW = im2bw(I,0.3);
figure, imshow(BW);

% 細線化
IV = bwmorph(BW, 'thin', Inf);
figure, imshow(IV);

%%% Hough変換
[H,T,R] = hough(IV,'RhoResolution',0.8,'ThetaResolution',0.3);
P = houghpeaks(H,10,'threshold',ceil(0.3*max(H(:))));

% ライン検出,プロット
lines = houghlines(IV,T,R,P,'FillGap',10,'MinLength',20);

figure, imshow(I), hold on

for k = 1:length(lines) % lineの数だけ繰り返し
xy = [lines(k).point1; lines(k).point2]; % 検知した点

l_tr(k) = (xy(2,2)-xy(1,2))/((xy(2,1)-xy(1,1)));
l_b(k) = xy(1,2) - l_tr(k)*xy(1,1);

% ラインの始点と終点をプロット
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

% ラインの始点と終点を終結
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

end
hold off

图片如下
http://www.labfans.com/bbs/attachment.php?attachmentid=2738&stc=1&d=1295789090

只需要显示路面就可以了,对路面的白线进行处理,还有多处需要调试,我可以自己再慢慢处理,只是目前的状态,有太多信息在照片中让我很纠结,希望大家帮帮忙,,,

kkwu
2011-01-24, 23:26
问题已经解决,网上到处都是