leonmakise commited on
Commit
18ac00c
1 Parent(s): 90a4a3e

Upload 4 files

Browse files
HyperSIGMA_super-resolution/crop_image.m ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [out] = crop_image(img, patch_size, stride, factor, file_name)
2
+
3
+ % Normalization for CAVE dataset
4
+ %img = double(img)./65535;
5
+ % Normalization for Pavia Center dataset
6
+ %img = double(img)./8000;
7
+ % Normalization for Chikusei dataset
8
+ img = double(img);
9
+
10
+ [H, W, C] = size(img);
11
+ p = patch_size;
12
+ pat_col_num = 1:stride:(H - p + 1);
13
+ pat_row_num = 1:stride:(W - p + 1);
14
+ total_num = length(pat_col_num) * length(pat_row_num);
15
+ index = 1;
16
+
17
+ % crop a single patch from whole image
18
+ for i=1:length(pat_col_num)
19
+ for j = 1:length(pat_row_num)
20
+ up = pat_col_num(i);
21
+ down = up + p - 1;
22
+ left = pat_row_num(j);
23
+ right = left + p - 1;
24
+ gt = img(up:down, left:right, :);
25
+ ms = single(imresize(gt, factor));
26
+ ms_bicubic = single(imresize(ms, 1/factor));
27
+ gt = single(gt);
28
+ file_path = strcat('/Users/miaoyuchun/Desktop/superx2/dataset/Houston_x2/trains_solely/block_', file_name, '_', num2str(index), '.mat');
29
+ % file_path = strcat('./dataset/Pavia_x2/trains/block_', file_name, '_', num2str(index), '.mat');
30
+ % file_path = strcat('./dataset/Chikusei_x2/trains/block_', file_name, '_', num2str(index), '.mat');
31
+ % file_path = strcat('./dataset/Chikusei_x8/trains/block_', file_name, '_', num2str(index), '.mat');
32
+ save(file_path,'gt','ms','ms_bicubic','-v6');
33
+ index = index + 1;
34
+ end
35
+ end
36
+ out = total_num;
37
+ end
38
+
39
+
HyperSIGMA_super-resolution/generate_Houston.m ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %% This is a demo code to show how to generate training and testing samples from the HSI %%
2
+ clc
3
+ clear
4
+ close all
5
+
6
+ addpath('include');
7
+
8
+ %% Step 1: generate the training and testing images from the original HSI
9
+ load('Houston2018.mat');%% Please down the Chikusei dataset (mat format) from https://www.sal.t.u-tokyo.ac.jp/hyperdata/
10
+ %% center crop this image to size 4172 x 1202
11
+ img = Houston2018;
12
+ clear Houston2018;
13
+ % normalization
14
+ img = single(img);
15
+ img = img ./ max(max(max(img)));
16
+
17
+ %% select first column as test images
18
+ [H, W, C] = size(img);
19
+ test_img_size = 256;
20
+ test_pic_num = floor(W / test_img_size);
21
+ mkdir test_Houston;
22
+ for i = 1:test_pic_num
23
+ left = (i - 1) * test_img_size + 1;
24
+ right = left + test_img_size - 1;
25
+ test = img(1:test_img_size,left:right,:);
26
+ save(strcat('./test_Houston/Houston_test_', int2str(i), '.mat'),'test');
27
+ end
28
+
29
+ %% the rest bottom for training
30
+ mkdir ('train_Houston');
31
+ img = img((test_img_size+1):end,:,:);
32
+ save('./train_Houston/Houston_train.mat', 'img');
33
+
34
+ %% Step 2: generate the testing images used in mains.py
35
+ generate_test_data;
36
+
37
+ %% Step 3: generate the training samples (patches) cropped from the training images
38
+ generate_train_data;
39
+
40
+ %% Step 4: Please manually remove 10% of the samples to the folder of evals
HyperSIGMA_super-resolution/generate_test_data.m ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fileFolder=fullfile('/Users/miaoyuchun/Desktop/superx2/test_Houston/');
2
+ dirOutput=dir(fullfile(fileFolder,'*.mat'));
3
+ fileNames={dirOutput.name};
4
+ factor = 0.5;
5
+ img_size = 256;
6
+ bands = 48;
7
+ gt = zeros(numel(fileNames),img_size,img_size,bands);
8
+ ms = zeros(numel(fileNames),img_size*factor,img_size*factor,bands);
9
+ ms_bicubic = zeros(numel(fileNames),img_size,img_size,bands);
10
+ % testFolder=fullfile('.\Cave\test\');
11
+ %testOutput=dir(fullfile(testFolder,'*.mat'));
12
+ %testNames={testOutput.name};
13
+
14
+ % cd test_Chikusei;
15
+ % cd test_Houston;
16
+ cd test_Houston;
17
+ for i = 1:numel(fileNames)
18
+ load(fileNames{i},'test');
19
+ img_ms = single(imresize(test, factor));
20
+ gt(i,:,:,:) = test;
21
+ ms(i,:,:,:) = img_ms;
22
+ ms_bicubic(i,:,:,:) = single(imresize(img_ms, 1/factor));
23
+ end
24
+
25
+ cd ..;
26
+ gt = single(gt);
27
+ ms = single(ms);
28
+ ms_bicubic = single(ms_bicubic);
29
+ save('/Users/miaoyuchun/Desktop/superx2/dataset/Houston_x2/Houston_x2.mat','gt','ms','ms_bicubic');
30
+
HyperSIGMA_super-resolution/generate_train_data.m ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % Convert HS dataset to patches
2
+
3
+ % List all '.mat' file in folder
4
+ % file_folder=fullfile('.\train');
5
+ file_folder=fullfile('/Users/miaoyuchun/Desktop/superx2/train_Houston');
6
+ file_list=dir(fullfile(file_folder,'*.mat'));
7
+ file_names={file_list.name};
8
+
9
+ % store cropped images in folders
10
+ for i = 1:1:numel(file_names)
11
+ name = file_names{i};
12
+ name = name(1:end-4);
13
+ load(strcat('/Users/miaoyuchun/Desktop/superx2/train_Houston/',file_names{i}));
14
+ %crop_image(img, 256, 128, 0.125, name);
15
+ crop_image(img, 128, 32, 0.5, name);
16
+ %crop_image(img, 128, 32, 0.125, name);
17
+ % crop(img, 512, 512, 0.5, name);
18
+ %crop_image(img, 128, 64, 0.25, name);
19
+ end