MATLAB图像增强总结程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

MATLAB图像增强程序举例

1.灰度变换增强程序:

% GRAY TRANSFORM

clc;

I=imread('pout.tif');

imshow(I);

J=imadjust(I,[0.3 0.7],[0 1],1); %transforms the walues in the %intensity image I to values in J by linealy mapping %values between 0.3 and 0.7 to values between 0 and 1. figure;

imshow(J);

J=imadjust(I,[0.3 0.7],[0 1],0.5); % if GAMMA is less than 1,the mapping si weighted to ward higher (brighter)

%output values.

figure;

imshow(J);

J=imadjust(I,[0.3 0.7],[0 1],1.5); % if GAMMA is greater than 1,the mapping si weighted toward lower (darker)

%output values.

figure;

imshow(J)

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

figure;

imshow(J);

2.直方图灰度变换

%直方图灰度变换

[X,map]=imread('forest.tif');

I=ind2gray(X,map);%把索引图像转换为灰度图像

imshow(I);

title('原图像');

improfile%用鼠标选择一条对角线,显示线段的灰度值

figure;subplot(121)

plot(0:0.01:1,sqrt(0:0.01:1))

axis square

title('平方根灰度变换函数')

subplot(122)

maxnum=double(max(max(I)));%取得二维数组最大值

J=sqrt(double(I)/maxnum);%把数据类型转换成double,然后进行平方根变换%sqrt函数不支持uint8类型

J=uint8(J*maxnum);%把数据类型转换成uint8类型

imshow(J)

title('平方根变换后的图像')

3.直方图均衡化程序举例

% HISTGRAM EAQUALIZATION

clc;

% Clear command window

I=imread('tire.tif');

% reads the image in tire.tif into I

imshow(I);

% displays the intensity image I with 256 gray levels figure;

%creates a new figure window

imhist(I);

% displays a histogram for the intensity image I

J=histeq(I,64);

% transforms the intensity image I,returning J an intensity figure;

%image with 64 discrete levels

imshow(J);

figure;

imhist(J);

J=histeq(I,32);

%transforms the intensity image ,returning in % J an intensity figure;

%image with 32 discrete levels

imshow(J);

figure;

imhist(J);

4.直方图规定化程序举例

% HISTGRAM REGULIZATION

clc;

%Clear command window

I=imread('tire.tif');

%reads the image in tire.tif into I

J=histeq(I,32);

%transforms the intensity image I,returning in

%J an intensity image with 32 discrete levels

[counts,x]=imhist(J);

%displays a histogram for the intensity image I

Q=imread('pout.tif');

%reads the image in tire.tif into I

figure;

imshow(Q);

figure;

imhist(Q);

M=histeq(Q,counts);

%transforms the intensity image Q so that the

%histogram of the output image M approximately matches counts figure;

imshow(M);

figure;

imhist(M);

空域滤波增强部分程序

1.线性平滑滤波

I=imread('eight.tif');

J=imnoise(I,'salt & pepper',0.02);

subplot(221),imshow(I)

title('原图像')

subplot(222),imshow(J)

title('添加椒盐噪声图像')

K1=filter2(fspecial('average',3),J)/255;%应用3*3邻域窗口法subplot(223),imshow(K1)

title('3x3窗的邻域平均滤波图像')

K2=filter2(fspecial('average',7),J)/255;%应用7*7邻域窗口法subplot(224),imshow(K2)

title('7x7窗的邻域平均滤波图像')

相关文档
最新文档