Open chengyingsong opened 2 years ago
Eason @.***> 于2022年4月14日周四 11:50写道:
It seems Pivia Center dataset preprocessing program is not exists. Can you provide it ?
— Reply to this email directly, view it on GitHub https://github.com/qianngli/ERCSR/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANJ3LI7QIY2DG5POLZMTAFTVE6IXHANCNFSM5TMQXKNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
clc clear close all
%% define hyperparameters Band = 102; patchSize = 32; randomNumber = 108; upscale_factor = 8; data_type = 'PaviaCentre'; P = 0; global count count = 0;
imagePatch = patchSize*upscale_factor; scales = [1.0, 0.75];
%% bulid upscale folder savePath=['E:\PaviaCentre\8\']; if ~exist(savePath, 'dir') mkdir(savePath) end
%% srPath = 'E:/数据集/HyperSR/PaviaCentre/'; fileFolder=fullfile(srPath); dirOutput=dir(fullfile(fileFolder,'*.mat')); fileNames={dirOutput.name}'; length(fileNames)
for i = 1:length(fileNames) name = char(fileNames(i)); disp(['----:',data_type,'----upscale_factor:',num2str(upscale_factor),'----deal with:',num2str(i),'----name:',name]); data_path = [srPath, '/', name]; load(data_path) %% normalization radHeight = size(pavia, 1); radWidth = size(pavia, 2); t = pavia / (1.0*max(max(max(pavia)))); t = t(1:876,:,:);
clear pavia;
%% for j = 1:randomNumber for sc = 1:length(scales) newt = imresize(t, scales(sc));
x_random = randperm(size(newt,1) - imagePatch, randomNumber);
y_random = randperm(size(newt,2) - imagePatch, randomNumber);
hrImage = newt(x_random(j):x_random(j)+imagePatch-1, y_random(j):y_random(j)+imagePatch-1, :);
label = hrImage;
lr = data_augment(label, upscale_factor, savePath);
sizeLR = size(lr);
band_mean(j*sc,:) = mean(reshape(lr,[sizeLR(1), sizeLR(2)*sizeLR(3)]), 2);
if (rand(1)> P)
label = imrotate(hrImage,180);
lr = data_augment(label, upscale_factor, savePath);
end
if (rand(1)> P)
label = imrotate(hrImage,90);
lr = data_augment(label, upscale_factor, savePath);
end
if (rand(1)> P)
label = imrotate(hrImage,270);
lr = data_augment(label, upscale_factor, savePath);
end
if (rand(1)> P)
label = flipdim(hrImage,1);
lr = data_augment(label, upscale_factor, savePath);
end
if (rand(1)> P)
label = flipdim(hrImage,2);
lr = data_augment(label, upscale_factor, savePath);
end
clear x_random;
clear y_random;
clear newt;
end
end clear t; end
clc clear close all
upscale = 4; dataset = 'PaviaCentre';
%% bulid upscale folder % savePath=['\10.168.63.225\Home Share\liqiang\hyperSR\test\',dataset,'\',num2str(upscale)]; savePath=['E:/',dataset,'/',num2str(upscale),'/']; if ~exist(savePath, 'dir') mkdir(savePath) end
%% srPath = 'E:/数据集/HyperSR/PaviaCentre/'; fileFolder=fullfile(srPath); dirOutput=dir(fullfile(fileFolder,'*.mat')); fileNames={dirOutput.name}'; length(fileNames) aver_PSNR = 0; aver_SAM = 0; aver_SSIM = 0; count = 0;
for i = 1:length(fileNames) name = char(fileNames(i)); disp(['----:',dataset,'----upscale_factor:',num2str(upscale),'----deal with:',num2str(i),'----name:',name]); data_path = [srPath, '/', name]; load(data_path)
%% normalization radHeight = size(pavia, 1); radWidth = size(pavia, 2); t = pavia / (1.0*max(max(max(pavia))));
one = t(878:end,1:357,:); two = t(878:end,358:end,:);
HR = modcrop(one, upscale);
LR = imresize(HR,1/upscale,'bicubic'); %LR
SR = imresize(LR,upscale,'bicubic');
save([savePath,'/1.mat'], 'HR', 'LR')
n_PSNR = PSNR(SR, HR);
n_SAM = SAM(SR, HR);
n_SSIM = SSIM(SR, HR);
aver_PSNR = aver_PSNR + n_PSNR;
aver_SAM = aver_SAM + n_SAM;
aver_SSIM = aver_SSIM + n_SSIM;
disp(['upscale_factor:',num2str(upscale),' ',num2str(1),' PSNR:',num2str(n_PSNR),' SAM:',num2str(n_SAM),...
' SSIM:',num2str(n_SSIM),' Name:',name]);
HR = modcrop(two, upscale);
LR = imresize(HR,1/upscale,'bicubic'); %LR
SR = imresize(LR,upscale,'bicubic');
save([savePath,'/2.mat'], 'HR', 'LR')
n_PSNR = PSNR(SR, HR);
n_SAM = SAM(SR, HR);
n_SSIM = SSIM(SR, HR);
aver_PSNR = aver_PSNR + n_PSNR;
aver_SAM = aver_SAM + n_SAM;
aver_SSIM = aver_SSIM + n_SSIM;
disp(['upscale_factor:',num2str(upscale),' ',num2str(2),' PSNR:',num2str(n_PSNR),' SAM:',num2str(n_SAM),...
' SSIM:',num2str(n_SSIM),' Name:',name]);
end disp(['-----averPSNR:',num2str(aver_PSNR/2),'------averSAM:',num2str(aver_SAM/2),... '-----SSIM:',num2str(aver_SSIM/2)]);
function sam2 = SAM(imagery1,imagery2)
tmp = (sum(imagery1.imagery2, 3) + eps) ... ./ (sqrt(sum(imagery1.^2, 3)) + eps) ./ (sqrt(sum(imagery2.^2, 3)) + eps); sam = mean2(real(acos(tmp))); % this ignores the pixels that have zero norm (all values zero - no color) ind = ~isnan(sam); sam2 = mean(sam(ind))180/pi; end
function total_ssim = SSIM(SR, HR, K, window, L)
total_ssim = 0;
for i = 1 : size(SR, 3)
img1 = SR(:,:,i);
img2 = HR(:,:,i);
%========================================================================
%SSIM Index, Version 1.0
%Copyright(c) 2003 Zhou Wang
%All Rights Reserved.
%
%The author is with Howard Hughes Medical Institute, and Laboratory
%for Computational Vision at Center for Neural Science and Courant
%Institute of Mathematical Sciences, New York University.
%
%----------------------------------------------------------------------
%Permission to use, copy, or modify this software and its documentation
%for educational and research purposes only and without fee is hereby
%granted, provided that this copyright notice and the original authors'
%names appear on all copies and supporting documentation. This program
%shall not be used, rewritten, or adapted as the basis of a commercial
%software or hardware product without first obtaining permission of the
%authors. The authors make no representations about the suitability of
%this software for any purpose. It is provided "as is" without express
%or implied warranty.
%----------------------------------------------------------------------
%
%This is an implementation of the algorithm for calculating the
%Structural SIMilarity (SSIM) index between two images. Please refer
%to the following paper:
%
%Z. Wang, A. C. Bovik, H. R. Sheikh, and E. P. Simoncelli, "Image
%quality assessment: From error measurement to structural similarity"
%IEEE Transactios on Image Processing, vol. 13, no. 1, Jan. 2004.
%
%Kindly report any suggestions or corrections to @.***
%
%----------------------------------------------------------------------
%
%Input : (1) img1: the first image being compared
% (2) img2: the second image being compared
% (3) K: constants in the SSIM index formula (see the above
% reference). defualt value: K = [0.01 0.03]
% (4) window: local window for statistics (see the above
% reference). default widnow is Gaussian given by
% window = fspecial('gaussian', 11, 1.5);
% (5) L: dynamic range of the images. default: L = 255
%
%Output: (1) mssim: the mean SSIM index value between 2 images.
% If one of the images being compared is regarded as
% perfect quality, then mssim can be considered as the
% quality measure of the other image.
% If img1 = img2, then mssim = 1.
% (2) ssim_map: the SSIM index map of the test image. The map
% has a smaller size than the input images. The actual size:
% size(img1) - size(window) + 1.
%
%Default Usage:
% Given 2 test images img1 and img2, whose dynamic range is 0-255
%
% [mssim ssim_map] = ssim_index(img1, img2);
%
%Advanced Usage:
% User defined parameters. For example
%
% K = [0.05 0.05];
% window = ones(8);
% L = 100;
% [mssim ssim_map] = ssim_index(img1, img2, K, window, L);
%
%See the results:
%
% mssim %Gives the mssim value
% imshow(max(0, ssim_map).^4) %Shows the SSIM index map
%
%========================================================================
if (nargin < 2 || nargin > 5)
ssim_index = -Inf;
ssim_map = -Inf;
return;
end
if (size(img1) ~= size(img2)) ssim_index = -Inf; ssim_map = -Inf; return; end
[M N] = size(img1);
if (nargin == 2) if ((M < 11) || (N < 11)) ssim_index = -Inf; ssim_map = -Inf; return end window = fspecial('gaussian', 11, 1.5); % K(1) = 0.01; % default settings K(2) = 0.03; % L = 1; % end
if (nargin == 3) if ((M < 11) || (N < 11)) ssim_index = -Inf; ssim_map = -Inf; return end window = fspecial('gaussian', 11, 1.5); L = 255; if (length(K) == 2) if (K(1) < 0 || K(2) < 0) ssim_index = -Inf; ssim_map = -Inf; return; end else ssim_index = -Inf; ssim_map = -Inf; return; end end
if (nargin == 4) [H W] = size(window); if ((H*W) < 4 || (H > M) || (W > N)) ssim_index = -Inf; ssim_map = -Inf; return end L = 255; if (length(K) == 2) if (K(1) < 0 || K(2) < 0) ssim_index = -Inf; ssim_map = -Inf; return; end else ssim_index = -Inf; ssim_map = -Inf; return; end end
if (nargin == 5) [H W] = size(window); if ((H*W) < 4 || (H > M) || (W > N)) ssim_index = -Inf; ssim_map = -Inf; return end if (length(K) == 2) if (K(1) < 0 || K(2) < 0) ssim_index = -Inf; ssim_map = -Inf; return; end else ssim_index = -Inf; ssim_map = -Inf; return; end end
C1 = (K(1)L)^2; C2 = (K(2)L)^2; window = window/sum(sum(window)); img1 = double(img1); img2 = double(img2);
mu1 = filter2(window, img1, 'valid'); mu2 = filter2(window, img2, 'valid'); mu1_sq = mu1.mu1; mu2_sq = mu2.mu2; mu1_mu2 = mu1.mu2; sigma1_sq = filter2(window, img1.img1, 'valid') - mu1_sq; sigma2_sq = filter2(window, img2.img2, 'valid') - mu2_sq; sigma12 = filter2(window, img1.img2, 'valid') - mu1_mu2;
if (C1 > 0 & C2 > 0) ssim_map = ((2mu1_mu2 + C1).(2sigma12 + C2))./((mu1_sq + mu2_sq + C1).(sigma1_sq + sigma2_sq + C2)); else numerator1 = 2mu1_mu2 + C1; numerator2 = 2sigma12 + C2; denominator1 = mu1_sq + mu2_sq + C1; denominator2 = sigma1_sq + sigma2_sq + C2; ssim_map = ones(size(mu1)); index = (denominator1.denominator2 > 0); ssim_map(index) = (numerator1(index).numerator2(index))./(denominator1(index).*denominator2(index)); index = (denominator1 ~= 0) & (denominator2 == 0); ssim_map(index) = numerator1(index)./denominator1(index); end
mssim = mean2(ssim_map);
total_ssim = total_ssim + mssim;
end
total_ssim = total_ssim/size(SR, 3);
end
function single_psnr = PSNR(HR_image, SR_image)
HR_image = reshape(HR_image, size(HR_image,1)size(HR_image, 2), size(HR_image,3));
SR_image = reshape(SR_image, size(SR_image,1)size(SR_image, 2), size(SR_image,3));
L = 1;
width = size(HR_image,2);
height = size(HR_image,1);
if( width ~= size(SR_image,2) || height ~= size(SR_image,1) )
disp('Please check the input image have the same size');
return
end
HR_image = double(HR_image);
SR_image = double(SR_image);
MES = mean((HR_image(:) - SR_image(:)).^2);
single_psnr=10*log10(L^2/MES);
end
which is the script for training and testing? I assume line 1-88 is for training. Here is an error:
why do this script have the metrics computation? this script is for input data generation, right?
It seems Pivia Center dataset preprocessing program is not exists. Can you provide it ?