-
-
Notifications
You must be signed in to change notification settings - Fork 691
Reading Dicom: Rescaling does not allow pixel format change #5290
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
Comments
Thank you for contributing an issue! 🙏 Welcome to the ITK community! 🤗👋☀️ We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜 This is an automatic message. Allow for time for the ITK community to be able to read the issue and comment on it. |
What happens if you replace this: |
@dzenanz unfortunately it changes nothing, I tried with a It seems in itkGDCMImageIO.cxx the output type is overwritten with scaling information, regardless what was provided as a template parameters |
@malaterre and @issakomi might have some opinion about this. |
I have created a test file and could reproduce the issue exactly as described above. Not sure what the lines should do if (pixeltype > outputpt)
{
itkAssertInDebugOrThrowInReleaseMacro("Pixel type larger than output type")
} There is no The rest seems to be just fine, Rescaler calculated the correct format. |
Maybe explicitly handle discrepancy between bits stored and bits allocated, and remove this assert? |
In the first version f00506b there was the Edit:
I also saw the comment in the #1882:
I don't understand what "out-of-sync" means and how this comparison can prevent it. BTW, in this particular example the input type is signed short, the output type is unsigned short, this is unusual (but not necessarily a mistake) and not "larger". |
@issakomi I know the data set is unusual but it is not a mistake, we had a manufacturer that produced this kind of files for X-rays (that are strictly positive values) (yes, they could have written with a Pixel Representation of 0 (unsigned), but they did not). From the compiler pov, yes I am fairly certain the If I understand correctly ideally this check shall be replaced with a another check that still verifies the sanity of the data, without blocking this situation? I can remove this assert locally and change for a test such as following in my local clone of ITK, but I would not feel confident enough to submit a PR of this. bool ptLarger = false;
switch (outputpt)
{
case gdcm::PixelFormat::UINT8:
ptLarger = pixeltype > gdcm::PixelFormat::INT8;
break;
case gdcm::PixelFormat::UINT12:
ptLarger = pixeltype > gdcm::PixelFormat::INT12;
break;
case gdcm::PixelFormat::UINT16:
ptLarger = pixeltype > gdcm::PixelFormat::INT16;
break;
case gdcm::PixelFormat::UINT32:
ptLarger = pixeltype > gdcm::PixelFormat::INT32;
break;
case gdcm::PixelFormat::UINT64:
ptLarger = pixeltype > gdcm::PixelFormat::INT64;
break;
default:
ptLarger = pixeltype > outputpt;
break;
}
if (ptLarger )
{
itkAssertInDebugOrThrowInReleaseMacro("Pixel type larger than output type")
} Also do you think there can later be issues with buffer size while reading the data later because of ignoring this check? |
IMHO, this exception and assert could have been removed. It was just an |
The original |
@PtiLuky do you want to give it a try? |
Uhm, my best guess would be the snippet I proposed above, using just the "bitsAllocated" would allow to cast f32 into i32, so testing explicitly the values for I don't specially want to be the author of this contribution since I'm not very familiar with the whole contribution workflow of this repo. But if nobody wants to take it, I can have a look. |
Description
I have a dicom image stored as short, which has a rescaling into the "unsigned short" domain that cannot be loaded with ITK.
When
itk::GDCMImageIO::ReadImageInformation
is called, there is an exception raised"Pixel type larger than output type"
.Steps to Reproduce
High level snippet:
Minimal code snippet:
This is also reproducible with the code taken directly from
void GDCMImageIO::InternalReadImageInformation()
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/GDCM/src/itkGDCMImageIO.cxx#L538Expected behavior
Load image correctly without any exception. Like in other readers such as VTK or MicroDicom.
Actual behavior
Exception raised
"Pixel type larger than output type"
.Printed logs:
Reproducibility
All the time given the problematic input image.
Versions
Currently testing with 5.2.1, but I see the problematic check still done in master branch.
Environment
Windows 10, MSVC
Additional Information
I do not see any reason for this check to be done, it means if my stored data is int32 and I have a rescale/slope that project the result into a int8 range itk raises an error? I see nothing wrong with that...
Would there be any workaround other than removing the rescaling from the tags, load the image, and then reapply it manually afterward?
The text was updated successfully, but these errors were encountered: