%%
%使用roberts算子对图像进行分割实验。 f=imread('room.tif');
[gv3,t5]=edge(f,'roberts','vertical');%使用edge函数对图像f提取垂直边缘 subplot(1,3,1);imshow(gv3);title('roberts(gv)');
[gb3,t6]=edge(f,'roberts','horizontal');%使用edge函数对图像f提取水平边缘 subplot(1,3,2);imshow(gb3);title('roberts(gb)');
w45=[-2 -1 0;-1 0 1;0 1 2];%指定模版使用imfilter计算45度方向的边缘 g45=imfilter(double(f),w45,'replicate'); T=0.3*max(abs(g45(:))); %设定阈值
g45=g45>=T; %进行阈值处理
subplot(1,3,3);imshow(g45);title('roberts(g45)'); %%
%图像像素值的标定
I=imread('room.tif'); rh=[-1 0; 0 1]; rv=[0 -1; 1 0];
g45=imfilter(double(I),rh,'replicate'); subplot(121); imshow(g45);
title('未标定');
cg45=(g45-min(g45(:)))/(max(g45(:))-min(g45(:))); subplot(122); imshow(cg45); title('已标定');
第 11 页 共 11 页