基于matlab的圖像處理源程序_第1頁
基于matlab的圖像處理源程序_第2頁
基于matlab的圖像處理源程序_第3頁
基于matlab的圖像處理源程序_第4頁
基于matlab的圖像處理源程序_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、function varargout = two(varargin)% Begin initialization code - DO NOT EDIT gui_Singleton = 1;gui_Se = struct(gui_Name,mfilename, .gui_Singleton,gui_Singleton, .gui_Callback, if nargin & ischar(varargin1), ., ., , . );gui_Se.gui_Callback = str2func(varargin1);endif nargoutvarargout1:nargout =else(gu

2、i_Se, varargin:);(gui_Se, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before erzhi is made visible.function(hObject, eventdata, handles, varargin)% This function has no output args, see.%接下來是菜單的程序function file_Callback(hObject, eventdata, handles)%文件打開程序function open_Callb

3、ack(hObject, eventdata, handles) name,path=uigetfile(*.bmp,載入圖像);if isequal(name,0)|isequal(path,0) errordlg(沒有選中文件,出錯); return;elsex=imread(path,name); axes(handles.axes_src); imshow(x); handles.img=x; handles.noise_img=x;guidata(hObjecndles)endfunction save_Callback(hObject, eventdata, handles)%文件

4、保存filename,pathname = uiputfile(*.bmp,保存為);if isequal(filename,pathname,0,0) errordlg(沒有保存,出錯); return;else file=strcat(pathname,filename); (handles.axes2); i=getimage(gca); imwrite(i,file);endfunction exit_Callback(hObject, eventdata, handles) clc;close all; close(gcf);%編輯菜單的程序function edit_Callbac

5、k(hObject, eventdata, handles)function huidu_Callback(hObject, eventdata, handles)%灰度處理 axes(handles.axes2); if isrgb(handles.img)y=rgb2gray(handles.img); %RGB imshow(y);elsemsgbox(這已經(jīng)是灰度圖像,轉(zhuǎn)換失敗);endfunction liangdu_Callback(hObject, eventdata, handles)%亮度處理prompt=輸入?yún)?shù) 1,輸入?yún)?shù) 2,輸入gamma; defans=0 0.7

6、,0 1,1;p=inputdlg(prompt,輸入?yún)?shù),1,defans); p1=str2num(p1);p2=str2num(p2); p3=str2num(p3); gamma=p3; x=(handles.img); y=imadjust(x,p1,p2,gamma); axes(handles.axes2); imshow(y);function jietu_Callback(hObject, eventdata, handles)%截圖sendles.axes2,HandleVisibility,ON);axes(handles.axes2); y=imcrop(handles

7、.img); imshow(y); handles.Timage=y;functionda_Callback(hObject, eventdata, handles)function lingjz_Callback(hObject, eventdata, handles)%鄰近插值放大 axes(handles.axes2); prompt=輸入放大倍數(shù):;defans=2;p=inputdlg(prompt,輸入放大倍數(shù),1,defans); p1=str2num(p1);y=imresize(handles.img,p1,nearest); imshow(y);%最近鄰插值法放大funct

8、ion shuangxianfa_Callback(hObject, eventdata, handles)%雙線放大 axes(handles.axes2); prompt=輸入放大倍數(shù):;defans=2;p=inputdlg(prompt,輸入放大倍數(shù),1,defans); p1=str2num(p1);y=imresize(handles.img,p1,bilinear); imshow(y);%最近鄰插值法放大function shuangsanci_Callback(hObject, eventdata, handles)%雙三次放大 axes(handles.axes2); pr

9、ompt=輸入放大倍數(shù):;defans=2;p=inputdlg(prompt,輸入放大倍數(shù),1,defans); p1=str2num(p1); y=imresize(handles.img,p1,bicubic); imshow(y);function suoxiao_Callback(hObject, eventdata, handles)%鄰近插值縮小 axes(handles.axes2); prompt=輸入放大倍數(shù):;defans=0.2;p=inputdlg(prompt,輸入放大倍數(shù),1,defans); p1=str2num(p1); y=imresize(handles.

10、img,p1,nearest);imshow(y);%最近鄰插值法縮小function shuangxian_Callback(hObject, eventdata, handles)%雙線性縮小 axes(handles.axes2); prompt=輸入放大倍數(shù):;defans=0.2;p=inputdlg(prompt,輸入放大倍數(shù),1,defans); p1=str2num(p1);y=imresize(handles.img,p1,bilinear);%最近鄰插值法縮小imshow(y);function shuangsancisuox_Callback(hObject, event

11、data, handles)%雙三次縮小 axes(handles.axes2); prompt=輸入放大倍數(shù):;defans=0.2;p=inputdlg(prompt,輸入放大倍數(shù),1,defans); p1=str2num(p1); y=imresize(handles.img,p1,bicubic); imshow(y);function xuanzhuan_Callback(hObject, eventdata, handles)function updown_Callback(hObject, eventdata, handles)%上下翻轉(zhuǎn) axes(handles.axes2)

12、; x=(handles.img);if isrgb(handles.img) for k=1:3y(:,:,k)=flipud(x(:,:,k);%上下翻轉(zhuǎn)函數(shù)end imshow(y); elsex=(handles.img); y=flipud(x); imshow(y);endfunction leftright_Callback(hObject, eventdata, handles)%左右翻轉(zhuǎn)axes(handles.axes2);if isrgb(handles.img) x=(handles.img);for k=1:3y(:,:,k)=fliplr(x(:,:,k);%左右翻

13、轉(zhuǎn)函數(shù) endimshow(y); elsex=(handles.img); y=fliplr(x); imshow(y);endFunction left90_Callback(hObject, eventdata, handles)%左轉(zhuǎn) 90 度 axes(handles.axes2); x=(handles.img); y=imroe(x,90); imshow(y);function right90_Callback(hObject, eventdata, handles)%右轉(zhuǎn) 90 度 axes(handles.axes2); x=(handles.img); y=imroe(x

14、,-90); imshow(y);function other_Callback(hObject, eventdata, handles)%任意角度旋轉(zhuǎn) axes(handles.axes2); prompt=輸入?yún)?shù) 1:;defans=30;p=inputdlg(prompt,輸入?yún)?shù),1,defans); p1=str2num(p1);y=imroe(handles.img,p1); imshow(y);function gs_Callback(hObject, eventdata, handles)%加入噪聲axes(handles.axes2);prompt=輸入?yún)?shù) 1:,輸入?yún)?shù)

15、 2;defans=0,0.02;p=inputdlg(prompt,輸入?yún)?shù),1,defans); p1=str2num(p1);p2=str2num(p2);y=imnoise(handles.img,gaussian,p1,p2);imshow(y); handles.noise_img=y;guidata(hObjecndles);function jy_Callback(hObject, eventdata, handles)%加入椒鹽噪聲prompt=輸入?yún)?shù) 1:;%框的設置,用戶輸入的是字符串defans=0.02;%缺省值p=inputdlg(prompt,輸入?yún)?shù),1,de

16、fans);p1=str2num(p1); axes(handles.axes2); x=(handles.img);%字符串轉(zhuǎn)化為數(shù)值y=imnoise(x,salt & pepper,p1); imshow(y); handles.noise_img=y;guidata(hObjecndles);function cx_Callback(hObject, eventdata, handles)%加入乘性噪聲 axes(handles.axes2); prompt=輸入?yún)?shù) 1:;defans=0.02;p=inputdlg(prompt,輸入?yún)?shù),1,defans); p1=str2num

17、(p1); y=imnoise(handles.img,speckle,p1); imshow(y);handles.noise_img=y; guidata(hObjecndles);function zhitutongji_Callback(hObject, eventdata, handles)function red_Callback(hObject, eventdata, handles)%R 直方圖sendles.axes2,HandleVisibility,ON);axes(handles.axes2);x=imhisndles.img(:,:,1);%直方圖統(tǒng)計x1=x(1:1

18、0:256); horz=1:10:256;bar(horz,x1);sendles.axes2,xtick,0:50:255);function gray_Callback(hObject, eventdata, handles)%G 直方圖sendles.axes2,HandleVisibility,ON);axes(handles.axes2); if isrgb(handles.img)x=imhisndles.img(:,:,2);%直方圖統(tǒng)計x1=x(1:10:256); horz=1:10:256;bar(horz,x1);sendles.axes2,xtick,0:50:255

19、); elsemsgbox(這是灰度圖像,旋轉(zhuǎn)失敗);endfunction blue_Callback(hObject, eventdata, handles)%B 直方圖sendles.axes2,HandleVisibility,ON);axes(handles.axes2); if isrgb(handles.img)x=imhisndles.img(:,:,3);%直方圖統(tǒng)計x1=x(1:10:256); horz=1:10:256;bar(horz,x1);%axis(0 255 0 150000);sendles.axes2,xtick,0:50:255);%se elsendl

20、es.axes2,ytick,0:2000:15000);msgbox(這是灰度圖像,旋轉(zhuǎn)失敗);endfunction junheng_Callback(hObject, eventdata, handles)%直方圖均衡sendles.axes2,HandleVisibility,ON);axes(handles.axes2); if isrgb(handles.img)a=histeq(handles.img(:,:,1);b=histeq(handles.img(:,:,2);c=histeq(handles.img(:,:,3); k(:,:,1)=a;k(:,:,2)=b;k(:,

21、:,3)=c;imshow(k);else h=histeq(handles.img); imshow(h);end%直方圖均衡%頻譜分析function pinpu_Callback(hObject, eventdata, handles)function pinputu_Callback(hObject, eventdata, handles)%顯示頻譜圖 axes(handles.axes2); x=(handles.img);if isrgb(x)m=fft2(x(:,:,1);y=fftshift(m); imshow(log(abs(y),);elsem=fft2(x); y=ff

22、tshift(m); imshow(log(abs(y),);endfunction frequency_Callback(hObject, eventdata, handles)%低通濾波器 axes(handles.axes2); x=(handles.img);if isrgb(x)msgbox(這是彩像,不能通過低通濾波器,失敗);elsey1=imnoise(x,salt & pepper);% 疊加椒鹽噪聲f=double(y1);% 數(shù)據(jù)類型轉(zhuǎn)換,不支持圖像的無符號整型的計算g=fft2(f); g=fftshift(g); M,N=size(g);%變換轉(zhuǎn)換數(shù)據(jù)矩陣nn=2;

23、d0=10;%(Butterworth)低通濾波器二階%截止頻率為 10m=fix(M/2); n=fix(N/2); for i=1:Mfor j=1:Nd=sqrt(i-m)2+(j-n)2); h=1/(1+0.414*(d/d0)(2*nn); result(i,j)=h*g(i,j);endend result=ifftshift(result); y2=ifft2(result);% 計算低通濾波器傳遞函數(shù)y3=u8(real(y2);imshow(y3);% 顯示濾波處理后的圖像endfunctiontong_Callback(hObject, eventdata, handle

24、s)%高通濾波器 axes(handles.axes2); x=(handles.img);if isrgb(x)msgbox(這是彩像,不能通過高通濾波器,失敗);elsey1=imnoise(x,gaussian);%加噪聲f=double(y1); k=fft2(f); g=fftshift(k); M,N=size(g); nn=2;d0=3;% 數(shù)據(jù)類型轉(zhuǎn)換%變換% 轉(zhuǎn)換數(shù)據(jù)矩陣%截止頻率為 3m=fix(M/2); n=fix(N/2); for i=1:Mfor j=1:Nd=sqrt(i-m)2+(j-n)2); if d=d0h=0;else h=1; endresult(i

25、,j)=h*g(i,j);endend result=ifftshift(result); y2=ifft2(result);% 計算高通濾波器傳遞函數(shù)y3=u8(real(y2);imshow(y3); end%接下來這是灰度圖像處理程序function huiduchuli_Callback(hObject, eventdata, handles)function erzhituxiang_Callback(hObject, eventdata, handles)%二值圖像 axes(handles.axes2); x=(handles.img);if isrgb(x)msgbox(這是彩

26、像,不能轉(zhuǎn)換為二值圖像,轉(zhuǎn)換失敗);else j=im2bw(x); imshow(j); endfunction tuxiangfushi_Callback(hObject, eventdata, handles)%圖像腐蝕 axes(handles.axes2); x=(handles.img);if isrgb(x)msgbox(這是彩像,不能進行圖像腐蝕,失敗);else j=im2bw(x); se=eye(5);bw=bwmorph(j,erode); imshow(bw);endfunction suoyuxiang_Callback(hObject, eventdata, ha

27、ndles)%創(chuàng)建索引圖像 axes(handles.axes2); x=(handles.img);if isrgb(x)msgbox(這是彩 else y=grayslice(x,16); axes(handles.axes2); imshow(y,jet(16); end像,不能創(chuàng)建索引圖像,創(chuàng)建失敗);%這段是顏色模型的轉(zhuǎn)換function ysmx_Callback(hObject, eventdata, handles)function hsv_Callback(hObject, eventdata, handles)%RGB 圖像轉(zhuǎn) HSV axes(handles.axes2)

28、; x=(handles.img);if isrgb(x) HSV=rgb2hsv(x); imshow(HSV); elsemsgbox(這是灰度圖像,不能轉(zhuǎn)換,轉(zhuǎn)換失敗);endfunction ntsc_Callback(hObject, eventdata, handles)%RGB 轉(zhuǎn) NTSCaxes(handles.axes2); x=(handles.img);if isrgb(x) ntsc=rgb2ntsc(x); imshow(ntsc); elsemsgbox(這是灰度圖像,不能轉(zhuǎn)換,轉(zhuǎn)換失敗);endfunction ycbcr_Callback(hObject, e

29、ventdata, handles)%RGB 轉(zhuǎn) YCBCRaxes(handles.axes2); x=(handles.img);if isrgb(x) ycbcr=rgb2ycbcr(x); imshow(ycbcr);elsemsgbox(這是灰度圖像,不能轉(zhuǎn)換,轉(zhuǎn)換失敗);end%這是濾波程序function lvbo_S str=get(hObject,string);(hObject, eventdata, handles)sendles.axes2,HandleVisibility,ON);axes(handles.axes2); i=handles.noise_img; if

30、 isrgb(i)a=handles.noise_img(:,:,1); b=handles.noise_img(:,:,2); c=handles.noise_img(:,:,3); switch strcase 中值濾波k(:,:,1)=medfilt2(a);k(:,:,2)=medfilt2(b);k(:,:,3)=medfilt2(c); imshow(k)case 自適應濾波k(:,:,1)=wiener2(a,5,5);k(:,:,2)=wiener2(b,5,5);k(:,:,3)=wiener2(c,5,5); imshow(k);case平滑濾波k(:,:,1)=filter2(fspel(average,3),a)/255;k(:,:,2)=filter2(fspek(:,:,3)=filter2(fspeimshow(k); endelseswitch strl(average,3),b)/255;l(average,3),c)/255;case 中值濾波k=medfilt2(handles.noise_img); imshow(k)case 線性濾波h=1 1 1;1 1 1;1 1 1;H=h/9; m=double(handles.noise_img); k=conv2(m,h);imshow(k,); cas

溫馨提示

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

評論

0/150

提交評論