├── BayesianFusion.m ├── ConvC.m ├── DE2_MS4_L1C_000000_20150530T183126_20150530T183129_DE2_5119_FC14.tif ├── DE2_PAN_L1C_000000_20150530T183126_20150530T183129_DE2_5119_FC14.tif ├── MatrixToKernel.m ├── README.md ├── downsamp_HS.m ├── fac.m ├── func_CloseForm ├── FastAuxMat.m ├── FastFusion.m ├── FasterAuxMat.m ├── FasterFusion.m ├── PMinus.m ├── PPlus.m ├── PPlus_s.m └── SylvesterFusion.m ├── idHSsub.m ├── im2mat.m ├── ima_interp_spline.m ├── main_BlindFuse.m ├── mat2im.m ├── sen_resp_est.m ├── upsamp_HS.m └── var_dim.m /BayesianFusion.m: -------------------------------------------------------------------------------- 1 | function [X_BayesFusion]= BayesianFusion(XH,XM,KerBlu,ratio,psfZ,E_hyper, prior,start_pos) 2 | %% This function is to implemnt the Bayesian Naive and Bayesian Sparse 3 | %% representation based method in the following paper: 4 | 5 | %[1] Qi Wei, Nicolas Dobigeon and Jean-Yves Tourneret, "Bayesian fusion of multi-band imagesn," 6 | %IEEE J. Sel. Topics Signal Process., vol. 9, no. 6, pp. 1-11, Sept. 2015. 7 | %[2] Qi Wei, Jos?Bioucas-Dias, Nicolas Dobigeon and Jean-Yves Tourneret, "Hyperspectral and 8 | %Multispectral Image Fusion based on a Sparse Representation," IEEE Trans. Geosci. and Remote 9 | %Sens., vol. 53, no. 7, pp. 3658-3668, July 2015. 10 | %[3] Qi Wei, Nicolas Dobigeon and Jean-Yves Tourneret, Fast Fusion of Multi-Band Images Based 11 | %on Solving a Sylvester Equationn", submitted. 12 | % which is also mentioned in 13 | %[4] Laetitia Loncan, Luis B. Almeida, Jose M. Bioucas-Dias, Xavier Briottet, 14 | % Jocelyn Chanussot, Nicolas Dobigeon, Sophie Fabre, Wenzhi Liao, 15 | % Giorgio A. Licciardi, Miguel Simoes, Jean-Yves Tourneret, 16 | % Miguel A. Veganzones, Gemine Vivone, Qi Wei and Naoto Yokoya, 17 | % "Introducing hyperspectral pansharpening," Geoscience and Remote Sensing 18 | % Magazine, 2015. 19 | 20 | %If you use this code, please cite the above papers. 21 | %% Input: 22 | %XH: Hyperspectral Image 23 | %XM: Multispectral Image (or Panchromatic Image) 24 | %overlap: The overlapping bands of HS and MS image 25 | %KerBlu: The blurring kernel 26 | %ratio: The downsampling factor 27 | %prior: 'Gaussian' or 'Sparse' 28 | %start_pos The starting point for the downsampling of HS 29 | %% Output: 30 | %X_BayesFusion: The fused high-resolution HS image 31 | %% ------------------------------------------------------------------------- 32 | % 33 | % Copyright (March, 2015): Qi WEI (qi.wei@n7.fr) 34 | % 35 | % BayesianFusion is distributed under the terms of 36 | % the GNU General Public License 2.0. 37 | % 38 | % Permission to use, copy, modify, and distribute this software for 39 | % any purpose without fee is hereby granted, provided that this entire 40 | % notice is included in all copies of any software which is or includes 41 | % a copy or modification of this software and in all copies of the 42 | % supporting documentation for such software. 43 | % This software is being provided "as is", without any express or 44 | % implied warranty. In particular, the authors do not make any 45 | % representation or warranty of any kind concerning the merchantability 46 | % of this software or its fitness for any particular purpose." 47 | % --------------------------------------------------------------------- 48 | %% Reshape the 3-D image to 2-D matrices 49 | [n_dr,n_dc,N_HS]=size(XH); 50 | [nr,nc,N_MS]=size(XM); 51 | 52 | %% Shift the XM image 53 | start_r=start_pos(1); 54 | start_c=start_pos(2); 55 | XM_shift=padarray(XM,[start_r-1 start_c-1],'circular','post'); 56 | XM_shift=XM_shift(start_r:end,start_c:end,:); 57 | 58 | VXM=reshape(XM_shift,[nr*nc N_MS])'; 59 | %% Noise Variances 60 | ChInv=eye(N_HS); 61 | CmInv=eye(N_MS); 62 | %%%%% 63 | P_dec=pinv(E_hyper); 64 | % E_hyper=eye(N_HS); 65 | % P_dec=eye(N_HS); 66 | L=size(E_hyper,2); 67 | sizeIM=[nr,nc,L]; 68 | %% Spectral mixture: spectral response R 69 | % psfZ=[ones(size(overlap))/length(overlap) zeros(1,N_HS-l_pan)]; 70 | %% Spatial Degradation: the blurring kernel B and HS Downsampling factor 71 | % define convolution operator 72 | % psfY.B=KernelToMatrix(KerBlu,nr,nc); 73 | psfY.B=KerBlu; 74 | psfY.ds_r=ratio; 75 | %% Interpolated the HS image with zeros 76 | XH_int=zeros(nr,nc,N_HS); 77 | XH_int(1:psfY.ds_r:end,1:psfY.ds_r:end,:)=XH; 78 | VXH_int=reshape(XH_int,[nr*nc N_HS])'; 79 | %% The spline interpolated image as the prior mean of target image 80 | % Xd_dec = ima_interp_spline(var_dim(XH,P_dec),psfY.ds_r); % give the prior in subspace 81 | Xd_dec = var_dim(ima_interp_spline(XH,psfY.ds_r),P_dec); 82 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 83 | % load('I_Hysure.mat'); 84 | % Xd_dec=I_HySure; 85 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 86 | N_AO=1; 87 | if strcmp(prior,'Sparse') 88 | learn_dic=0;train_support=0; 89 | if learn_dic==1 90 | [time_LD,D_s]=Dic_Para(XM_shift,E_hyper,learn_dic,train_support,0,inf); 91 | save Dic_Learn D_s time_LD -v7.3; 92 | else 93 | load('Dic_Learn.mat') 94 | end 95 | N_AO=20; 96 | end 97 | VX=SylvesterFusion(VXH_int,VXM,psfY,psfZ,ChInv,CmInv,E_hyper,Xd_dec,sizeIM,N_AO,prior); 98 | % [HSFusion.(FusMeth),Costime,diff_X,RMSE_sub,RMSE_org,invCov_U,VX_dec_set]=AlterOpti(XHd_int,XH,XM,psfY,... 99 | % psfZ_unk,sigma2y_real,sigma2z_real,P_dec,P_inc,MatScale,FusMeth,X_real,ADMM,Para_Prior); 100 | %% Transforming from the subspace 101 | VX_BayesFusion = E_hyper*VX; 102 | X_BayesFusion = reshape(VX_BayesFusion',[nr nc N_HS]); 103 | %% Shift back 104 | X_BayesFusion = padarray(X_BayesFusion,[start_r-1 start_c-1],'circular','pre'); 105 | X_BayesFusion = X_BayesFusion(1:nr,1:nc,:); -------------------------------------------------------------------------------- /ConvC.m: -------------------------------------------------------------------------------- 1 | function [A] = ConvC(X, FK, nl) 2 | %ConvC - defines a circular convolution (the same for all bands) accepting 3 | % a matrix and returnig a matrix. FK is the fft2 of a one-band filter 4 | 5 | [p, n] = size(X); 6 | nc = n/nl; 7 | A = reshape(real(ifft2(fft2(reshape(X', nl, nc, p)).*repmat(FK,[1, 1, p]))), nl*nc, p)'; 8 | -------------------------------------------------------------------------------- /DE2_MS4_L1C_000000_20150530T183126_20150530T183129_DE2_5119_FC14.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qw245/BlindFuse/167c8c8d8ba2b9418c80ec010055ead38ab985e5/DE2_MS4_L1C_000000_20150530T183126_20150530T183129_DE2_5119_FC14.tif -------------------------------------------------------------------------------- /DE2_PAN_L1C_000000_20150530T183126_20150530T183129_DE2_5119_FC14.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qw245/BlindFuse/167c8c8d8ba2b9418c80ec010055ead38ab985e5/DE2_PAN_L1C_000000_20150530T183126_20150530T183129_DE2_5119_FC14.tif -------------------------------------------------------------------------------- /MatrixToKernel.m: -------------------------------------------------------------------------------- 1 | function [KerBlu]=MatrixToKernel(B,len_hor,len_ver) 2 | % the size of the kernel 3 | lx = (len_hor-1)/2; % rows 4 | ly = (len_ver-1)/2; % columns 5 | [nr,nc]=size(B); 6 | mid_col=round((nc+1)/2); 7 | mid_row=round((nr+1)/2); 8 | % range of the pixels 9 | % B=circshift(B,[mid_row-1,mid_col-1]); %% equivalent with fftshift 10 | B=fftshift(B); % center the low-frequency component 11 | KerBlu=B(mid_row-lx:mid_row+lx,mid_col-ly:mid_col+ly); 12 | KerBlu=rot90(KerBlu,2); 13 | 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlindFuse 2 | 3 | The main file 'main_BlindFuse.m' is to implement the blind model-based fusion of multi-band and panchromatic images. 4 | If you use this code, please cite the following papers: 5 | 6 | Q. Wei, N. Dobigeon, J-Y. Tourneret, J. M. Bioucas-Dias and S. Godsill, "R-FUSE: Robust fast fusion of multi-Band images based on solving a Sylvester equation," IEEE Signal Process. Lett. , to appear, 2016. 7 | 8 | Q. Wei, J. M. Bioucas-Dias, N. Dobigeon, J-Y. Tourneret and S. Godsill, ''Blind model-based fusion of multi-band and panchromatic images,'' Proc. IEEE Int. Conf. Multisensor Fusion and Integr. for Intell. Syst. (MFI), Baden-Baden, Germany, Sept. 2016, to appear. 9 | 10 | Copyright (June, 2016): Qi WEI (qi.wei@eng.cam.ac.uk) 11 | 12 | All the codes are distributed under the terms of the GNU General Public License 2.0. Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software. This software is being provided "as is", without any express or implied warranty. In particular, the authors do not make any representation or warranty of any kind concerning the merchantability of this software or its fitness for any particular purpose." 13 | -------------------------------------------------------------------------------- /downsamp_HS.m: -------------------------------------------------------------------------------- 1 | function [Yhim] = downsamp_HS(Yhim_up, downsamp_factor, shift) 2 | %downsamp_HS - the equivalent of applying matrix M 3 | 4 | [nl, nc, L] = size(Yhim_up); 5 | Yhim = zeros(ceil(nl/downsamp_factor), ceil(nc/downsamp_factor), L); 6 | for i=1:L 7 | Yhim(:,:,i) = downsample(downsample(Yhim_up(:,:,i), downsamp_factor, shift)', downsamp_factor, shift)'; 8 | end -------------------------------------------------------------------------------- /fac.m: -------------------------------------------------------------------------------- 1 | function [P_tem,eig_val]=fac(Y) 2 | % [P_tem,Eig_val]=eig(cov(reshape(Y,[size(Y,1)*size(Y,2) size(Y,3)]))); 3 | % [eig_val,Index]=sort(diag(Eig_val),'descend'); 4 | % N=max(N,3); 5 | % P_vec=P_tem(:,Index(1:N)); % P_vec is an L*N matrix 6 | temp=reshape(Y,[size(Y,1)*size(Y,2) size(Y,3)]); 7 | [P_tem,eig_val,~]=svd(temp'*temp/size(temp,1)); 8 | % [P_tem,eig_val,~]=svd(temp'*temp); 9 | % eig_val=diag(eig_val); 10 | eig_val=diag(sqrt(eig_val)); 11 | % ratio_t=0;N=0; 12 | % while ratio_t < ratio 13 | % N=N+1; 14 | % ratio_t=sum(eig_val(1:N))/sum(eig_val); 15 | % end 16 | % P_vec=P_tem(:,1:N); % P_vec is an L*N matrix -------------------------------------------------------------------------------- /func_CloseForm/FastAuxMat.m: -------------------------------------------------------------------------------- 1 | function [Q,Cc,InvDI,InvLbd,C3Cons] = FastAuxMat(yyh,yym,FBs,FBCs,sizeIM,n_dr,n_dc,InvCov,ER1E,RER2RE,B2Sum) 2 | %FastAuxMat(yyh,yym,FBs,FBCs,E,R,dsf,nr,nc,n_dr,n_dc,p,InvCov,R1,R2) 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | %% Input: 5 | %yyh: Normalized HS data 6 | %yym: Normalized MS data 7 | %FBs: FFT of blurring kernel 8 | %FBCs: Conjugate of FBs 9 | %sizeIM: [nr nc L], where nr and nc are the row and column of reference 10 | % image, L is the dimension of subspace 11 | %n_dr,n_dc: The row and column of the HS image 12 | %InvCov: Covariance matrix of the Gaussian prior 13 | %ER1E: Auxillary matrix E*inv(Cov_HS)*E 14 | %RER2RE: Auxillary matrix (RE)*inv(Cov_HS)*(RE) 15 | %B2Sum: Auxillary matrix 1/d \sum_{i=1}^d \underline{D}_i (the first n_dr rows and first n_dc columns) 16 | %% Output: 17 | %Q: The invertible matrix decomposed from C1 18 | %Cc: The Cc in Eq. (27) 19 | %InvDI: In line 7, the inversion after C3 20 | %InvLbd: The inversion of Lambda matrix 21 | %C3Cons: The Cs in Eq. (27) 22 | 23 | %If you use this code, please cite the following paper: 24 | 25 | % [1] Qi Wei, Nicolas Dobigeon and Jean-Yves Tourneret, Fast Fusion of Multi-Band Images Based on Solving a Sylvester Equationn", submitted. 26 | %% ------------------------------------------------------------------------- 27 | % 28 | % Copyright (March, 2015): Qi WEI (qi.wei@n7.fr) 29 | % 30 | % FastAuxMat is distributed under the terms of 31 | % the GNU General Public License 2.0. 32 | % 33 | % Permission to use, copy, modify, and distribute this software for 34 | % any purpose without fee is hereby granted, provided that this entire 35 | % notice is included in all copies of any software which is or includes 36 | % a copy or modification of this software and in all copies of the 37 | % supporting documentation for such software. 38 | % This software is being provided "as is", without any express or 39 | % implied warranty. In particular, the authors do not make any 40 | % representation or warranty of any kind concerning the merchantability 41 | % of this software or its fitness for any particular purpose." 42 | % --------------------------------------------------------------------- 43 | [Q,Lambda]=eig(ER1E\(RER2RE+InvCov)); %% Eigendecomposition of C1 % C1=ER1E\(RER2RE+InvCov); 44 | Lambda=reshape(diag(Lambda),[1 1 sizeIM(3)]); 45 | Cc=(ER1E*Q)\InvCov; 46 | temp=(ER1E*Q)\eye(sizeIM(3)); % temp=Cc/InvCov; Temporay varaible 47 | InvDI=1./(B2Sum(1:n_dr,1:n_dc,:)+repmat(Lambda,[n_dr n_dc 1])); 48 | InvLbd=1./repmat(Lambda,[sizeIM(1) sizeIM(2) 1]); 49 | C3Cons=PPlus((fft2(reshape((temp*yyh)',sizeIM)).*FBCs+fft2(reshape((temp*yym)',sizeIM))).*FBs,n_dr,n_dc); 50 | % tic;C2Cons=PPlus(fft2(reshape((Cc/mu*(ConvC(yyh,FBCs(:,:,1),nr)+yym))',[nr nc p])).*FBs,n_dr,n_dc);toc %mask.*yyh -------------------------------------------------------------------------------- /func_CloseForm/FastFusion.m: -------------------------------------------------------------------------------- 1 | function [VXF] = FastFusion(MU,Q,Cc,InvDI,InvLbd,C3Cons,B2Sum,FBs,FBCNs,sizeMAT,sizeIM,n_dr,n_dc,dsf) 2 | %% This function is to implement the fast fusion based on solving Sylvester Equation 3 | %% Input: 4 | %MU: The prior mean in frequence domain 5 | %Q: The invertible matrix decomposed from C1 6 | %Cc: EThe Cc in Eq. (27) 7 | %InvDI: In line 7, the inversion after C3 8 | %InvLbd: The inversion of Lambda matrix 9 | %C3Cons: The Cs in Eq. (27) 10 | %B2Sum: Auxillary matrix 1/d \sum_{i=1}^d \underline{D}_i 11 | %FBs: FFT of blurring kernel (matrix D in Step 1 of Algo.1) 12 | %FBCNs: The inversion of FBs (matrix D^{-1} in step 12 of Algo.1) 13 | %sizeMAT: [L nr*nc] 14 | %sizeIM: [nr nc L] 15 | %n_dr,n_dc: The row and column of HS image 16 | %dsf: the convolution kernel 17 | %% Output: 18 | %VXF: The FFT of fused image (in matrix form) 19 | %If you use this code, please cite the following paper: 20 | 21 | % [1] Qi Wei, Nicolas Dobigeon and Jean-Yves Tourneret, Fast Fusion of Multi-Band Images Based on Solving a Sylvester Equationn", submitted. 22 | %% ------------------------------------------------------------------------- 23 | % 24 | % Copyright (March, 2015): Qi WEI (qi.wei@n7.fr) 25 | % 26 | % FastAuxMat is distributed under the terms of 27 | % the GNU General Public License 2.0. 28 | % 29 | % Permission to use, copy, modify, and distribute this software for 30 | % any purpose without fee is hereby granted, provided that this entire 31 | % notice is included in all copies of any software which is or includes 32 | % a copy or modification of this software and in all copies of the 33 | % supporting documentation for such software. 34 | % This software is being provided "as is", without any express or 35 | % implied warranty. In particular, the authors do not make any 36 | % representation or warranty of any kind concerning the merchantability 37 | % of this software or its fitness for any particular purpose." 38 | % --------------------------------------------------------------------- 39 | C3bar = C3Cons+PPlus(reshape((Cc*MU)',sizeIM).*FBs,n_dr,n_dc); % The implementation in frequency domain 40 | MXsub = (C3bar-repmat(C3bar(1:n_dr,1:n_dc,:).*InvDI,[dsf dsf 1]).*B2Sum).*InvLbd;% InvDI= (1/d \sum D_i + \lambda_c^l In)^{-1} 41 | % FBCNs represents the normalized conjugate of FBs: transform divide to multiply 42 | VXF = Q*reshape(PMinus(MXsub,n_dr,n_dc).*FBCNs,sizeMAT)';%% The invertible transforming %./FBs -------------------------------------------------------------------------------- /func_CloseForm/FasterAuxMat.m: -------------------------------------------------------------------------------- 1 | function [Q,Cc,InvDI,InvLbd,C3Cons] = FasterAuxMat(yyh,yym,FBs,FBCs,sizeIM,n_dr,n_dc,InvCov,ER1E,RER2RE,B2Sum) 2 | %FastAuxMat(yyh,yym,FBs,FBCs,E,R,dsf,nr,nc,n_dr,n_dc,p,InvCov,R1,R2) 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | %% Input: 5 | %yyh: Normalized HS data 6 | %yym: Normalized MS data 7 | %FBs: FFT of blurring kernel 8 | %FBCs: Conjugate of FBs 9 | %sizeIM: [nr nc L], where nr and nc are the row and column of reference 10 | % image, L is the dimension of subspace 11 | %n_dr,n_dc: The row and column of the HS image 12 | %InvCov: Covariance matrix of the Gaussian prior 13 | %ER1E: Auxillary matrix E*inv(Cov_HS)*E 14 | %RER2RE: Auxillary matrix (RE)*inv(Cov_HS)*(RE) 15 | %B2Sum: Auxillary matrix 1/d \sum_{i=1}^d \underline{D}_i (the first n_dr rows and first n_dc columns) 16 | %% Output: 17 | %Q: The invertible matrix decomposed from C1 18 | %Cc: The Cc in Eq. (28) 19 | %InvDI: In line 7, the inversion after C3 20 | %InvLbd: The inversion of Lambda matrix 21 | %C3Cons: The Cs in Eq. (28) 22 | 23 | %If you use this code, please cite the following paper: 24 | 25 | % [1] Qi Wei, Nicolas Dobigeon and Jean-Yves Tourneret, "R-FUSE: Robust Fast Fusion of Multi-Band Images Based on Solving a Sylvester Equation", submitted. 26 | %% ------------------------------------------------------------------------- 27 | % 28 | % Copyright (March, 2015): Qi WEI (qi.wei@n7.fr) 29 | % 30 | % FastAuxMat is distributed under the terms of 31 | % the GNU General Public License 2.0. 32 | % 33 | % Permission to use, copy, modify, and distribute this software for 34 | % any purpose without fee is hereby granted, provided that this entire 35 | % notice is included in all copies of any software which is or includes 36 | % a copy or modification of this software and in all copies of the 37 | % supporting documentation for such software. 38 | % This software is being provided "as is", without any express or 39 | % implied warranty. In particular, the authors do not make any 40 | % representation or warranty of any kind concerning the merchantability 41 | % of this software or its fitness for any particular purpose." 42 | % --------------------------------------------------------------------- 43 | [Q,Lambda]=eig(ER1E\(RER2RE+InvCov)); %% Eigendecomposition of C1 % C1=ER1E\(RER2RE+InvCov); 44 | Lambda=reshape(diag(Lambda),[1 1 sizeIM(3)]); 45 | Cc=(ER1E*Q)\InvCov; 46 | temp=(ER1E*Q)\eye(sizeIM(3)); % temp=Cc/InvCov; Temporay varaible 47 | InvDI=1./(B2Sum(1:n_dr,1:n_dc,:)+repmat(Lambda,[n_dr n_dc 1])); 48 | InvLbd=1./repmat(Lambda,[sizeIM(1) sizeIM(2) 1]); 49 | C3Cons=(fft2(reshape((temp*yyh)',sizeIM)).*FBCs+fft2(reshape((temp*yym)',sizeIM))).*InvLbd; 50 | % tic;C2Cons=PPlus(fft2(reshape((Cc/mu*(ConvC(yyh,FBCs(:,:,1),nr)+yym))',[nr nc p])).*FBs,n_dr,n_dc);toc %mask.*yyh -------------------------------------------------------------------------------- /func_CloseForm/FasterFusion.m: -------------------------------------------------------------------------------- 1 | function [VXF] = FasterFusion(MU,Q,Cc,InvDI,InvLbd,C5Cons,FBs,FBCs,sizeMAT,sizeIM,n_dr,n_dc,dsf) 2 | %% This function is to implement the fast fusion based on solving Sylvester Equation 3 | %% Input: 4 | %MU: The prior mean in frequence domain 5 | %Q: The invertible matrix decomposed from C1 6 | %Cc: EThe Cc in Eq. (27) 7 | %InvDI: In line 7, the inversion after C3 8 | %InvLbd: The inversion of Lambda matrix 9 | %C5Cons: The Cs in Eq. (27) 10 | %FBs: FFT of blurring kernel (matrix D in Step 1 of Algo.1) 11 | %FBCs: Conjugate of FBCs 12 | %sizeMAT: [L nr*nc] 13 | %sizeIM: [nr nc L] 14 | %n_dr,n_dc: The row and column of HS image 15 | %dsf: the convolution kernel 16 | %% Output: 17 | %VXF: The FFT of fused image (in matrix form) 18 | %If you use this code, please cite the following paper: 19 | 20 | % [1] Qi Wei, Nicolas Dobigeon and Jean-Yves Tourneret, Fast Fusion of Multi-Band Images Based on Solving a Sylvester Equationn", submitted. 21 | %% ------------------------------------------------------------------------- 22 | % 23 | % Copyright (March, 2015): Qi WEI (qi.wei@n7.fr) 24 | % 25 | % FastAuxMat is distributed under the terms of 26 | % the GNU General Public License 2.0. 27 | % 28 | % Permission to use, copy, modify, and distribute this software for 29 | % any purpose without fee is hereby granted, provided that this entire 30 | % notice is included in all copies of any software which is or includes 31 | % a copy or modification of this software and in all copies of the 32 | % supporting documentation for such software. 33 | % This software is being provided "as is", without any express or 34 | % implied warranty. In particular, the authors do not make any 35 | % representation or warranty of any kind concerning the merchantability 36 | % of this software or its fitness for any particular purpose." 37 | % --------------------------------------------------------------------- 38 | %% Faster Fusion using matrix inverse lemma 39 | % C5 = C5Cons+fft2(reshape((Cc*VXd_dec)',sizeIM)).*InvLbd; 40 | C5bar = C5Cons+reshape((Cc*MU)',sizeIM).*InvLbd; 41 | temp = PPlus_s(C5bar/(dsf^2).*FBs,n_dr,n_dc); % The operation: temp=1/d*C5bar*Dv 42 | invQUF = C5bar-repmat(temp.*InvDI,[dsf dsf 1]).*FBCs; % The operation: C5bar- temp*(\lambda_j d Im+\Sum_i=1^d Di^2)^{-1}Dv^H) 43 | VXF = Q*reshape(invQUF,sizeMAT)'; -------------------------------------------------------------------------------- /func_CloseForm/PMinus.m: -------------------------------------------------------------------------------- 1 | function [X]=PMinus(X,n_dr,n_dc) 2 | Y=X;Y(1:n_dr,1:n_dc,:)=0;%[nr,nc,nb]=size(X); 3 | Y=PPlus(Y,n_dr,n_dc); 4 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | % %% Sum according to the column 6 | % Temp=reshape(Y,[nr*n_dc nc/n_dc nb]);%(:,:,i) 7 | % Temp(:,1,:)=sum(Temp,2); 8 | % % Temp1=reshape(Temp(:,1,:),[nr n_dc nb]); 9 | % %% Sum according to the row 10 | % Temp1=reshape(permute(reshape(Temp(:,1,:),[nr n_dc nb]),[2 1 3]),[n_dr*n_dc nr/n_dr nb]); % Only process the low-frequency information 11 | % Y(1:n_dr,1:n_dc,:)=permute(reshape(sum(Temp1,2),[n_dc n_dr nb]),[2 1 3]); 12 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | X(1:n_dr,1:n_dc,:)=X(1:n_dr,1:n_dc,:)-Y(1:n_dr,1:n_dc,:); 14 | %% Abadoned implementation 15 | % [nr,nc,nb]=size(X); 16 | % for i=1:nb 17 | % %% X: matrix of size nr*nc 18 | % X1=X(1:n_dr,1:n_dc,i); 19 | % X(1:n_dr,1:n_dc,i)=0; 20 | % %% Minus according to the column 21 | % Temp=im2col(X(:,:,i),[nr n_dc],'distinct'); 22 | % Temp(:,1)=Temp(:,1)+sum(Temp(:,2:end),2); 23 | % Temp=col2im(Temp,[nr n_dc],[nr nc],'distinct'); 24 | % %% Minus according to the row 25 | % Temp=im2col(Temp,[n_dr nc],'distinct'); 26 | % Temp(:,1)=Temp(:,1)+sum(Temp(:,2:end),2); 27 | % Y_temp=col2im(Temp,[n_dr nc],[nr nc],'distinct'); 28 | % Y(1:n_dr,1:n_dc,i)=X1-Y_temp(1:n_dr,1:n_dc); 29 | % end 30 | %% Prove that all the operation is invertiable 31 | % % Test 32 | % tempX=fft2(reshape((Q\VX_real)',[nr nc nb_sub])).*FZ_s; 33 | % for i=1:nb_sub 34 | % tempX(:,:,i)=PPlus(tempX(:,:,i),nr,nc,n_dr,n_dc); 35 | % end 36 | % for i=1:nb_sub 37 | % X_est(:,:,i)=ifft2(PMinus(tempX(:,:,i),nr,nc,n_dr,n_dc)./FBm); 38 | % end 39 | % VX_est=real(Q*conv2mat(X_est,nb_sub)); -------------------------------------------------------------------------------- /func_CloseForm/PPlus.m: -------------------------------------------------------------------------------- 1 | function [X]=PPlus(X,n_dr,n_dc) 2 | %% Input X: matrix of size nr*nc 3 | %% Each block of X: matrix of size n_dr*n_dc 4 | %% This function adds all the blocks to the 1st block, i.e., multiply by P^{-1} 5 | % e.g. The input is 6 | % X=[X11 X12 X13 X14; 7 | % X21 X22 X23 X24; 8 | % X31 X32 X33 X34; 9 | % X41 X42 X43 X44] 10 | % The output is 11 | % X=[\sum_{i,j}X_{i,j} X12 X13 X14; 12 | % X21 X22 X23 X24; 13 | % X31 X32 X33 X34; 14 | % X41 X42 X43 X44] 15 | [nr,nc,nb]=size(X); 16 | %% Sum according to the column 17 | Temp=reshape(X,[nr*n_dc nc/n_dc nb]); 18 | Temp(:,1,:)=sum(Temp,2); 19 | % Temp1=reshape(Temp(:,1,:),[nr n_dc nb]); 20 | %% Sum according to the row 21 | Temp1=reshape(permute(reshape(Temp(:,1,:),[nr n_dc nb]),[2 1 3]),[n_dc*n_dr nr/n_dr nb]); % Only process the low-frequency information 22 | X(1:n_dr,1:n_dc,:)=permute(reshape(sum(Temp1,2),[n_dc n_dr nb]),[2 1 3]); %% Pay attention the shape of reshape: it is transposed 23 | end 24 | % tic 25 | % X(1:n_dr,1:n_dc,:)=sum(cell2mat(reshape(mat2cell(X,n_dr*ones(1,nr/n_dr),n_dc*ones(1,nc/n_dc),nb),[1 1 1 (nr/n_dr)*(nc/n_dc)])),4); 26 | % toc 27 | %% Three implementation methods 28 | %% Use im2col 29 | % for i=1:nb 30 | % Temp=im2col(X(:,:,i),[nr n_dc],'distinct'); 31 | % Temp=col2im(Temp,[nr n_dc],[nr nc],'distinct'); 32 | % Temp=im2col(Temp,[n_dr nc],'distinct'); 33 | % Y_temp=col2im(Temp,[n_dr nc],[nr nc],'distinct'); 34 | % end 35 | %% reshape 36 | % Temp=reshape(Temp,[nr nc]); 37 | % Temp=reshape(Temp',[n_dr*nc nr/n_dr]); 38 | % Y_temp=reshape(Temp,[nc nr])'; 39 | % Temp(:,1)=sum(Temp(:,1:end),2);%Temp(:,1)+ 40 | % Y(1:n_dr,1:n_dc,i)=Y_temp(1:n_dr,1:n_dc); 41 | 42 | % dr=nr/n_dr;dc=nc/n_dc; 43 | % for i=1:nb; 44 | % X(1:n_dr,1:n_dc,i)=blockfun(X(:,:,i),[dr dc],@sum); 45 | % end -------------------------------------------------------------------------------- /func_CloseForm/PPlus_s.m: -------------------------------------------------------------------------------- 1 | function [Y]=PPlus_s(X,n_dr,n_dc) 2 | %% The only difference with PPlus is that the output Y is of size n_dr*n_dc 3 | % e.g. The input is 4 | % X=[X11 X12 X13 X14; 5 | % X21 X22 X23 X24; 6 | % X31 X32 X33 X34; 7 | % X41 X42 X43 X44] 8 | % The output is 9 | % X=[\sum_{i,j}X_{i,j} X12 X13 X14; 10 | % X21 X22 X23 X24; 11 | % X31 X32 X33 X34; 12 | % X41 X42 X43 X44] 13 | [nr,nc,nb]=size(X); 14 | %% Sum according to the column 15 | Temp=reshape(X,[nr*n_dc nc/n_dc nb]);%(:,:,i) 16 | Temp(:,1,:)=sum(Temp,2); 17 | % Temp1=reshape(Temp(:,1,:),[nr n_dc nb]); 18 | %% Sum according to the row 19 | Temp1=reshape(permute(reshape(Temp(:,1,:),[nr n_dc nb]),[2 1 3]),[n_dc*n_dr nr/n_dr nb]); % Only process the low-frequency information 20 | Y=permute(reshape(sum(Temp1,2),[n_dc n_dr nb]),[2 1 3]); %% Pay attention the shape of reshape: it is transposed 21 | end 22 | -------------------------------------------------------------------------------- /func_CloseForm/SylvesterFusion.m: -------------------------------------------------------------------------------- 1 | function [VX]=SylvesterFusion(VXH_int,VXM,psfY,psfZ,ChInv,CmInv,E_hyper,Xd_dec,sizeIM,N_AO,prior) 2 | %% function SylvesterFusion is designed for demo purpose (1.IEEEGRSM paper 2.Airbus dataset) 3 | nr=sizeIM(1); 4 | nc=sizeIM(2); 5 | L =sizeIM(3); 6 | sizeMAT=[nr*nc L]; 7 | 8 | n_dr=nr/psfY.ds_r; 9 | n_dc=nc/psfY.ds_r; 10 | E_multi = psfZ*E_hyper; 11 | %Auxiliary Matrices 12 | FBm = fft2(psfY.B); 13 | FBmC = conj(FBm); 14 | FBs = repmat(FBm,[1 1 L]); 15 | FBCs = repmat(FBmC,[1 1 L]); 16 | FBCNs= repmat(FBmC./(abs(FBmC).^2),[1 1 L]); 17 | B2Sum=PPlus(abs(FBs).^2./(psfY.ds_r^2),n_dr,n_dc); 18 | 19 | % Normalized HS and MS data 20 | NmVXH_int= ChInv*VXH_int; 21 | NmVXM = CmInv*VXM; 22 | yyh = E_hyper'*NmVXH_int; 23 | yym = E_multi'*NmVXM; 24 | ER1E = E_hyper'*ChInv*E_hyper; 25 | RER2RE = E_multi'*CmInv*E_multi; 26 | 27 | if strcmp(prior,'Gaussian') 28 | % invCov = 3e-2*eye(L); %% Airbus 29 | % invCov = 1e-1*eye(L); %% Airbus VCA ( or no subspace): 1e-1 PCA:1e-3 30 | % [~,eig_val,~]=svd(VXH_int*VXH_int'/size(VXH_int,2)*psfY.ds_r*psfY.ds_r); 31 | % invCov = eig_val*eye(L)*1e-1; % it is equivalent to assign prior in orignial space 32 | invCov = 1e-3*eye(L); 33 | elseif strcmp(prior,'ML') 34 | invCov = 1e-17*eye(L); %% ML ratio 1e-13 35 | end 36 | % invCov = 1e-1*eye(L); %% Airbus 37 | % [Q,Cc,InvDI,InvLbd,C2Cons]=FastAuxMat(yyh,yym,FBs,FBCs,sizeIM,n_dr,n_dc,invCov,ER1E,RER2RE,B2Sum); 38 | [Q,Cc,InvDI,InvLbd,C2Cons]=FasterAuxMat(yyh,yym,FBs,FBCs,sizeIM,n_dr,n_dc,invCov,ER1E,RER2RE,B2Sum); 39 | if strcmp(prior,'Sparse') 40 | load('Dic_Learn.mat'); 41 | end 42 | for i=1:N_AO 43 | meanVIm = reshape(fft2(Xd_dec),sizeMAT)';%VXd_dec VXHd_int VX_real Maybe problem here 44 | % VX_FFT = FastFusion(meanVIm,Q,Cc,InvDI,InvLbd,C2Cons,B2Sum,FBs,FBCNs,sizeMAT,sizeIM,n_dr,n_dc,psfY.ds_r); 45 | VX_FFT = FasterFusion(meanVIm,Q,Cc,InvDI,InvLbd,C2Cons,FBs,FBCs,sizeMAT,sizeIM,n_dr,n_dc,psfY.ds_r); 46 | VX=reshape(real(ifft2(reshape(VX_FFT',sizeIM))),sizeMAT)'; 47 | % A-Step using OMP: Compute the L(DA) band by band 48 | if strcmp(prior,'Sparse') 49 | for k=1:L 50 | Xd_dec(:,:,k) = restoreFromSupp(reshape(VX(k,:)',[nr nc]), D_s); 51 | % Im = restoreFromSupp(reshape(VX(k,:)',[nr nc]), D,supp); 52 | end 53 | end 54 | end -------------------------------------------------------------------------------- /idHSsub.m: -------------------------------------------------------------------------------- 1 | %% HS subspace identification: Identifying the subspace where HS data live in 2 | function [P_inc, P_dec, D, nb_sub]=idHSsub(XHd,subMeth,scale,varargin) 3 | temp=reshape(XHd,[size(XHd,1)*size(XHd,2) size(XHd,3)])'; 4 | % temp=temp-repmat(mean(temp,2),[1,size(temp,2)]); % or equally temp=bsxfun(@minus, temp, mean(temp,2)); 5 | if nargin == 4 6 | nb_sub=varargin{1}; 7 | end 8 | if strcmp(subMeth,'Hysime') 9 | [w,Rn] = estNoise(temp); 10 | [nb_sub,P_vec,eig_val]=hysime(temp,w,Rn);%diag(sigma2y_real) 11 | eig_val=sqrt(eig_val); %% Note that the square root is required as the eig_val is the eigen value of X'*X; 12 | % nb_sub=5; 13 | P_vec=P_vec(:,1:nb_sub); 14 | elseif strcmp(subMeth,'PCA') 15 | [P_vec,eig_val]=fac(XHd); 16 | %[w,Rn] = estNoise(temp); [nb_sub,~,~]=hysime(temp,w,Rn);%diag(sigma2y_real) 17 | PCA_ratio=sum(eig_val(1:nb_sub))/sum(eig_val); %[P_vec,eig_val]=fac(X_real); 18 | P_vec=P_vec(:,1:nb_sub); % Each column of P_vec is a eigenvector 19 | elseif strcmp(subMeth,'VCA') 20 | % Find endmembers with VCA (pick the one with smallest volume from 20 21 | % runs of the algorithm) 22 | max_vol = 0; 23 | vol = zeros(1, 20); 24 | for idx_VCA = 1:20 25 | E_aux = VCA(temp,'Endmembers',nb_sub,'SNR',0,'verbose','off'); 26 | vol(idx_VCA) = abs(det(E_aux'*E_aux)); 27 | if vol(idx_VCA) > max_vol 28 | P_vec = E_aux; 29 | max_vol = vol(idx_VCA); 30 | end 31 | end 32 | end 33 | if scale==1 34 | % D=diag(sqrt(eig_val(1:nb_sub))); %% Note that there is no square root 35 | D=diag(eig_val(1:nb_sub)); 36 | % % here.( D=diag(sqrt(eig_val(1:nb_sub))) is wrong!!!) 37 | % D=diag(eig_val(1:nb_sub)); 38 | P_dec=D\P_vec'; 39 | P_inc=P_vec*D; 40 | elseif scale==0 41 | D=eye(nb_sub); 42 | P_dec=P_vec'; 43 | P_inc=P_vec; 44 | end -------------------------------------------------------------------------------- /im2mat.m: -------------------------------------------------------------------------------- 1 | function [A] = im2mat(X) 2 | %im2mat - converts a 3D image to a matrix 3 | 4 | [nl, nc, p] = size(X); 5 | A = reshape(X, nl*nc, p)'; -------------------------------------------------------------------------------- /ima_interp_spline.m: -------------------------------------------------------------------------------- 1 | function X_interp=ima_interp_spline(X,ds_r) 2 | % Example for the usage of interp2 3 | % Bicubic smoothing of an image 4 | X = padarray(X,[1 1],'symmetric'); 5 | nr = size(X,1);nc = size(X,2); 6 | % [x,y] = meshgrid(1:nr,1:nc); 7 | % [xi,yi] = meshgrid(1:1/ds_r:nr+1-1/ds_r,1:1/ds_r:nc+1-1/ds_r); 8 | X_interp=zeros(nr*ds_r,nc*ds_r,size(X,3)); 9 | for k = 1:size(X,3) 10 | % X_interp(:,:,k) = interp2(x,y,X(:,:,k),xi,yi,'spline'); 11 | X_interp(:,:,k) = interp2(1:nc,1:nr,X(:,:,k),[1:1/ds_r:nc+1-1/ds_r]',1:1/ds_r:nr+1-1/ds_r,'spline');%spline nearest cubic linear 12 | % Ref: http://bbs.06climate.com/forum.php?mod=viewthread&tid=11294 13 | end 14 | X_interp=X_interp(ds_r+1:end-ds_r,ds_r+1:end-ds_r,:); 15 | % figure; 16 | % subplot(1,2,1);imagesc(mean(X,3));% axis square; 17 | % subplot(1,2,2);imagesc(mean(X_interp,3));% axis square; -------------------------------------------------------------------------------- /main_BlindFuse.m: -------------------------------------------------------------------------------- 1 | clear;warning off; 2 | addpath([pwd,'\func_CloseForm']); 3 | %% This script is to implement the joint fusion and unmixing of multi-band images 4 | %If you use this code, please cite the following paper: 5 | 6 | % [1] Q. Wei, J. M. Bioucas-Dias, N. Dobigeon, J-Y. Tourneret and S. Godsill, 7 | % Blind Model-Based Fusion of Multi-band and Panchromatic Images, 8 | % Proc. IEEE Int. Conf. Multisensor Fusion and Integr. for Intell. Syst. (MFI), 9 | % Baden-Baden, Germany, Sept. 2016, to appear. 10 | 11 | %% Processing the MS+PAN data 12 | normColor = @(R)max(min((R-mean(R(:)))/std(R(:)),5),-5)/4+0.5; 13 | %% Deimos-2 data loading 14 | PAN=double(imread('DE2_PAN_L1C_000000_20150530T183126_20150530T183129_DE2_5119_FC14.tif'));const=max(PAN(:)); 15 | PAN=PAN/const;PAN=rot90(PAN,3);%PAN=permute(PAN,[2 1]); 16 | MS=double(imread('DE2_MS4_L1C_000000_20150530T183126_20150530T183129_DE2_5119_FC14.tif'));MS=MS/const;MS=rot90(MS,3);%MS=permute(MS,[2 1 3]); 17 | MSband_show=[2 3 4]; 18 | nr_start=300;nr_wid=500; 19 | nc_start=300;nc_wid=500; 20 | 21 | ratio=4; 22 | MS=MS(nr_start:nr_start+nr_wid-1,nc_start:nc_start+nc_wid-1,:); 23 | PAN=PAN((nr_start-1)*ratio+1:(nr_start-1+nr_wid)*ratio,(nc_start-1)*ratio+1:(nc_start-1+nc_wid)*ratio,:); 24 | 25 | figure(1);imshow(normColor(MS(:,:,MSband_show))); 26 | title('MS','FontSize',15); 27 | figure(2);imshow(normColor(PAN)); 28 | title('PAN','FontSize',15); 29 | drawnow; 30 | %% Plot the observed MS and PAN images 31 | zoom_1=[{1400:1500-1},{830:960-1}]; % Contest 1 32 | zoom_2=[{1280:1380-1},{440:570-1}]; % Contest 2 33 | zoom_3=[{20:120-1},{200:330-1}]; % Contest 3 34 | zoom_1=[{690:790-1},{500:600-1}]; %show blue block 35 | zoom_2=[{1340:1440-1},{920:1120-1}]; %show containers 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 | %% Estimate the blurring kernel and spectral response 38 | fprintf('***Start estimating the degradation operators...***\n'); 39 | lambda_R = 1e1; 40 | lambda_B = 1e1; 41 | p=4; %p=20; for Qunming' data 42 | intersection = cell(1,1); 43 | overlap=1:p; % for Qunming' data % overlap=1:50; % overlap=1:48; 44 | intersection{1} = overlap; 45 | contiguous=intersection; 46 | % Blur's support: [hsize_h hsize_w] 47 | hsize_h = 11; 48 | hsize_w = 11; 49 | % hsize_h = 1; % for Qunming' data 50 | % hsize_w = 1; 51 | shift = 0; % 'phase' parameter in MATLAB's 'upsample' function 52 | blur_center = 0; % to center the blur kernel according to the simluated data 53 | [~, R_est, B_est] = sen_resp_est(MS, PAN, ratio, intersection, contiguous,... 54 | p, lambda_R, lambda_B, hsize_h, hsize_w, shift, blur_center); 55 | fprintf('***Finish estimating the degradation operators!***\n'); 56 | 57 | BluKer=MatrixToKernel(B_est,hsize_h,hsize_w); 58 | 59 | figure(5);imagesc(BluKer);axis image;axis off; 60 | set(gca,'FontSize',15); 61 | colorbar;title('Estimated Spatial Blurring'); 62 | 63 | figure(6);plot(R_est','o-','LineWidth',2); 64 | text([1 2-0.05 3-0.05 4-0.2],R_est+0.04,cellstr(num2str(round(R_est,5)')),'FontSize',15); 65 | xlabel('MS bands','FontSize',15); 66 | set(gca,'xtick',[1 2 3 4],'FontSize',15); 67 | set(gca,'XTickLabel',{'NIR-1';'Red-2';'Green-3';'Blue-4'},'FontSize',15) 68 | % ax = gca;ax.XTickLabel = {'NIR','Red','Green','Blue'}; 69 | title('Estimated Spectral Blurring'); 70 | drawnow; 71 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 72 | fprintf('***Start fusing two images...***\n'); 73 | start_pos(1)=1; start_pos(2)=1; % The starting point of downsampling 74 | %% Subspace identification 75 | scale=1;[E_hyper, ~, ~, ~]=idHSsub(MS,'PCA',scale,p); 76 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 77 | % ML estimator 78 | tic 79 | [I_ML] = BayesianFusion(MS,PAN,B_est,ratio,R_est,E_hyper,'ML',start_pos); 80 | ML_time=toc; 81 | tic 82 | [I_BayesNaive]= BayesianFusion(MS,PAN,B_est,ratio,R_est,E_hyper,'Gaussian',start_pos); 83 | Gaussian_time=toc; 84 | 85 | % Compare with the results of ADMM 86 | % tic 87 | % [I_TV,Cost_set] = FuseTV(MS,PAN,B_est,ratio,R_est,E_hyper); 88 | % TV_time=toc; 89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 90 | fprintf('***Finish fusing two images!***\n'); 91 | fprintf('***We use %4.2f seconds to restore a %4.0f*%4.0f*%1.0f image using ML estimator!*** \n',... 92 | ML_time,size(PAN,1),size(PAN,2),size(MS,3)); 93 | fprintf('***We use %4.2f seconds to restore a %4.0f*%4.0f*%1.0f image using Gaussian prior!*** \n',... 94 | Gaussian_time,size(PAN,1),size(PAN,2),size(MS,3)); 95 | % fprintf('***We use %4.2f seconds to restore a %4.0f*%4.0f*%1.0f image using TV prior!*** \n',... 96 | % TV_time,size(PAN,1),size(PAN,2),size(MS,3)); 97 | %% Plot the fused MS images 98 | figure(3);imshow(normColor(I_ML(:,:,MSband_show))); 99 | set(gca,'FontSize',15);title('Fusion ML'); 100 | % print(figure(3),'-dpng','E:\qwei2\Bayesian_fusion\figures\I_ML.png') 101 | % print(figure(3),'-depsc','E:\qwei2\Bayesian_fusion\figures\I_ML.eps') 102 | figure(4);imshow(normColor(I_BayesNaive(:,:,MSband_show)));%title('Fusion'); 103 | set(gca,'FontSize',15);title('Fusion Bayes'); 104 | drawnow; 105 | 106 | figure(32); 107 | % zoomed 1 part 108 | subplot(2,2,1);imshow(normColor(MS(round(zoom_1{1}/4),round(zoom_1{2}/4),MSband_show)));title('MS','FontSize',15); 109 | subplot(2,2,2);imshow(normColor(PAN(zoom_1{1},zoom_1{2},:))); title('PAN','FontSize',15); 110 | subplot(2,2,3);imshow(normColor(I_ML(zoom_1{1},zoom_1{2},MSband_show)));title('ML','FontSize',15); 111 | subplot(2,2,4);imshow(normColor(I_BayesNaive(zoom_1{1},zoom_1{2},MSband_show)));title('Bayes','FontSize',15); 112 | % subplot(3,2,5);imshow(normColor(I_TV(zoom_1{1},zoom_1{2},MSband_show))); 113 | 114 | figure(33); 115 | % zoomed 2 part 116 | subplot(2,2,1);imshow(normColor(MS(round(zoom_2{1}/4),round(zoom_2{2}/4),MSband_show)));title('MS','FontSize',15); 117 | subplot(2,2,2);imshow(normColor(PAN(zoom_2{1},zoom_2{2},:)));title('PAN','FontSize',15); 118 | subplot(2,2,3);imshow(normColor(I_ML(zoom_2{1},zoom_2{2},MSband_show)));title('ML','FontSize',15); 119 | subplot(2,2,4);imshow(normColor(I_BayesNaive(zoom_2{1},zoom_2{2},MSband_show)));title('Bayes','FontSize',15); 120 | % subplot(3,2,5);imshow(normColor(I_TV(zoom_2{1},zoom_2{2},MSband_show))); 121 | 122 | figure(34); 123 | % details for zoomed 1 part 124 | subplot(4,4,2);imshow(normColor(MS(round(zoom_1{1}/4),round(zoom_1{2}/4),MSband_show)));title('MS'); 125 | subplot(4,4,1);imshow(normColor(PAN(zoom_1{1},zoom_1{2},:)));title('PAN'); 126 | subplot(4,4,3);imshow(normColor(I_ML(zoom_1{1},zoom_1{2},MSband_show)));title('ML'); 127 | subplot(4,4,4);imshow(normColor(I_BayesNaive(zoom_1{1},zoom_1{2},MSband_show)));title('Bayes'); 128 | subplot(4,4,5); imshow(MS(round(zoom_1{1}/4),round(zoom_1{2}/4),1),[]);colorbar;caxis([0 0.5]);title('NIR');ylabel('MS'); 129 | subplot(4,4,6);imshow(MS(round(zoom_1{1}/4),round(zoom_1{2}/4),2),[]);colorbar;caxis([0 0.5]);title('Red'); 130 | subplot(4,4,7);imshow(MS(round(zoom_1{1}/4),round(zoom_1{2}/4),3),[]);colorbar;caxis([0 0.5]);title('Green'); 131 | subplot(4,4,8);imshow(MS(round(zoom_1{1}/4),round(zoom_1{2}/4),4),[]);colorbar;caxis([0 0.5]);title('Blue'); 132 | 133 | subplot(4,4,9);imshow(I_ML(zoom_1{1},zoom_1{2},1),[]);colorbar;caxis([0 0.5]);ylabel('ML'); 134 | subplot(4,4,10);imshow(I_ML(zoom_1{1},zoom_1{2},2),[]);colorbar;caxis([0 0.5]) 135 | subplot(4,4,11);imshow(I_ML(zoom_1{1},zoom_1{2},3),[]);colorbar;caxis([0 0.5]) 136 | subplot(4,4,12);imshow(I_ML(zoom_1{1},zoom_1{2},4),[]);colorbar;caxis([0 0.5]) 137 | 138 | subplot(4,4,13);imshow(I_BayesNaive(zoom_1{1},zoom_1{2},1),[]);colorbar;caxis([0 0.5]);ylabel('Bayes'); 139 | subplot(4,4,14);imshow(I_BayesNaive(zoom_1{1},zoom_1{2},2),[]);colorbar;caxis([0 0.5]); 140 | subplot(4,4,15);imshow(I_BayesNaive(zoom_1{1},zoom_1{2},3),[]);colorbar;caxis([0 0.5]); 141 | subplot(4,4,16);imshow(I_BayesNaive(zoom_1{1},zoom_1{2},4),[]);colorbar;caxis([0 0.5]); 142 | 143 | figure(35); 144 | % details for zoomed 2 part 145 | subplot(4,4,1);imshow(normColor(MS(round(zoom_2{1}/4),round(zoom_2{2}/4),MSband_show)));title('MS'); 146 | subplot(4,4,2);imshow(normColor(PAN(zoom_2{1},zoom_2{2},:)));title('PAN'); 147 | subplot(4,4,3);imshow(normColor(I_ML(zoom_2{1},zoom_2{2},MSband_show)));title('ML'); 148 | subplot(4,4,4);imshow(normColor(I_BayesNaive(zoom_2{1},zoom_2{2},MSband_show)));title('Bayes'); 149 | 150 | subplot(4,4,5); imshow(MS(round(zoom_2{1}/4),round(zoom_2{2}/4),1),[]);colorbar;caxis([0 0.5]);title('NIR');ylabel('MS'); 151 | subplot(4,4,6);imshow(MS(round(zoom_2{1}/4),round(zoom_2{2}/4),2),[]);colorbar;caxis([0 0.5]);title('Red'); 152 | subplot(4,4,7);imshow(MS(round(zoom_2{1}/4),round(zoom_2{2}/4),3),[]);colorbar;caxis([0 0.5]);title('Green'); 153 | subplot(4,4,8);imshow(MS(round(zoom_2{1}/4),round(zoom_2{2}/4),4),[]);colorbar;caxis([0 0.5]);title('Blue'); 154 | 155 | subplot(4,4,9);imshow(I_ML(zoom_2{1},zoom_2{2},1),[]);colorbar;caxis([0 0.5]);ylabel('ML'); 156 | subplot(4,4,10);imshow(I_ML(zoom_2{1},zoom_2{2},2),[]);colorbar;caxis([0 0.5]) 157 | subplot(4,4,11);imshow(I_ML(zoom_2{1},zoom_2{2},3),[]);colorbar;caxis([0 0.5]) 158 | subplot(4,4,12);imshow(I_ML(zoom_2{1},zoom_2{2},4),[]);colorbar;caxis([0 0.5]) 159 | 160 | subplot(4,4,13);imshow(I_BayesNaive(zoom_2{1},zoom_2{2},1),[]);colorbar;caxis([0 0.5]);ylabel('Bayes'); 161 | subplot(4,4,14);imshow(I_BayesNaive(zoom_2{1},zoom_2{2},2),[]);colorbar;caxis([0 0.5]); 162 | subplot(4,4,15);imshow(I_BayesNaive(zoom_2{1},zoom_2{2},3),[]);colorbar;caxis([0 0.5]); 163 | subplot(4,4,16);imshow(I_BayesNaive(zoom_2{1},zoom_2{2},4),[]);colorbar;caxis([0 0.5]); 164 | 165 | % figure(100);%title('Cost function') 166 | % semilogy(Cost_set,'b-','LineWidth',2); 167 | % xlim([1 length(Cost_set)]); 168 | % set(gca,'FontSize',13); 169 | % xlabel('Iteration number','FontSize',18); 170 | % ylabel('Cost function','FontSize',18); 171 | % print(figure(100),'-depsc','E:\qwei2\Bayesian_fusion\figures\Cost.eps') 172 | -------------------------------------------------------------------------------- /mat2im.m: -------------------------------------------------------------------------------- 1 | function [A] = mat2im(X, nl) 2 | %mat2im - converts a matrix to a 3D image 3 | 4 | [p, n] = size(X); 5 | nc = n/nl; 6 | A = reshape(X', nl, nc, p); -------------------------------------------------------------------------------- /sen_resp_est.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qw245/BlindFuse/167c8c8d8ba2b9418c80ec010055ead38ab985e5/sen_resp_est.m -------------------------------------------------------------------------------- /upsamp_HS.m: -------------------------------------------------------------------------------- 1 | function [Yhim_up] = upsamp_HS(Yhim, downsamp_factor, nl, nc, shift) 2 | %upsamp_HS - convert image Ymim to an image matrix with the same size as 3 | % Ymim. The result is a matrix filled with zeros. 4 | 5 | [nlh, nch, L] = size(Yhim); 6 | aux = zeros(nlh*downsamp_factor, nch*downsamp_factor, L); 7 | for i=1:L 8 | aux(:,:,i) = upsample(upsample(Yhim(:,:,i), downsamp_factor, shift)', downsamp_factor, shift)'; 9 | end 10 | Yhim_up = aux(1:nl, 1:nc, :); 11 | -------------------------------------------------------------------------------- /var_dim.m: -------------------------------------------------------------------------------- 1 | function [out] = var_dim(X,P) 2 | out=reshape(reshape(X,[size(X,1)*size(X,2) size(X,3)])*P',[size(X,1) size(X,2) size(P,1)]); 3 | --------------------------------------------------------------------------------