%程序名称: Laplacian算子的边缘检测的实现
%程序功能: 利用Laplacian算子实现图像的边缘检测
%本程序具体可实现:1、支持对二值图像、索引图像、灰度图像和真彩图像(如:.PCX、.HDF、.JPG、.BMP、.PMG、.TIF、.XWD、.PNG等)的打开、保存和处理。
% 2、利用Laplacian算子对所选择的图像进行边缘检测处理。
% 3、将原图和处理之后的图进行对比。
%作者姓名:白燕 学号:40701
%完成日期:2005 年 6 月 27 日
function thresholdcompare(filename)
%获取需要处理的图象文件对话框
[filename,pathname]=uigetfile({'*.tif','TIF Files (*.tif)';'*.jpg','JPEG Files (*.jpeg)';'*.*','All Files (*.*)'},'Load new Image');%get filename and pathname
%读入图像数据
rgb=imread(filename);
%判断是否为二值图像
flag=isbw(rgb)
switch flag
case 1
A=rgb;
subplot(1,1,1)
subimage(A);
title('原图像已为二值图像');
otherwise
flag=isgray(rgb) %判断是否为灰度图像
switch flag
case 1
A=rgb;
[COUNTS,S] = imhist(A);
stem(S,COUNTS);
otherwise
flag=isrgb(rgb)%判断是否为真彩图像
switch flag
case 0
A=rgb;
[COUNTS,S] = imhist(A);
stem(S,COUNTS);
case 1
A=rgb2gray(rgb);
[COUNTS,S] = imhist(A);
stem(S,COUNTS);
otherwise
flag=isind(rgb) %判断是否为索引图像
switch flag
case 0
A=rgb;
[COUNTS,S] = imhist(A);
stem(S,COUNTS);
case 1
A=ind2gray(rgb,map);
[COUNTS,S] = imhist(A);
stem(S,COUNTS);
otherwise
error('Unknown Image Option!');%出错显示
end;
end;
end;
end;
subplot(2,3,1);
subimage(rgb);
title('原图像');
% subplot(2,4,2);
% subimage(A);
% title('灰度图');
%%%================================================================
%%% Laplacian算子
%%%================================================================
subplot(2,3,2);
L=edge(A,'log'); % 产生Laplacian算子
%imshow(L);
subimage(L);
title('Laplacian算子边缘检测图像');
%%%================================================================
%%% Canny法
%%%================================================================
subplot(2,3,3);
C=edge(A,'canny'); %用canny方法进行检测
subimage(C);
title('canny算子检测图像');
%%%================================================================
%%% roberts 算子检测
%%%================================================================
subplot(2,3,4);
R=edge(A,'roberts'); %用roberts算子进行检测
subimage(R);
title('roberts算子检测图像');
%%%================================================================
%%% sobel 算子检测
%%%================================================================
subplot(2,3,5);
S=edge(A,'sobel'); %用sobel算子进行检测
subimage(S);
title('sobel算子检测图像');
%%%================================================================
%%% prewitt算子检测
%%%================================================================
subplot(2,3,6);
P=edge(A,'prewitt'); %用prewitt算子进行检测
subimage(P);
title('prewitt算子检测图像');