实验内容
1、分别用Roberts、Prewitt、Sobel三种边缘检测算子,对图像wire.bmp进行水平、垂直及各个方向的边界检测,并将检测结果转化为白底黑线条的方式显示出来;
%图像边缘检测
%加载图片并读取图片信息
srcImage=imread('L:\图像处理\实验文件\wire.bmp');
%srcImageInfo=imfinfo('E:\MatlabWorkSpace\实验三边缘检测\image.bmp');%图像为truecolor,首先转化为灰度图
%将图像转化为灰度图
grayImage=rgb2gray(srcImage);
%分别使用Roberts\Sobel\Prewitt\Canny算子进行边缘检测
imageRoberts=edge(grayImage,'roberts');
imageSobel=edge(grayImage,'sobel');
imagePrewitt=edge(grayImage,'prewitt');
imageCanny=edge(grayImage,'canny');
%显示检测图像
subplot(2,3,1);imshow(grayImage);title('原图像');
subplot(2,3,2);imshow(~imageRoberts);title('roberts');
subplot(2,3,3);imshow(~imageSobel);title('sobel');
subplot(2,3,4);imshow(~imagePrewitt);title('prewitt');
subplot(2,3,5);imshow(~imageCanny);title('canny');
2、使用手动阈值分割法对bottle图像进行分割,显示分割结果,并分析其优缺点。
subplot(2,2,1);
img = imread('L:\图像处理\实验文件\bottle.png');
imshow(img);
title('原图');
subplot(2,2,[3,4]);
imhist(img);
title('直方图');
[m,n] = size(img);
thresh = 90;
for i = 1:m
for j = 1:n
if(img(i,j) > thresh)
img(i,j) = 255;
else
img(i,j) = 0;
end
end
end
subplot(2,2,2);
imshow(img);
title('分割图像');
3、对下图A进行处理,得到类似图B的样子;
a=imread('L:\图像处理\实验文件\A.jpg');
%灰度二值图像
a=rgb2gray(a);
%分别使用Roberts\Sobel\Prewitt\Canny算子进行边缘检测
aRoberts=edge(a,'roberts');
aSobel=edge(a,'sobel');
aPrewitt=edge(a,'prewitt');
aCanny=edge(a,'canny');
%imshow()时,使用非~进行黑白色对调
subplot(2,3,1);imshow(a);title('原图像');
subplot(2,3,2);imshow(~aRoberts);title('roberts');
subplot(2,3,3);imshow(~aSobel);title('sobel');
subplot(2,3,4);imshow(~aPrewitt);title('prewitt');
subplot(2,3,5);imshow(~aCanny);title('canny');