Skip to content

Commit

Permalink
customize common DICOM tags
Browse files Browse the repository at this point in the history
  • Loading branch information
constracti committed May 13, 2019
1 parent 97ae697 commit 8575bc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nifti2dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def nifti2dicom(path):
shape = nifti.get_shape()
# prepare DICOM pixel data by transposing NIfTI data
data = numpy.asarray(nifti.dataobj).swapaxes(0, 1)
# customize common DICOM dataset
# customize common DICOM tags
dataset.ProtocolName = re.sub("\.nii(?:\.gz)$", "", os.path.split(niftipath)[-1], flags=re.I)
dataset.SeriesInstanceUID = pydicom.uid.generate_uid()
# save DICOM files
Expand Down
9 changes: 9 additions & 0 deletions nifti2dicom2.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def nifti2dicom(path):
if not numpy.all(shape == nifti.get_shape()):
print("skipping NIfTI file: incompatible shape")
continue
# customize common DICOM tags
protocol_name = re.sub("\.nii(?:\.gz)$", "", os.path.split(niftipath)[-1], flags=re.I)
series_instance_uid = pydicom.uid.generate_uid()
# prepare DICOM pixel data by transposing NIfTI data
data = numpy.asarray(nifti.dataobj).swapaxes(0, 1)
# save DICOM files
Expand Down Expand Up @@ -67,6 +70,12 @@ def nifti2dicom(path):
jbeg, jend = jbeg + jinc, jend + jinc
else:
data_slice = data[:, :, dicomcnt]
# (0x0018, 0x1030) Protocol Name
if (0x0018, 0x1030) in dataset:
dataset[0x0018, 0x1030].value = protocol_name
# (0x0020, 0x000e) Series Instance UID
if (0x0020, 0x000e) in dataset:
dataset[0x0020, 0x000e].value = series_instance_uid
# (0x0028, 0x0106) Smallest Image Pixel Value
if (0x0028, 0x0106) in dataset:
dataset[0x0028, 0x0106].value = data_slice.min()
Expand Down

0 comments on commit 8575bc6

Please sign in to comment.