本博文主要讲解matlab下的图像基本操作,图片使用下方的一张图片,只需要右击收藏就行了。给出讲解内容有:
文章目录
或者随便网上找一张也可以
1、图像信息查询
在MATLAB中,可以使用imfinfo函数来获取图像处理工具箱支持的任何格式图像文件的信息。
1.1语法格式
info = imfinfo(filename,fmt)
info = imfinfo(filename)
info = imfinfo(URL,...)
1.2 案例1
2、图像文件读取
MATLAB通过函数imread完成图像的读取,该函数语法格式如下:
2.1 语法格式
A = imread(filename,fmt)
[X,map] = imread(filename,fmt)
[...] = imread(filename)
[...] = imread(URL,...)
[...] = imread(...,idx) (CUR, GIF, ICO, and TIFF only)
[...] = imread(...,'frames',idx) (GIF only)
[...] = imread(...,ref) (HDF only)
[...] = imread(...,'BackgroundColor',BG) (PNG only)
[A,map,alpha] = imread(...) (ICO, CUR, and PNG only)
2.2 案例演示
info = imread('24.jpg')
3、图像文件的写入
MATLAB函数imwrite来存储图像文件,该函数的语法格式如下:
3.1 语法格式
imwrite(A,filename,fmt)
imwrite(X,map,filename,fmt)
imwrite(...,filename)
imwrite(...,Param1,Val1,Param2,Val2...)
3.2 案例演示
将刚才运行的命令写入到另一个jpg里
imwrite(info,'25.jpg','jpg')
4、图像显示
MATLAB包含两个显示图像的函数image 和imagesc;另外MATLAB图像工具箱中也包含两个显示图像的函数imview 和 imshow。
4.1 语法格式
image(C)image(x,y,C)
image(x,y,C,'PropertyName',PropertyValue,...)
image('PropertyName',PropertyValue,...)
handle = image(...)
4.2 案例演示1
打开24.jpg
image(info)
5、图像自动缩放
imagesc函数具有对显示的数据进行自动缩放的功能。函数语法如下:
5.1 语法格式
imagesc(C)
imagesc(x,y,C)imagesc(...,clims)
imagesc('PropertyName',PropertyValue,...)
h = imagesc(...)
5.2 案例演示:对24.jpg进行自动缩放
imagesc(info)
6、自动设置图像窗口、坐标轴和图像属性
6.1 语法格式
imshow函数显示一幅数字图像时,将自动设置图像窗口、坐标轴和图像属性。该函数的语法格式如下
imshow(I,n)
imshow(I,[low high])
imshow(BW)
imshow(X,map)
imshow(RGB)
imshow(...,display_option)
imshow(x,y,A,...)
imshow filename
h = imshow(...)
6.2 案例演示:索引图像显示
[X,map] = imread('canoe.tif');
imshow(X,map);