mat2gray
将矩阵转换为灰度图像
说明
示例
将矩阵转换为图像
读取一个图像并显示它。
I = imread('rice.png');
figure
imshow(I)
执行一种返回数值矩阵的运算。此运算寻找边缘。
J = filter2(fspecial('sobel'),I);
min_matrix = min(J(:))
min_matrix = -779
max_matrix = max(J(:))
max_matrix = 560
请注意,矩阵的数据类型 double
的值超出 [0,1] 范围,包含负值。
显示运算结果。由于矩阵的数据范围在 imshow
的默认显示范围之外,因此每个正值像素显示为白色,每个负值或零值像素显示为黑色。查看米粒的边缘很有挑战性。
figure imshow(J)
将矩阵转换为图像。显示图像的最大值和最小值。
K = mat2gray(J); min_image = min(K(:))
min_image = 0
max_image = max(K(:))
max_image = 1
请注意,值的数据类型仍是 double
,但所有值都在 [0, 1] 范围内。
显示转换结果。像素显示一系列灰度颜色,这使得边缘的位置更加明显。
figure imshow(K)
输入参数
输出参数
I
— 输出强度图像
数值矩阵
输出强度图像,以 [0, 1] 范围中的值组成的数值矩阵形式返回。
数据类型: double
扩展功能
GPU 代码生成
使用 GPU Coder™ 为 NVIDIA® GPU 生成 CUDA® 代码。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅Run MATLAB Functions in Thread-Based Environment。
GPU 数组
通过使用 Parallel Computing Toolbox™ 在图形处理单元 (GPU) 上运行来加快代码执行。
此函数完全支持 GPU 数组。有关详细信息,请参阅GPU 上的图像处理。
版本历史记录
在 R2006a 之前推出R2022a: 使用 GPU Coder 生成 CUDA 代码
mat2gray
现在支持生成优化的 CUDA® 代码(需要 GPU Coder™)。
R2021b: 支持基于线程的环境
mat2gray
现在支持基于线程的环境。
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)