Skip to content

Commit

Permalink
Add Frame Group information to DICOM
Browse files Browse the repository at this point in the history
  • Loading branch information
lamyj committed Jul 12, 2018
1 parent 87fabb0 commit bedcddc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/cli/bruker2dicom
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ def main():
default="ImplicitVRLittleEndian",
help="Transfer syntax of the output files"
)
convert_parser.add_argument(
"--multiframe", "-m", action="store_true",
help="Generate multiframe dicom files"
)
# Disabled in order to correctly store the Frame Group index: since some
# frame groups are empty (i.e. in VisuFGOrderDesc one where the last value
# is 0), we store the Frame Group index in Contributing Equipment Sequence;
# however, this is per-instance and no frame-level element exist to match
# this.
# convert_parser.add_argument(
# "--multiframe", "-m", action="store_true",
# help="Generate multiframe dicom files"
# )
convert_parser.add_argument(
"--dicomdir", "-d", action="store_true", help="Create a DICOMDIR")
convert_parser.add_argument(
Expand All @@ -57,6 +62,7 @@ def main():
convert_parser.set_defaults(function=convert)

arguments = vars(parser.parse_args())
arguments["multiframe"] = False # cf. previous comment

if "function" not in arguments:
parser.error("too few arguments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ def _get_frame_groups(data_set):
frame_groups = []
for description in data_set.get("VisuFGOrderDesc", []):
frame_count, name, _, begin, fields_count = description
fields = [x[0] for x in data_set["VisuGroupDepVals"][begin:begin+fields_count]]
if fields_count == 0:
fields = []
else:
fields = [
x[0] for x in
data_set["VisuGroupDepVals"][begin:begin+fields_count]]
frame_groups.append([frame_count, name]+[fields])
# CAUTION: the frame groups are listed in innermost-to-outermost
# order, while FrameIndexGenerator uses outermost-to-innermost order.
Expand Down
23 changes: 21 additions & 2 deletions src/python/dicomifier/bruker_to_dicom/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#########################################################################

import datetime
import json
import re

import numpy
Expand Down Expand Up @@ -192,6 +193,23 @@ def _get_geometry_of_kSpace_traversal(data_set, generator, frame_index):
else:
return None

def _get_frame_index(bruker_data_set, generator, frame_index):
purpose = odil.DataSet()
purpose.add("CodeValue", ["109102"])
purpose.add("CodingSchemeDesignator", ["DCM"])
purpose.add("CodeMeaning", ["Processing Equipment"])

data_set = odil.DataSet()
data_set.add("PurposeOfReferenceCodeSequence", [purpose])
data_set.add("Manufacturer", ["Dicomifier"])
data_set.add("ManufacturerModelName", ["Bruker Frame Group index"])
contribution = [
[fg[1], frame_index[i]]
for i, fg in enumerate(generator.frame_groups)
if fg[1] != 'FG_SLICE']
data_set.add("ContributionDescription", [json.dumps(contribution)])

return data_set

GeneralImage = [ # http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.html#sect_C.7.6.1
(None, "InstanceNumber", 2, lambda d,g,i: [1+g.get_linear_index(i)], None),
Expand Down Expand Up @@ -355,12 +373,13 @@ def _get_geometry_of_kSpace_traversal(data_set, generator, frame_index):
]

SOPCommon = [ # http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.12.html#sect_C.12.1
# Will be add further in the converting function (mr_image_storage or enhanced_mr_image_storage)
# (None, "SOPClassUID", 1, lambda d,g,i: [odil.registry.MRImageStorage], None),
(None, "SOPInstanceUID", 1, lambda d,g,i: [odil.generate_uid()], None),
#SpecificCharacterSet
(None, "InstanceCreationDate", 3, lambda d,g,i: [str(datetime.datetime.now())], None),
(None, "InstanceCreationTime", 3, lambda d,g,i: [str(datetime.datetime.now())], None),
(
None, "ContributingEquipmentSequence", 3,
lambda d,g,i: [_get_frame_index(d,g,i)], None)
]


Expand Down

0 comments on commit bedcddc

Please sign in to comment.