《数字图像处理》实验指导书201403.doc_第1页
《数字图像处理》实验指导书201403.doc_第2页
《数字图像处理》实验指导书201403.doc_第3页
《数字图像处理》实验指导书201403.doc_第4页
《数字图像处理》实验指导书201403.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

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

文档简介

1直方图均衡化clear all; close all % Clear the MATLAB workspace of any variables % and close open figure windows.I = imread(pout.tif); % Reads the sample images pout.tif, and stores it in imshow(I) % an array named I.display the imagefigure, imhist(I) % Create a histogram of the image and display it in % a new figure window.I2,T = histeq(I); % Histogram equalization.figure, imshow(I2) % Display the new equalized image, I2, in a new figure window.figure, imhist(I2) % Create a histogram of the equalized image I2.figure,plot(0:255)/255,T); % plot the transformation curve.imwrite (I2, pout2.png); % Write the newly adjusted image I2 to a disk file named% pout2.png.imfinfo(pout2.png) % Check the contents of the newly written file2直接灰度变换clear all; close allI = imread(cameraman.tif);J = imadjust(I,0 0.2,0.5 1);imshow(I)figure, imshow(J)X,map = imread(forest.tif);figure,imshow(X,map)I2 = ind2gray(X,map);J2 = imadjust(I2,0.5); figure,imshow(I2)figure, imshow(J2)J3 = imadjust(I2,1.5); figure, imshow(J3)help imadjust % Display the imadjust() function information.3空域平滑滤波(模糊、去噪)clear all; close allI = imread(eight.tif);h1 = ones(3,3) / 9;h2 = ones(5,5) / 25;I1 = imfilter(I,h1);I2 = imfilter(I,h2);figure(1), imshow(I), title(Original Image);figure(2), imshow(I1), title(Filtered Image With 3*3 )figure(3), imshow(I2), title(Filtered Image With 5*5 )% 加入Gaussian 噪声J1 = imnoise(I,gaussian,0,0.005);% 加入椒盐噪声J2 = imnoise(I,salt & pepper,0.02);% 对J1、J2进行平均值平滑滤波K1 = imfilter(J1,fspecial(average,3);K2 = imfilter(J2,fspecial(average,3);figure(4);subplot(2,2,1), imshow(J1) , title(gaussian);subplot(2,2,2), imshow(J2), title(salt & pepper );subplot(2,2,3), imshow(K1), title(average );subplot(2,2,4), imshow(K2);% 对J1、J2进行中值滤波K3 = medfilt2(J1,3 3);K4 = medfilt2(J2,3 3);figure(5);subplot(2,2,1), imshow(J1) , title(gaussian);subplot(2,2,2), imshow(J2), title(salt & pepper );subplot(2,2,3), imshow(K3), title( Median filtering );subplot(2,2,4), imshow(K4)4空域锐化滤波clear all; close allI = imread(moon.tif);w=fspecial(laplacian,0)w8=1,1,1;1,-8,1;1,1,1I1= imfilter(I,w, replicate);figure(1); imshow(I), title(Original Image);figure(2), imshow(I1), title(Laplacian Image);f = im2double(I);f1= imfilter(f,w, replicate);figure(3), imshow(f1,), title(Laplacian Image);f2= imfilter(f,w8, replicate);f4 = f-f1;f8 = f-f2;figure(4), imshow(f4);figure(5), imshow(f8);。1傅立叶变换(1) 简单人工二值图像clear all;close all;clc;f = zeros(50,50);f(15:35,23:28) = 1;figure(1), imshow(f,notruesize)F = fft2(f,128,128);F1 = fftshift(F);figure(2), imshow(log(abs(F1), -1 5); colormap(gray); colorbarfigure(3), mesh(1:128,1:128, abs(F1); colormap(gray); colorbarF2 = fft2(imrotate(f,90),128,128);F3 = fftshift(F2);figure(4), imshow(imrotate(f,90),notruesize)figure(5), imshow(log(abs(F3), -1 5); colormap(gray); colorbarfigure(6), mesh(1:128,1:128, abs(F3); colormap(gray); colorbar(2)Laplacian 图像锐化增强的频域实现clear all;close all;clc;I = imread(moon.tif);I = im2double(I); %标定到0-1imshow(I);MN=size(I);PQ=2*MN;F=fft2(I,PQ(1),PQ(2);F1 =abs(F);figure,imshow(F1,);F2=log(1+abs(F);figure,imshow(F2,);F3=log(1+abs(fftshift(F);figure,imshow(F3,);h = fspecial(laplacian);H = fft2 (h,PQ(1),PQ(2);H = fftshift(H);H1=log(1+abs(H);figure,imshow(H1,);% calculate the laplacian imageG = fftshift(F).*H;g = real(ifft2(ifftshift(G);g1 = imcrop(g,1,1,MN(2)-1,MN(1)-1); figure, imshow(mat2gray(g1),);% calculate the enhanced image using laplacian operatorg2 = g1/max(max(abs(g1); %标定到0-1G = I-g2;figure, imshow(G); (3) 频率域平滑滤波close all;clear all;clc;I = imread(text.png);imshow(I);MN=size(I);PQ=2*MN;F = fft2(I,PQ(1),PQ(2);h = fspecial(average);H = fft2 (h,PQ(1),PQ(2);I1 = real(ifft2(F .* H);G = imcrop(I1, 1,1,MN(2)-1, MN(1)-1);figure, imshow(G,); %Display, scaling data to appropriate range.2离散余弦变换(DCT)% 对cameraman.tif图像的离散余弦变换及逆变换重建clear all, close allf=imread(cameraman.tif); %读一幅cameraman.tifimshow(f);F=dct2(f); %做余弦变换AbsFT=abs(F);figure, imshow(log(AbsFT);FinvT=idct2(F); %做余弦反变换figure, imshow(mat2gray(FinvT);%仅保留余弦变换频谱的左上角50*50个数据,然后做余弦反变换,观察输出图像F1=F;m,n=size(F1);F1(50:m,50:n)=0;AbsFT=abs(F1);figure, imshow(log(AbsFT);FinvT=idct2(F1); %做余弦反变换figure, imshow(mat2gray(FinvT);1膨胀与腐蚀(Dilation and Erosion)(1)对简单二值图像进行膨胀与腐蚀clear all, close allBW = zeros(9,10); BW(4:6,4:7) = 1;BWSE = strel(square,3) BW1 = imdilate(BW,SE)BW2 = imerode (BW,SE)figure(1),subplot(1,2,1), imshow(BW,notruesize), title( Original Image );subplot(1,2,2), imshow(BW1,notruesize), title( Dilated Image );figure(2),subplot(1,2,1), imshow(BW,notruesize), title( Original Image );subplot(1,2,2), imshow(BW2,notruesize), title( Eroded Image );(2)对文本图像进行膨胀与腐蚀clear all, close allI = imread(Fig0907(a)(text_gaps_1_and_2_pixels).tif); % 说明:上述图片可从Gonzalez网站下载SE = 0,1,0;1,1,1;0,1,0BW1 = imdilate(I, SE);BW2 = imerode (I, SE);figure(1),subplot(1,2,1), imshow(I,notruesize), title( Original Image );subplot(1,2,2), imshow(BW1,notruesize), title( Dilated Image );figure(2),subplot(1,2,1), imshow(I,notruesize), title( Original Image );subplot(1,2,2), imshow(BW2,notruesize) , title( Eroded Image );2. 开、闭操作(Opening and Closing)clear all, close all;I = imread(Fig0911(a)(noisy_fingerprint).tif); % 说明:上述图片可从Gonzalez网站下载se = strel(square,3);bw1 = imopen(I,se);subplot(1,2,1), imshow(I), title(Original Image)subplot(1,2,2), imshow(bw1), title(After opening)bw2 = imclose(I,se);figure;subplot(1,2,1), imshow(I, truesize), title( Original Image)subplot(1,2,2), imshow(bw2, truesize), title(After Closing)说明:改变结构元素形状、大小,重做上述实验,比较实验结果,分析结构元素对运算的影响;3细化与骨架抽取clear all, close allBW = imread(logo.tif);BW1 = bwmorph(BW,thin,Inf);BW2 = bwmorph(BW,skel,Inf);subplot(1,3,1), imshow(BW), title( Original Image );subplot(1,3,2), imshow(BW1), title( Thinned Image );subplot(1,3,3), imshow(BW2), title( Image skeleton);%查看bwmorph函数使用说明help bwmorph1图像阈值分割clear all, close all;I = imread(rice.tif);figure (1),imshow(I)figure(2); imhist(I)T=120/255;Ibw1 = im2bw(I,T); %选择阈值T=120/255对图像二值化;figure(3);subplot(1,2,1), imshow(Ibw1);T=graythresh(I); %采用Otsu方法计算最优阈值T对图像二值化;L = uint8(T*255)Ibw2 = im2bw(I,T); subplot(1,2,2), imshow(Ibw2);help im2bw;help graythresh;(令取不同值,重做上述试验,观察试验结果)2边缘检测clear all, close all;I = imread(rice.tif);BW1 = edge(I,sobel);BW2 = edge(I,canny);BW3 = edge(I,prewitt);BW4 = edge(I,roberts);BW5 = edge(I,log);figure(1), imshow(I), title(Original Image);figure(2), imshow(BW1), title(sobel);figure(3), imshow(BW2), title(canny);figure(4), imshow(BW3), title(prewitt);figure(5), imshow(BW4), title(roberts);figure(6), imshow(BW5), title(log);(二)图像分割中运动的运用(运动目标检测)% Moving object detection ver1.0 2012-10-23% Writen by Zhangyunchuclear all;close all;clc;% read a avi file information, cartest.avi 为待处理的视频文件,格式为.avifileinfo = aviinfo(cartest.avi); numFrames = fileinfo.NumFrames;% To avoid consuming too much memories, read only a clip of 200 frames each timeclipframes = 200;Clips = floor(numFrames/clipframes);% Read the first frame in the video sequence as the reference background image %在matlab2010 版本中,可采用函数mmreader,详见matlab2010 helpFref = aviread(cartest.avi,10);Iref =Fref.cdata; % predefine the thresholdThreh = 15;% Define a structure elementse=strel(disk,3);for m = 1:Clips % Calculate the start and end frame index of the m-th movie clip startframe = (m - 1)* clipframes + 1; if m = Clips endframe = numFrames -1; else

温馨提示

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

评论

0/150

提交评论