-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsave_image.m
More file actions
59 lines (53 loc) · 2.26 KB
/
save_image.m
File metadata and controls
59 lines (53 loc) · 2.26 KB
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
function save_image(recon, bg_sub_fac, cent_g, bg_g, cb, datafilepath, format, varargin)
vargs = varargin;
nargs = length(vargs)/2;
names = vargs(1:2:2*nargs);
values = vargs(2:2:2*nargs);
split = strsplit(datafilepath, '\');
LoadDataFileName = split{end};
LoadDataPathName = strjoin(split(1:end-1), '\');
savename = strsplit(LoadDataFileName,'.');
savename = savename{1};
dname = uigetdir(LoadDataPathName);
fname = savename
stringpart = sprintf('_Reconstruction_%.dnm_central_%dnmbg_%dconst_%.2f_centbg_rat', cent_g, bg_g, cb, bg_sub_fac)
savepath = strcat(dname, '\', fname, stringpart);
disp(strcat('Saving in :', savename))
savepath_check = savepath;
new_ver = 2;
while exist(savepath_check) == 7
savepath_check = strcat(savepath, '_', num2str(new_ver));
new_ver = new_ver + 1;
end
savepath = savepath_check;
mkdir(savepath)
imsidey = size(recon, 1);
imsidex = size(recon, 2);
imsidez = size(recon, 3);
% output = recon - min(recon(:));
% output = uint16(2^16*output/max(output(:)));
%% Scale values appropriatly
recon = recon - min(recon(:)); % add offset to accomodate negative values.
mr = max(recon(:));
if mr < 2^16/500
output = uint16(500*recon); % 500 arbitrarily chosen to fit normal data
elseif mr < 2^16/50
output = uint16(50*recon);
elseif mr < 2^16/5
output = uint16(5*recon);
else
output = uint16(recon.*(2^16/mr));
end
if strcmp(format,'tif')
imwrite(output, strcat(savepath, '\', fname, '_Reconstructed_Sthlm', '.tif')),
elseif strcmp(format,'hdf5')
h5create(strcat(savepath, '\', fname, '_Stack'),'/data', [imsidey imsidex imsidez])
h5write(strcat(savepath, '\', fname, '_Stack'),'/data', recon);
end
if nargs == 1
widefield = values{1};
widefield = widefield - min(widefield(:));
widefield = uint16(2^16*widefield/max(widefield(:)));
imwrite(widefield, strcat(savepath, '\', fname, '_WF', '.tif'))
end
end