Matlab使用Prewitte算子进行边缘检测
来源:互联网 发布:装网络摄像头怎么安装 编辑:程序博客网 时间:2024/06/18 15:58
算子比较
比较常见的边缘检测算子有Roberts、Prewitt和Sobel。这里给出一些简单比较:
- Roberts算子:边缘定位准,但是对噪声敏感。适用于边缘明显且噪声较少的图像分割。Roberts边缘检测算子是一种利用局部差分算子寻找边缘的算子,Robert算子图像处理后结果边缘不是很平滑。经分析,由于Robert算子通常会在图像边缘附近的区域内产生较宽的响应,故采用上述算子检测的边缘图像常需做细化处理,边缘定位的精度不是很高。
- Prewitt算子:对噪声有抑制作用,抑制噪声的原理是通过像素平均,但是像素平均相当于对图像的低通滤波,所以Prewitt算子对边缘的定位不如Roberts算子。
- Sobel算子:Sobel算子和Prewitt算子都是加权平均,但是Sobel算子认为,邻域的像素对当前像素产生的影响不是等价的,所以距离不同的像素具有不同的权值,对算子结果产生的影响也不同。一般来说,距离越远,产生的影响越小。
- Isotropic Sobel算子:加权平均算子,权值反比于邻点与中心点的距离,当沿不同方向检测边缘时梯度幅度一致,就是通常所说的各向同性。
简单定义
当
代码实现:
在主文件中进行了手动给出阀值T 和 不给出阀值T,让函数自动迭代生成。
prewittee.m
function prewittee(FILENAME)%prewittee(FILENAME) takes a gray scale image with filename FILENAME.% Read the image.Im = im2double(imread(FILENAME));% Show the image in a new window.figure;imshow(Im, [min(min(Im)) max(max(Im))]);title('Original Image');disp('Original image is read and displayed successfully.');%% Generate the corresponding binary edge image of the given image Im.T = double(max(max(Im)))*0.2;direction = 'all';g = myprewittedge(Im,T,direction);% Show the image in a new window.figure;imshow(g, [0 1]);title('Binary Edge Image 1');disp('The corresponding binary edge image is computed and displayed successfully.');%% Generate the corresponding binary edge image of the given image Im% without specifying the thresholddirection = 'all';f = myprewittedge(Im,[],direction);% Show the image in a new window.figure;imshow(f, [0 1]);title('Binary Edge Image 2');disp('The corresponding binary edge image is computed and displayed successfully.');
myprewittedge.m
% myprewittedge computes a binary edge image from the given image.%% g = myprewittedge(Im,T,direction) computes the binary edge image from the% input image Im.% % The function myprewittedge, with the format g=myprewittedge(Im,T,direction), % computes the binary edge image from the input image Im. This function takes % an intensity image Im as its input, and returns a binary image g of the % same size as Im (mxn), with 1's where the function finds edges in Im and 0's % elsewhere. This function finds edges using the Prewitt approximation to the % derivatives with the assumption that input image values outside the bounds % are zero and all calculations are done using double-precision floating % point. The function returns g with size mxn. The image g contains edges at % those points where the absolute filter response is above or equal to the % threshold T.% % Input parameters:% Im = An intensity gray scale image.% T = Threshold for generating the binary output image. If you do not% specify T, or if T is empty ([ ]), myprewittedge(Im,[],direction) % chooses the value automatically according to the Algorithm 1 (refer% to the assignment descripton).% direction = A string for specifying whether to look for% 'horizontal' edges, 'vertical' edges, positive 45 degree 'pos45'% edges, negative 45 degree 'neg45' edges or 'all' edges.function g = myprewittedge(Im,T,direction) if isempty(T) T = (max(max(Im)) + min(min(Im))) / 2; for i = 1:10 G1 = Im .* (Im > T); G2 = Im .* (Im < T); m1 = mean(G1(G1~=0)); m2 = mean(G2(G2~=0)); T = (m1 + m2) / 2; end end [m, n] = size(Im);% temp = Im; prewittNum = 0; for j = 2:m-1 for k = 2:n-1 prewittNum = abs(Im(j-1,k+1)-Im(j+1,k+1)+Im(j-1,k)-Im(j+1,k)+Im(j-1,k-1)-Im(j+1,k-1))+abs(Im(j-1,k+1)+Im(j,k+1)+Im(j+1,k+1)-Im(j-1,k-1)-Im(j,k-1)-Im(j+1,k-1)); if (prewittNum > T) temp(j,k) = 255; else temp(j,k) = 0; end end end g = temp;
示例输入与输出
输入文件
手动给出阀值T
自动生成阀值T
阅读全文
0 0
- Matlab使用Prewitte算子进行边缘检测
- matlab:使用canny算子检测边缘
- 使用Scharr 算子进行边缘检测
- 简述:MATLAB中使用Laplace算子对彩色图像进行边缘检测的方法
- CImage对象使用罗伯特算子进行边缘检测
- Canny 边缘检测算子 MATLAB实现
- 边缘检测算子的MATLAB代码
- matlab sobel canny prewitt 边缘检测算子
- 基于MATLAB边缘检测算子的实现
- opencv中用Sobel算子进行边缘检测
- opencv中用Sobel算子进行边缘检测
- OpenCV中用Canny算子进行边缘检测
- 使用roberts Prewitt Sobel 三种算子对raw格式图像进行边缘检测
- 转载:数字图像处理——边缘检测算子(MATLAB)
- Sobel算子边缘检测Matlab实现(转)
- 图像边缘检测经典算子及MATLAB实现
- Matlab图像边缘检测Roberts\Sobel\Prewitt\Canny算子
- 图像边缘检测经典算子及MATLAB实现
- Unity_DOTween动画的学习(十一)_DOTweenPath路径编辑器的使用补充_结合按钮触发不同点击事件控制播放状态_Waypoints
- Java 并发 ---ReentrantLock源码分析
- IllegalStateException: Fragment null must be a public static class to be properly recreated from ins
- 单层感知器-学习实践
- 如何利用连接池C3P0连接数据库
- Matlab使用Prewitte算子进行边缘检测
- js事件冒泡
- ThreadLocal管理Session
- OS学习笔记三:处理器调度
- 数据结构——顺序表删除之移位算法
- JAVA面向对象编程——继承
- ArrayList的elementData为什么要用transient修饰
- 数据结构学习日记(3)——环形队列的代码实现
- HDU-1372 Knight Moves