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
/
covid_half_acquisition_slave_OAR.m
691 lines (439 loc) · 21.7 KB
/
covid_half_acquisition_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
% function to prepare tetra-acquisition scans by concatenation and complete
% normalisation of the HA and TA scans. Concatenation on one side only in
% order to keep the fine tuning of center of rotation and to generate
% classical HA scans with large field of view
% origin Paul Tafforeau ESRF 2020
function covid_half_acquisition_slave_OAR(first,last,parentdir,resultdir,namestr,HA_scan,nvue,refon,acc_nb_frames,max_SR_current,border_Vcorr_width,back_16,force_BF_1,force_BF_mode,BF_corr,HA_opt,BF_max_trans_level,BF_max_trans_size)
if isdeployed
first=str2num(first)
last=str2num(last)
nvue=str2num(nvue)
refon=str2num(refon)
acc_nb_frames=str2num(acc_nb_frames)
max_SR_current=str2num(max_SR_current)
border_Vcorr_width=str2num(border_Vcorr_width)
back_16=str2num(back_16)
force_BF_1=str2num(force_BF_1)
BF_corr=str2num(BF_corr)
HA_opt=str2num(HA_opt)
BF_max_trans_level=str2num(BF_max_trans_level)
BF_max_trans_size=str2num(BF_max_trans_size)
end
if first==last
test=first;
figure(1);
else
test=0;
end
%% reading of the two max SRcurrent references for HA and TA scans
if exist('HA_REF.edf')
HA_REF=single(edfread('HA_REF.edf'));
use_HA_REF=1;
else
if exist(sprintf('%s/%s/refHST0000.edf',parentdir,HA_scan));
fprintf('you are using the classical reference system or you used a complex reference scan for of axis local tomography \n')
HA_REF=single(edfread(sprintf('%s/%s/refHST0000.edf',parentdir,HA_scan)));
use_HA_REF=0;
else
fprintf('I cannot find either normal references or the generic reference for HA scans that should be called HA_REF.edf, to be prepared with covid_total_mean macro \n')
return
end
end
%% preparing a dark picture
fp=fopen(sprintf('%s/%s/dark.edf',parentdir,HA_scan));
if fp~=-1
dark=edfread(sprintf('%s/%s/dark.edf',parentdir,HA_scan));
disp('reading dark file')
if mean2(dark)<acc_nb_frames*100*0.9
disp ('there is a problem with dark, I replace it by accumulation*100')
dark=HA_REF*0+100*acc_nb_frames;
end
else
disp('I found no dark');
if replace_ref==1
disp('I create a dark at 100*accumulation in average');
dark=HA_REF*0+100*acc_nb_frames;
end
end
if use_HA_REF==0
fprintf('reading all the references and forcing them to the max SRcurrent level \n');
for k=0:((round(nvue/10)*10)/refon)
flatname=sprintf('%s/%s/refHST%4.4i.edf',parentdir,HA_scan,k*refon);
fp2=fopen(sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,k*refon));
if fp2~=-1
hd2=fscanf(fp2,'%c',1024);
fclose(fp2);
REF_SR_current=findheader(hd2,'SRCUR','float');
end
f=single(edfread(flatname)-dark)/REF_SR_current*max_SR_current+dark;
flat(:,:,k+1)=f;
disp (flatname)
end
size(flat)
end
dark_level=mean2(dark);
general_ref_level=max2(medfilt_rapid(HA_REF-dark,[50 50],'replicate'));
%% reading of center of rotation from the par file
if HA_opt>0
parfilename=sprintf('%s/%s/%sslice_pag.par',parentdir,HA_scan,HA_scan);
fid = fopen(parfilename,'r');
parf=fscanf(fid,'%c');
if parf~=-1
fclose(fid);
stringbeg='ROTATION_AXIS_POSITION = ';
posbeg1 = findstr(parf,stringbeg)+size(stringbeg,2);
stringend=' # Position in pixels';
posend1 = findstr(parf,stringend);
lateral_shift=str2num(parf(posbeg1:posend1));
% lateral_shift=lateral_shift-size(HA_REF,1)/2
else
disp (' there is no par file to find the center of rotation, please run fasttomo at least once')
return
end
end
%% main loop for concatenation
first_im_name=sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,1);
fp2=fopen(first_im_name);
if fp2~=-1
hd2=fscanf(fp2,'%c',1024);
fclose(fp2);
LAST_OK_SCAN_SRcurrent=findheader(hd2,'SRCUR','float')
if LAST_OK_SCAN_SRcurrent==-1
disp('there is a problem with the recorded SRcurrent value in the first picture, tying to find a correct value on another projection')
SR_im_name=sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,100);
fp3=fopen(SR_im_name);
hd3=fscanf(fp3,'%c',1024');
fclose(fp3);
LAST_OK_SCAN_SRcurrent=findheader(hd3,'SRCUR','float')
if LAST_OK_SCAN_SRcurrent==-1
disp('there is a problem with the recorded SRcurrent value in the first picture, tying to find a correct value on another projection')
SR_im_name=sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,200);
fp4=fopen(SR_im_name);
hd4=fscanf(fp4,'%c',1024');
fclose(fp4);
LAST_OK_SCAN_SRcurrent=findheader(hd4,'SRCUR','float')
end
end
end
if HA_opt>0
first_im_name2=sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,floor(nvue/2));
fp2=fopen(first_im_name2);
if fp2~=-1
hd2=fscanf(fp2,'%c',1024);
fclose(fp2);
LAST_OK_SCAN_SRcurrent2=findheader(hd2,'SRCUR','float')
if LAST_OK_SCAN_SRcurrent==-1
disp('there is a problem with the recorded SRcurrent value in the first picture, tying to find a correct value on another projection')
SR_im_name=sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,floor(nvue/2)+100);
fp3=fopen(SR_im_name);
hd3=fscanf(fp3,'%c',1024');
fclose(fp3);
LAST_OK_SCAN_SRcurrent2=findheader(hd3,'SRCUR','float')
if LAST_OK_SCAN_SRcurrent==-1
disp('there is a problem with the recorded SRcurrent value in the first picture, tying to find a correct value on another projection')
SR_im_name=sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,floor(nvue/2)+200);
fp4=fopen(SR_im_name);
hd4=fscanf(fp4,'%c',1024');
fclose(fp4);
LAST_OK_SCAN_SRcurrent2=findheader(hd4,'SRCUR','float')
end
end
end
end
for i=first:last
HA_im_name=sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,i);
fp2=fopen(HA_im_name);
if fp2~=-1
hd2=fscanf(fp2,'%c',1024);
fclose(fp2);
SCAN_SRcurrent=findheader(hd2,'SRCUR','float')
if SCAN_SRcurrent<20
SCAN_SRcurrent=LAST_OK_SCAN_SRcurrent-LAST_OK_SCAN_SRcurrent*0.0000019 % SRcurrent decrease calibrated on 100 pictures
end
LAST_OK_SCAN_SRcurrent= SCAN_SRcurrent;
end
if use_HA_REF==1
HA_im=((single(edfread(HA_im_name))-dark)/SCAN_SRcurrent*max_SR_current)./(HA_REF-dark);
else
refn1=refon*floor(i/refon)
refn2=min(refn1+refon,round(nvue/10)*10)
ref_interval=max(refn2-refn1,1);
w1=(refn2-i)/ref_interval;
w2=1-w1;
ind1=refn1/refon+1;
ind2=min(refn2/refon+1,size(flat,3));
HA_REF = w1*flat(:,:,ind1) + w2*flat(:,:,ind2);
HA_im=((single(edfread(HA_im_name))-dark)/SCAN_SRcurrent*max_SR_current)./(HA_REF-dark);
end
if HA_opt>0
if i<nvue/2+1
ibis=i+floor(nvue/2);
else
ibis=i-floor(nvue/2);
end
HA2_im_name=sprintf('%s/%s/%s%4.4i.edf',parentdir,HA_scan,HA_scan,ibis);
fp2=fopen(HA2_im_name);
if fp2~=-1
hd2=fscanf(fp2,'%c',1024);
fclose(fp2);
SCAN_SRcurrent2=findheader(hd2,'SRCUR','float');
if SCAN_SRcurrent2<20
SCAN_SRcurrent2=LAST_OK_SCAN_SRcurrent2-LAST_OK_SCAN_SRcurrent2*0.0000019 % SRcurrent decrease calibrated on 100 pictures
end
LAST_OK_SCAN_SRcurrent2= SCAN_SRcurrent2;
end
if use_HA_REF==1
HA2_im=((single(edfread(HA2_im_name))-dark)/SCAN_SRcurrent2*max_SR_current)./(HA_REF-dark);
else
refn1=refon*floor(ibis/refon);
refn2=min(refn1+refon,round(nvue/10)*10);
w1=(refn2-ibis)/refon;
w2=1-w1;
ind1=refn1/refon+1;
ind2=min(refn2/refon+1,size(flat,3));
HA_REF = w1*flat(:,:,ind1) + w2*flat(:,:,ind2);
HA2_im=((single(edfread(HA2_im_name))-dark)/SCAN_SRcurrent2*max_SR_current)./(HA_REF-dark);
end
end
%%
if HA_opt>0
% cropping in 4 parts
common_size=round((size(HA_im,1)-lateral_shift)*2);
common1=imcrop(HA_im,[1 size(HA_im,1)-common_size+1 size(HA_im,2) common_size-1]);
common2=flipud(imcrop(HA2_im,[1 size(HA2_im,1)-common_size+1 size(HA2_im,2) common_size-1]));
% checking grey levels in the comon parts to define the best of the two pictures to be used as a reference (or the two of them)
common1_test=mean2(abs(medfilt_rapid(common1,[200 10],'symmetric')-mean2(common1)));
common2_test=mean2(abs(medfilt_rapid(common2,[200 10],'symmetric')-mean2(common2)));
common1_cor=median(medfilt_rapid(common1,[200 10],'symmetric'));
common2_cor=median(medfilt_rapid(common2,[200 10],'symmetric'));
div_test=abs((common1_test-common2_test)/(max(common1_test,common2_test))*100);
if div_test<5
disp('less than 5% of error, we use both image for a bilateral normalisation')
common_level=median(medfilt_rapid((common1+common2)/2,[200 10],'symmetric'));
else
if common1_test<common2_test
disp('using the first picture as reference for the vertical normalisation')
common_level=median(medfilt_rapid(common1,[200 10],'symmetric'));
else
disp('using the second picture as reference for the vertical normalisation')
common_level=median(medfilt_rapid(common2,[200 10],'symmetric'));
end
end
common1_cor=blurring_rapid(imresize(common_level-common1_cor,[size(HA_im,1) size(HA_im,2)]),10,'replicate');
common2_cor=blurring_rapid(imresize(common_level-common2_cor,[size(HA_im,1) size(HA_im,2)]),10,'replicate');
HA_im=HA_im+common1_cor;
HA2_im=HA2_im+common2_cor;
end
%% projections corrections
if border_Vcorr_width > 0
left_filter=HA_im-medfilt_rapid(HA_im,[ceil(border_Vcorr_width/1) ceil(size(HA_im,2)*1.5)],'symmetric');
left_filter=medfilt_rapid(left_filter,[1 ceil(size(HA_im,2)/4)],'replicate');
left_filter=medfilt_rapid(left_filter,[1 ceil(size(HA_im,2)/4)],'replicate');
left_filter=left_filter-medfilt_rapid(left_filter,[ceil(border_Vcorr_width/1) ceil(size(HA_im,2)*1.5)],'symmetric');
left_border=HA_im-left_filter;
HA_im(1:ceil(border_Vcorr_width/2)-1,:,:)=left_border(1:ceil(border_Vcorr_width/2)-1,:,:);
for l=1:border_Vcorr_width %ceil(border_Vcorr_width/2):ceil(border_Vcorr_width*1.5)
Wcom1=1-(l/border_Vcorr_width);
Wcom2=1-Wcom1;
HA_im(l+ceil(border_Vcorr_width/2),:,:)=left_border(l+ceil(border_Vcorr_width/2),:,:)*Wcom1+HA_im(l+ceil(border_Vcorr_width/2),:,:)*Wcom2;
end
if HA_opt>0
left_filter=HA2_im-medfilt_rapid(HA2_im,[ceil(border_Vcorr_width/1) ceil(size(HA2_im,2)*1.5)],'symmetric');
left_filter=medfilt_rapid(left_filter,[1 ceil(size(HA2_im,2)/4)],'replicate');
left_filter=medfilt_rapid(left_filter,[1 ceil(size(HA2_im,2)/4)],'replicate');
left_filter=left_filter-medfilt_rapid(left_filter,[ceil(border_Vcorr_width/1) ceil(size(HA2_im,2)*1.5)],'symmetric');
left_border=HA2_im-left_filter;
HA2_im(1:ceil(border_Vcorr_width/2)-1,:,:)=left_border(1:ceil(border_Vcorr_width/2)-1,:,:);
for l=1:border_Vcorr_width %ceil(border_Vcorr_width/2):ceil(border_Vcorr_width*1.5)
Wcom1=1-(l/border_Vcorr_width);
Wcom2=1-Wcom1;
HA2_im(l+ceil(border_Vcorr_width/2),:,:)=left_border(l+ceil(border_Vcorr_width/2),:,:)*Wcom1+HA2_im(l+ceil(border_Vcorr_width/2),:,:)*Wcom2;
end
end
end
if BF_max_trans_level>0 %first pass to normalize on a large scale
%HA_im_BF=medfilt_rapid(HA_im,[BF_max_trans_size BF_max_trans_size],'replicate');
HA_im_BF=blurring_rapid(HA_im,BF_max_trans_size*5,'replicate');
HA_im_HF=HA_im-HA_im_BF;
HA_im_BF=min(HA_im_BF,BF_max_trans_level);
HA_im=HA_im_HF+HA_im_BF;
if HA_opt>0
%HA2_im_BF=medfilt_rapid(HA2_im,[BF_max_trans_size BF_max_trans_size],'replicate');
HA2_im_BF=blurring_rapid(HA2_im,BF_max_trans_size*5,'replicate');
HA2_im_HF=HA2_im-HA2_im_BF;
HA2_im_BF=min(HA2_im_BF,BF_max_trans_level);
HA2_im=HA2_im_HF+HA2_im_BF;
end
end
%%
if force_BF_1>0
if HA_opt>0
concat_im=[imcrop(HA_im,[1 1 size(HA_im,2) size(HA_im,1)-common_size-1])' (flipud(HA2_im))']';
if border_Vcorr_width>0
imt_norm_REF=imcrop( concat_im,[ 1 border_Vcorr_width size(concat_im,2) size(concat_im,1)-border_Vcorr_width+1]);
imt_norm_REF=medfilt_rapid(imt_norm_REF,[force_BF_1 force_BF_1],'replicate');
else
imt_norm_REF=medfilt_rapid(concat_im,[force_BF_1 force_BF_1],'replicate');
end
else
if border_Vcorr_width>0
imt_norm_REF=imcrop( HA_im,[ 1 border_Vcorr_width size(HA_im,2) size(HA_im,1)-border_Vcorr_width+1]);
imt_norm_REF=medfilt_rapid(imt_norm_REF,[force_BF_1 force_BF_1],'replicate');
else
imt_norm_REF=medfilt_rapid(HA_im,[force_BF_1 force_BF_1],'replicate');
end
end
switch force_BF_mode
case 'min'
imt_norm=imresize(min(imt_norm_REF),[size(HA_im,1) size(HA_im,2)])-1;
case 'max'
imt_norm=imresize(max(imt_norm_REF),[size(HA_im,1) size(HA_im,2)])-1;
case 'avg'
imt_norm=imresize(mean(imt_norm_REF),[size(HA_im,1) size(HA_im,2)])-1;
end
imt_norm=medfilt_rapid(imt_norm,[1 100],'replicate');
HA_im=HA_im-imt_norm;
if HA_opt>0
HA2_im=HA2_im-imt_norm;
end
%%
if BF_max_trans_level>0 %second pass to normalize with the final size of the filter
%HA_im_BF=medfilt_rapid(HA_im,[BF_max_trans_size BF_max_trans_size],'replicate');
HA_im_BF=blurring_rapid(HA_im,BF_max_trans_size,'replicate');
HA_im_HF=HA_im-HA_im_BF;
HA_im_BF=min(HA_im_BF,BF_max_trans_level);
HA_im=HA_im_HF+HA_im_BF;
if HA_opt>0
%HA2_im_BF=medfilt_rapid(HA2_im,[BF_max_trans_size BF_max_trans_size],'replicate');
HA2_im_BF=blurring_rapid(HA2_im,BF_max_trans_size,'replicate');
HA2_im_HF=HA2_im-HA2_im_BF;
HA2_im_BF=min(HA2_im_BF,BF_max_trans_level);
HA2_im=HA2_im_HF+HA2_im_BF;
end
end
end
%%
if BF_corr >0 %
left_part1=blurring_rapid(imcrop(HA_im,[1 1 size(HA_im,1) BF_corr-1]),BF_corr,'replicate');
left_level1=mean2(left_part1);
if HA_opt>0
left_part2=blurring_rapid(imcrop(flipud(HA2_im),[1 1 size(HA2_im,1) BF_corr-1]),BF_corr,'replicate');
left_level2=mean2(left_part2);
end
norm_mask1=HA_im*0+1;
for n=1:size(HA_im,1)-BF_corr
w2=n/(size(HA_im,1)-BF_corr);
w1=1-w2;
level=left_level1*w1+w2;
norm_mask1(n,:,:)=level;
end
norm_mask1=imresize(norm_mask1,[size(HA_im,1) size(HA_im,2)]);
if HA_opt>0
norm_mask2=HA_im*0+1;
for n=1:size(HA2_im,1)-BF_corr
w2=n/(size(HA2_im,1)-BF_corr);
w1=1-w2;
level2=left_level2*w1+w2;
norm_mask2(n,:,:)=level2;
end
norm_mask2=imresize(norm_mask2,[size(HA2_im,1) size(HA2_im,2)]);
end
HA_im=HA_im./norm_mask1;
HA2_im=HA2_im./norm_mask2;
end
if HA_opt>0 && test>0
concat_im=[imcrop(HA_im,[1 1 size(HA_im,2) size(HA_im,1)-common_size-1])' (flipud(HA2_im))'];
figure;imshow(concat_im,[]);
return
end
%% removing the reference to go back to original scale
if back_16==1
HA_im=HA_im.*general_ref_level/acc_nb_frames+dark_level/acc_nb_frames;
else
HA_im=HA_im.*general_ref_level+dark_level;
end
if test>0
imshow(HA_im',[]);impixelinfo
fprintf('processing of the projection %4.4i is finished \n',i);
else
%% writing the result
new_imname=sprintf('%s/%s%4.4i.edf',resultdir,namestr,i);
fprintf('writing the new projection file %s%4.4i.edf on a total of %4.4i \n',namestr,i,nvue);
if back_16==1
edfwrite(new_imname,uint16(HA_im),'uint16');
else
edfwrite(new_imname,HA_im,'float32');
end
end
end
if last==nvue
disp ('attempting to write the new references and new dark')
if back_16==1
mean2(HA_im)
final_ref_level=general_ref_level/acc_nb_frames+dark_level/acc_nb_frames
new_ref=uint16(zeros(size(HA_im,1),size(HA_im,2))*0+final_ref_level);
mean2(new_ref)
new_dark=uint16(HA_im*0+dark_level/acc_nb_frames);
edfwrite(sprintf('%s/refHST0000.edf',resultdir),new_ref,'uint16');
edfwrite(sprintf('%s/refHST%4.4i.edf',resultdir,nvue),new_ref,'uint16');
edfwrite(sprintf('%s/dark.edf',resultdir),new_dark,'uint16');
else
new_ref=HA_im*0+general_ref_level+dark_level;
new_dark=HA_im*0+dark_level;
edfwrite(sprintf('%s/refHST0000.edf',resultdir),new_ref,'float32');
edfwrite(sprintf('%s/refHST%4.4i.edf',resultdir,nvue),new_ref,'float32');
edfwrite(sprintf('%s/dark.edf',resultdir),new_dark,'float32');
end
disp ('writting successful')
disp ('copying and renaming of the .info .xml and .cfg files to keep the motor positions and other informations of the scans. Be aware that the picture sizes are not updated')
system(sprintf('cp %s/%s/%s.info %s/%s.info',parentdir,HA_scan,HA_scan,resultdir,namestr))
system(sprintf('cp %s/%s/%s.xml %s/%s.xml',parentdir,HA_scan,HA_scan,resultdir,namestr))
system(sprintf('cp %s/%s/%s.cfg %s/%s.cfg',parentdir,HA_scan,HA_scan,resultdir,namestr))
%% updating info file with the correct refon in case of use of multiple references
infoname=sprintf('%s/%s.info',resultdir,namestr);
fid = fopen(infoname,'r');
info=fscanf(fid,'%c');
fclose(fid);
stringbeg='REF_ON= ';
posbeg1 = findstr(info,stringbeg)+size(stringbeg,2);
stringend='REF_N= ';
posend1 = findstr(info,stringend);
new_string1=sprintf('%1.0i\n',nvue);
new_info=[info(1:posbeg1-1) new_string1 info(posend1:end)];
fid2=fopen(infoname,'w');
fwrite(fid2,new_info,'uchar');
fclose(fid2);
fprintf('the new info file has been updated for the refon \n');
%% updating info .cfg file with the accumulation level if going back to 16 bits
cfgname=sprintf('%s/%s.cfg',resultdir,namestr);
fid = fopen(cfgname,'r');
cfg=fscanf(fid,'%c');
fclose(fid);
if back_16==1
stringbeg='acc_nb_frames ';
posbeg1 = findstr(cfg,stringbeg)+size(stringbeg,2);
stringend='accel_disp';
posend1 = findstr(cfg,stringend);
new_string1=sprintf('%1.0i\n',1);
new_cfg=[cfg(1:posbeg1-1) new_string1 cfg(posend1:end)];
fid2=fopen(cfgname,'w');
fwrite(fid2,new_cfg,'uchar');
fclose(fid2);
cfgname=sprintf('%s/%s.cfg',resultdir,namestr);
fid = fopen(cfgname,'r');
cfg=fscanf(fid,'%c');
fclose(fid);
if back_16==1
stringbeg='ccd_acq_mode ';
posbeg1 = findstr(cfg,stringbeg)+size(stringbeg,2);
stringend='ccd_flip_horz';
posend1 = findstr(cfg,stringend);
new_string1=sprintf('SINGLE \n',1);
new_cfg=[cfg(1:posbeg1-1) new_string1 cfg(posend1:end)];
fid2=fopen(cfgname,'w');
fwrite(fid2,new_cfg,'uchar');
fclose(fid2);
end
fprintf('the new cfg file has been updated for the projections and the accumulation level \n');
end
end