forked from petteriTeikari/twoPhotonVessels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_stack_toDisk.m
53 lines (42 loc) · 1.71 KB
/
export_stack_toDisk.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
function export_stack_toDisk(fileOut, im)
%{
disp(['Writing ', fileOut, ' to disk as .nrrd'])
pixelspacing = [1 1 1];
origin = [0,0,0];
encoding = 'raw';
ok = nrrdWriter(fileOut, im, pixelspacing, origin, encoding);
% pixelspacing - boxel size
% origin - point from the image is generated
% encoding - raw, ascii, gzip
%}
fileOut = strrep(fileOut, '.nrrd', '.tif');
disp([' .. Writing ', fileOut, ' to disk as multilayer 16-bit TIF'])
% whos
% [min(im(:)) max(im(:))]
im = im - min(im(:));
im = im / max(im(:));
imOut = uint16(im * 65535);
%uniqueValues = length(unique(im))
%uniqueValuesOut = length(unique(imOut))
%{
whos
figure
imshow(im(:,:,1)); drawnow()
figure
imshow(im(:,:,1)); drawnow()
%}
imwrite(imOut(:,:,1), fileOut, 'tif', 'Compression', 'lzw')
for k = 2:size(imOut,3)
imwrite(imOut(:,:,k), fileOut, 'tif', 'writemode', 'append', 'Compression', 'lzw');
end
%{
% http://stackoverflow.com/questions/874461/read-mat-files-in-python
fileOut = strrep(fileOut, '.tif', '.mat');
disp([' .. Writing ', fileOut, ' to disk as MAT file (with -7.3 flag)'])
save(fileOut, 'im', '-v7.3')
%{
fileOut = strrep(fileOut, '.tif', '.h5');
disp([' .. Writing ', fileOut, ' to disk as HDF5'])
hdf5write(fileOut, '/dataset1', im)
%}
%}