
Matlab图像读取函数imread用法介绍
讲解Matlab中图片读取函数imread的使用,即Matlab如何读取图片。我们就可以处理图片,比如大小重定义,图片去噪,图片加噪,图片分割等。说一下imread函数的存储原理,将图片读取后存放为一个三维矩阵,由三个二维矩阵组成,分别存放图片中的rgb三个色彩。二维矩阵的行号列号表示图片的横纵像素点,每个二维矩阵元素对应的值即为rgb,三个二维矩阵刚好组成一个rgb颜色,即可存储图片。
imread函数的基本用法就是给定图片的名称、路径、格式。假设我们有一个0827.jpg图片,放置于D:\MATLAB\R2016a\mine目录下
- 名称:0827
- 格式:jpg
- 路径:该图片在硬盘中的位置,D:\MATLAB\R2016a\mine
imread实际使用中,我们可以把图片放于Matlab的m文件同目录下
下面是实际使用的几个例子,以供参考:
%%
%清理工作区与命令区
clc
clear
close all
%%
%图片读取
I1 = imread('0827','jpg');
I2 = imread('0827.jpg');
I3 = imread('D:\MATLAB\R2016a\mine\0827.jpg');
figure(1)
imshow(I1)
上述的figure(1)表示作图,imshow(I1)表示把I1变量的矩阵输出到图片中。实际操作中,如果原图过大,可以使用imresize函数重新定义下图片的大小即可。
大致的用法就上面几种了,关于官方给的help文件中的介绍如下,感兴趣的可以看看,Matlab在图片读取中的bit信息相关吧。不感兴趣的可以略过。
>> help imread
imread Read image from graphics file.
A = imread(FILENAME,FMT) reads a grayscale or color image from the file
specified by the string FILENAME. FILENAME must be in the current
directory, in a directory on the MATLAB path, or include a full or
relative path to a file.
The text string FMT specifies the format of the file by its standard
file extension. For example, specify 'gif' for Graphics Interchange
Format files. To see a list of supported formats, with their file
extensions, use the IMFORMATS function. If imread cannot find a file
named FILENAME, it looks for a file named FILENAME.FMT.
The return value A is an array containing the image data. If the file
contains a grayscale image, A is an M-by-N array. If the file contains
a truecolor image, A is an M-by-N-by-3 array. For TIFF files containing
color images that use the CMYK color space, A is an M-by-N-by-4 array.
See TIFF in the Format-Specific Information section for more
information.
The class of A depends on the bits-per-sample of the image data,
rounded to the next byte boundary. For example, imread returns 24-bit
color data as an array of uint8 data because the sample size for each
color component is 8 bits. See the Remarks section for a discussion of
bitdepths, and see the Format-Specific Information section for more
detail about supported bitdepths and sample sizes for a particular
format.
[X,MAP] = imread(FILENAME,FMT) reads the indexed image in FILENAME into
X and its associated colormap into MAP. Colormap values in the image
file are automatically rescaled into the range [0,1].
[...] = imread(FILENAME) attempts to infer the format of the file
from its content.
[...] = imread(URL,...) reads the image from an Internet URL.
PPM -- Portable Pixmap
Supported Raw ASCII (Plain) Output
Bitdepths Binary Encoded Class
------------------------------------------------
up to 16-bit x - uint8
Arbitrary - x
RAS -- Sun Raster
Supported Output
Bitdepths Class Notes
----------------------------------------------------
1-bit logical Bitmap
8-bit uint8 Indexed
24-bit uint8 RGB (8-bit samples)
32-bit uint8 RGB with Alpha (8-bit samples)
TIFF -- Tagged Image File Format
NOTE: Images with a YCbCr photometric interpretation are converted to
the RGB colorspace.
Please read the file libtiffcopyright.txt for more information.
Example:
imdata = imread('ngc6543a.jpg');
See also imfinfo, imwrite, imformats, fread, image, double, uint8.
imread 的参考页
最后,再附上几篇关于imread读取后,为何是三维数组的相关介绍:《Matlab图像灰度转换函数rgb2gray》以及《Matlab求解三维数组中的最值问题》。其实,你可以理解为任何颜色都是由红色R、绿色G、蓝色B构成的RGB组,那么图片就可以分解为R、G、B三个二维数组,也就相当于一个三维数组了。
文/来源:https://iymark.com/program/matlab-picture-imread.html
常见问题FAQ
- 部分免费版权图片来自www.freepik.com
- 本站资源和文章版权声明
- 购买商品请必看特别声明
- 免费下载或者贵宾会员专享资源能否直接商用?
- 点击下载链接不跳转怎么回事?