Skip to content

Commit f90bfdb

Browse files
committed
fixes to account for flipped resolution rods setup
1 parent 783564f commit f90bfdb

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

niftypet/nimpa/acr/params.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
# angle of rotations for the initial position of resolution rods (cold)
5353
rods_rotate = 0
5454

55+
# flip left-right of the resolution rods (the rods can be inserted both ways)
56+
rods_fliplr = 0
57+
5558
# > buffer size for the activity image for registration purposes
5659
buff_size = 16
5760

@@ -151,6 +154,7 @@ def get_params(cpath=None):
151154
'scl': scl,
152155
'intord': intord,
153156
'rods_rotate': rods_rotate,
157+
'rods_fliplr': rods_fliplr,
154158

155159
'itr_nac': itr_nac,
156160
'itr_qnt': itr_qnt,

niftypet/nimpa/acr/templates.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ def create_nac_core(Cntd, return_raw=False):
334334
return None
335335

336336

337-
def create_reso(Cntd, return_raw=False):
337+
def create_reso(Cntd, return_raw=False, forced=False):
338338
"""Create the resolution rods for the mu-map and for registration."""
339-
if all(os.path.isfile(Cntd['out'][f]) for f in ('fresomu', 'fresdmu', 'fresdWmu', 'fresdQmu')):
339+
340+
if not forced and all(os.path.isfile(Cntd['out'][f]) for f in ('fresomu', 'fresdmu', 'fresdWmu', 'fresdQmu')):
340341
return None
341342

342343
if 'fqntup' in Cntd and Path(Cntd['fqntup']).is_file():
@@ -349,12 +350,12 @@ def create_reso(Cntd, return_raw=False):
349350
# ------------------------------------------------------
350351
# > form 3D digital resolution part of the phantom for registration
351352
# > and attenuation purposes
352-
renpng = imageio.imread(Cntd['frenpng'])
353-
respng = imageio.imread(Cntd['frespng'])
353+
renpng = imageio.v2.imread(Cntd['frenpng'])
354+
respng = imageio.v2.imread(Cntd['frespng'])
354355

355356
# > these are rods mixed with water
356-
renWpng = imageio.imread(Cntd['frenWpng'])
357-
resWpng = imageio.imread(Cntd['fresWpng'])
357+
renWpng = imageio.v2.imread(Cntd['frenWpng'])
358+
resWpng = imageio.v2.imread(Cntd['fresWpng'])
358359
# ------------------------------------------------------
359360

360361
ren = np.float32((renpng[..., 0] == Cntd['png_prspx']) * Cntd['mu_prspx'])
@@ -380,6 +381,12 @@ def create_reso(Cntd, return_raw=False):
380381
'''
381382
# --END-PRINT--
382383

384+
if Cntd['rods_fliplr'] != 0:
385+
ren = np.flip(ren, axis=1)
386+
res = np.flip(res, axis=1)
387+
renW = np.flip(renW, axis=1)
388+
resW = np.flip(resW, axis=1)
389+
383390
if Cntd['rods_rotate'] != 0:
384391
ren = ndi.rotate(ren, Cntd['rods_rotate'], reshape=False, order=Cntd['intord'],
385392
mode='constant')
@@ -391,6 +398,9 @@ def create_reso(Cntd, return_raw=False):
391398
resW = ndi.rotate(resW, Cntd['rods_rotate'], reshape=False, order=Cntd['intord'],
392399
mode='constant')
393400

401+
# > copy array here for easy QC
402+
res_qc = res.copy()
403+
394404
ren = ndi.zoom(ren, Cntd['scl'], output=None, order=Cntd['intord'], mode='constant')
395405
res = ndi.zoom(res, Cntd['scl'], output=None, order=Cntd['intord'], mode='constant')
396406

@@ -506,7 +516,7 @@ def create_reso(Cntd, return_raw=False):
506516
imupd['transpose'].index(2)), flip=imupd['flip'])
507517

508518
if return_raw:
509-
return {'resoW': resoW, 'resdW': resdW, 'resd': resd, 'reso': reso}
519+
return {'resoW': resoW, 'resdW': resdW, 'resd': resd, 'reso': reso, 'res2d':res_qc}
510520

511521

512522
# =======================================================================
@@ -598,6 +608,10 @@ def create_sampl_reso(Cntd, return_raw=False):
598608
for j, lvl in enumerate(g[i, g[i, :] > 0]):
599609
srods[y == lvl] = off + j
600610

611+
# > flipping and/or rotating the rods
612+
if Cntd['rods_fliplr'] != 0:
613+
srods = np.flip(srods, axis=1)
614+
601615
if Cntd['rods_rotate'] != 0:
602616
srods = ndi.rotate(srods, Cntd['rods_rotate'], reshape=False, order=Cntd['intord'],
603617
mode='constant')

0 commit comments

Comments
 (0)