通信原理實驗程序課堂基礎(chǔ)_第1頁
通信原理實驗程序課堂基礎(chǔ)_第2頁
通信原理實驗程序課堂基礎(chǔ)_第3頁
通信原理實驗程序課堂基礎(chǔ)_第4頁
通信原理實驗程序課堂基礎(chǔ)_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、.三.主程序:function varargout = yasuo(varargin)if nargin = 0 % fig = openfig(mfilename,'reuse');handles = guihandles(fig);guidata(fig, handles);if nargout > 0varargout1 = fig;endelseif ischar(varargin1) tryif (nargout)varargout1:nargout = feval(varargin:); elsefeval(varargin:); % FEVAL switch

2、yardendcatchdisp(lasterr);endend % -function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) img=imread('lena.bmp'); img=im2double(img); img2=blkproc(img,16 16,'walsh(x)'); fileid=fopen('img.dat','w');fileid2=fopen('data.dat','w');fil

3、edata=0;filescaledata=0; subplot(findobj('tag','axes1'); imshow(img);axis off; title('原圖'); lut=8 8 8 8 8 8 8 8 4 4 4 4 4 4 4 4 8 8 4 4 4 4 4 4 4 4 2 2 2 2 2 2 8 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 8 4 4 4 2 2 2 2 2 2 2 2 0 0 0 0 8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 8 4 4 2 0 0 0 0 0 0

4、0 0 0 0 0 0 8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 04

5、 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0; for i=1:16, for j=1:16, if lut(i,j)=0, subdata,subscale=quantizing(img2,lut(i,j),i,j); filedata=filedata,subdata; filescaledata=filescaledata,subscale; end endend filedata=filedata(2:length(filedata); filescaledata=filescaledata(2:length(filescaledata);fwrite(fileid,f

6、iledata,'ubit1');fwrite(fileid2,filescaledata,'double');fclose(fileid); set(findobj('tag','text2'),'string',256/50); % -function varargout = pushbutton2_Callback(h, eventdata, handles, varargin)img=im2double(imread('lena.bmp'); fileid=fopen('img.da

7、t','r'); fileid2=fopen('data.dat','r');filescaledata=fread(fileid2,'double');filedata=fread(fileid,'ubit1');filedata=filedata'filescaledata=filescaledata'filedata=double(filedata);img3=zeros(512);offset1=0;offset2=0;m=0;lut=8 8 8 8 8 8 8 8 4 4 4 4

8、4 4 4 4 8 8 4 4 4 4 4 4 4 4 2 2 2 2 2 2 8 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 8 4 4 4 2 2 2 2 2 2 2 2 0 0 0 0 8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 08 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 2 0 0 0 0 0 0 0 0 0 0 0 04 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2

9、2 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0;for i=1:16, for j=1:16, if lut(i,j)=0, img3=dequantizing(img3,filedata,filescaledata,lut(i,j),i,j,offset1,offset2)

10、; m=m+1; offset1=offset1+1024*lut(i,j); offset2=2*m; end endend img4=blkproc(img3,16 16,'dewalsh(x)');fclose(fileid);fclose(fileid2); subplot(findobj('tag','axes2');imshow(img4);axis off;title('壓縮圖像'); error=(img-img4).2; MSE=sum(error(:)/sum(img(:).2); SNR=-10*log10(

11、MSE); set(findobj('tag','text4'),'string',SNR);% -function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)clear;close('yasuo'); 三實驗程序function varargout = xu3(varargin)if nargin = 0 fig = openfig(mfilename,'reuse'); set(fig,'Color',get

12、(0,'defaultUicontrolBackgroundColor'); handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout1 = fig; endelseif ischar(varargin1) try if (nargout)varargout1:nargout = feval(varargin:); elsefeval(varargin:); end catch disp(lasterr); endend% -function varargout = pushbut

13、ton1_Callback(h, eventdata, handles, varargin)lena=imread('lena.bmp');lena=im2double(lena);%mohu%for i=1:512 for j=1:512 if i=1|i=512|j=1|j=512 lena1(i,j)=0; else lena1(i,j)=lena(i+1,j)+lena(i-1,j)+lena(i,j+1)+lena(i,j-1)-4*lena(i,j); end endendlena2=0.05*lena1+lena;%tidu%for i=1:512 for j=1

14、:512 if i=1|i=512|j=1|j=512 lena3(i,j)=0; elseif sqrt(lena2(i,j)-lena2(i+1,j)2+(lena2(i,j)-lena2(i,j+1)2)>=512 lena3(i,j)=512; else lena3(i,j)=sqrt(lena2(i,j)-lena2(i+1,j)2+(lena2(i,j)-lena2(i,j+1)2); end endendlena3=lena-lena3;%laplace%for i=1:512 for j=1:512 if i=1|i=512|j=1|j=512 lena4(i,j)=0;

15、 else lena4(i,j)=lena2(i+1,j)+lena2(i-1,j)+lena2(i,j+1)+lena2(i,j-1)-4*lena2(i,j); end endendlena4=lena-lena4; subplot(2,2,1);imshow(lena);title('原始圖像'); subplot(2,2,2);imshow(lena2);title('模糊圖像'); subplot(2,2,3);imshow(lena3);title('梯度銳化圖像'); subplot(2,2,4);imshow(lena4);tit

16、le('拉普拉斯銳化圖像');三源程序:% -function varargout = pushbutton2_Callback(h, eventdata, handles, varargin)%復(fù)原clear;f1=zeros(256,256);f2=zeros(256,256);gf=zeros(256,256);h=zeros(256,256);h2=zeros(256,256);f=zeros(256,256);ff2=zeros(256,256);p1=0;p2=0;g=im2double(imread('peppers_degraded.tif');

17、f=im2double(imread('peppers.tif');gf=fft2(g);for i=1:256 for j=1:256 h(i,j)=(1/(1+(i-129)2+(j-129)2)/362)5); endend%反向濾波for i=1:256 for j=1:256 ff(i,j)=1/2562*gf(i,j)/h(i,j); endendf1=ifft2(ff)/max(max(ifft2(ff);%維納濾波gf=fftshift(gf);for i=1:256 for j=1:256 ff2(i,j)=gf(i,j)*(1/h(i,j)*(abs(h(i

18、,j)2/(abs(h(i,j)2+17); endendf2=ifft2(fftshift(ff2)/max(max(ifft2(fftshift(ff2);h2=ff2./gf;%求峰值信噪比for i=1:256 for j=1:256 p1=(g(i,j)-f1(i,j)2+p1; p2=(g(i,j)-f2(i,j)2+p2; endendpmse1=-10*log10(1/2562*p1/double(max(max(g)2)pmse2=-10*log10(1/2562*p2/double(max(max(g)2)subplot(2,2,1)imshow(f)subplot(2,2

19、,2)imshow(g)subplot(2,2,3)imshow(abs(f1)subplot(2,2,4)imshow(abs(f2)% -function varargout = pushbutton4_Callback(h, eventdata, handles, varargin)%邊沿檢測clear;f=double(imread('lena.bmp');f1=zeros(512,512);f2=zeros(512,512);f3=zeros(512,512);for i=2:511 for j=2:511 f1(i,j)=(sqrt(f(i,j)-f(i-1,j-1

20、)2+(f(i-1,j)-f(i,j-1)2); f3(i,j)=(abs(f(i+1,j)+f(i-1,j)+f(i,j+1)+f(i,j-1)-4*f(i,j); f2(i,j)=(sqrt(f(i-1,j+1)+2*f(i,j+1)+f(i+1,j+1)-(f(i-1,j-1)+2*f(i,j-1)+f(i+1,j-1)2+(f(i-1,j-1)+2*f(i-1,j)+f(i-1,j+1)-(f(i+1,j-1)+2*f(i+1,j)+f(i+1,j+1)2); endendf1=uint8(f1);f2=uint8(f2);f3=uint8(f3);f=uint8(f);figurei

21、mshow(f)title('原圖')figureimshow(f1)title('robert');figureimshow(f2)title('sobol')figureimshow(f3)title('laplacian')% -function varargout = pushbutton5_Callback(h, eventdata, handles, varargin)%銳化clear;f=double(imread('lena.bmp');f1=zeros(512,512);f1=f;f3=zeros

22、(512,512);for i=2:511 for j=2:511 if (sqrt(f(i,j)-f(i+1,j+1)2+(f(i+1,j)-f(i,j+1)2)>50 f1(i,j)=(sqrt(f(i,j)-f(i+1,j+1)2+(f(i+1,j)-f(i,j+1)2); end f3(i,j)=(abs(f(i+1,j)+f(i-1,j)+f(i,j+1)+f(i,j-1)-4*f(i,j); endendfigureimshow(uint8(f)title('原圖')figureimshow(uint8(f1)title('robert');f

23、igureimshow(uint8(f-f3)title('laplacian')% -function varargout = figure1_ButtonDownFcn(h, eventdata, handles, varargin)% -function varargout = pushbutton1_Callback(h, eventdata, handles, varargin三實驗程序:% 用Robert算子邊緣檢測clear;img=imread('lena.bmp');img=double(img);a1=-1,0;0,1;a2=0,-1;1,0;z1=conv2(img,a1,'same');z2=conv2(img,a2,'same');r=sqrt(z1.2+z2.2);r=uint8(r);imwrite(r,'robert.bmp');subplot(1,1,1);imshow(r);title('robert算子檢測');% 用Sobel算子邊緣檢測clear;img=imread('lena

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論