changeset 4975:5e7404f23fa8

Improved decoding of US Images with Implicit VR
author Alain Mazy <am@osimis.io>
date Wed, 13 Apr 2022 10:51:22 +0200
parents fcdf399f9fc0
children 03632ed1eb67 8b95fc86b8d9
files NEWS OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp
diffstat 2 files changed, 31 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Apr 08 11:48:54 2022 +0200
+++ b/NEWS	Wed Apr 13 10:51:22 2022 +0200
@@ -1,6 +1,12 @@
 Pending changes in the mainline
 ===============================
 
+General
+-------
+
+* Improved decoding of US Images with Implicit VR.
+
+
 
 Version 1.10.1 (2022-03-23)
 ===========================
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Fri Apr 08 11:48:54 2022 +0200
+++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Wed Apr 13 10:51:22 2022 +0200
@@ -437,12 +437,35 @@
         if (r != "256\\0\\16" ||
             rc != 256 ||
             gc != 256 ||
-            bc != 256 ||
-            pixelLength != target->GetWidth() * target->GetHeight())
+            bc != 256)
         {
           throw OrthancException(ErrorCode_NotImplemented);
         }
 
+        if (pixelLength != target->GetWidth() * target->GetHeight())
+        {
+          DcmElement *elem;
+          Uint16 bitsAllocated = 0;
+
+          if (!dataset.findAndGetUint16(DCM_BitsAllocated, bitsAllocated).good())
+          {
+            throw OrthancException(ErrorCode_NotImplemented);  
+          }
+
+          if (!dataset.findAndGetElement(DCM_PixelData, elem).good())
+          {
+            throw OrthancException(ErrorCode_NotImplemented);  
+          }
+
+          // In implicit VR files, pixelLength is expressed in words (OW) although pixels can actually be 8 bits
+          // -> pixelLength is wrong by a factor of two and the image can still be decoded!
+          // seen in some Philips ClearVue 650 images (using 8 bits LUT)
+          if (!(elem->getVR() == EVR_OW && bitsAllocated == 8 && (2*pixelLength == target->GetWidth() * target->GetHeight())))  
+          {
+            throw OrthancException(ErrorCode_NotImplemented);
+          }
+        }
+
         const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData);
         const unsigned int width = target->GetWidth();
         const unsigned int height = target->GetHeight();