-
Notifications
You must be signed in to change notification settings - Fork 635
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
Bulk data Endianness not retained when converting from dicom to XML and back #849
Comments
I did notice that the ContentHandlerAdapter uses the bigEndianness of the Attributes element passed into its constructor, so I tried setting that value based on the transfer syntax. |
You have to include the File Meta Information attributes - particularly (0002,0010) TransferSyntaxUID - into the XML representation! $ dcm2xml -I /tmp/src.dcm
<?xml version="1.0" encoding="UTF-8"?><NativeDicomModel xml:space="preserve">
<DicomAttribute keyword="FileMetaInformationVersion" tag="00020001" vr="OB">
<InlineBinary>AAE=</InlineBinary>
</DicomAttribute>
<DicomAttribute keyword="MediaStorageSOPClassUID" tag="00020002" vr="UI">
<Value number="1">1.2.840.10008.5.1.4.1.1.6.1</Value>
</DicomAttribute>
<DicomAttribute keyword="MediaStorageSOPInstanceUID" tag="00020003" vr="UI">
<Value number="1">1.2.840.1136190195280574824680000700.3.0.1.19970424140438</Value>
</DicomAttribute>
<DicomAttribute keyword="TransferSyntaxUID" tag="00020010" vr="UI">
<Value number="1">1.2.840.10008.1.2.2</Value>
</DicomAttribute>
... $ dcm2xml /tmp/src.dcm | xml2dcm -o /tmp/out.dcm -x - $ dcmdump -w110 /tmp/out.dcm
0: [0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
132: (0002,0000) UL #4 [204] FileMetaInformationGroupLength
144: (0002,0001) OB #2 [0\1] FileMetaInformationVersion
158: (0002,0002) UI #28 [1.2.840.10008.5.1.4.1.1.6.1] MediaStorageSOPClassUID
194: (0002,0003) UI #58 [1.2.840.1136190195280574824680000700.3.0.1.19970424140438] MediaStorageSOPInstanceUID
260: (0002,0010) UI #20 [1.2.840.10008.1.2.2] TransferSyntaxUID
... |
it is in the XML:
|
I don't see any code in the ContentHandlerAdapter that reads the transfer syntax from the XML though |
Could reproduce the issue. |
Is the expectation that I submit a PR for this bug or will someone who is more familiar with the library be able to take a look ?? We have a client that is blocked by this bug and in the short term I might have to provide a custom ContentHandlerAdapter in my code using the work-around that I've found. I can attempt to provide a proper solution and PR if someone could give me some pointers though. |
Fixed by permitting to pass public ContentHandlerAdapter(Attributes attrs) {
this(attrs, false);
}
public ContentHandlerAdapter(Attributes attrs, boolean lenient) {
... and - if so - defer creation of <DicomAttribute keyword="TransferSyntaxUID" tag="00020010" vr="UI">
<Value number="1">1.2.840.10008.1.2.2</Value>
</DicomAttribute> Add public Attributes getDataset() {
return items.getFirst();
} to access created |
thanks |
Hi @gunterze, I have loaded the 5.23.0 release and trying my code but it looks like I'm still running into the same issue. I am initializing my ContentHandlerAdapter like this now: final ContentHandlerAdapter contentHandler = new ContentHandlerAdapter(null, false); I am getting this error:
|
Should be fixed... (replaced binary distribution with fixed version and moved tag 5.23.0 in git) |
I am testing with the 5.23.0 jar files right now. And it's not working, I am getting the error I pasted above. I am trying to look at this library's source code to understand if it's something I'm doing wrong. But I can see if I pass in NULL into the ContentHandlerAdapter constructor, the first time a new Attribute object is added to the items variable, is probably inside startItem. But that will add an Attribute with bigEndian set to false, and it's a final field, so it's not going to change again. So according to my understanding, the ContentHandlerAdapter needs to know the bigEndian value before it starts adding Attribute values to the items field.
Also, when it is time to parse the bulkData element, it uses the bigEndian value of the previous element. Or am I missing something? |
Oh, i see you made a change. Ok, i'll download it from sourceforge and try again... |
ok that seems to work now. |
If I convert a dcm file to XML using the dcm4che library, and I set the setIncludeBulkData to IncludeBulkData.URI it saves the path to the original dcm file with an offset in the output XML.
But there is no bigEndian (true/false) sort of value.
The problem is, if I later try and convert the XML back to a dcm file, the output file is corrupted and the resulting images appear inverted (black and white colors switched).
Some image viewers have a mechanism to fix that, but I would have expected dcm to XML and XML to dcm to retain all information.
My code to convert DCM to XML is as follows:
And my code to convert XML back into DCM is as follows:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The final DCM image should not be inverted
I notice in the ContentHandlerAdapter class that when it reads the bulk data element, it sets its bigEndian value based on items.getLast().bigEndian().
I couldn't figure out why or what items.getLast() would be at this point, but this is where I would sort of expect it to read the big endian value from an attribute that was saved in the XML.
I tested my theory by creating my own SAXWriter and ContentHandlerAdapter classes where I set and read a bigEndian attribute on the BulkData element and it worked for my case.
I would be happy to create a PR for this, but not sure if that is the correct solution.
Maybe I'm missing something more obvious.
Thanks in advance.
The text was updated successfully, but these errors were encountered: