This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tif_to_jpeg2000_slave_OAR.m
102 lines (71 loc) · 2.34 KB
/
tif_to_jpeg2000_slave_OAR.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
% that function aims to calculate 3D binning from tif stack, resulting
% in a new 8 bits tif stack, it asks the factor to be used for the binning
% origin Paul Tafforeau, ESRF 09/2007
function tif_to_jpeg2000_slave_OAR(first,last,directory,compression_factor)
if isdeployed
first=str2num(first)
last=str2num(last)
compression_factor=str2num(compression_factor)
end
cd (directory)
cleandirectoryname(pwd)
% selection of all the files having the same radix
d=dir('*.tif');
fname={d.name};
number_of_files=size(d,1);
scan_dir=cleandirectoryname(pwd);
% n2: fileprefix, taken from directory name
pos=findstr(scan_dir,'/');
scan_dir=scan_dir(pos(end)+1:end);
cd ..
voltif_dir=cleandirectoryname(pwd);
resultdir=[voltif_dir '/' scan_dir sprintf('jp2-%1.0i_',compression_factor)];
%%%%%%%%%%%%%%%%%
% create result directory if not-existing
%%%%%%%%%%%%%%%%%
newdirectory=isempty(what(resultdir));
if newdirectory
unix(sprintf('mkdir %s',resultdir))
stat = 1;
if stat
disp(sprintf('New directory %s created successfully',resultdir))
unix(sprintf('chmod 777 %s',resultdir));
else
disp('Problems creating new directory, permissions ???')
return % EXITING PROGRAM !!!
end
end
cd (directory)
%%
for i=first:last
disp(sprintf('processing slice %1.0f',i));
slice_name=sprintf(fname{i});
slice=imread(slice_name);
final_slice_name=[resultdir '/' slice_name(1:end-3) 'jp2'];
imwrite(slice,final_slice_name,'CompressionRatio',compression_factor);
end
if last>=number_of_files
dinfo=dir(['reconstruction_log.info']);
infoname={dinfo.name};
if size(infoname,1)>0
infoname=infoname{1};
fp=fopen(infoname,'r');
if fp~=-1 % *.info exists
hd=fscanf(fp,'%c');
fclose(fp);
end
else
hd=[];
end
file=hd;
file=[file sprintf('tif_to_jpeg2000_slave_OAR\n')];
file=[file sprintf('number_of_files=%1.0f\n',number_of_files)];
file=[file sprintf('wdir=%s\n',directory)];
file=[file sprintf('compression_factor=%1.0f\n',compression_factor)];
file=[file sprintf('------------------------\n\n')];
logname=sprintf('%s/reconstruction_log.info',resultdir);
fid=fopen(logname,'a+');
fwrite(fid,file,'uchar');
fclose(fid);
end
end