实验一Matlab图像处理基础及图像灰度变换

实验一 Matlab图像处理基础及图像灰度变换

一、 实验目的

了解Matlab平台下的图像编程环境,熟悉Matlab中的DIP (Digital Image Processing)工具箱;掌握Matlab中图像的表示方法,图像类型、数据类型的种类及各自的特点,并知道怎样在它们之间进行转换。掌握Matlab环境下的一些最基本的图像处理操作,如读图像、写图像、查看图像信息和格式、尺寸和灰度的伸缩等等;通过实验掌握图像直方图的描绘方法,加深直方图形状与图像特征间关系间的理解;加深对直方图均衡算法的理解。

二、 实验内容

1. 从硬盘中读取一幅灰度图像;

2. 显示图像信息,查看图像格式、大小、位深等内容; 3. 用灰度面积法编写求图像方图的Matlab程序,并画图;

4. 把第3步的结果与直接用Matlab工具箱中函数histogram的结果进行比较,以衡量第3步中程序的正确性。

5. 对读入的图像进行直方图均衡化,画出处理后的直方图,并比较处理前后图像效果的变化。

三、 知识要点

1. Matlab6.5支持的图像图形格式

TIFF, JEPG, GIF, BMP, PNG, XWD (X Window Dump),其中GIF不支持写。 2. 与图像处理相关的最基本函数

读:imread; 写:imwrite; 显示:imshow; 信息查看:imfinfo; 3. Matlab6.5支持的数据类

double, unit8, int8, uint16, int16, uint32, int32, single, char (2 bytes per element), logical. 4. Matlab6.5支持的图像类型

Intensity images, binary images, indexed images, RGB image 5. 数据类及图像类型间的基本转换函数

数据类转换:B = data_class_name(A); IPT图像数据类型转换函数: 函数名 im2uint8 输出图像数据类型 uint8 输入图像数据类型 logical, uint8, uint16, double im2uint16 mat2gray im2doule im2bw uint16 double([0, 1]) double logical logical, uint8, uint16, double double logical, uint8, uint16, double logical, uint8, uint16, double 四、 参考程序和参考结果

1.求灰度直方图

=====================================================================

% Experiment 1: calculate the histogram of gray-scale through gray-scale area % function

f=imread('J:\\ebook and code_ex\\image processing\\digital image process2_Woods\\DIP using Matlab\\image database\\dipum_images_ch02\\dipum_images_ch02\\Fig0206(a)(rose-original).tif'); [m,n]=size(f);

gray_area=zeros(1,256);

% compute the area under certain gray level for k=0:255

ind = find(f == k);

gray_area(k+1) = length(ind); end

% compute the histogram by performing the difference for gray_area hist=zeros(1,256); for k=0:254

hist(k+1)=gray_area(k+2)-gray_area(k+1); end

% normalization hist=hist/numel(f); subplot(121); imshow(f);

subplot(122);stem([1:1:256],hist,'.'); axis([1 256 0 max(hist)]);

===============================================================================

0.090.080.070.060.050.040.030.020.01050100150200250 2. 直方图均衡化

f = imread('Fig0308(a)(pollen).tif'); subplot(221); imshow(f); title('the orignal image'); subplot(222); imhist(f); ylim('auto');

g = histeq(f, 256);

subplot(223); imshow(g);

title('image after equalization'); subplot(224); imhist(g); ylim('auto');

the orignal image2x 1041.510.50050100150200250image after equalization2x 1041.510.50050100150200250

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4