imgradientxy
查找二维图像的定向梯度
说明
示例
使用 Prewitt 方法计算定向梯度
将图像读入工作区。
I = imread('coins.png');
使用 Prewitt 梯度算子计算 x 和 y 定向梯度。
[Gx, Gy] = imgradientxy(I,'prewitt');
显示定向梯度。
figure imshowpair(Gx, Gy, 'montage'); title('Directional Gradients: x-direction, Gx (left), y-direction, Gy (right), using Prewitt method')
使用定向梯度计算梯度幅值和方向
将图像读入工作区。
I = imread('coins.png');
计算 x 和 y- 定向梯度。默认情况下,imgradientxy
使用 Sobel 梯度算子。
[Gx,Gy] = imgradientxy(I);
显示定向梯度。
imshowpair(Gx,Gy,'montage') title('Directional Gradients Gx and Gy, Using Sobel Method')
使用定向梯度计算梯度幅值和方向。
[Gmag,Gdir] = imgradient(Gx,Gy);
显示梯度幅值和方向。
imshowpair(Gmag,Gdir,'montage') title('Gradient Magnitude (Left) and Gradient Direction (Right)')
输入参数
I
— 输入图像
二维灰度图像 | 二维二值图像
输入图像,指定为二维灰度图像或二维二值图像。
数据类型: single
| double
| int8
| int32
| uint8
| uint16
| uint32
| logical
method
— 梯度算子
'sobel'
(默认) | 'prewitt'
| 'central'
| 'intermediate'
梯度算子,指定为下列值之一。
方法 | 描述 |
---|---|
'sobel' | Sobel 梯度算子。像素的梯度是 3×3 邻域内像素的加权和。在垂直 (y) 方向,权重为: [ 1 2 1 0 0 0 -1 -2 -1 ] |
'prewitt' | Prewitt 梯度算子。像素的梯度是 3×3 邻域内像素的加权和。在垂直 (y) 方向,权重为: [ 1 1 1 0 0 0 -1 -1 -1 ] |
'central' | 中心差分梯度。一个像素的梯度是相邻像素的加权差。在 y 方向为 |
'intermediate' | 中间差分梯度。一个像素的梯度是相邻像素和当前像素之间的差。在 y 方向为 |
数据类型: char
| string
输出参数
提示
当在图像边界应用梯度算子时,图像边界之外的值假定为等于最接近的图像边界值。
算法
算法用于计算相对于 x 轴和 y 轴的定向梯度。x 轴沿向右的列定义,而 y 轴沿向下的行定义。
imgradientxy
不会对梯度输出进行归一化。如果梯度输出图像的范围必须与输入图像的范围匹配,请考虑对梯度图像进行归一化,具体取决于所使用的 method
参数。例如,对于 Sobel 核,归一化因子是 1/8,对于 Prewitt 是 1/6。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
imgradientxy
支持 C 代码生成(需要 MATLAB® Coder™)。请注意,如果您选择通用的MATLAB Host Computer
目标平台,imgradientxy
生成的代码将使用平台特定的预编译共享库。使用共享库可保留性能上的优化,但适用范围仅限于生成的代码所适用的目标平台。有关详细信息,请参阅Image Processing Toolbox 中代码生成支持的类型。method
的值必须为编译时常量。
GPU 数组
通过使用 Parallel Computing Toolbox™ 在图形处理单元 (GPU) 上运行来加快代码执行。
此函数完全支持 GPU 数组。有关详细信息,请参阅GPU 上的图像处理。
版本历史记录
在 R2012b 中推出R2021b: 使用 MATLAB Coder 生成 C 代码
现在 imgradientxy
支持 C 代码生成(需要 MATLAB Coder)。
另请参阅
edge
| fspecial
| imgradient
| imgradient3
| imgradientxyz
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)