Extracting 4G pixel data to file (raw) without loading...

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

Extracting 4G pixel data to file (raw) without loading...

#1 Post by theonlylawislove »

...all data into memory?

I am implementing a STORE-SCP. I save the dicom file directly to disk, to be processed later.

Later, I need to extract that raw pixel data. How do I do this without loading all 4GB's of pixel data into memory?

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Extracting 4G pixel data to file (raw) without loading..

#2 Post by J. Riesmeier »

In case of uncompressed pixel data, you could use DcmElement::getPartialValue() on the pixel data element.

theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

Re: Extracting 4G pixel data to file (raw) without loading..

#3 Post by theonlylawislove »

I am trying to refer to source to complete this the best I can, but I am stuck.

I am loading a simple dataset (without loading it all into memory).

Code: Select all

DcmDataset* ds = new DcmDataset();
ds->loadFile("test.dcm");
Then, I get the DCM_PixelData element, and attempt to perform this loop.

Code: Select all

DcmXfer outXfer(EXS_LittleEndianExplicit); // where should I get this?
DcmWriteCache writeCache;

writeCache.init(dcm, element->getLengthField(), 0, outXfer.getByteOrder()/*where should I get this?*/);
Uint32 len = 0;
Uint32 buflen = 0;
Uint32 transferedBytes = 0;
Uint32 fieldLength = element->getLengthField();
bool done = transferedBytes == fieldLength;

while(!done)
{
    cond = writeCache.fillBuffer(*element);
    buflen = writeCache.contentLength();

    if (cond.good())
    {
        len = writeCache.writeBuffer(outputFileStream);

        transferedBytes += len;
        cond = outputFileStream.status();
    }

    done = cond.bad() || (len < buflen) || (transferedBytes == fieldLength);
}
After stepping into the debugger, this fails, because in getPartialValue, on this line...

https://github.com/commontk/DCMTK/blob/ ... m.cc#L1615

...the check fails.

PS: I am using official git repo, at DCMTK-3.6.1_20170228.

If you take my file buffer loop out of the mix, the issue is I simple can't call getPartialValue.

Any ideas?

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Extracting 4G pixel data to file (raw) without loading..

#4 Post by J. Riesmeier »

Not sure what you are trying to do there but what I wanted to say in my previous posting: get the Pixel Data element, e.g. using findAndGetElement(), and then call getPartialValue() on this element.

theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

Re: Extracting 4G pixel data to file (raw) without loading..

#5 Post by theonlylawislove »

This is the simplest example, and I am getting the same issue.

Code: Select all

DcmFileFormat* fileFormat = new DcmFileFormat();
OFCondition cond = fileFormat->loadFile("/home/pknopf/git/medxchange.dicom/dcmfile.dcm");
DcmDataset* dataset = fileFormat->getDataset();

DcmElement* element = NULL;
cond = dataset->findAndGetElement(DCM_PixelData, element);

DcmWriteCache writeCache;
writeCache.init(dataset, element->getLengthField(), 0, EBO_LittleEndian);

// this fails with "illegal call, perhaps wrong parameters"
cond = writeCache.fillBuffer(*element);

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Extracting 4G pixel data to file (raw) without loading..

#6 Post by J. Riesmeier »

No, just call getPartialValue() on the "element" and pass a pointer to a DcmFileCache instance to it (in case of multiple calls in order to increase performance).

I'm still not sure why you use DcmWriteCache...

theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

Re: Extracting 4G pixel data to file (raw) without loading..

#7 Post by theonlylawislove »

The DcmWriteCache simply calls getPartialValue. That is pretty much all it does on "fill".

getPartialValue is returning the error.

If I replace DcmWriteCache with a direct getPartialValue, the error still persists.
Last edited by theonlylawislove on Tue, 2017-03-28, 14:30, edited 1 time in total.

theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

Re: Extracting 4G pixel data to file (raw) without loading..

#8 Post by theonlylawislove »

It fails because the pixel data element doesn't have the internal fLoadValue used to access the file again.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Extracting 4G pixel data to file (raw) without loading..

#9 Post by J. Riesmeier »

OK, so maybe it's easier with an example (which I wrote just for you :) ):

Code: Select all

#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcelem.h"
#include "dcmtk/dcmdata/dcfcache.h"

#define BUFFER_SIZE 1024

int main (int argc, char**argv)
{
    DcmFileFormat dcmFileFormat;
    OFCondition condition = dcmFileFormat.loadFile("image.dcm");
    if (condition.bad())
        COUT << condition.text() << OFendl;
    DcmDataset *dataset = dcmFileFormat.getDataset();

    DcmElement *element = NULL;
    condition = dataset->findAndGetElement(DCM_PixelData, element);
    if (condition.bad())
        COUT << condition.text() << OFendl;

    DcmFileCache cache;
    Uint8 buffer[BUFFER_SIZE];
    Uint32 offset = 0;
    while (condition.good())
    {
        COUT << "reading " << STD_NAMESPACE dec << BUFFER_SIZE << " bytes at offset " << offset << ": ";
        condition = element->getPartialValue(buffer, offset, BUFFER_SIZE, &cache);
        if (condition.good())
            COUT << "first byte is " << STD_NAMESPACE hex << (int)*buffer << OFendl;
        else
            COUT << condition.text() << OFendl;
        offset += BUFFER_SIZE;
    }
    return 0;
}

Post Reply

Who is online

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