Skip to content

Commit

Permalink
BUG in md.ai: series with different ids are merged
Browse files Browse the repository at this point in the history
```
dicom_dir = "/path/mdai_uab_project_7YNdkRbz_images_dataset_D_vbqBVJ_2023-12-05-204930/2.25.110967036091011695929745405069706570938/2.25.5167441598658014961040621600906584607"
io = itk.GDCMSeriesFileNames.New()
io.AddSeriesRestriction("0008|0021")
io.SetUseSeriesDetails(True)
io.SetDirectory(str(dicom_dir))
io.Update()

series_uids = io.GetSeriesUIDs()
print(series_uids)
```

Gives two different series:
('2.25.5167441598658014961040621600906584607.2016051021.250000512512',
 '2.25.5167441598658014961040621600906584607.2016051022.500000512512')

Where md.ai treat those as a single series_uid:
`2.25.5167441598658014961040621600906584607`

To workaround it, we log an error asking the user to solve it, but pick
the series with more number of files.
Chances are that the different serie id comes from a summary image.
  • Loading branch information
phcerdan committed Dec 21, 2023
1 parent c46c8c2 commit 7bf64c8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions mdai_utils/download_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,29 @@ def get_dicom_names_ordered_and_metadata(dicom_dir):

series_uids = io.GetSeriesUIDs()

selected_index = 0
if len(series_uids) == 0:
raise ValueError(f"Found no series in folder: {dicom_dir}")
elif len(series_uids) > 1:
raise ValueError(f"Found more than one series in the same folder: {dicom_dir}")
series_id = series_uids[0]
error_msg = f"""Found more than one series in the same folder: {dicom_dir}.
Probably BUG in md.ai, which is merging different series_ids into one."""
num_files = []
for index, s in enumerate(series_uids):
files = io.GetFileNames(s)
len_files = len(files)
num_files.append(len_files)
error_msg += f"\nSeries {index}: {s} with {len_files} files"
# Select the index with more files:
selected_index = np.argmax(num_files)
error_msg += (
f"\nSelected series {selected_index} with {num_files[selected_index]} files"
)
error_msg += (
"\nPlease fix it in md.ai to avoid this warning and clean the dataset."
)
logger.error(error_msg)

series_id = series_uids[selected_index]
# Ordered by z position
dicom_names_ordered = io.GetFileNames(series_id)
# Get also SOPInstanceUID for each file
Expand Down

0 comments on commit 7bf64c8

Please sign in to comment.