MATLAB图像增强程序举例.doc_第1页
MATLAB图像增强程序举例.doc_第2页
MATLAB图像增强程序举例.doc_第3页
MATLAB图像增强程序举例.doc_第4页
MATLAB图像增强程序举例.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

MATLAB图像增强程序举例1.灰度变换增强程序:% GRAY TRANSFORMclc;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 toward 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 TOPBOTTOM,the output image is reversed,as in a photographic negative.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 squaretitle(平方根灰度变换函数)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 EAQUALIZATIONclc;% Clear command windowI=imread(tire.tif);% reads the image in tire.tif into Iimshow(I);% displays the intensity image I with 256 gray levelsfigure;%creates a new figure windowimhist(I);% displays a histogram for the intensity image IJ=histeq(I,64);% transforms the intensity image I,returning J an intensityfigure;%image with 64 discrete levelsimshow(J);figure;imhist(J);J=histeq(I,32);%transforms the intensity image ,returning in % J an intensityfigure;%image with 32 discrete levelsimshow(J);figure;imhist(J);4.直方图规定化程序举例% HISTGRAM REGULIZATIONclc;%Clear command windowI=imread(tire.tif);%reads the image in tire.tif into IJ=histeq(I,32);%transforms the intensity image I,returning in%J an intensity image with 32 discrete levelscounts,x=imhist(J);%displays a histogram for the intensity image IQ=imread(pout.tif);%reads the image in tire.tif into Ifigure;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 countsfigure;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窗的邻域平均滤波图像)2.中值滤波器MATLAB中的二维中值滤波函数medfit2来进行图像中椒盐躁声的去除%IMAGE NOISE REDUCTION WITH MEDIAN FILTERclc;hood=3;%滤波窗口I,map=imread(eight.tif);imshow(I,map);noisy=imnoise(I,salt & pepper,0.05);figure;imshow(noisy,map);filtered1=medfilt2(noisy,hood hood);figure;imshow(filtered1,map);hood=5;filtered2=medfilt2(noisy,hood hood);figure;imshow(filtered2,map);hood=7;filtered3=medfilt2(noisy,hood hood);figure;imshow(filtered3,map);3. 4邻域8邻域平均滤波算法% IMAGE NOISE REDUCTION WITH MEAN ALGORITHMclc;I,map=imread(eight.tif);noisy=imnoise(I,salt & pepper,0.05);myfilt1=0 1 0;1 1 1;0 1 0;%4邻域平均滤波模版myfilt1=myfilt1/9;%对模版归一化filtered1=filter2(myfilt1,noisy);imshow(filtered1,map);myfilt2=1 1 1;1 1 1;1 1 1;myfilt2=myfilt2/9;filtered2=filter2(myfilt2,noisy);figure;imshow(filtered2,map);频域增强程序举例1.低通滤波器% LOWPASS FILTERclc;I,map=imread(eight.tif);noisy=imnoise(I,gaussian,0.05);imshow(noisy,map);myfilt1=1 1 1;1 1 1;1 1 1;myfilt1=myfilt1/9;filtered1=filter2(myfilt1,noisy);figure;imshow(filtered1,map);myfilt2=1 1 1;1 2 1;1 1 1;myfilt2=myfilt2/10;filtered2=filter2(myfilt2,noisy);figure;imshow(filtered2,map);myfilt3=1 2 1;2 4 2; 1 2 1;myfilt3=filter2(myfilt3,noisy);figure;imshow(filtered3,map);2.布特沃斯低通滤波器图像实例I=imread(saturn.png);J=imnoise(I,salt & pepper,0.02);subplot(121),imshow(J)title(含噪声的原图像)J=double(J);f=fft2(J);g=fftshift(f);M,N=size(f);n=3;d0=20;n1=floor(M/2);n2=floor(N/2);for i=1:M;for j=1:N;d=sqrt(i-n1)2+(j-n2)2);h=1/(1+0.414*(d/d0)(2*n);g(i,j)=h*g(i,j);endendg=ifftshift(g);g=uint8(real(ifft2(g);subplot(122),imshow(g)title(三阶Butterworth滤波图像)色彩增强程序举例1.真彩色增强实例:%真彩色图像的分解clc;RGB=imread(peppers.png);subplot(221),imshow(RGB)title(原始真彩色图像)subplot(222),imshow(RGB(:,:,1)title(真彩色图像的红色分量)subplot(223),imshow(RGB(:,:,2)title(真彩色图像的绿色分量)subplot(224),imshow(RGB(:,:,3)title(真彩色图像的蓝色分量)2.伪彩色增强举例:I=imread(cameraman.tif);imshow(I);X=grayslice(I,16);%thresholds the intensity image I using%threshold values 1/16,2/16,.,15/16,returning an indexed %image in Xfigure;imshow(X,hot(16);3.假彩色增强处理

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论