DCMTK accusing missing tag that is NOT missing.

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
tiagostein
Posts: 5
Joined: Thu, 2015-01-15, 15:32

DCMTK accusing missing tag that is NOT missing.

#1 Post by tiagostein »

Hello. I am still learning how to use DCMTK and was trying to learn how to change my prototypes to read data from memory and not from file. In order to do so I made minimal program to try it.

Issue is, it accuses an error of
"E: can't determine 'PhotometricInterpretation' of decompressed image
E: mandatory attribute 'PhotometricInterpretation' is missing or can't be determined"

But the Photometric interpretation is there, (MONOCHROME2)

Any hints what I could be doing wrong? Bellow a very short example that I can reproduce the issue:

Code: Select all

int main(int argc, char *argv[])
{
    	OFLog::configure(OFLogger::INFO_LOG_LEVEL);

        std::ifstream file("/tmp/test_image.dcm", std::ios::binary);
        file.seekg(0, std::ios::end);
        std::streamsize size = file.tellg();
        file.seekg(0, std::ios::beg);

        std::vector<char> buffer(size);
        if (!file.read(buffer.data(), size))
            {
                std::cout<<"Did not work"<<std::endl;  
            }
    	
	DcmInputStream* dcmInputStream = new DcmInputBufferStream();

	((DcmInputBufferStream*)dcmInputStream)->setBuffer(&(buffer.front()), size);
	((DcmInputBufferStream*)dcmInputStream)->setEos();

        DcmFileFormat dicom_format;
        dicom_format.transferInit();

        dcmEnableAutomaticInputDataCorrection.set(OFTrue);
        dcmAcceptOddAttributeLength.set(OFTrue);
        dcmAutoDetectDatasetXfer.set(OFTrue);

        dicom_format.getDataset()->read(*dcmInputStream, 
                                                           EXS_JPEGProcess1TransferSyntax, 
                                                           EGL_noChange,
                                                           size);
       
        dicom_format.transferEnd();
	
        std::cout<<"Before Image creation"<<std::endl;
        DicomImage *image = new DicomImage( &dicom_format,
                                                                    EXS_JPEGProcess1TransferSyntax,
                                                                    CIF_UsePartialAccessToPixelData, 0, 1); 
  
      std::cout<<"After image creation...  here the error already happened"<<std::endl;

    if (image->getStatus() == EIS_Normal)

    {
        int a;	
        do {
            DCMIMGLE_INFO("processing frame " << image->getFirstFrame() + 1 << " to " 
                                              << image->getFirstFrame() + image->getFrameCount());
        	std::cin>>a;
        } while (image->processNextFrames());
    }

    delete image;

    return 0;
}
for testing purposes, I decompressed it on disk in another try, and used the LE Explicit TS. It does not complain about the photometric Interpretation but it does say that there is no pixel data in the dataset.

If I just read it from with DCMTK file it works perfectly. But I need to discover hwo to use DCMTK from in memory buffers. Surely I am doing something very wrong.

tiagostein
Posts: 5
Joined: Thu, 2015-01-15, 15:32

Re: DCMTK accusing missing tag that is NOT missing.

#2 Post by tiagostein »

After a few more hours, and reading DCMTK internals I got the problem. I was asking to the dataset inside the file format to read the stream, not the file format directly.

NOW is working.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest