Examples using getInterData()

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
mhavu
Posts: 15
Joined: Wed, 2005-11-23, 16:23
Location: Jyväskylä, Finland

Examples using getInterData()

#1 Post by mhavu »

I'm trying to construct a program that uses DicomImage::getInterData() to access the pixel data. However, the getCount() method of the DiPixel object I get from it always seems to return 0. Could someone point me to a working example of how to use the new getInterData() method, please?

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

Did you check whether the image could be loaded at all?

Here's a little sample program that works for me:

Code: Select all

// test program for DicomImage::getInterData()
// -- requires DCMTK version 3.5.4
// -- works for monochrome images only

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmimgle/dcmimage.h"

int main(int argc, char *argv[])
{
    if (argc > 1)
    {
        DicomImage image(argv[1]);
        if (image.getStatus() == EIS_Normal)
        {
            const DiPixel *inter = image.getInterData();
            if (inter != NULL)
            {
                COUT << "number of bytes: " << inter->getCount() << endl;
            }
        } else
            CERR << "cannot load file: " << argv[1] << endl;
    }
    return 0;
}

mhavu
Posts: 15
Joined: Wed, 2005-11-23, 16:23
Location: Jyväskylä, Finland

Examples using getInterData()

#3 Post by mhavu »

Thanks! That did it. Here's a version that supports compressed and color images as well, in case someone is interested:

Code: Select all

// test program for DicomImage::getInterData() 
// -- requires DCMTK version 3.5.4 

#include "dcmtk/config/osconfig.h" 
#include "dcmtk/dcmimgle/dcmimage.h" 
#include "dcmtk/dcmimage/diregist.h"   // Support for color images
#include "dcmtk/dcmdata/dcrledrg.h"    // Support for RLE images
#include "dcmtk/dcmjpeg/djdecode.h"    // Support for JPEG images

class DicomCodecRegistration 
{ 
public: 
    DicomCodecRegistration(void) 
    { 
		  // register decompression codecs
        DcmRLEDecoderRegistration::registerCodecs(); 
        DJDecoderRegistration::registerCodecs(); 
    } 
    ~DicomCodecRegistration(void) 
    { 
		  // deregister decompression codecs
        DcmRLEDecoderRegistration::cleanup(); 
        DJDecoderRegistration::cleanup(); 
    } 
};

int main(int argc, char *argv[]) 
{ 
	DicomCodecRegistration registerCodecs;
	
    if (argc > 1) 
    { 
        DicomImage image(argv[1]); 
        if (image.getStatus() == EIS_Normal) 
        { 
            const DiPixel *pixeldata = image.getInterData(); 
            if (pixeldata != NULL) 
            { 
                COUT << "number of pixels: " << pixeldata->getCount() << endl; 
            } 
        } else 
            CERR << "cannot load file: " << argv[1] << endl; 
    } 
    return 0; 
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest