Skip to content

Commit

Permalink
quick fixes
Browse files Browse the repository at this point in the history
Former-commit-id: 5e118add39a6796a6d03d9c6729146981da7f44f
  • Loading branch information
skim2257 committed May 11, 2022
1 parent 65d66d2 commit 8ac1dfd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 48 deletions.
97 changes: 50 additions & 47 deletions imgtools/utils/crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,65 @@ def crawl_one(folder):

# instance (slice) information
for dcm in dicoms:
meta = dcmread(dcm)
patient = str(meta.PatientID)
study = str(meta.StudyInstanceUID)
series = str(meta.SeriesInstanceUID)
instance = str(meta.SOPInstanceUID)
try:
meta = dcmread(dcm, force=True)
patient = str(meta.PatientID)
study = str(meta.StudyInstanceUID)
series = str(meta.SeriesInstanceUID)
instance = str(meta.SOPInstanceUID)

reference_ct, reference_rs, reference_pl = " ", " ", " "
try: #RTSTRUCT
reference_ct = str(meta.ReferencedFrameOfReferenceSequence[0].RTReferencedStudySequence[0].RTReferencedSeriesSequence[0].SeriesInstanceUID)
except:
try: #RTDOSE
reference_rs = str(meta.ReferencedStructureSetSequence[0].ReferencedSOPInstanceUID)
except:
pass
reference_ct, reference_rs, reference_pl = " ", " ", " "
try: #RTSTRUCT
reference_ct = str(meta.ReferencedFrameOfReferenceSequence[0].RTReferencedStudySequence[0].RTReferencedSeriesSequence[0].SeriesInstanceUID)
except:
try: #RTDOSE
reference_rs = str(meta.ReferencedStructureSetSequence[0].ReferencedSOPInstanceUID)
except:
pass
try:
reference_ct = str(meta.ReferencedImageSequence[0].ReferencedSOPInstanceUID)
except:
pass
try:
reference_pl = str(meta.ReferencedRTPlanSequence[0].ReferencedSOPInstanceUID)
except:
pass

try:
reference_ct = str(meta.ReferencedImageSequence[0].ReferencedSOPInstanceUID)
reference_frame = str(meta.FrameOfReferenceUID)
except:
pass
try:
reference_frame = str(meta.ReferencedFrameOfReferenceSequence[0].FrameOfReferenceUID)
except:
reference_frame = ""

try:
reference_pl = str(meta.ReferencedRTPlanSequence[0].ReferencedSOPInstanceUID)
study_description = str(meta.StudyDescription)
except:
pass

try:
reference_frame = str(meta.FrameOfReferenceUID)
except:
study_description = ""

try:
reference_frame = str(meta.ReferencedFrameOfReferenceSequence[0].FrameOfReferenceUID)
series_description = str(meta.SeriesDescription)
except:
reference_frame = ""

try:
study_description = str(meta.StudyDescription)
except:
study_description = ""
series_description = ""

try:
series_description = str(meta.SeriesDescription)
if patient not in database:
database[patient] = {}
if study not in database[patient]:
database[patient][study] = {'description': study_description}
if series not in database[patient][study]:
database[patient][study][series] = {'instances': [],
'instance_uid': instance,
'modality': meta.Modality,
'description': series_description,
'reference_ct': reference_ct,
'reference_rs': reference_rs,
'reference_pl': reference_pl,
'reference_frame': reference_frame,
'folder': path}
database[patient][study][series]['instances'].append(instance)
except:
series_description = ""

if patient not in database:
database[patient] = {}
if study not in database[patient]:
database[patient][study] = {'description': study_description}
if series not in database[patient][study]:
database[patient][study][series] = {'instances': [],
'instance_uid': instance,
'modality': meta.Modality,
'description': series_description,
'reference_ct': reference_ct,
'reference_rs': reference_rs,
'reference_pl': reference_pl,
'reference_frame': reference_frame,
'folder': path}
database[patient][study][series]['instances'].append(instance)
pass

return database

Expand Down
2 changes: 1 addition & 1 deletion imgtools/utils/imageutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def physical_points_to_idxs(image, points, continuous=False):

vectorized_transform = np.vectorize(lambda x: np.array(transform(x)), signature='(3)->(3)')

# transformed points, ContourSequence/Data-wise
# transform indices to ContourSequence/ContourData-wise
t_points = []
for slc in points:
t_points.append(vectorized_transform(slc)[:,::-1])
Expand Down

0 comments on commit 8ac1dfd

Please sign in to comment.