-
Notifications
You must be signed in to change notification settings - Fork 10
/
PreprocessValidation.m
executable file
·83 lines (68 loc) · 2.85 KB
/
PreprocessValidation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/octave -qf
%
% PreprocessValidation
% Makes hdf5 validation file from raw images and corresponding labels
%
% Syntax : PreprocessValidation ~/validation/images/ ~/validation/labels/ ~/validation/combined
%
%
%----------------------------------------------------------------------------------------
%% PreprocessTraining for Deep3M -- NCMIR/NBCR, UCSD -- Author: M Haberl -- Date: 04/2018
%----------------------------------------------------------------------------------------
%
% Runtime: <1 min
%
% ----------------------------------------------------------------------------------------
%% Initialize
% ----------------------------------------------------------------------------------------
disp('Starting Validation data Preprocessing');
pkg load hdf5oct
pkg load image
script_dir = fileparts(make_absolute_filename(program_invocation_name()));
addpath(genpath(script_dir));
arg_list = argv ();
if numel(arg_list)<3; disp('Use -> PreprocessValidation /validation/images/ /validation/labels/ /validdation/combined'); return; end
tic
trainig_img_path = arg_list{1};
disp('Validation Image Path:');disp(trainig_img_path);
label_img_path = arg_list{2};
disp('Validation Label Path:');disp(label_img_path);
outdir = arg_list{3};
disp('Output Path:');disp(outdir);
% ----------------------------------------------------------------------------------------
%% Load images
% ----------------------------------------------------------------------------------------
disp('Loading:');
disp(trainig_img_path);
[imgstack] = imageimporter(trainig_img_path);
disp('Verifying images');
checkpoint_nobinary(imgstack);
% ----------------------------------------------------------------------------------------
%% Load labels
% ----------------------------------------------------------------------------------------
disp('Loading:');
disp(label_img_path);
[lblstack] = imageimporter(label_img_path);
disp('Verifying labels');
checkpoint_isbinary(lblstack);
% ----------------------------------------------------------------------------------------
%% Convert and save
% ----------------------------------------------------------------------------------------
img_v1 =single(imgstack);
lb_v1 =single(lblstack);
d_details = '/data';
l_details = '/label';
if ~exist(outdir,'dir'), mkdir(outdir); end
ext = '.h5';
img=permute(img_v1,[3 1 2]); %from tiff to h5 /100*1000*1000
lb=permute(lb_v1,[3 1 2]); %from tiff to h5 /100*1000*1000
filename = fullfile(outdir, sprintf('validation_stack_v%s%s', num2str(1), ext));
fprintf('Saving: %s\n', filename);
h5write(filename,d_details,img);
h5write(filename,l_details,lb);
clear img lb
% ----------------------------------------------------------------------------------------
%% Completed
% ----------------------------------------------------------------------------------------
toc
fprintf('Validation data stored in %s\n', outdir);