Skip to content

How can I distinguish several different DICOM series which in a same directory? #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Williamongh opened this issue Apr 10, 2018 · 4 comments

Comments

@Williamongh
Copy link

Williamongh commented Apr 10, 2018

Thanks for your work and share.
Here I have several different DICOM series, they are all in a same directory. I want to use these code to identify different DICOM image:

imageReader = sitk.ImageSeriesReader()
dicom_names = imageReader.GetGDCMSeriesFileNames(path)
print(dicom_names )

Then I found I can only get the first image.
I wonder how can I identify them, and get the right image I want?
Thank you !

@zivy
Copy link
Member

zivy commented Apr 10, 2018

You will first need to get the list of series ids in the directory:
series_ids = imageReader.GetGDCMSeriesIDs(path)

Then you select the relevant series (somehow), and get the specific file names associated with it:

i=3
imageReader.GetGDCMSeriesFileNames(path, series_ids[i])

For an example with a dropbox see this Jupyter notebook.

You may be interested in the examples shown in the notebooks in general, see the main notebook repository.

@Williamongh
Copy link
Author

Thanks a lot! It works!
BTW, here is a new question. After I read a DICOM series, I want get the meta data with it:

imageReader= sitk.ImageSeriesReader()
imageReader.LoadPrivateTagsOn()
series_ids = imageReader.GetGDCMSeriesIDs(path)
series_file_names = imageReader.GetGDCMSeriesFileNames(path, series_ids [0])
imageReader.SetFileNames(series_file_names)
image = imageReader.Execute()  # type: sitk.Image
print(image.GetMetaDataKeys())

But it returns an empty list, what should I do?
Thank you !

@zivy
Copy link
Member

zivy commented Apr 11, 2018

Three points:

  1. In SimpleITK, the returned image will not have a meta data dictionary - rationale: this is most often a 3D image where each of the 2D images from which it was created had a separate meta-data dictionary. We can't know how to combine them together (there is slice specific information in each).

  2. To access the meta-data keys and information on a per-slice basis you have three functions, as illustrated below:

slice_number = 0
slice_keys = imageReader.GetMetaDataKeys (slice_number) 
imageReader.HasMetaDataKey(slice_number, '0010|0010')
imageReader.GetMetaData(slice_number, '0010|0010')
  1. You are missing a line before "LoadPrivateTagsOn" which tells the reader to actually load the tags:
    imageReader.MetaDataDictionaryArrayUpdateOn()

@Williamongh
Copy link
Author

Thank you for your time. It helps a lot!
I've solved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants