您好,欢迎来到爱go旅游网。
搜索
您的当前位置:首页实验一图像的灰度直方图实验

实验一图像的灰度直方图实验

来源:爱go旅游网
 实验一 图像的灰度直方图实验

1 实验目的:

1) 熟悉MATLAB软件界面和初步使用图像处理工具箱。 2) 掌握图像格式转换和图像矩阵显示方法。 3) 掌握图像灰度直方图的显示和灰度调整方法。 2 实验内容:

1)图像类型转换和不同图像显示方法 图像类型转换:

dither: 将灰度图像变成索引图像或将灰度图像变成二值图像。 [X,map]=gray2ind(I,n) ;n---灰度级数,缺省为

BW=dither(I) 例子程序:

clear ; %清除内存原有一切变量

RGB=imread('gyy1.jpg'); % 把RGB图读入矩阵 I=rgb2gray(RGB); %把RGB图变为灰度图 [A,map]=gray2ind(I,128); %把灰度图变索引图 BW=dither(I); %把灰度图变为二值图 subplot(2,2,1),imshow(RGB);title('yuantu'); %显示原图 subplot(2,2,2),imshow(A,map),title('xmap'); %显示索引图 subplot(2,2,3),imshow(I),title('graytu'); %显示灰度图 subplot(2,2,4),imshow(BW),title('BWtu'); %显示二值图

gray2ind: 将二值图像转换为索引图像。

[X,map]=gray2ind(BW,n) ; n---灰度级数,缺省为 grayslice: 将灰度图像转为索引图像。 X=grayslice(I,n);

im2bw: 将灰度图像、索引图像、真彩色图像转为二值图像。

BW=im2bw(I,level); BW=im2bw(X,map,level); BW=im2bw(RGB,level) level---- 归一化阈值,取值在[0,1]之间。

eg: BW=im2bw(X,map,0.6) im2double: 转换为双精度型。

I2=im2double(I1); RGB2=im2double(RGB1); X2=im2double(X1,’indexed’) im2uint8: 转换为8位无符号型.

I2=im2uint8(I1); RGB2=im2uint8(RGB1); X2=im2uint8(X1,’indexed’) ind2gray: 索引图像变为灰度图像。 I=ind2gray(X,map);

ind2rgb: RGB=ind2rgb(X,map)

mat2gray: 数据矩阵转为灰度图像。

I=mat2gray(A,[amin amax]); I=mat2gray(A) rgb2gray: I=rgb2gray(RGB)

rgb2ind: [X,map]=rgb2ind(RGB,n); X=rgb2ind(RGB,map) 例子程序: RGB=imread('gyy1.jpg');

[X1,map]=rgb2ind(RGB,);

1

X2=rgb2ind(RGB,map);

subplot(2,2,1),imshow(RGB);title('yuantu'); subplot(2,2,2),imshow(X1,map);title('x1map'); subplot(2,2,3),imshow(X2,map);title('x2map');

图像显示:

显示索引图像: image(X); colormap(map); 或 imshow(X,map) 显示灰度图像: imshow(I,[low high]); 或imshow(I,n) 显示真彩色图像:image(RGB) 或 imshow(RGB) 2)计算出一幅灰度图像的直方图 Clear; close all; I=imread('a1.bmp'); imhist(I);

title('实验1 直方图');

例子:

clear ; %清除内存原有一切变量

RGB=imread('a.jpg'); % 把RGB图读入矩阵 I=rgb2gray(RGB); %把RGB图变为灰度图 imhist(I);

subplot(2,2,1), imhist(I),title('实验1 直方图');

3)对灰度图像进行简单灰度线形变换,

RGB=imread(‘a.jpg’); I=rgb2gray(RGB);

subplot(2,2,1),imshow(I); subplot(2,2,2),imhist(I);

J=histeq(I);

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

subplot(2,2,4), imhist(J); title('实验2 -直方图均衡化”);

例子:

clear ; %清除内存原有一切变量

RGB=imread('a.jpg'); % 把RGB图读入矩阵 I=rgb2gray(RGB); %把RGB图变为灰度图 subplot(2,2,1),imshow(I); title('灰度图');

subplot(2,2,2),imhist(I); title('灰度图像的直方图'); J=histeq(I);

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

subplot(2,2,4), imhist(J); title('实验2 -直方图均衡化');

2

4) 看直方图的对应变化和图像对比度的变化。

原图像 f(m,n) 的灰度范围 [a,b] 线形变换为图像 g(m,n),灰度范围[a’,b’] 公式: g(m,n)=a’+(b’-a’)* f(m,n) /(b-a) Figure;

subplot(2,2,1),imshow(I);

J=imadjust(I,[0.3,0.7],[0,1],1);

title(' 实验3 用 g(m,n)=a’+(b’-a’)* f(m,n) /(b-a)进行变换 ');

subplot(2,2,2),imshow(J);

subplot(2,2,3), imshow(I); J=imadjust(I,[0.5,0.8],[0,1],1); subplot(2,2,4), imshow(J);

3 实验报告要求

提交实验的原始图像和结果图像。写出程序清单、实验结果和结果分析。分析程序未调试出来的原因。 4 思考题

Matlab和 C 语言有什么区别?

3

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igat.cn 版权所有 赣ICP备2024042791号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务