comparison OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp @ 5323:138e9d0c08c1

added DicomMap::GuessPixelDataValueRepresentation()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 25 Jun 2023 12:29:39 +0200
parents a904a4caf5b7
children 303e930fff0f
comparison
equal deleted inserted replaced
5322:a904a4caf5b7 5323:138e9d0c08c1
74 #include "FromDcmtkBridge.h" 74 #include "FromDcmtkBridge.h"
75 #include "Internals/DicomFrameIndex.h" 75 #include "Internals/DicomFrameIndex.h"
76 #include "Internals/DicomImageDecoder.h" 76 #include "Internals/DicomImageDecoder.h"
77 #include "ToDcmtkBridge.h" 77 #include "ToDcmtkBridge.h"
78 78
79 #include "../DicomFormat/DicomImageInformation.h"
79 #include "../Images/Image.h" 80 #include "../Images/Image.h"
80 #include "../Images/ImageProcessing.h" 81 #include "../Images/ImageProcessing.h"
81 #include "../Images/PamReader.h" 82 #include "../Images/PamReader.h"
82 #include "../Logging.h" 83 #include "../Logging.h"
83 #include "../OrthancException.h" 84 #include "../OrthancException.h"
2177 } 2178 }
2178 2179
2179 2180
2180 ValueRepresentation ParsedDicomFile::GuessPixelDataValueRepresentation() const 2181 ValueRepresentation ParsedDicomFile::GuessPixelDataValueRepresentation() const
2181 { 2182 {
2182 /**
2183 * This approach is validated in "Tests/GuessPixelDataVR.py":
2184 * https://hg.orthanc-server.com/orthanc-tests/file/tip/Tests/GuessPixelDataVR.py
2185 **/
2186
2187 DicomTransferSyntax ts; 2183 DicomTransferSyntax ts;
2188 if (LookupTransferSyntax(ts)) 2184 if (LookupTransferSyntax(ts))
2189 { 2185 {
2190 if (ts == DicomTransferSyntax_LittleEndianExplicit || 2186 DcmItem& dataset = *GetDcmtkObjectConst().getDataset();
2191 ts == DicomTransferSyntax_BigEndianExplicit) 2187
2192 { 2188 uint16_t bitsAllocated;
2193 /** 2189 if (!dataset.findAndGetUint16(DCM_BitsAllocated, bitsAllocated).good())
2194 * Same rules apply to Little Endian Explicit and Big Endian 2190 {
2195 * Explicit (now retired). The VR of the pixel data directly 2191 bitsAllocated = 8;
2196 * depends upon the "Bits Allocated (0028,0100)" tag: 2192 }
2197 * https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_A.2.html 2193
2198 * https://dicom.nema.org/medical/dicom/2016b/output/chtml/part05/sect_A.3.html 2194 return DicomImageInformation::GuessPixelDataValueRepresentation(ts, bitsAllocated);
2199 **/
2200 DcmItem& dataset = *GetDcmtkObjectConst().getDataset();
2201
2202 uint16_t bitsAllocated;
2203 if (dataset.findAndGetUint16(DCM_BitsAllocated, bitsAllocated).good() &&
2204 bitsAllocated > 8)
2205 {
2206 return ValueRepresentation_OtherWord;
2207 }
2208 else
2209 {
2210 return ValueRepresentation_OtherByte;
2211 }
2212 }
2213 else if (ts == DicomTransferSyntax_LittleEndianImplicit)
2214 {
2215 // Assume "OW" for DICOM Implicit VR Little Endian Transfer Syntax
2216 // https://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_A.html#sect_A.1
2217 return ValueRepresentation_OtherWord;
2218 }
2219 else
2220 {
2221 // Assume "OB" for all the compressed transfer syntaxes
2222 // https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_A.4.html
2223 return ValueRepresentation_OtherByte;
2224 }
2225 } 2195 }
2226 else 2196 else
2227 { 2197 {
2228 // Assume "OB" if the transfer syntax is unknown 2198 // Assume "OB" if the transfer syntax is unknown
2229 return ValueRepresentation_OtherByte; 2199 return ValueRepresentation_OtherByte;