Skip to content
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

save as the dicom but doesn't show in dicompyler or other software #821

Closed
wangjiangyuan opened this issue Mar 15, 2019 · 36 comments
Closed
Labels

Comments

@wangjiangyuan
Copy link

wangjiangyuan commented Mar 15, 2019

Description

I created a dicom file in pydicom,
I used the code to write.
I wrote the dicom file in pydicom as that message and it is showed in pydicom as follow:
The dicom file just 79 kb, I don't know how to get a correct format.
Please help me,thanks
code:

    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = RS_SOPInstanceUID
    file_meta.MediaStorageSOPInstanceUID = "RT Structure Set Storage"
    file_meta.TransferSyntaUID='Explicit VR Little Endian'
    file_meta.ImplementationClassUID = "1.2.250.1.59.3.0.3.3.1"
    RT_imageStorage = FileDataset(save_path, {},
                 file_meta=file_meta, preamble=b"\0" * 128)
    RT_imageStorage.SpecificCharacterSet=CT.SpecificCharacterSet
    RT_imageStorage.InstanceCreationDate=InstanceCreationDate
    RT_imageStorage.InstanceCreationTime=InstanceCreationTime
    RT_imageStorage.SOPClassUID='RT Structure Set Storage'
    RT_imageStorage.SOPInstanceUID= RS_SOPInstanceUID
    RT_imageStorage.StudyDate=CT.StudyDate
    RT_imageStorage.StudyTime=CT.StudyTime
    RT_imageStorage.AccessionNumber=''
    RT_imageStorage.Modality='RTSTRUCT
    RT_imageStorage.is_little_endian = False
    RT_imageStorage.is_implicit_VR = False
    RT_imageStorage.save_as('/public/home/write2dcm/123/test/1234.dcm')'

(3006, 002a) ROI Display Color IS: ['0', '147', '0']
(3006, 0040) Contour Sequence 12 item(s) ----
(3006, 0016) Contour Image Sequence 1 item(s) ----
(0008, 1150) Referenced SOP Class UID UI: CT Image Storage
(0008, 1155) Referenced SOP Instance UID UI: 1.3.6.1.4.1.2452.6.3054396209.xxxxxxxx.1983321519.xxxxxxxxx
---------
(3006, 0042) Contour Geometric Type CS: 'CLOSED_PLANAR'
(3006, 0046) Number of Contour Points IS: "58"
(3006, 0048) Contour Number IS: "1"
(3006, 0050) Contour Data DS: ['24.671679', '-57.148172', '31.000000', '25.532824', '-57.054517', '31.000000', '26.378794', '-56.868305', '31.000000', '27.199673', '-56.591719', '31.000000', '27.985835', '-56.228001', '31.000000', '28.728064', '-55.781417', '31.000000', '29.417658', '-55.257201', '31.000000', '30.046531', '-54.661501', '31.000000', '30.607312', '-54.001299', '31.000000', '31.093425', '-53.284336', '31.000000', '31.499171', '-52.519018', '31.000000', '31.819793', '-51.714317', '31.000000', '32.051532', '-50.879669', '31.000000', '32.191671', '-50.024857', '31.000000', '32.238568', '-49.159905', '31.000000', '32.191671', '-48.294953', '31.000000', '32.051532', '-47.440141', '31.000000', '31.819793', '-46.605493', '31.000000', '31.499171', '-45.800792', '31.000000', '31.093425', '-45.035474', '31.000000', '30.607312', '-44.318511', '31.000000', '30.046531', '-43.658309', '31.000000', '29.417658', '-43.062609', '31.000000', '28.728064', '-42.538393', '31.000000', '27.985835', '-42.091809', '31.000000', '27.199673', '-41.728091', '31.000000', '26.378794', '-41.451505', '31.000000', '25.532824', '-41.265293', '31.000000', '24.671679', '-41.171638', '31.000000', '23.805456', '-41.171638', '31.000000', '22.944312', '-41.265293', '31.000000', '22.098341', '-41.451505', '31.000000', '21.277462', '-41.728091', '31.000000', '20.491300', '-42.091809', '31.000000', '19.749071', '-42.538393', '31.000000', '19.059477', '-43.062609', '31.000000', '18.430604', '-43.658309', '31.000000', '17.869823', '-44.318511', '31.000000', '17.383710', '-45.035474', '31.000000', '16.977964', '-45.800792', '31.000000', '16.657342', '-46.605493', '31.000000', '16.425603', '-47.440141', '31.000000', '16.285464', '-48.294953', '31.000000', '16.238568', '-49.159905', '31.000000', '16.285464', '-50.024857', '31.000000', '16.425603', '-50.879669', '31.000000', '16.657342', '-51.714317', '31.000000', '16.977964', '-52.519018', '31.000000', '17.383710', '-53.284336', '31.000000', '17.869823', '-54.001299', '31.000000', '18.430604', '-54.661501', '31.000000', '19.059477', '-55.257201', '31.000000', '19.749071', '-55.781417', '31.000000', '20.491300', '-56.228001', '31.000000', '21.277462', '-56.591719', '31.000000', '22.098341', '-56.868305', '31.000000', '22.944312', '-57.054517', '31.000000', '23.805456', '-57.148172', '31.000000']

Steps/Code to Reproduce

Expected Results

Actual Results

Versions

@scaramallion
Copy link
Member

scaramallion commented Mar 15, 2019

Could you explain in a bit more detail what problem you're having?

Also "RT Structure Set Storage" is not a valid UID

@wangjiangyuan
Copy link
Author

Hello, thank your reply.
I wanna get a RT- dicom file from CT's, and I want to see the mask.
I write codes for that by pydicom and it can export tags and value successful in pydicom.dcmread.
The RT-Dicom file just 73kb and can't show in the windows 2D dicom software, it is also said "unvailble dcm" in the dicompyler.
and I used the code to do the work.

@wangjiangyuan
Copy link
Author

Here is the RT-dicom file.

@mrbean-bremen
Copy link
Member

file_meta.MediaStorageSOPClassUID = RS_SOPInstanceUID

This is certainly not right - this is the SOPClassUID, not the SOPInstanceUID

file_meta.MediaStorageSOPInstanceUID = "RT Structure Set Storage"

As has been already mentioned, you need a UID here ('1.2.840.10008.5.1.4.1.1.481.3' in this case)

file_meta.TransferSyntaUID='Explicit VR Little Endian'

Same here, use pydicom.uid.ExplicitVRLittleEndian instead

RT_imageStorage.SOPClassUID='RT Structure Set Storage'

Same as above.

RT_imageStorage.is_little_endian = False

Are you sure you want to write BigEndian data? This is deprecated in DICOM for a long time now

RT_imageStorage.save_as('/public/home/write2dcm/123/test/1234.dcm')'

So where's the actual RTStruct data coming from?
I'm not sure what you are trying to accomplish. As I understand, you want to visualize some RTStruct data, but I don't understand where you getting it from. The dump you added in your original post seems like a valid RTStruct - is that what you have created, or is it the source?
Please explain a bit more what is your objective here.

@wangjiangyuan
Copy link
Author

I did the work for CT-image segmentation, and I have lots of CT image from my partner who is a imaging doctor.
I trained some deep-learning model to get the ContourData, and we'd like to creat a new RTStruct file. The code is too long so I pasted the main code. I don't know what wrong with it, it seems like a valid file. I can provide the whole code if possible.

@mrbean-bremen
Copy link
Member

It would help if you could attach the problematic file - I think you intented to, but the file did not get attached.

@wangjiangyuan
Copy link
Author

Here is my whole code.
Thank you very much.

@wangjiangyuan
Copy link
Author

Could you get the file? I am not sure it is upload successfully.

@mrbean-bremen
Copy link
Member

There is nothing uploaded yet.
The created RTStruct file would be interesting to see, to check what is wrong with it first.

@wangjiangyuan
Copy link
Author

wangjiangyuan commented Mar 16, 2019

[non-anonymised data removed - scaramallion]

Yeah, It is successful to upload.
There are my code and file.

@mrbean-bremen
Copy link
Member

Ok, this time it worked. At a first glance, the DICOM file is at least readable, though it seems to have the incorrect SOPClassUID (CTImageStorage instead of RTStructureSetStorage). I will have another look later.

@mrbean-bremen
Copy link
Member

Ok, and the MediaStorageSOPClassUID and MediaStorageSOPInstanceUID are reversed, as I already mentioned above. The rest of the tags looks look ok to me (given that the referenced UIDs are correct, of course).
Maybe you try to fix these errors (MediaStorageSOPClassUID , MediaStorageSOPInstanceUID and SOPClassUID) first and check if that works.

Also, I don't know what Windows 2D software you are using - if this is software to handle RT Structure Sets, it should work, otherwise, RTStructs have no pixel data, so there can be no images shown.
I don't know dicompyler (haven't worked with RT data myself), but maybe there is a more specific error message. "Unavailable DICOM" could for example relate to the unavailability of the referenced CT data, but that is just a wild guess.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Mar 16, 2019

Ah, and also don't use Big Endian - use Little Endian instead (as mentioned above), I'm not sure if all software still supports Big Endian data.

@bastula
Copy link
Contributor

bastula commented Mar 16, 2019 via email

@wangjiangyuan
Copy link
Author

wangjiangyuan commented Mar 17, 2019

There are the CT image and RS(5.6M in '2013-03-12 2013.28. npc' dir) from doctor and RTSTRUCT (57K) I created. And I want to show the mask wrote in ContourData like RS file.

[non-anonymised dataset removed - scaramallion]

@mrbean-bremen
Copy link
Member

So, did you make the changes?

@wangjiangyuan
Copy link
Author

RTSTRUCT(57K) is the new dicom test file that predicted by our models. And what is your 'changes' refer to

@mrbean-bremen
Copy link
Member

Maybe you try to fix these errors (MediaStorageSOPClassUID , MediaStorageSOPInstanceUID and SOPClassUID) first and check if that works.

I mean this.

@wangjiangyuan
Copy link
Author

yeah, I have done that.

file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.2'
file_meta.MediaStorageSOPInstanceUID = "1.2.840.10008.5.1.4.1.1.481.3"
file_meta.TransferSyntaUID=pydicom.uid.ExplicitVRLittleEndian

file_meta.ImplementationClassUID = "1.2.250.1.59.3.0.3.3.1"
RT_ReferencedStudySequence.ReferencedSOPClassUID='1.2.840.10008.3.1.2.3.2'

I have made the changges,but there is still the error.
1552810724(1)

@wangjiangyuan
Copy link
Author

wangjiangyuan commented Mar 17, 2019

The figure 1 is my created RT file opend with Notepad++. Figure 2 is the doctor's file

[non-anonymised data removed - scaramallion]

@mrbean-bremen
Copy link
Member

Ah ok, this is a more concrete error, thanks. Looks like something is still wrong in the meta header. I will have a closer later.

@wangjiangyuan
Copy link
Author

I also use the doctor's RT file for the 'body', and I changed some message to 'create' the RT file. I can change the PatientID and other tag's value.When I change the Sequence such as ReferencedFrameOfReferenceSequence, something will be wrong.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Mar 17, 2019

Ok, I had another look, and still not sure what's wrong in the file meta. Apart from a missing group length, and the problems I already mentioned (which you have appearently fixed), I don't see anything looking too wrong. Can you please check which version of pydicom you are using? I can't relate the callstack in your comment to a version.
Maybe you can attach another version of the RTStruct file that causes the problem?

@bastula
Copy link
Contributor

bastula commented Mar 18, 2019

So there is a bug in the released version of dicompyler that doesn't read some malformed DICOM data. This was fixed in pydicom probably some time ago. However, using the latest source version of dicompyler in combination with pydicom, the data is able to be parsed and read successfully.

FYI, the data that has been uploaded has not been anonymized, so I would consider deleting it from the thread.

@wangjiangyuan
Copy link
Author

The version I used is 1.2.0.
And I try the version 1.1.0, there is still the error.

@scaramallion
Copy link
Member

@wangjiangyuan please don't upload non-anonymised data

@wangjiangyuan
Copy link
Author

@scaramallion Thank you for reminding me. I will delete it and upload the anonymised data.

@scaramallion
Copy link
Member

scaramallion commented Mar 18, 2019

I don't know what you used to anonymise the datasets but the results are non-conformant.

(0008,0018) UI [**]                                                 #   2, 1, SOPInstanceUID

Amongst many others

@bastula
Copy link
Contributor

bastula commented Mar 18, 2019

I think your file has the wrong SOPClassUID for the newly created RTSTRUCT. It should be set to 1.2.840.10008.5.1.4.1.1.481.3 which is for RT Structure Set Image Storage. Currently you have: 1.2.840.10008.5.1.4.1.1.2 which is for CT Image Storage.

@scaramallion
Copy link
Member

scaramallion commented Mar 18, 2019

And its still not anonymised completely, check the 1111/2013-03-12 2013.28. npc folder

@wangjiangyuan
Copy link
Author

Maybe I should use another soft to anonymise my datasets.

@bastula
Copy link
Contributor

bastula commented Mar 18, 2019

I forgot to mention, he/she did anonymize the data properly. They need to remove this file from the zip: RTSTRUCT_1.2.246.352.205.2613782019031612345.2613782148282148281.dcm

@scaramallion
Copy link
Member

scaramallion commented Mar 18, 2019

Almost all of the time when there have been issues like yours its because the dataset was non-conformant.

  1. Check the RT Structure Set IOD documentation and make sure you have all the mandatory modules (the ones with 'M' in Table A.19.3-1) and all the mandatory elements for those modules.
  2. Check your element values and make sure they match the required format for each Value Representation (VR).

For instance, if you have an element with a VR of 'UI' then its value must meet the requirements of the UI entry in Table 6.2-1 (ASCII characters '0-9' and '.', 64 maximum characters, no components starting with 0 unless the component itself is 0).

@mrbean-bremen
Copy link
Member

Argh - for some reason I was under the impression that these are fake patient data, should have noticed that!

@mrbean-bremen
Copy link
Member

@wangjiangyuan - did you get anywhere with your problem?

@darcymason
Copy link
Member

@wangjiangyuan, am closing this to try to clean up our issues list. If not resolved, please reopen.

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

No branches or pull requests

5 participants