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

Warn about precision loss when extracting values #155

Open
dgobbi opened this issue Jul 4, 2018 · 1 comment
Open

Warn about precision loss when extracting values #155

dgobbi opened this issue Jul 4, 2018 · 1 comment

Comments

@dgobbi
Copy link
Owner

dgobbi commented Jul 4, 2018

The vtkDICOMValue class has AsInt(), AsDouble(), AsString() etc. methods for extracting the value of a DICOM data element. This extraction can result in loss of precision. For example:

  • extracting 'DS' with AsDouble() or AsFloat() is inexact (decimal mantissa to binary mantissa)
  • extracting 'DS' with AsInt() results in truncation

Of course, the only lossless way to extract 'DS' is with AsString(), but that is not useful when the value is to be used as a number.

For each VR, each conversion can be characterized as:

  • exact
  • inexact (DS to floating-point)
  • loss of precision (truncation, or insufficient bits)
  • signed to unsigned or vice-versa
  • nonsensical (value not representable after conversion)

Whenever a conversion is not exact, it might be good to have a warning produced at runtime if the code is compiled in debug mode. The signed/unsigned is tricky because sometimes DICOM is hazy on 'US' vs. 'SS', e.g. for implicit VR it can depend on PixelRepresentation. Also, the first/third values in the lookup table descriptor are always to be interpreted as unsigned even if the VR is 'SS'.

@dgobbi
Copy link
Owner Author

dgobbi commented Jul 4, 2018

Of course, it would be better to report precision loss at compile time. For example, GDCM uses a template to map tags to VRs and from there to type and encoding: 'DS' has type 'double' and encoding 'ascii'. Philosophically, this is very different from vtk-dicom where the dictionary is simply a data structure. Architecturally, vtk-dicom uses metaprogramming only in its implementation, never in its interface.

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

1 participant