数字图像处理报告 (2).doc_第1页
数字图像处理报告 (2).doc_第2页
数字图像处理报告 (2).doc_第3页
数字图像处理报告 (2).doc_第4页
数字图像处理报告 (2).doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

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

文档简介

4.4 I=imread(lena.bmp);imshow(I);I=double(I);M,N=size(I);for k=1:8 J=zeros(M,N); for i=1:M for j=1:N temp=I(i,j); s1=0; s2=0; range=k: -1: 1; for d=range s1=2(8-d)+s1;s2=2(8-d+1); if temp=s1&temps2; J(i,j)=255;break; end end end end J=unint8(J); figure;imshow(J);end 4.14I=imread(saturn.jpg);J=imnoise(I,salt & pepper,0.02); %给原图像加入椒盐噪声subplot(121);imshow(J);tilte(含有椒盐噪声图像)J=double(J);%采用傅里叶变换f=fft2(J);%数据规陈平衡g=fftshift(f)M,N=size(f);n=3;d0=20n1=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+(d/d0)(2*n); g(i,j)=h*g(i,j); endendg=ifftshift(g);g=uint8(real(ifft2(g);subplot(122);imshow(g);4.16J=imread(eight.tif); %读入原图subplot(121);imshow(J);J=double(J);f=fft2(J); %采用傅里叶变换g=fftshift(f); M,N=size(f); d0=10; rl=0.5; rh=2 c=4; 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=(rh-rl)*(1-exp(-c*(d.2/d0.2)+rl; g(i,j)=h*g(i,j); end end g=ifftshift(g); g=uint8(real(ifft2(g); subplot(122);imshow(g);5.3F=checkerboard(8); figure(1);imshow(F,);PSF=fspecial(motion,7,45); MF=imfilter(F,PSF,circular);noise=imnoise(zeros(size(F),gaussian,0,0.001); MFN=MF+noise; figure(2);imshow(MFN,);NSR=sum(noise(:).2)/sum(MFN(:).2); %计算噪信比figure(3);imshow(deconvwnr(MFN,PSF),); %逆滤波复原figure(4);imshow(deconvwnr(MFN,PSF,NSR),); %维纳滤波复原 5.7 f=imread(ll.jpg);figure(1);imshow(f);title(原始图象);g=imnoise(f,salt & pepper,0.2);figure(2);imshow(g);title(椒盐噪声污染的图像);g1=double(g)/255;j1=medfilt2(g1,symmetric);figure(3);imshow(j1);title(中值滤波图像);j2=ordfilt2(g1,median(1:3*3),ones(3,3),symmetric);figure(4);imshow(j2);title(中点滤波图像);j3=ordfilt2(g1,1,ones(3,3);figure(5);imshow(j3);title(最小值滤波图像);j4=ordfilt2(g1,9,ones(3,3);figure(6);imshow(j4);title(最大值滤波图像);6.9I=imread(image2g.jpg);I=double(I);M,N=size(I);L=256;for i=1:M for j=1:N if I(i,j)L/4 R(i,j)=0; G(i,j)=4*I(i,j); B(i,j)=L; else if I(i,j)=L/2 R(i,j)=0; G(i,j)=L; B(i,j)=-4*I(i,j)+2*L; else if I(i,j)1 index1=symbols_index1; index2=symbols_index2; codeword_tmp(index1)=addnode(codeword_tmp(index1),uint8(0); codeword_tmp(index2)=addnode(codeword_tmp(index2),uint8(1); f=sum(f(1:2)f(3:end); symbols_indexindex1,index2symbols_index(3: end); f,sortindex=sort(f); symbols_index=symbols_index(sortindex);endcodeword=cell(256,1);codeword(symbols)=codeword_tmp;len=0;for index=1: length(vector) len=len+length(codeworddouble(vector(index)+1);endstring=repmat(uint8(0),1,len);pinter=1;for index=1: length(vector) code=codeworddouble(vector(index)+1; len=length(code); string(pointer+(0:length)=code; pointer=pointer+len;endlen=length(string);pad=8-mod(len,8);if pad0 string=string uint8(zeros(1,pad);endcodeword=codeword(symbols);codelen=zeros(size(codeword);weigths=2.(0: 23);maxcodelen=0;for index=1: length(codeword) len=length(codewordindex); if lenmaxcodelen maxlcodelen=len;end if len0 code=sum(weigths(codewordindex= =1); code=bitset(code, len+1); codewordindex=code; codelen(index)=len; endcodeword=codeword:;cols=length(string)/8;string=reshape(string,8,cols);weigths=2.(0:7);zipped=uint8(weigth*duoble(string);%码表存储到一个稀疏矩阵huffcodes=sparse(1,1);for index=1:nnz(codeword %length(codeword) %numel(codeword) huffcodes(codeword(index),1)=symbols(index);end%填写解码时所需的结构信息info.pad=pad;info.huffcodes=huffcodes;info.ratio=cols./length(vector);info.length=length(vector);info.maxcodelen=maxcodelen;info.rows=m;info.cols=n;%huffcode函数对输入矩阵vector进行huffman解码,返回解压后的图像数据function vector=huffcode(zipped,info,image)ifisa(zipped,uint8) error(input argument must be a uint8 vector);end%产生0,1序列,每位占一个字节len=length(zipped);string=repmat(uint8(0),1,len*8);bitindex=1:8;for index=1:len string(bitindex+8.*(index-1)=uint8(bitget(zipped(index),bitindex);endstring=logical(string(:);len=length(string);string(len-info.pad+1):end)=;len=length(string);&开始解码weight=2.(0:51);vector=repmat(uint8(0),1,info.length);vectorindex=1;codeindex=1;code=0;for index=1:len code=bieset(code,codeindex,string(index); codeindex=codeindex+1; byte=decode(bitset(code,codeindex),info); if byte0 vector(vectorindex)=byte-1; codeindex=1; code=0; vectorindex=vectorindex+1; endendvector=reshape(vector,info.rows,info.cols);%函数addnode添加结点function codeword_new=addnode(codeword_old,item)codeword_new=cell(size(codeword_old);for index=1:length(codeword-old) codeword_newindex=item codeword_oldindex;end%函数frequency计算各符号出现的概率function f=frequency(vector)ifisa(vector,uint8) error(input argument must be a uint8 vector);endf=rempat(0,1,256);len=length(vector);for index=0:255 f(index+1)=sum(vector=uint8(index);endf=f./len%函数decode返回码字对应的符号function byte=decode(code,info)byte=info.huffcodes(code);7.11X=14 15 14 15 13 15 15 14 20 26 27 28 27 27 29 37 47 62 75 77 78 79 80 81 81 82 82t=entropy(X)a=1;delt=6.5;y=DMencode(X,a,delt);XX=DMdecode(y);ax=0:1:26X2,Y2=STAIRS(ax,XX)plot(X2,Y2,k,ax,X,k)function y=DMencode(x,a,delt)error(nargchk(1,3,nargin)if nargin3 delt=6.5 if nargin0 qe(i,j)=delt; else qe(i,j)=-delt; end if(i,j)=p(i,j)+qe(i,j); endendy=qe;function x=DMencode(y,a)error(nargchk(1,2,nargin);if nargin2 a=1;endm,n=size(y);x=zeros(m,n+1);for j=1:n jj=j+1; x(:,jj)=y(:,j)+a.*x(:,(jj-1);endx=x(:,1+1:end); 7.14cr=0.5;I1=imread(cameraman.tif);I1=double(I1)/255;figure(1);imshow(I1);fftcoe=blkproc(I1,8 8,fft2(x);coevar=im2col(fftcoe,8 8,distinct);coe=coevar;y,ind=sort(coevar);m,n=size(coevar);snum=64-64*cr;for i=1:ncoe(ind(1:snum),i)=0;endB2=col2im(coe,8 8,256 256,distinct);I2=blkproc(B2,8 8,ifft2(x);figure(2);imshow(I2);e=double(I1)-double(I2);m,n=size(e);erms=sqrt(sum(e(:).2)/(m*n)9.5f=imread(circle.bmp);subplot(1, 2, 1);imshow(f);title(原始图像)g=im2double(f);w=fspecial(laplacian,0);g=imfilter(g, w, replictae);h=boundary_tracr2(g)subplot(1, 2, 2);imshow(h);title(边界跟踪结果)Function g=boundary_trace2(f)cell_cp=0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1;cell_n=-1,1,1,1,0,1;-1,0,0,1,-1,1;-1,-1,-1,1,-1,0; 0,-1,-1,0,-1,-1,1,-1,-1,-1,0,-1;1,0,0,-1, 1,-1;1,1,1,-1,1,0;0,1,1,0,1,1; f=padarray(f,1,1,0,both);boundaryval=-100;maxval=max(f(:);rv,cv=find(f=maxval);S=rv(1),cv(1);P=S;minval=min(f(:);T=(maxval+minval)/2;f(S(1),S(2)=boundaryval;g=f(S(1)-1:S(1)+1,S(2)-1:S(2)+1);maxval=max(g(:);rv,cv=find(g=maxval);C=P+rv(1)-2,cv(1)-2;done=f(C(1),C(2)T;f(S(1),S(2)=-boundaryval;while donef(C(1),C(2)=boundaryval;c_p=C_P;for dir=1:length(cell_cp) if cell_cpdir=c_p break; endendmaxval=boundaryval;for i=1:size(cell_n,2) N2=C+cell_ndir,i; if(maxvalf(N2(1),N2(2) maxval=f(N2(1),N2(2); N=N2; endendif(f(N(1),N(2)T)|(N=S) done=true break;endP=C;C=N;end%whilebi=find(f=boundaryval);f(:)=0;f(bi)=1;f(S(1),S(2)=1;f=f(2:end-1,2:end-1);g=im2bw(f);分析:运行该代码只显示原始图像,显示图像的matlab代码是imshow(f),观察代码,在代码中有相关的命令显示边界跟踪结果图,可是却没有显示,还需仔细的分析代码,没有找到相关的方法来解决这个问题。9.9 f=imread(rice.bmp);subplot(2,2,1);imshow(f);title(a)原始图像);subplot(2,2,2);%计算距离函数hv=fspecial(prewitt);hh=hv.;gv=abs(imfilter(f,hv,replicate);gh=abs(imfilter(f,hh,replicate);g=sqrt(gv.2+gh.2);%watershed算法分割subplot(2,2,2);L=watershed(g);wr=L=0;imshow(wr);t

温馨提示

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

最新文档

评论

0/150

提交评论