comparison OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 5322:a904a4caf5b7

unit testing ParsedDicomFile::GuessPixelDataValueRepresentation()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 25 Jun 2023 11:48:47 +0200
parents f2e1ad71e49c
children 138e9d0c08c1
comparison
equal deleted inserted replaced
5321:5fae323b11ed 5322:a904a4caf5b7
3262 ASSERT_EQ("OW", visitor.GetResult() [PIXEL_DATA]["vr"].asString()); 3262 ASSERT_EQ("OW", visitor.GetResult() [PIXEL_DATA]["vr"].asString());
3263 } 3263 }
3264 } 3264 }
3265 3265
3266 3266
3267 #include "../Sources/DicomFormat/DicomArray.h"
3268 TEST(ParsedDicomFile, RemoveFromPixelData) 3267 TEST(ParsedDicomFile, RemoveFromPixelData)
3269 { 3268 {
3270 ParsedDicomFile dicom(true); 3269 ParsedDicomFile dicom(true);
3271 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString(DcmTag(0x7fe0, 0x0000), "").good()); 3270 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString(DcmTag(0x7fe0, 0x0000), "").good());
3272 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString(DcmTag(0x7fe0, 0x0009), "").good()); 3271 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString(DcmTag(0x7fe0, 0x0009), "").good());
3306 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0000)); 3305 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0000));
3307 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0009)); 3306 ASSERT_TRUE(m.HasTag(0x7fe0, 0x0009));
3308 ASSERT_FALSE(m.HasTag(DICOM_TAG_PIXEL_DATA)); 3307 ASSERT_FALSE(m.HasTag(DICOM_TAG_PIXEL_DATA));
3309 ASSERT_FALSE(m.HasTag(0x7fe0, 0x0011)); 3308 ASSERT_FALSE(m.HasTag(0x7fe0, 0x0011));
3310 ASSERT_FALSE(m.HasTag(0x7fe1, 0x0000)); 3309 ASSERT_FALSE(m.HasTag(0x7fe1, 0x0000));
3310 }
3311 }
3312
3313
3314 TEST(ParsedDicomFile, GuessPixelDataValueRepresentation)
3315 {
3316 typedef std::list< std::pair<E_TransferSyntax, DicomTransferSyntax> > Syntaxes;
3317
3318 // Create a list of the main non-retired transfer syntaxes, from:
3319 // https://www.dicomlibrary.com/dicom/transfer-syntax/
3320 Syntaxes compressedSyntaxes;
3321 compressedSyntaxes.push_back(std::make_pair(EXS_DeflatedLittleEndianExplicit, DicomTransferSyntax_DeflatedLittleEndianExplicit));
3322 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGProcess1, DicomTransferSyntax_JPEGProcess1));
3323 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGProcess2_4, DicomTransferSyntax_JPEGProcess2_4));
3324 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGProcess14, DicomTransferSyntax_JPEGProcess14));
3325 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGProcess14SV1, DicomTransferSyntax_JPEGProcess14SV1));
3326 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGLSLossless, DicomTransferSyntax_JPEGLSLossless));
3327 compressedSyntaxes.push_back(std::make_pair(EXS_JPEGLSLossy, DicomTransferSyntax_JPEGLSLossy));
3328 compressedSyntaxes.push_back(std::make_pair(EXS_JPEG2000LosslessOnly, DicomTransferSyntax_JPEG2000LosslessOnly));
3329 compressedSyntaxes.push_back(std::make_pair(EXS_JPEG2000, DicomTransferSyntax_JPEG2000));
3330 compressedSyntaxes.push_back(std::make_pair(EXS_JPEG2000MulticomponentLosslessOnly, DicomTransferSyntax_JPEG2000MulticomponentLosslessOnly));
3331 compressedSyntaxes.push_back(std::make_pair(EXS_JPEG2000Multicomponent, DicomTransferSyntax_JPEG2000Multicomponent));
3332 compressedSyntaxes.push_back(std::make_pair(EXS_JPIPReferenced, DicomTransferSyntax_JPIPReferenced));
3333 compressedSyntaxes.push_back(std::make_pair(EXS_JPIPReferencedDeflate, DicomTransferSyntax_JPIPReferencedDeflate));
3334 compressedSyntaxes.push_back(std::make_pair(EXS_RLELossless, DicomTransferSyntax_RLELossless));
3335 compressedSyntaxes.push_back(std::make_pair(EXS_MPEG2MainProfileAtMainLevel, DicomTransferSyntax_MPEG2MainProfileAtMainLevel));
3336 compressedSyntaxes.push_back(std::make_pair(EXS_MPEG4HighProfileLevel4_1, DicomTransferSyntax_MPEG4HighProfileLevel4_1));
3337 compressedSyntaxes.push_back(std::make_pair(EXS_MPEG4BDcompatibleHighProfileLevel4_1, DicomTransferSyntax_MPEG4BDcompatibleHighProfileLevel4_1));
3338
3339 for (unsigned int i = 0; i < 3; i++)
3340 {
3341 unsigned int bitsAllocated;
3342 switch (i)
3343 {
3344 case 0: bitsAllocated = 1; break;
3345 case 1: bitsAllocated = 8; break;
3346 case 2: bitsAllocated = 16; break;
3347 default:
3348 throw OrthancException(ErrorCode_InternalError);
3349 }
3350
3351 for (Syntaxes::const_iterator it = compressedSyntaxes.begin(); it != compressedSyntaxes.end(); ++it)
3352 {
3353 // All the compressed transfer syntaxes must have "OB" pixel data
3354 ParsedDicomFile dicom(true);
3355 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good());
3356 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(it->first, NULL).good());
3357 dicom.GetDcmtkObject().removeAllButCurrentRepresentations();
3358 DicomTransferSyntax ts;
3359 ASSERT_TRUE(dicom.LookupTransferSyntax(ts));
3360 ASSERT_EQ(ts, it->second);
3361 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation());
3362 }
3363
3364 {
3365 // Little endian implicit is always OW
3366 ParsedDicomFile dicom(true);
3367 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good());
3368 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianImplicit, NULL).good());
3369 dicom.GetDcmtkObject().removeAllButCurrentRepresentations();
3370 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation());
3371 }
3372 }
3373
3374 // Explicit little and big endian with <= 8 bpp is OB
3375
3376 for (unsigned int i = 0; i < 2; i++)
3377 {
3378 unsigned int bitsAllocated;
3379 switch (i)
3380 {
3381 case 0: bitsAllocated = 1; break;
3382 case 1: bitsAllocated = 8; break;
3383 default:
3384 throw OrthancException(ErrorCode_InternalError);
3385 }
3386
3387 {
3388 ParsedDicomFile dicom(true);
3389 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good());
3390 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianExplicit, NULL).good());
3391 dicom.GetDcmtkObject().removeAllButCurrentRepresentations();
3392 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation());
3393 }
3394
3395 {
3396 ParsedDicomFile dicom(true);
3397 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, bitsAllocated).good());
3398 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_BigEndianExplicit, NULL).good());
3399 dicom.GetDcmtkObject().removeAllButCurrentRepresentations();
3400 ASSERT_EQ(ValueRepresentation_OtherByte, dicom.GuessPixelDataValueRepresentation());
3401 }
3402 }
3403
3404 // Explicit little and big endian with > 8 bpp is OW
3405
3406 {
3407 ParsedDicomFile dicom(true);
3408 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, 16).good());
3409 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_LittleEndianExplicit, NULL).good());
3410 dicom.GetDcmtkObject().removeAllButCurrentRepresentations();
3411 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation());
3412 }
3413
3414 {
3415 ParsedDicomFile dicom(true);
3416 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertUint16(DCM_BitsAllocated, 16).good());
3417 ASSERT_TRUE(dicom.GetDcmtkObject().chooseRepresentation(EXS_BigEndianExplicit, NULL).good());
3418 dicom.GetDcmtkObject().removeAllButCurrentRepresentations();
3419 ASSERT_EQ(ValueRepresentation_OtherWord, dicom.GuessPixelDataValueRepresentation());
3311 } 3420 }
3312 } 3421 }
3313 3422
3314 3423
3315 TEST(ParsedDicomFile, DISABLED_InjectEmptyPixelData2) 3424 TEST(ParsedDicomFile, DISABLED_InjectEmptyPixelData2)