前言
其實數字圖像處理并不是我的研究方向遵绰,僅僅是因為在開題中簡單提到了基于圖像的設備安全監(jiān)控辽幌,就這樣被導師安排去學習圖像處理的相關知識。
Orz……好吧椿访,假期回家還不到兩周就這樣匆匆忙忙的提前趕回了學校乌企,和實驗室三維重建方向的的筒子們一起去上美國羅文大學唐瑛(Ying (Gina) Tang)教授開設的數字圖像處理入門課程。這周從周一到周三一共上了三節(jié)大課成玫,算是簡單了解了圖像處理的相關內容吧加酵,課程結束后估計也就是淺嘗輒止。
在唐教授的安排下閱讀了Oliva, Torrallaba, 和Schyns所發(fā)表的論文《Hybrid images》哭当,今天主要寫寫如何用matlab將論文所提到的圖像混合進行代碼的實現(xiàn)(估計這是圖像處理小白級的內容了吧猪腕,大神請無視哈~)
實現(xiàn)的整體思想比較簡單,就是對兩幅圖像分別進行高通和低通濾波钦勘,從而將兩幅圖像融合到一起陋葡,同時通過修改截止頻率還可以改善融合效果,這樣就可以實現(xiàn)在近處看是其中一副圖像的效果彻采,而在遠處看又是另一幅圖像的效果脖岛,如下所示:
- 待混合圖像1
- 待混合圖像2
- 混合完成圖像
matlab實現(xiàn)hybrid images
hybrid_images函數的編寫
對兩幅圖像分別進行高通和低通濾波,其中涉及到傅里葉變換和反變換颊亮,圖像混合函數所在文件hybrid_images.m
如下:
function re=hybrid_images(ImageFile1,ImageFile2,radius_input)
I1=ImageFile1;
I2=ImageFile2;
ImgFileOut='C:\Users\dell\Desktop\hybird_images/out.jpg';
radius = radius_input;
I1_ = fftshift(fft2(double(I1))); %進行傅里葉變換柴梆,并將零點移動到中心
I2_ = fftshift(fft2(double(I2)));
[m, n, z]=size(I1);
h = fspecial('gaussian', [m,n], radius);
h = h./max(max(h));
for colorI = 1:3
J_(:,:,colorI) = I1_(:,:,colorI).*(1-h) + I2_(:,:,colorI).*h;
end
J = uint8(real(ifft2(ifftshift(J_)))); %反變換
imwrite(J,ImgFileOut); %圖片保存到本地
re=J;
end
GUI設計
GUI關鍵代碼
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im1;
[filename,pathname]=uigetfile({'*.*';'*.bmp';'*.jpg';'*.tif';'*.jpg'},'選擇圖像');
if isequal(filename,0)||isequal(pathname,0)
errordlg('您還沒有選取圖片!终惑!','溫馨提示');%如果沒有輸入绍在,則創(chuàng)建錯誤對話框
return;
else
image=[pathname,filename];%合成路徑+文件名
im1=imread(image);%讀取圖像
set(handles.axes1,'HandleVisibility','ON');%打開坐標,方便操作
axes(handles.axes1);%%使用圖像,操作在坐標1
imshow(im1);%在坐標axes1顯示原圖像
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im2;
[filename,pathname]=uigetfile({'*.*';'*.bmp';'*.jpg';'*.tif';'*.jpg'},'選擇圖像');
if isequal(filename,0)||isequal(pathname,0)
errordlg('您還沒有選取圖片3ザ伞臼寄!','溫馨提示');%如果沒有輸入,則創(chuàng)建錯誤對話框
return;
else
image=[pathname,filename];%合成路徑+文件名
im2=imread(image);%讀取圖像
set(handles.axes2,'HandleVisibility','ON');%打開坐標溜宽,方便操作
axes(handles.axes2);%%使用圖像吉拳,操作在坐標1
imshow(im2);%在坐標axes1顯示原圖像
end
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
slide_value=get(hObject,'Value');%獲取滑塊當前值
global im1;
global im2;
radius=slide_value;
set(handles.edit1,'string',num2str(slide_value));
x=hybrid_images(im1,im2,radius);
set(handles.axes5,'HandleVisibility','ON');%打開坐標,方便操作
axes(handles.axes5)
imshow(x);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
運行程序
paper鏈接
http://cvcl.mit.edu/hybrid/OlivaTorralb_Hybrid_Siggraph06.pdf