Skip to content

Commit

Permalink
using image patient position z axis to sort dicom
Browse files Browse the repository at this point in the history
  • Loading branch information
marshuang80 committed Feb 26, 2020
1 parent 2af3eee commit 13aeb13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test_from_dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ def main(args):
else:
args.gpu_ids = [int(args.gpu_ids)]

main(args)
main(args)
15 changes: 6 additions & 9 deletions util/single_study_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,16 @@ def dicom_2_npy(input_study, series_description):
return

# sort slices
dcm_slices_sorted = sorted(dcm_slices, key=lambda dcm: int(dcm.InstanceNumber))

# test using image patient location instead
#dcm_slices_sorted = sorted(dcm_slices, key=lambda dcm: int(dcm.InstanceNumber))
dcm_slices_sorted = sorted(dcm_slices, key=lambda dcm: int(dcm.ImagePositionPatient[-1]))
# save as npy_volume
npy_volume = np.array([dcm.pixel_array for dcm in dcm_slices_sorted])

# reverse volumne if patient position defer from standard
if dcm.PatientPosition == "FFS":
npy_volume = npy_volume[::-1]

# TODO: normalize numpy?
#npy_volume = np.interp(npy_volume, (npy_volume.min(), npy_volume.max()), (-3024, 3071))
#npy_volume[npy_volume > 3071] = 3071
#npy_volume[npy_volume < -3024] = -3024
# test using image patient location instead
#if dcm.PatientPosition == "FFS":
# npy_volume = npy_volume[::-1]

return npy_volume

Expand Down

0 comments on commit 13aeb13

Please sign in to comment.