Skip to content

Commit 10fd7fc

Browse files
committed
added extraction of horizontal and vertical bed positions
1 parent 2af5ae5 commit 10fd7fc

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

niftypet/nipet/img/mmrimg.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ def hmu_origin(hdr):
861861

862862

863863
def hmu_offset(hdr):
864-
# pegular expression to find the origin
864+
# regular expression to find the origin
865865
p = re.compile(r'(?<=:=)\s*\d{1,5}[.]\d{1,10}')
866866
if hdr.find('$origin offset') > 0:
867867
# x: dim [1]
@@ -887,7 +887,7 @@ def rd_hmu(fh):
887887
hdr = f.read()
888888
f.close()
889889
# -----------------
890-
# pegular expression to find the file name
890+
# regular expression to find the file name
891891
p = re.compile(r'(?<=:=)\s*\w*[.]\w*')
892892
i0 = hdr.find('!name of data file')
893893
i1 = i0 + hdr[i0:].find('\n')
@@ -900,11 +900,32 @@ def rd_hmu(fh):
900900
return hdr, im
901901

902902

903+
def get_bedpos(datain, Cnt):
904+
''' Get horizontal bed position
905+
'''
906+
ihdr, csainfo = mmraux.hdr_lm(datain, Cnt)
907+
908+
# start horizontal bed position
909+
p = re.compile(r'start horizontal bed position.*\d{1,3}\.*\d*')
910+
m = p.search(ihdr)
911+
fi = ihdr[m.start():m.end()].find('=')
912+
hbedpos = 0.1 * float(ihdr[m.start() + fi + 1:m.end()])
913+
914+
# start vertical bed position
915+
p = re.compile(r'start vertical bed position.*\d{1,3}\.*\d*')
916+
m = p.search(ihdr)
917+
fi = ihdr[m.start():m.end()].find('=')
918+
vbedpos = 0.1 * float(ihdr[m.start() + fi + 1:m.end()])
919+
920+
return hbedpos, vbedpos
921+
922+
923+
903924
def get_hmupos(datain, parts, Cnt, outpath=''):
904925

905926
# ----- get positions from the DICOM list-mode file -----
906927
ihdr, csainfo = mmraux.hdr_lm(datain, Cnt)
907-
# pable position origin
928+
# table position origin
908929
fi = csainfo.find(b'TablePositionOrigin')
909930
tpostr = csainfo[fi:fi + 200]
910931
tpo = re.sub(b'[^a-zA-Z0-9.\\-]', b'', tpostr).split(b'M')
@@ -946,17 +967,7 @@ def get_hmupos(datain, parts, Cnt, outpath=''):
946967
# get the reference nii image
947968
fref = os.path.join(dirhmu, 'hmuref.nii.gz')
948969

949-
# ptart horizontal bed position
950-
p = re.compile(r'start horizontal bed position.*\d{1,3}\.*\d*')
951-
m = p.search(ihdr)
952-
fi = ihdr[m.start():m.end()].find('=')
953-
hbedpos = 0.1 * float(ihdr[m.start() + fi + 1:m.end()])
954-
955-
# ptart vertical bed position
956-
p = re.compile(r'start vertical bed position.*\d{1,3}\.*\d*')
957-
m = p.search(ihdr)
958-
fi = ihdr[m.start():m.end()].find('=')
959-
vbedpos = 0.1 * float(ihdr[m.start() + fi + 1:m.end()])
970+
hbedpos, vbedpos = get_bedpos(datain, Cnt)
960971

961972
log.info('creating reference NIfTI image for resampling')
962973
B = np.diag(np.array([-10 * Cnt['SO_VXX'], 10 * Cnt['SO_VXY'], 10 * Cnt['SO_VXZ'], 1]))

0 commit comments

Comments
 (0)