一、簡介
1 拉普拉斯金字塔
在高斯金字塔的運算過程中,圖像經過卷積和下采樣操作會丢失部分高頻細節資訊。為描述這些高頻資訊,人們定義了拉普拉斯金字塔(Laplacian Pyramid, LP)。用高斯金字塔的每一層圖像減去其上一層圖像上采樣并高斯卷積之後的預測圖像,得到一系列的內插補點圖像即為 LP 分解圖像。
将Gl内插方法得到放大圖像Gl,使Gl的尺寸與Gl-1的尺寸相同,即放大算子Expand。
該式子實作兩個步驟:在偶數行和列插入0,然後使用下采樣中的高斯核進行濾波處理,得到和l-1層一樣大小的圖像。
N為拉普拉斯金字塔頂層的層号LPl是拉普拉斯金字塔分解的第L層圖像。由LP0,LP1、LP2…LPN構成的金字塔即為拉普拉斯金字塔。它的每一層L0圖像是高斯金字塔本層G0圖像與其高一層圖像G1經内插放大後圖像G1的差,此過程相當于帶通濾波,是以拉普拉斯金字塔又稱為帶通金字塔分解。
内插方法:opencv中有實作的函數pyrup。可以得到*G1。然後在兩個函數作差,相減就可以得到拉普拉斯金字塔。
求得每個圖像的拉普拉斯金字塔後需要對相應層次的圖像進行融合,具體的融合規則有,取大、取小,等等。
首先對原始圖像Gi進行向下取樣,然後向上采用,最後與原始圖像相減,得到拉普拉斯金字塔圖像。
下面這張圖也是比較常見的:
使用原始圖像 套入公式得到拉普拉斯金字塔第0層。
使用原始圖像向下采樣Od 代入公式 得到 拉普拉色金字塔第1層。
這張圖在看一些資料的時候也經常看到:
2 融合應用
圖像拉普拉斯金字塔分解的目的是将源圖像分别分解到不同的空間頻帶上,融合過程是在各空間頻率層上分别進行的,這樣就可以針對不同分解層的不同頻帶上的特征與細節,采用不同的融合算子以達到突出特定頻帶上特征與細節的目的。即有可能将來自不同圖像的特征與細節融合在一起。
(1)頂層處理
設LAl和LBl分别為源圖像A,B經過拉普拉斯金字塔分解後得到的第l層圖像,融合後的結果為LFl。當l=N時,LAN和LBN分别為源圖像A,B經過拉普拉斯金字塔分解後得到的頂層圖像。對于頂層圖像的融合,首先計算以其各個像素為中心的區域大小為M*N(M、N取奇數且M >= 3、N >= 3)的區域平均梯度:
其中,Ix與Iy分别為像素f(x,y)在x與y方向上的一階差分,定義如下:
是以對于頂層圖像中的每一個像素LAN(i, j)和LBN(i, j)都可以得到與之相對應的區域平均梯度GA(i, j)和GB(i, j)。由于平均梯度反映了圖像中的微小細節反差和紋理變化特征,同時也反映出圖像的清晰度。一般來說平均梯度越大,圖像層次也豐富,則圖像越清晰。是以頂層圖像的融合結果為:
(2)各層次處理
當0<l<N時,則對于經過拉普拉斯金字塔分解的第l層圖像,首先計算其區域能量:
則其他層次圖像的融合結果為:
在得到金字塔各個層次的融合圖像LF1、LF2、LFN後。通過前面的重構,便可得到最終的融合圖像。
第二種融合規則:
采用最高層系數取平均,其餘各層系數絕對值取大的融合政策進行融合。融合後圖像的系數(灰階值)越接近較清晰圖像的灰階值就說明融合效果好。
二、源代碼
function varargout = gui(varargin)
% GUI M-file for gui.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help gui
% Last Modified by GUIDE v2.5 27-May-2011 17:39:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui is made visible.
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to gui (see VARARGIN)
% Choose default command line output for gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --------------------------------------------------------------------
function Open_Callback(hObject, eventdata, handles)
[name,path]=uigetfile( ...
{'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
'*.*','All Files' },...
'請選擇要融合的低分辨率圖檔');
fullpath=strcat(path,name);
[name2,path2]=uigetfile( ...
{'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
'*.*','All Files' },...
'請選擇要融合的高分辨率圖檔(');
fullpath2=strcat(path2,name2);
save path.mat fullpath fullpath2
% 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)
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in add_fu_button.
function add_fu_button_Callback(hObject, eventdata, handles)
axes(handles.axes1);
cla;
axes(handles.axes2);
cla;
axes(handles.axes3);
cla;
a=get(handles.radiobutton5,'value');
b=get(handles.radiobutton6,'value');
c=get(handles.radiobutton7,'value');
if a==1
load path.mat
axes(handles.axes1);
low=imread(fullpath);
imshow(low);
axes(handles.axes2);
high=imread(fullpath2);
imshow(high);
addfusion;
load image.mat
axes(handles.axes3);
imshow(fusionresult);
%
end
if b==1
load path.mat
axes(handles.axes1);
low=imread(fullpath);
imshow(low);
axes(handles.axes2);
high=imread(fullpath2);
imshow(high);
sel_h_fusion;
load image.mat
axes(handles.axes3);
imshow(fusionresult);
%
end
if c==1
load path.mat
axes(handles.axes1);
low=imread(fullpath);
imshow(low);
axes(handles.axes2);
high=imread(fullpath2);
imshow(high);
sel_l_fusion;
load image.mat
axes(handles.axes3);
imshow(fusionresult);
%
end
%axes(handles.axes4);
%cla;
%load path.mat
%axes(handles.axes1);
%low=imread(fullpath);
%imshow(low);
%axes(handles.axes2);
%high=imread(fullpath2);
%imshow(high);
%addfusion;
%load image.mat
%axes(handles.axes3);
%imshow(fusionresult);
% hObject handle to add_fu_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pretreat_button.
function pretreat_button_Callback(hObject, eventdata, handles)
load path.mat
axes(handles.axes4);
low=imread(fullpath);
imshow(low);
axes(handles.axes5);
high=imread(fullpath2);
imshow(high);
pretreat;
load image.mat
NbColors=255;
map=gray(NbColors);
axes(handles.axes6);
image(pretreat_result_low);
colormap(map);
axes(handles.axes7);
image(pretreat_result_high);
colormap(map);
% hObject handle to pretreat_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)