Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for additional metric (q2n: Q4/Q8) #25

Open
KSJhon opened this issue Aug 12, 2021 · 4 comments
Open

Request for additional metric (q2n: Q4/Q8) #25

KSJhon opened this issue Aug 12, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@KSJhon
Copy link

KSJhon commented Aug 12, 2021

Dears!
Except for those metrics given by author, there is another important q2n metric (also called Q4/Q8).
Please add this metric when updating sewar package.
If anyone know the answer, i want to share it with me, and thank him/her in advance.

@andrewekhalel
Copy link
Owner

Hi @KSJhon,

Can you share any source on the implementation for this metric?

@KSJhon
Copy link
Author

KSJhon commented Mar 21, 2022

You can find the related code in Pansharpening toolbox 1.3 (https://rscl-grss.org/coderecord.php?id=541).
This code is generally approved in pansharpening community. Q.m calculates the QAVE index.

@magamig
Copy link
Contributor

magamig commented Apr 25, 2022

References for Q2ⁿ:

MATLAB code extracted from "Yokoya, N., Grohnfeldt, C., & Chanussot, J. (2017). Hyperspectral and multispectral data fusion: A comparative review of the recent literature. IEEE Geoscience and Remote Sensing Magazine, 5(2), 29-56." [paper] [code]

function [Q2n_index, Q2n_index_map] = q2n(I_GT, I_F, Q_blocks_size, Q_shift)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Inputs:
%           I_GT:               Ground-Truth image;
%           I_F:                Fused Image;
%           Q_blocks_size:      Block size of the Q-index locally applied;
%           Q_shift:            Block shift of the Q-index locally applied.
%
% Outputs:
%           Q2n_index:          Q2n index;
%           Q2n_index_map:      Map of Q2n values.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[N1,N2,N3]=size(I_GT);
size2=Q_blocks_size;

stepx=ceil(N1/Q_shift);
stepy=ceil(N2/Q_shift);

if stepy<=0
    stepy=1;
    stepx=1;
end;

est1=(stepx-1)*Q_shift+Q_blocks_size-N1;
est2=(stepy-1)*Q_shift+Q_blocks_size-N2;

if sum([(est1~=0),(est2~=0)])>0
  refref=[];
  fusfus=[];
  
  for i=1:N3
      a1=squeeze(I_GT(:,:,1));
    
      ia1=zeros(N1+est1,N2+est2);
      ia1(1:N1,1:N2)=a1;
      ia1(:,N2+1:N2+est2)=ia1(:,N2:-1:N2-est2+1);
      ia1(N1+1:N1+est1,:)=ia1(N1:-1:N1-est1+1,:);
      refref=cat(3,refref,ia1);
      
      if i<N3
          I_GT=I_GT(:,:,2:end);
      end
  end

  I_GT=refref;
  clear refref
  
  for i=1:N3
      a2=squeeze(I_F(:,:,1));
      
      ia2=zeros(N1+est1,N2+est2);
      ia2(1:N1,1:N2)=a2;
      ia2(:,N2+1:N2+est2)=ia2(:,N2:-1:N2-est2+1);
      ia2(N1+1:N1+est1,:)=ia2(N1:-1:N1-est1+1,:);
      fusfus=cat(3,fusfus,ia2);
      
      if i<N3
          I_F=I_F(:,:,2:end);
      end
  end
  
  I_F=fusfus;
  clear fusfus a1 a2 ia1 ia2

end

I_F=uint16(I_F);
I_GT=uint16(I_GT);

[N1,N2,N3]=size(I_GT);

if ((ceil(log2(N3)))-log2(N3))~=0
    Ndif=(2^(ceil(log2(N3))))-N3;
    dif=zeros(N1,N2,Ndif);
    dif=uint16(dif);
    I_GT=cat(3,I_GT,dif);
    I_F=cat(3,I_F,dif);
end
[~,~,N3]=size(I_GT);

valori=zeros(stepx,stepy,N3);

for j=1:stepx
    for i=1:stepy
        o=onions_quality(I_GT(((j-1)*Q_shift)+1:((j-1)*Q_shift)+Q_blocks_size,((i-1)*Q_shift)+1:((i-1)*Q_shift)+size2,:),I_F(((j-1)*Q_shift)+1:((j-1)*Q_shift)+Q_blocks_size,((i-1)*Q_shift)+1:((i-1)*Q_shift)+size2,:),Q_blocks_size);
        valori(j,i,:)=o;    
    end
end

Q2n_index_map=sqrt(sum((valori.^2),3));

Q2n_index=mean2(Q2n_index_map);

end

@JUSTM0VE0N
Copy link

Is there a python version of Q8?

@andrewekhalel andrewekhalel added the enhancement New feature or request label Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants