当前位置:文档之家› 数字图像的matlab基本操作

数字图像的matlab基本操作

数字图像的基本操作

姓名:吴风

学号:20101302012

班级:通信10-3班

一、常用函数

3、利用imread( )函数读取一幅图像,假设其名为flower.tif,存入一个数组中;.利用whos 命令提取该读入图像flower.tif的基本信息;利用imshow()函数来显示这幅图像;利用imfinfo 函数来获取图像文件的压缩,颜色等等其他的详细信息;利用imwrite()函数来压缩这幅图象,将其保存为一幅压缩了像素的jpg文件,设为flower.jpg;语法:imwrite(原图像,新图像,‘quality’,q), q取0-100。同样利用imwrite()函数将最初读入的tif图象另存为一幅bmp图像,设为flower.bmp。

代码:

a=imread('flow.tif');

whos,

imshow(a),

imfinfo('flow.tif')

结果:

Name Size Bytes Class Attributes

a 296x394x3 349872 uint8

ans 1x1 1888 struct

b 300x300x3 270000 uint8

c 256x256x3 196608 uint8

ans =

Filename: 'flow.tif'

FileModDate: '09-十月-2013 10:33:13'

FileSize: 270528

Format: 'tif'

FormatVersion: []

Width: 394

Height: 296

BitDepth: 24

ColorType: 'truecolor'

FormatSignature: [73 73 42 0]

ByteOrder: 'little-endian'

NewSubFileType: 0

BitsPerSample: [8 8 8]

Compression: 'LZW'

PhotometricInterpretation: 'RGB'

StripOffsets: [30x1 double]

SamplesPerPixel: 3

RowsPerStrip: 10

StripByteCounts: [30x1 double]

XResolution: 220

YResolution: 220

ResolutionUnit: 'Inch'

Colormap: []

PlanarConfiguration: 'Chunky'

TileWidth: []

TileLength: []

TileOffsets: []

TileByteCounts: []

Orientation: 1

FillOrder: 1

GrayResponseUnit: 0.0100

MaxSampleValue: [255 255 255]

MinSampleValue: 0

Thresholding: 1

Offset: 269800

Predictor: 'Horizontal differencing'

UnknownTags: [2x1 struct]

代码:

imwrite(a,'flow2.jpg','quality',50)

imwrite(a,'flow3.jpg','quality',100)

imwrite(a,'flow4.jpg','quality',0)

结果:

大小:14K

大小:83.7K

大小:2.98K

代码:

imwrite(a,'flower.bmp'

结果:

4.用imread()读入图像:Lenna.jpg 和camema.jpg;.用imfinfo()获取图像Lenna.jpg和camema.jpg 的大小;用figure,imshow()分别将Lenna.jpg和camema.jpg显示出来,观察两幅图像的质量。

代码:

b=imread('lenna.jpg');imfinfo('lenna.jpg'),c=imread('came.jpg');imfinfo('came.jpg')

结果:

ans =

Filename: 'lenna.jpg'

FileModDate: '09-十月-2013 10:34:50'

FileSize: 16500

Format: 'jpg'

FormatVersion: ''

Width: 300

Height: 300

BitDepth: 24

ColorType: 'truecolor'

FormatSignature: ''

NumberOfSamples: 3

CodingMethod: 'Huffman'

CodingProcess: 'Sequential'

Comment: {}

ans =

Filename: 'came.jpg'

FileModDate: '09-十月-2013 10:34:22'

FileSize: 15021

Format: 'jpg'

FormatVersion: ''

Width: 256

Height: 256

BitDepth: 24

ColorType: 'truecolor'

FormatSignature: ''

NumberOfSamples: 3

CodingMethod: 'Huffman'

CodingProcess: 'Sequential'

Comment: {}

代码:

figure(1);imshow(b),figure(2);imshow(c)

结果:

二、MATLAB实现图像类型转换

2、编写一个m文件:读入任意一幅RGB图像,变换为灰度图像和二值图像,并在同一个窗口内分成三个子窗口来分别显示RGB图像和灰度图像,注上文字标题。将语句拷贝下来,贴入实验报告,并且将得到得到的图像效果贴入实验报告。

M1.m:

RGB=imread('onion.png');

Y=rgb2gray(RGB);

bw=im2bw(RGB,0.5);

subplot(1,3,1),imshow(RGB);

subplot(1,3,2),imshow(Y);

subplot(1,3,3),imshow(bw);

三、MATLAB实现图像运算

对两幅不同图像执行加、减、乘、除操作,在同一个窗口内分成五个子窗口来分别显示,注上文字标题。

M3.m

I1 = imread('d:\hehua.jpg');

I2 = imread('d:\hua.jpg');

I3 =imadd(I1, I2); I4 =imsubtract(I1, I2);

I5=immultiply(I1, I2);

I6=imdivide(I1, I2);

subplot(2, 3, 1); imshow(I1);

subplot(2, 3, 2); imshow(I2);

subplot(2, 3, 3); imshow(I3);

subplot(2, 3, 4),imshow(I4);

subplot(2, 3, 5),imshow(I5);

subplot(2, 3, 6),imshow(I6);

对以下图像进行点运算,实现图像变亮、变暗和负片效果,在同一个窗口内分成四个子窗口来分别显示,注上文字标题。

M4.m

pears=imread('pears.png');

I=double(pears);

I1=1*I+70; %对比度不变,图像变亮;

I2=1*I-30; %对比度不变,图像变暗;

I3=-1*I; %图像取负片效果;

X=uint8(I1);

Y=uint8(I2);

Z=uint8(I3);

subplot(1,4,1),imshow(pears);

subplot(1,4,2),imshow(X);

subplot(1,4,3),imshow(Y);

subplot(1,4,4),imshow(Z);

相关主题
文本预览
相关文档 最新文档