原图
处理后
close all; a = imread('test.jpg'); % 读取图像 a = im2bw(a); % 二值化 figure,imshow(a); line1 = [13,168;358,55]; % 两条直线,坐标格式[row1,col1;row2,col2] line2 = [15,280;364,437]; k1 = (line1(1,1)-line1(2,1))/(line1(1,2)-line1(2,2)); % 直线斜率1 k2 = (line2(1,1)-line2(2,1))/(line2(1,2)-line2(2,2)); [m,n] = size(a); % 尺寸 for i=1:m for j=1:n if i-line1(2,1)<k1*(j-line1(2,2)) % 清除直线1左边 a(i,j) = 0; end if i-line2(2,1)<k2*(j-line2(2,2)) % 清除直线2右边 a(i,j) = 0; end end end figure,imshow(a);
No comments :
Post a Comment