图像文件的操作MATLAB基础函数使用

简介

MATLAB中的图像处理工具箱体统了一套全方位的标准算法和图形工具,用于进行图像处理、分析、可视化和算法开发。这里仅仅对常用的基础函数做个使用介绍。

查询图像文件的信息

使用如下函数

imfinfo(filename,fmt)

函数imfinfo返回一个结构体的info,其中包括了图像文件的信息,filename是指定图像文件的字符串,fmt是指定图像文件格式的字符串。通过此函数获得的信息与图像文件格式的字符串。通过此函数获得的信息与图像文件的类型有关,但至少包含以下一些内容。

imfinfo

Matlab 复制代码
>> info = imfinfo('测试图片.jpg')

info = 

           Filename: 'C:\Users\Dell\Desktop\atongbu\text\测试图片.jpg'
        FileModDate: '08-Sep-2023 14:37:07'
           FileSize: 226226
             Format: 'jpg'
      FormatVersion: ''
              Width: 1488
             Height: 878
           BitDepth: 24
          ColorType: 'truecolor'
    FormatSignature: ''
    NumberOfSamples: 3
       CodingMethod: 'Huffman'
      CodingProcess: 'Sequential'
            Comment: {}

图像文件的读写

MATLAB提供了imread函数来读取图像文件到工作区中。通过imread函数,用户可以导入多种格式的图像数据,如TIFF/HDF/BMP/JPEG/GIF/PCX/XWD/Cursor/Icon和PNG等格式。

Matlab 复制代码
>> RGB = imread('测试图片.jpg');
>> whos
  Name        Size                  Bytes  Class    Attributes

  RGB       878x1488x3            3919392  uint8              

>>

为了把MATLAB工作中的图像数据用一种标准格式输出到图像文件中,需要使用imwrite函数来完成这个工作。Imwrite函数用于将数据输出为多种标准的图像文件。

图像文件的显示

在MATLAB中,使用函数imshow来显示图像文件。

imshow(I) displays image I in a Handle Graphics® figure, where I is a grayscale, RGB (truecolor), or binary image. For binary images, imshow displays pixels with the value 0 (zero) as black and 1 as white. imshow optimizes figure, axes, and image object properties for image display.

example

imshow(X,map) displays the indexed image X with the colormap map. A colormap matrix can have any number of rows, but it must have exactly 3 columns. Each row is interpreted as a color, with the first element specifying the intensity of red light, the second green, and the third blue. Color intensity can be specified on the interval 0.0 to 1.0.

example

imshow(filename) displays the image stored in the graphics file specified by filename.

imshow(I,low high) displays grayscale image I, specifying the display range as a two-element vector, low high. For more information, see the DisplayRange parameter.

imshow(___,Name,Value) displays an image, using name-value pairs to control aspects of the operation.

himage = imshow(___) returns the handle to the image object created by imshow.

imshow(I) 显示灰度图像I

imshow(I,low high) 显示灰度图像I,low, high为图像数据的值域

imshow(RGB)显示真彩图像RGB

imshow(X,map)显示索引图像,X为索引图像的数据矩阵,map为颜色表

imshow(filename)显示filename文件的图像

himage = imshow(___)返回船舰图像对象的句柄

Matlab 复制代码
>> imshow('测试图片.jpg')
>>

图像的格式转换

rgb2gray

I = rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity image I. The rgb2gray function converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance. If you have Parallel Computing Toolbox™ installed, rgb2gray can perform this conversion on a GPU.

example

newmap = rgb2gray(map) returns a grayscale colormap equivalent to map.

相关推荐
MATLAB代码顾问4 小时前
【硬核推导+源码复现】永磁同步电机(PMSM)矢量控制(FOC)全流程解析:数学建模、PI参数整定与七段式SVPWM仿真
数学建模·matlab
MATLAB代码顾问6 小时前
Simulink PI 参数扫描与批量仿真完整 MATLAB 代码
开发语言·matlab
slandarer9 小时前
MATLAB | 趣味编程——动态字符串甜甜圈和爱心
数据结构·matlab·趣味编程
Matlab程序猿10 小时前
【MATLAB源码-第461期】基于matlab的高速铁路 双链路 QPSK 误码性能仿真与风险驱动自适应复制控制仿真
matlab·高速铁路通信·双链路通信·截止期约束
li星野17 小时前
【学习记录】射线补偿原理与实现:从物理模型到MATLAB代码
开发语言·学习·matlab
星夜离尘561 天前
MATLAB 多传感器时间对齐 用 interp1 建立公共时间网格并限制外推
matlab·插值·传感器·时间序列·interp1
北纬的小熊2 天前
Matlab Simulink电力电子仿真-全桥 LLC 谐振变换器调频控制(PFM)仿真研究
嵌入式硬件·matlab
星夜离尘563 天前
MATLAB 清洗 CSV 采样日志:重复时间戳、无效行、分组统计与自动出图
开发语言·matlab·数据分析·数据清洗·csv
星夜离尘563 天前
MATLAB FFT 单边幅度谱:归一化、奇偶长度与频谱泄漏的完整实验
开发语言·matlab·信号处理·频谱分析·fft
星夜离尘563 天前
MATLAB 5 点滑动平均:filter 与 conv 的输出对齐,以及 2 样本延时的含义
开发语言·算法·matlab·滤波·fir