matlab實(shí)現(xiàn)數(shù)字圖像處理Photoshop小程序_第1頁
matlab實(shí)現(xiàn)數(shù)字圖像處理Photoshop小程序_第2頁
matlab實(shí)現(xiàn)數(shù)字圖像處理Photoshop小程序_第3頁
matlab實(shí)現(xiàn)數(shù)字圖像處理Photoshop小程序_第4頁
matlab實(shí)現(xiàn)數(shù)字圖像處理Photoshop小程序_第5頁
已閱讀5頁,還剩19頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、實(shí) 驗(yàn) 報(bào) 告 課程名稱 數(shù)字圖像處理 分院 班 組 姓名 學(xué)號 日期 年 月 日 程序所實(shí)現(xiàn)的功能:1)圖像的讀取和保存。 2)設(shè)計(jì)圖形用戶界面,讓用戶能夠?qū)D像進(jìn)行任意的亮度和對比度變化調(diào)整,顯示和對比變換前后的圖像。 3)設(shè)計(jì)圖形用戶界面,讓用戶能夠用鼠標(biāo)選取圖像感興趣區(qū)域,顯示和保存該選擇區(qū)域。 4)圖像直方圖均衡,要求顯示直方圖統(tǒng)計(jì),比較直方圖均衡后的效果。 5)能對圖像加入各種噪聲,并通過幾種濾波算法實(shí)現(xiàn)去噪并顯示結(jié)果。6) 底片效果7)邊緣信息8)圖像反轉(zhuǎn)程序?qū)崿F(xiàn)的亮點(diǎn)設(shè)計(jì)簡潔的菜單欄以及常用工具的快捷圖標(biāo)也可以使用對應(yīng)功能的快捷鍵,包括新建,打開(CTRL+O),保存(CTRL

2、+S);菜單欄里更是增加了操作撤銷與圖像還原的操作,可是實(shí)現(xiàn)返回操作??傮w設(shè)計(jì)圖1軟件的總體設(shè)計(jì)界面布局如上圖所示,主要分為 2 個(gè)部分:顯示區(qū)域與操作區(qū)域。 顯示區(qū)域:顯示載入原圖,以及通過處理后的圖像。 操作區(qū)域:通過功能鍵實(shí)現(xiàn)對圖像的各種處理,為了實(shí)現(xiàn)界面的簡潔,大部分的功能放到了 菜單欄里。 在截圖中可見,左部為一系列功能按鍵如“對比度調(diào)節(jié)”、“亮度調(diào)節(jié)”、“裁剪”等等 ;界面正中部分為圖片顯示部分,界面中下方為系列功能切換選擇組。 菜單欄的設(shè)計(jì)展示圖2具體設(shè)計(jì) 現(xiàn)介紹各個(gè)功能模塊的功能與實(shí)現(xiàn)。4.1 菜單欄的設(shè)計(jì)。 通過 Menu Editor 創(chuàng)建如下菜單,通過以下菜單來控制顯示或

3、隱藏功能按鍵圖3以“文件”菜單中“打開”為例說明實(shí)現(xiàn)用戶界面功能鍵“打開”的顯示與隱藏。 實(shí)現(xiàn)該功能通過添加callback就可以了: 通過Toolbar Editor可以添加快捷圖標(biāo),如下圖:圖4 圖像的讀取和保存。 (1) 利用“文件”菜單中的“打開”、“ 保存”或者使用菜單欄下的快捷圖標(biāo)分別實(shí)現(xiàn)圖片的讀取與保存。 圖5如果沒有選中文件還會(huì)提示圖6(2)圖像保存。 利用“uiputfile”、“imwrite”函數(shù)實(shí)現(xiàn)圖像文件的保存。 圖7同樣按下去下取消鍵會(huì)提示:圖8(3)程序的退出。 你可以在菜單欄使用退出鍵,或者在主界面右下角有關(guān)閉按鈕就可以退出程序。對圖像進(jìn)行任意的亮度和對比度變化

4、調(diào)整,顯示和對比變換前后的圖像。 按下亮度調(diào)節(jié)按鈕會(huì)彈出輸入框,輸入調(diào)節(jié)倍數(shù),如下圖:圖9(注意:這里的倍數(shù)是相反的調(diào)節(jié),你會(huì)發(fā)現(xiàn)輸入0.1后亮度會(huì)變亮)調(diào)節(jié)后的圖像如下:圖11對比度的調(diào)節(jié)跟亮度一樣,調(diào)節(jié)后的圖像如下:圖12 44 用鼠標(biāo)選取圖像感興趣區(qū)域,顯示和保存該選擇區(qū)域。按下裁剪按鈕把鼠標(biāo)移動(dòng)到處理后的圖像窗口,光標(biāo)會(huì)變成十字形狀,拖動(dòng)光標(biāo)會(huì)出現(xiàn)方框,如下:圖13雙擊方框里的圖像就完成了裁剪。4.5 圖像轉(zhuǎn)化為灰度圖像。由于在matlab中較多的圖像處理函數(shù)支持對灰度圖像進(jìn)行處理,故對圖像進(jìn)行灰度轉(zhuǎn)化十分必要??衫胷gb2gray(X)函數(shù)對其他圖像進(jìn)行灰度圖像的轉(zhuǎn)化。 轉(zhuǎn)化實(shí)例如

5、下: 圖144.8 加入各種噪聲,并通過幾種濾波算法實(shí)現(xiàn)去噪。(1) 加入噪聲。通過imnoise(I,type,parameters)來加入各種噪聲。加入椒鹽噪聲 圖15加入噪聲后:圖16高斯噪聲:乘性噪聲:圖17這幾種噪聲我加入的參數(shù)都是0.02,效果逐漸加深。濾波:選擇線性濾波的結(jié)果如下,可以看出濾去了大部分噪聲,(注意:這幾個(gè)濾波不可以疊加使用,否則出現(xiàn)白屏)圖17翻轉(zhuǎn):左右翻轉(zhuǎn)圖18上下翻轉(zhuǎn):圖19工具底片效果:圖20邊緣信息:圖215、結(jié)果分析 軟件測試基本成功,課題所要求的功能均能較好實(shí)現(xiàn)。但一些功能只支持灰度圖像的處理。 其中值得一提的是在濾波處理中的低通濾波與高通濾波的效果。

6、由于一般圖像中含有較多的低頻信息成分高頻成分較少,通過低通濾波后,噪聲以及高頻成分被濾除,圖像雖有少量失真,略顯模糊,但尚可辨識。但若是通過高通濾波后,大量的有效低頻信息被濾除,圖像嚴(yán)重失真,不可辨識。 源碼:function duibidu_SelectionChangeFcn(hObject, eventdata, handles)% hObject handle to the selected object in duibidu % eventdata structure with the following fields (see UIBUTTONGROUP)%EventName: s

7、tring 'SelectionChanged' (read only)%OldValue: handle of the previously selected object or empty if none was selected%NewValue: handle of the currently selected object% handles structure with handles and user data (see GUIDATA)global T global strstr=get(hObject,'string'); axes(handle

8、s.axes2); switch str case'增強(qiáng)' T=getimage; prompt='輸入?yún)?shù):' defans='1' p=inputdlg(prompt,'input',1,defans); p1=str2double(p1); f=immultiply(handles.img,p1); imshow(f); handles.img=f; guidata(hObject,handles); case'減弱' T=getimage; prompt='輸入?yún)?shù):' defans=

9、9;1' p=inputdlg(prompt,'input',1,defans); p1=str2double(p1); f=imdivide(handles.img,p1); imshow(f); handles.img=f; guidata(hObject,handles); end% - Executes on button press in liangdu.function liangdu_Callback(hObject, eventdata, handles)% hObject handle to liangdu (see GCBO)% eventdata

10、reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global T axes(handles.axes2); T=getimage; prompt='調(diào)整倍數(shù)' defans='1' p=inputdlg(prompt,'input',1,defans); p1=str2double(p1); y=imadjust(handles.img, , ,p1); %亮度調(diào)節(jié) i

11、mshow(y); handles.img=y; guidata(hObject,handles);% -function wenjian_Callback(hObject, eventdata, handles)% hObject handle to wenjian (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% -function open_Callback(hOb

12、ject, eventdata, handles)% hObject handle to open (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)filename,pathname=uigetfile('*.jpg''*.bmp''*.tif''*.*','載入圖像');if isequal(

13、filename,0)|isequal(pathname,0) errordlg('沒有選中文件','出錯(cuò)'); return;else file=pathname,filename; global S %設(shè)置一個(gè)全局變量S,保存初始圖像路徑,以便之后的還原操作? S=file; x=imread(file); set(handles.axes1,'HandleVisibility','ON'); axes(handles.axes1); imshow(x); set(handles.axes1,'HandleVisibi

14、lity','OFF'); axes(handles.axes2); imshow(x); handles.img=x; guidata(hObject,handles);end% -function save_Callback(hObject, eventdata, handles)% hObject handle to save (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user da

15、ta (see GUIDATA) sfilename ,sfilepath=uiputfile('*.jpg''*.bmp''*.tif''*.*','保存圖像文件','untitled.jpg'); if isequal(sfilename,sfilepath,0,0) sfilefullname=sfilepath ,sfilename; imwrite(handles.img,sfilefullname); else msgbox('你按了取消鍵','保存失敗'

16、); end % -function exit_Callback(hObject, eventdata, handles)% hObject handle to exit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)clc; close all; close(gcf); clear; % -function IM_Callback(hObject, eventdata,

17、 handles)% hObject handle to IM (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% -function duibidu_SelectionChangeFcn(hObject, eventdata, handles)% hObject handle to the selected object in duibidu % eventdata st

18、ructure with the following fields (see UIBUTTONGROUP)%EventName: string 'SelectionChanged' (read only)%OldValue: handle of the previously selected object or empty if none was selected%NewValue: handle of the currently selected object% handles structure with handles and user data (see GUIDATA

19、)global T global strstr=get(hObject,'string'); axes(handles.axes2); switch str case'增強(qiáng)' T=getimage; prompt='輸入?yún)?shù):' defans='1' p=inputdlg(prompt,'input',1,defans); p1=str2double(p1); f=immultiply(handles.img,p1); imshow(f); handles.img=f; guidata(hObject,handle

20、s); case'減弱' T=getimage; prompt='輸入?yún)?shù):' defans='1' p=inputdlg(prompt,'input',1,defans); p1=str2double(p1); f=imdivide(handles.img,p1); imshow(f); handles.img=f; guidata(hObject,handles); end% -function huidu_Callback(hObject, eventdata, handles)% hObject handle to hui

21、du (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) global T axes(handles.axes2); T=getimage; x=rgb2gray(handles.img); imshow(x); handles.img=x; guidata(hObject,handles); % -function caijian_Callback(hObject, eve

22、ntdata, handles)% hObject handle to caijian (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global T axes(handles.axes2); T=getimage; x=imcrop(handles.img); %截圖 imshow(x); handles.img=x; guidata(hObject,handles);

23、 % - Executes on button press in zhifangtu.function zhifangtu_Callback(hObject, eventdata, handles)% hObject handle to zhifangtu (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2); T=geti

24、mage; h=histeq(handles.img); imshow(h); handles.img=h; guidata(hObject,handles); % - Executes when selected object is changed in uipanel4.function uipanel4_SelectionChangeFcn(hObject, eventdata, handles)% hObject handle to the selected object in uipanel4 % eventdata structure with the following fiel

25、ds (see UIBUTTONGROUP)%EventName: string 'SelectionChanged' (read only)%OldValue: handle of the previously selected object or empty if none was selected%NewValue: handle of the currently selected object% handles structure with handles and user data (see GUIDATA)global T str=get(hObject,'

26、string'); axes(handles.axes2); switch str case '椒鹽噪聲' T=getimage; prompt='數(shù)日椒鹽噪聲參數(shù)1:' defans='0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); f=imnoise(handles.img,'salt & pepper',p1); imshow(f); handles.img=f; guidata(hObject,handles); case

27、 '高斯噪聲' T=getimage; prompt='輸入高斯噪聲1:','輸入高斯噪聲2' defans='0','0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); p2=str2num(p2); f=imnoise(handles.img,'gaussian',p1,p2); imshow(f); handles.img=f; guidata(hObject,handles); case '乘性噪聲&#

28、39; T=getimage; prompt='輸入乘性噪聲1:' defans='0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); f=imnoise(handles.img,'speckle',p1); imshow(f); handles.img=f; guidata(hObject,handles); end % - Executes when selected object is changed in uipanel5.function uipanel5

29、_SelectionChangeFcn(hObject, eventdata, handles)% hObject handle to the selected object in uipanel5 % eventdata structure with the following fields (see UIBUTTONGROUP)%EventName: string 'SelectionChanged' (read only)%OldValue: handle of the previously selected object or empty if none was sel

30、ected%NewValue: handle of the currently selected object% handles structure with handles and user data (see GUIDATA)global T str=get(hObject,'string'); axes(handles.axes2);switch str case '中值濾波' T=getimage; k=medfilt2(handles.img); imshow(k); handles.img=k; guidata(hObject,handles); c

31、ase '線性濾波' T=getimage; h=1 1 1;1 1 1;1 1 1; H=h/9; i=double(handles.img); k=convn(i,h); imshow(k,); handles.img=k; guidata(hObject,handles); case '自適應(yīng)濾波' T=getimage; k=wiener2(handles.img,5,5); imshow(k); handles.img=k; guidata(hObject,handles); end % -function bianji_Callback(hObjec

32、t, eventdata, handles)% hObject handle to bianji (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% -function gongju_Callback(hObject, eventdata, handles)% hObject handle to gongju (see GCBO)% eventdata reserved -

33、 to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% -function ditong_Callback(hObject, eventdata, handles)% hObject handle to ditong (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and

34、user data (see GUIDATA)axes(handles.axes2); y1=handles.img; f=double(y1); % 數(shù)據(jù)類型轉(zhuǎn)換,matlab不支持圖像的無符號整型的計(jì)算 g=fft2(f); % 傅里葉變換 g=fftshift(g); % 轉(zhuǎn)換數(shù)據(jù)矩陣 M,N=size(g); nn=2; %二階巴特沃斯低通濾波器 d0=50; %截止頻率50 m=fix(M/2); n=fix(N/2); for i=1:M for j=1:N d=sqrt(i-m)2+(j-n)2); h=1/(1+0.414*(d/d0)(2*nn); % 計(jì)算低通濾波器傳遞函數(shù)

35、 result(i,j)=h*g(i,j); end end result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2); imshow(y3); % 顯示處理后的圖像 % -function gaotong_Callback(hObject, eventdata, handles)% hObject handle to gaotong (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure wi

36、th handles and user data (see GUIDATA)axes(handles.axes2); x=(handles.img); f=double(x); % 數(shù)據(jù)類型轉(zhuǎn)換 k=fft2(f); % 傅里葉變換 g=fftshift(k); % 轉(zhuǎn)換數(shù)據(jù)矩陣 M,N=size(g); nn=2; d0=25; %截止頻率25 m=fix(M/2); n=fix(N/2); for i=1:M for j=1:N d=sqrt(i-m)2+(j-n)2); % 計(jì)算高通濾波器傳遞函數(shù) if d<=d0 h=0; else h=1; end result(i,j)=h*

37、g(i,j); end end result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2); imshow(y3); % 顯示濾波處理后的圖像 % -function chexiao_Callback(hObject, eventdata, handles)% hObject handle to chexiao (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles an

38、d user data (see GUIDATA)axes(handles.axes2); %撤銷 global T imshow(T); handles.img=T; guidata(hObject,handles); % -function huanyuan_Callback(hObject, eventdata, handles)% hObject handle to huanyuan (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with h

39、andles and user data (see GUIDATA) global S %還原 axes(handles.axes2); y=imread(S); f=imshow(y); handles.img=y; guidata(hObject,handles); % - Executes when selected object is changed in uipanel6.function uipanel6_SelectionChangeFcn(hObject, eventdata, handles)% hObject handle to the selected object in

40、 uipanel6 % eventdata structure with the following fields (see UIBUTTONGROUP)%EventName: string 'SelectionChanged' (read only)%OldValue: handle of the previously selected object or empty if none was selected%NewValue: handle of the currently selected object% handles structure with handles and user data (see GUIDATA)str=get(hObject,'string'); axes(handles.axes2); global T switch str case '左右翻轉(zhuǎn)' T=handles.img; f=fliplr(handles.img);

溫馨提示

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

最新文檔

評論

0/150

提交評論