MATLAB的Roberts算子与Sobel算子

function [ output_args ] = Untitled4( input_args )
close all
clear all
I=imread('PeppersRGB.bmp'); 
%读取图像
I1=im2double(I); 
%将彩图序列变成双精度
I2=rgb2gray(I1); 
%将彩色图变成灰色图
[thr, sorh, keepapp]=ddencmp('den','wv',I2);
I3=wdencmp('gbl',I2,'sym4',2,thr,sorh,keepapp);
%小波除噪
I4=medfilt2(I3,[9 9]);
%中值滤波
I5=imresize(I4,0.2,'bicubic'); 
%图像大小
BW1=edge(I5,'sobel'); 
%sobel图像边缘提取
BW2=edge(I5,'roberts');
%roberts图像边缘提取
BW4=edge(I5,'log'); 
%log图像边缘提取
BW5=edge(I5,'canny'); 
%canny图像边缘提取
h=fspecial('gaussian',5); 
%高斯滤波
BW6=edge(I5,'zerocross',[ ],h); 
%zerocross图像边缘提取
figure;
subplot(1,3,1); 
imshow(I2); 
title('原图');
subplot(1,3,2);
imshow(BW1);
title('Sobel算子<span style="font-family: Arial, Helvetica, sans-serif;">');</span>
subplot(1,3,3);
imshow(BW2);
title('Roberts算子');

end

  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用MATLAB实现Roberts算子、Prewitt算子Sobel算子、Laplacian算子、Canny算子的对比程序: ```matlab % 读入图像 img = imread('lena.png'); % 转为灰度图像 img_gray = rgb2gray(img); %% Roberts算子 % 定义Roberts算子的模板 roberts_mat = [-1 0; 0 1]; % 应用Roberts算子 img_roberts = imfilter(double(img_gray), roberts_mat); % 显示结果 figure; imshow(uint8(img_roberts)); title('Roberts算子'); %% Prewitt算子 % 定义Prewitt算子的模板 prewitt_mat = [-1 -1 -1; 0 0 0; 1 1 1]; % 应用Prewitt算子 img_prewitt = imfilter(double(img_gray), prewitt_mat); % 显示结果 figure; imshow(uint8(img_prewitt)); title('Prewitt算子'); %% Sobel算子 % 定义Sobel算子的模板 sobel_mat = [-1 -2 -1; 0 0 0; 1 2 1]; % 应用Sobel算子 img_sobel = imfilter(double(img_gray), sobel_mat); % 显示结果 figure; imshow(uint8(img_sobel)); title('Sobel算子'); %% Laplacian算子 % 定义Laplacian算子的模板 laplacian_mat = [0 -1 0; -1 4 -1; 0 -1 0]; % 应用Laplacian算子 img_laplacian = imfilter(double(img_gray), laplacian_mat); % 显示结果 figure; imshow(uint8(img_laplacian)); title('Laplacian算子'); %% Canny算子 % 应用Canny算子 img_canny = edge(img_gray, 'canny'); % 显示结果 figure; imshow(img_canny); title('Canny算子'); ``` 运行上述代码,可以得到Roberts、Prewitt、Sobel、Laplacian和Canny算子处理后的图像。你可以将代码中的`lena.png`替换为你自己的图像,并调整算子的参数进行实验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值