- Check pixels on the right legth (for odd length data)
- Allow a difference of +/-1 between native image and decompressed image for
each pixel
- Display the warnings at the right place
- Count successes and failures
Warning :
-> It seems that *all* the failures 'pixels differ as expanded in memory'
shouldn't appear (resulting image looks perfect ?!?)
-> For some images :
gdcmData/
05115014-mr-siemens-avanto-syngo-with-palette-icone.dcm
gdcmData/
05119865-mr-siemens-avanto-syngo.dcm
gdcmData/
05148044-mr-siemens-avanto-syngo.dcm
gdcmData/CT-SIEMENS-Icone-With-PaletteColor.dcm
gdcmData/GE_CT_With_Private_compressed-icon.dcm
gdcmData/MR_GE_with_Private_Compressed_Icon_0009_1110.dcm
gdcmData/SiemensMagnetomPhoenixWithCSAinfo.dcm
gdcmData/MR-sonata-3D-as-Tile.dcm
gdcmData/CT_Phillips_UNvsSQ_fixed.dcm
gdcmData/MR-SIEMENS-DICOM-WithOverlays.dcm
gdcmData/MR-SIEMENS-DICOM-WithOverlays-extracted-overlays.dcm
gdcmData/PICKER-16-MONO2-Nested_icon.dcm
gdcmData/PrivateGEImplicitVRBigEndianTransferSyntax16Bits.dcm
compression leads to non gdcm-parsable result.
:-(
Program: gdcm
Module: $RCSfile: TestReadWriteJPEGReadCompare.cxx,v $
Language: C++
Program: gdcm
Module: $RCSfile: TestReadWriteJPEGReadCompare.cxx,v $
Language: C++
- Date: $Date: 2007/08/28 16:57:00 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2007/08/29 08:26:54 $
+ Version: $Revision: 1.3 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
const unsigned int MAX_NUMBER_OF_DIFFERENCE = 10;
const unsigned int MAX_NUMBER_OF_DIFFERENCE = 10;
+int nb_of_success___;
+int nb_of_failure___;
static int CompareInternalJPEG(std::string const &filename, std::string const &output)
{
static int CompareInternalJPEG(std::string const &filename, std::string const &output)
{
<< "Test::TestReadWriteJPEGReadCompare: Image not gdcm compatible:"
<< filename << std::endl;
file->Delete();
<< "Test::TestReadWriteJPEGReadCompare: Image not gdcm compatible:"
<< filename << std::endl;
file->Delete();
return 1;
}
std::cout << " step 1...";
//////////////// Step 2:
GDCM_NAME_SPACE::FileHelper *filehelper = GDCM_NAME_SPACE::FileHelper::New( file );
return 1;
}
std::cout << " step 1...";
//////////////// Step 2:
GDCM_NAME_SPACE::FileHelper *filehelper = GDCM_NAME_SPACE::FileHelper::New( file );
- int dataSize = filehelper->GetImageDataSize();
- uint8_t *imageData = filehelper->GetImageData(); //EXTREMELY IMPORTANT
+ int dataSize = filehelper->GetImageDataRawSize();
+ uint8_t *imageData = filehelper->GetImageDataRaw(); //EXTREMELY IMPORTANT
// Sure, it is : It's up to the user to decide if he wants to
// GetImageData or if he wants to GetImageDataRaw
// (even if we do it by setting a flag, *he* will have to decide)
//filehelper->SetImageData(imageData, dataSize);
// Sure, it is : It's up to the user to decide if he wants to
// GetImageData or if he wants to GetImageDataRaw
// (even if we do it by setting a flag, *he* will have to decide)
//filehelper->SetImageData(imageData, dataSize);
-
- // Just to be sure the further Write() doesn't corrupt imageData ...
- std::cout << std::endl;
- int i,j;
- for(i=0, j=0;i<dataSize && j<MAX_NUMBER_OF_DIFFERENCE;i++)
- {
- std::cout << std::hex << "(" << i << " : "
- << std::hex << (int)(imageData[i]) << ") "
- << std::dec;
- ++j;
- }
- std::cout << std::endl;
-
- filehelper->SetWriteModeToRGB();
-
+
+ filehelper->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE); // lossless compression : pixels reain unimpared
+ filehelper->SetWriteModeToRaw();
filehelper->SetWriteTypeToJPEG( );
filehelper->SetWriteTypeToJPEG( );
filehelper->SetUserData(imageData,dataSize); // This one ensures the compression
filehelper->Write( output );
filehelper->SetUserData(imageData,dataSize); // This one ensures the compression
filehelper->Write( output );
- // Just to be sure the previous Write() didn't corrupt imageData ..
- for(i=0, j=0;i<dataSize && j<MAX_NUMBER_OF_DIFFERENCE;i++)
- {
- std::cout << std::hex << "(" << i << " : "
- << std::hex << (int)(imageData[i]) << ") "
- << std::dec;
- ++j;
- }
- std::cout << std::endl << std::endl;
-
std::cout << "2...";
//////////////// Step 3:
std::cout << "2...";
//////////////// Step 3:
file->Delete();
filehelper->Delete();
fileout->Delete();
file->Delete();
filehelper->Delete();
fileout->Delete();
std::cout << "3...";
// For the next step:
std::cout << "3...";
// For the next step:
- int dataSizeWritten = reread->GetImageDataSize();
- uint8_t *imageDataWritten = reread->GetImageData();
-
- // Just to see
- std::cout << std::endl;
- for(i=0, j=0;i<dataSize && j<MAX_NUMBER_OF_DIFFERENCE;i++)
- {
- std::cout << std::hex << "(" << i << " : "
- << std::hex << (int)(imageDataWritten[i]) << ") "
- << std::dec;
- ++j;
- }
- std::cout << std::endl << std::endl;
+ int dataSizeWritten = reread->GetImageDataRawSize();
+ uint8_t *imageDataWritten = reread->GetImageDataRaw();
//////////////// Step 4:
// Test the image size
//////////////// Step 4:
// Test the image size
file->GetZSize() != reread->GetFile()->GetZSize())
{
std::cout << "Failed" << std::endl
file->GetZSize() != reread->GetFile()->GetZSize())
{
std::cout << "Failed" << std::endl
<< "X: " << file->GetXSize() << " # "
<< reread->GetFile()->GetXSize() << " | "
<< "Y: " << file->GetYSize() << " # "
<< "X: " << file->GetXSize() << " # "
<< reread->GetFile()->GetXSize() << " | "
<< "Y: " << file->GetYSize() << " # "
filehelper->Delete();
fileout->Delete();
reread->Delete();
filehelper->Delete();
fileout->Delete();
reread->Delete();
filehelper->Delete();
fileout->Delete();
reread->Delete();
filehelper->Delete();
fileout->Delete();
reread->Delete();
return 1;
}
// Test the data content
return 1;
}
// Test the data content
- if (memcmp(imageData, imageDataWritten, dataSize) !=0)
+ if (memcmp(imageData, imageDataWritten, dataSizeFixed) !=0)
- std::string PixelType = filehelper->GetFile()->GetPixelType();
- std::string ts = filehelper->GetFile()->GetTransferSyntax();
-
- std::cout << " Failed" << std::endl
- << " pixel ("
- << PixelType
- << ") differ (as expanded in memory)."
- << std::endl
- << " compression : "
- << GDCM_NAME_SPACE::Global::GetTS()->GetValue(ts) << std::endl;
-
- std::cout << " list of the first " << MAX_NUMBER_OF_DIFFERENCE
- << " pixels differing (pos : original - written) :"
- << std::endl;
-
- int i;
- unsigned int j;
- for(i=0, j=0;i<dataSize && j<MAX_NUMBER_OF_DIFFERENCE;i++)
+ unsigned int j =0;
+ for(int i1=0; i1<dataSizeFixed; i1++)
+ {
+ if (abs ((int)imageData[i1]-(int)imageDataWritten[i1]) > 2)
- //if(imageData[i]!=imageDataWritten[i])
- if (abs ((int)imageData[i]-(int)imageDataWritten[i]) > 2)
- {
- std::cout << std::hex << "(" << i << " : "
+ j=1;
+ break;
+ }
+ }
+
+ if (j!=0)
+ {
+ std::string PixelType = filehelper->GetFile()->GetPixelType();
+ std::string ts = filehelper->GetFile()->GetTransferSyntax();
+
+ std::cout << " Failed" << std::endl
+ << " pixel ("
+ << PixelType
+ << ") differ (as expanded in memory)."
+ << std::endl
+ << " compression : "
+ << GDCM_NAME_SPACE::Global::GetTS()->GetValue(ts) << std::endl;
+
+ std::cout << " list of the first " << MAX_NUMBER_OF_DIFFERENCE
+ << " pixels differing (pos : original - written) :"
+ << std::endl;
+
+ for(int i=0, j=0;i<dataSizeFixed && j<MAX_NUMBER_OF_DIFFERENCE;i++)
+ {
+ if (abs ((int)imageData[i]-(int)imageDataWritten[i]) > 2)
+ {
+ std::cout << std::hex << "(" << i << " : "
<< std::hex << (int)(imageData[i]) << " - "
<< std::hex << (int)(imageDataWritten[i]) << ") "
<< std::dec;
<< std::hex << (int)(imageData[i]) << " - "
<< std::hex << (int)(imageDataWritten[i]) << ") "
<< std::dec;
- }
- std::cout << std::endl;
-
- if (j !=0 ) {
- file->Delete();
- filehelper->Delete();
- fileout->Delete();
- reread->Delete();
- return 1;
- }
+ }
+ std::cout << std::endl;
+
+ file->Delete();
+ filehelper->Delete();
+ fileout->Delete();
+ reread->Delete();
+ nb_of_failure___++;
+ return 1;
+ }
- std::cout << "========================================= 4...OK." << std::endl ;
-
+ std::cout << "=============== 4...OK." << std::endl ;
+ nb_of_success___ ++;
//////////////// Clean up:
file->Delete();
filehelper->Delete();
//////////////// Clean up:
file->Delete();
filehelper->Delete();
int TestReadWriteJPEGReadCompare(int argc, char *argv[])
{
int result = 0;
int TestReadWriteJPEGReadCompare(int argc, char *argv[])
{
int result = 0;
+ nb_of_success___ =0;
+ nb_of_failure___ =0;
if (argc == 4)
GDCM_NAME_SPACE::Debug::DebugOn();
if (argc == 4)
GDCM_NAME_SPACE::Debug::DebugOn();
result += CompareInternalJPEG(filename, "TestReadWriteJPEGReadCompare.dcm");
}
}
result += CompareInternalJPEG(filename, "TestReadWriteJPEGReadCompare.dcm");
}
}
+ std::cout << "==================================" << std::endl;
+ std::cout << "nb of success " << nb_of_success___ << std::endl;
+ std::cout << "nb of failure " << nb_of_failure___ << std::endl;
+