BUG: DCMTK reader wrongly rejects file with preamble#4501
BUG: DCMTK reader wrongly rejects file with preamble#4501thewtex merged 3 commits intoInsightSoftwareConsortium:masterfrom
Conversation
c8850bb to
0c9fd3d
Compare
|
Great suggestions, @N-Dekker , added. |
0c9fd3d to
4606503
Compare
Are you sure it's issue 4801? I cannot find it 🤷 |
jhlegarreta
left a comment
There was a problem hiding this comment.
Can a minimal test be added if an appropriate dataset can be found, please?
|
@pieper do you have a test file? |
Almost every DICOM file has the "preamble". There are old ACR-NEMA files without preamble / prefix / header (0x0002 group). Here is one without preamble and prefix, starts with the header (0x0002 group), specially for testing purposes. Most DICOM viewers can open it. It is also 'dciodvfy' clean. Edit: |
A previous optimization didn't take into account the preamble of a dicom file. This adds a check. Fixes InsightSoftwareConsortium#4108.
Both GDCM and DCMTK. Related to InsightSoftwareConsortium#4108. From @issakomi: > Almost every DICOM file has the "preamble". There are old ACR-NEMA files without preamble / prefix / header (0x0002 group). > Strictly speaking, the preamble consists of 128 (zero) bytes at the beginning (reserved), and the subsequent 4 bytes "DICM" are called the prefix. > https://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html > > Here is one without preamble and prefix, starts with the header (0x0002 group), specially for testing purposes. Most DICOM viewers can open it. It is also 'dciodvfy' clean. > https://data.kitware.com/#item/65efb5f18353a45974ec399b > > Here is one tiny and 'dciodvfy' clean file with correct preamble/prefix, just for simplicity, if a dedicated test is required. But again, every modern DICOM file should have this > https://data.kitware.com/#item/65efb9518353a45974ec399e
|
@issakomi awesome, thank you! I added tests accordingly for both GDCM, DCMTK. |
4606503 to
8427bbe
Compare
|
Please give me some time for more test. I am not sure that we have tested DCMTKIO CanReadFile. It seems to reject no_preamble.dcm. The name of the PR is a little bit not precise. The DCMTKIO reader doesn't reject files with preamble. DCMTKIO CanReadFile returns false for usual and valid files with preamble, but it is usually not invoked at all, only if a user calls it explicitly. |
|
Here is test with CanReadFile and readers for both DCMTKIO and GDCMIO. Failure for DCMTK CanReadFile with preamble will be fixed by this PR Not sure that it is important, no_preamble.dcm is synthetic, but both readers work with it. SIEMENS_GBS_III-16-ACR_NEMA_1.acr is real ACR-NEMA file, DCMTKIO reader fails (and CanReadFile too). #include "itkImage.h"
#include "itkDCMTKImageIO.h"
#include "itkGDCMImageIO.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include <iostream>
int main(int argc, char ** argv)
{
if (argc < 2)
{
std::cout << "Filename is required" << std::endl;
}
{
using ImageType = itk::Image<short, 2>;
using ImageIOType = itk::DCMTKImageIO;
auto io = ImageIOType::New();
////////////////////////////////////////////////////////////////////////
//
// Bug https://github.com/InsightSoftwareConsortium/ITK/issues/4108
//
try
{
const bool r = io->CanReadFile(argv[1]);
std::cout << "\nDCMTKIO CanReadFile(" << argv[1] << "): " << (r ? "true" : "false") << std::endl;
}
catch (const itk::ExceptionObject & e)
{
std::cout << e.GetDescription() << std::endl;
}
//
//
////////////////////////////////////////////////////////////////////////
itk::ImageFileReader<ImageType>::Pointer reader = itk::ImageFileReader<ImageType>::New();
reader->SetImageIO(io);
reader->SetFileName(argv[1]);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & e)
{
std::cout << "DCMTKIO reader failed\n" << e.GetDescription() << std::endl;
}
}
//
{
using ImageType = itk::Image<short, 2>;
using ImageIOType = itk::GDCMImageIO;
auto io = ImageIOType::New();
////////////////////////////////////////////////////////////////////////
//
//
try
{
const bool r = io->CanReadFile(argv[1]);
std::cout << "\nGDCMIO CanReadFile(" << argv[1] << "): " << (r ? "true" : "false") << std::endl;
}
catch (const itk::ExceptionObject & e)
{
std::cout << e.GetDescription() << std::endl;
}
//
//
////////////////////////////////////////////////////////////////////////
itk::ImageFileReader<ImageType>::Pointer reader = itk::ImageFileReader<ImageType>::New();
reader->SetImageIO(io);
reader->SetFileName(argv[1]);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & e)
{
std::cout << "GDCMIO reader failed\n" << e.GetDescription() << std::endl;
}
}
return 0;
}Edit: updated image type to short, but it doesn't change anything, just for correctness (ACR-NEMA test file is 16 bits allocated) |
issakomi
left a comment
There was a problem hiding this comment.
Approved for clarity. Despite of issues reported above, the PR is a step in the right direction.
Testing coverage for InsightSoftwareConsortium#4108. We are re-using the test coverage of CanReadFile in the no-preamble test to ensure that files with a preamble are also evaluated correctly.
|
@issakomi thank you for helping us progress forward in the right direction on this!! I added a few more tests that improve our coverage based on your remarks. |
|
/azp run ITK.macOS |
…cmtk-preamble BUG: DCMTK reader wrongly rejects file with preamble
A previous optimization didn't take into account the preamble of a dicom file. This adds a check.
Fixes #4108