MATLAB 图像处理实例详解(四)

1. 文件信息的读取

matlab中,对文件操作,往往要知道文件的相关信息,如文件名,文件格式等等,

我们用imfinfo()这个函数来查看文件信息

>> info = imfinfo('cameraman.tif')
info = 
                     Filename: 'C:\Program Files\MATLAB\MA...'
                  FileModDate: '04-十二月-2000 05:57:54'
                     FileSize: 65240
                       Format: 'tif'
                FormatVersion: []
                        Width: 256
                       Height: 256
                     BitDepth: 8
                    ColorType: 'grayscale'
              FormatSignature: [77 77 0 42]
                    ByteOrder: 'big-endian'
               NewSubFileType: 0
                BitsPerSample: 8
                  Compression: 'PackBits'
    PhotometricInterpretation: 'BlackIsZero'
                 StripOffsets: [1x8 double]
              SamplesPerPixel: 1
                 RowsPerStrip: 32
              StripByteCounts: [1x8 double]
                  XResolution: 72
                  YResolution: 72
               ResolutionUnit: 'Inch'
                     Colormap: []
          PlanarConfiguration: 'Chunky'
                    TileWidth: []
                   TileLength: []
                  TileOffsets: []
               TileByteCounts: []
                  Orientation: 1
                    FillOrder: 1
             GrayResponseUnit: 0.0100
               MaxSampleValue: 255
               MinSampleValue: 0
                 Thresholding: 1
                       Offset: 64872
             ImageDescription: 'This image is distributed ...'

1.1 特殊图像格式的读取

%网页上保存gif图只需拖到指定位置即可。
[gif, map] = imread('gif.gif', 2); %因为是彩色的,所以保存为索引图。读取第二帧的图像
[gif1, map1] = imread('gif.gif', 12); %读取第12帧的图像
figure,
subplot(121), imshow(gif, map); %显示第二帧的图像
subplot(122), imshow(gif1, map1);

rgb = imread('rgb.jpg');
imwrite(rgb, 'rgb.png'); %将 jpg 格式保存为 png格式。
png = imread('rgb.png', 'BackgroundColor', [1 0 0]); %读取图像,并设置该图像的
%透明像素与白色合成,最后是RGB图像。
figure,
imshow(png)

 

函数 imshow( )

clc, clear;
I = imread('gray.jpg');
subplot(121),imshow(I);%显示原图
subplot(122),imshow(I, [60, 120]); %灰度级上下为[60, 120],灰度值较大的地方比较亮,
%灰度值较小的地方比较暗

函数 colorbar( )

I = imread('tire.tif');
H = [1, 2, 1; 0 0 0; -1 -2 -1];%sobel算子
X = filter2(H, I); %对灰度图像二次滤波,实现边缘检测
subplot(1,3,1), imshow(I);
subplot(1,3,2), imshow(X,[]),colorbar(); %添加彩色条,默认在图像外右侧
subplot(1,3,3), imshow(X,[]),colorbar('east') %添加彩色条,在图像右侧

函数 montage()----多帧图像显示

I = zeros(128, 128, 1, 27); %生成一个四位矩阵,大小128的灰度图, 27张(mri.tif的大小是128*128)
for i = 1:27
    [I(:,:,:,i), map] = imread('mri.tif', i); %读取第i张,保存为128*128大小的灰度图
end
montage(I, map); %多张图显示.

函数 warp( )

I = imread('football.jpg');
figure;
% warp(I); %显示原图像,效果类似imshow()
[x, y, z] = sphere;
% 创建三个(N+1)*(N+1)的矩阵,使得surf(X,Y,Z)建立一个球面,默认N=20
subplot(121),warp(I);
subplot(122),warp(x,y,z,I);
grid; %建立网格

  • 17
    点赞
  • 115
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值