二、權重平均法簡介
1 權重平均法圖像融合算法的原理
對原圖像的像素值直接取相同的權值,然後進行權重平均得到融合圖像的像素值,舉例說比如要融合兩幅圖像A,B,那它們的融合後圖像的像素值就是A50%+B50%,就這麼簡單。
2 權重平均融合法融合過程
權重平均融合法是将源圖像像素的灰階值進行線性權重平均,生成新的融合圖像,是一種最簡單、直接的圖像融合方法,融合過程如下圖所示,一般形式如下:
三、部分源代碼
clear g_R=0; g_G=0; g_B=0; h_R=0; h_G=0; h_B=0; fenzi_R=0; fenzi_G=0; fenzi_B=0; fenmu_up_R=0; fenmu_up_G=0; fenmu_up_B=0; fenmu_low_R=0; fenmu_low_G=0; fenmu_low_B=0; tableR=[]; tableG=[]; tableB=[]; up=imread('high.jpg'); %讀圖像 low=imread('low.jpg'); figure(1) imshow(up); %讀RGB數值 [M,N,color]=size(up); title('權重-RGB表示的高分辨率圖像'); figure(2) imshow(low); title('權重-RGB表示的低分辨率圖像'); r=double(up(:,:,1)); g=double(up(:,:,2)); b=double(up(:,:,3)); r_low=double(low(:,:,1)); g_low=double(low(:,:,2)); b_low=double(low(:,:,3)); RGB(:,:,1)=0.5*r+0.5*r_low; RGB(:,:,2)=0.5*g+0.5*g_low; RGB(:,:,3)=0.5*b+0.5*b_low; R=RGB(:,:,1); G=RGB(:,:,2); B=RGB(:,:,3); RGB=uint8(round(RGB)); figure(3) imshow(RGB) title('權重-RGB轉化後的圖像'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 下面是計算平均梯度G % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for ii=1:M-1 for jj=1:N-1 g_R=g_R+sqrt((((r(ii+1,jj)-r(ii,jj))^2+(r(ii,jj+1)-r(ii,jj))^2))/2); g_G=g_G+sqrt((((g(ii+1,jj)-g(ii,jj))^2+(g(ii,jj+1)-g(ii,jj))^2))/2); g_B=g_B+sqrt((((b(ii+1,jj)-b(ii,jj))^2+(b(ii,jj+1)-b(ii,jj))^2))/2); end end fprintf('\n\n highR的清晰度為:%.4f\n highG的清晰度為:%.4f\n highG的清晰度為:%.4f',... g_R/(M-1)/(N-1),g_G/(M-1)/(N-1),g_B/(M-1)/(N-1)); g_R=0; g_G=0; g_B=0; for ii=1:M-1 for jj=1:N-1 g_R=g_R+sqrt((((r_low(ii+1,jj)-r_low(ii,jj))^2+(r_low(ii,jj+1)-r_low(ii,jj))^2))/2); g_G=g_G+sqrt((((g_low(ii+1,jj)-g_low(ii,jj))^2+(g_low(ii,jj+1)-g_low(ii,jj))^2))/2); g_B=g_B+sqrt((((b_low(ii+1,jj)-b_low(ii,jj))^2+(b_low(ii,jj+1)-b_low(ii,jj))^2))/2); end end fprintf('\n\n lowR的清晰度為:%.4f\n lowG的清晰度為:%.4f\n lowG的清晰度為:%.4f',... g_R/(M-1)/(N-1),g_G/(M-1)/(N-1),g_B/(M-1)/(N-1)); g_R=0; g_G=0; g_B=0; for ii=1:M-1 for jj=1:N-1 g_R=g_R+sqrt((((R(ii+1,jj)-R(ii,jj))^2+(R(ii,jj+1)-R(ii,jj))^2))/2); g_G=g_G+sqrt((((G(ii+1,jj)-G(ii,jj))^2+(G(ii,jj+1)-G(ii,jj))^2))/2); g_B=g_B+sqrt((((B(ii+1,jj)-B(ii,jj))^2+(B(ii,jj+1)-B(ii,jj))^2))/2); end
四、運作結果
五、matlab版本及參考文獻
1 matlab版本
2014a
2 參考文獻
[1] 蔡利梅.MATLAB圖像處理——理論、算法與執行個體分析[M].清華大學出版社,2020.
[2]楊丹,趙海濱,龍哲.MATLAB圖像處理執行個體詳解[M].清華大學出版社,2013.
[3]周品.MATLAB圖像處理與圖形使用者界面設計[M].清華大學出版社,2013.
[4]劉成龍.精通MATLAB圖像處理[M].清華大學出版社,2015.