Extracting 4G pixel data to file (raw) without loading...
Moderator: Moderator Team
-
- Posts: 34
- Joined: Thu, 2014-07-17, 09:07
Extracting 4G pixel data to file (raw) without loading...
...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?
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?
-
- DCMTK Developer
- Posts: 2506
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: Extracting 4G pixel data to file (raw) without loading..
In case of uncompressed pixel data, you could use DcmElement::getPartialValue() on the pixel data element.
-
- Posts: 34
- Joined: Thu, 2014-07-17, 09:07
Re: Extracting 4G pixel data to file (raw) without loading..
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).
Then, I get the DCM_PixelData element, and attempt to perform this loop.
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?
I am loading a simple dataset (without loading it all into memory).
Code: Select all
DcmDataset* ds = new DcmDataset();
ds->loadFile("test.dcm");
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);
}
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?
-
- DCMTK Developer
- Posts: 2506
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: Extracting 4G pixel data to file (raw) without loading..
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.
-
- Posts: 34
- Joined: Thu, 2014-07-17, 09:07
Re: Extracting 4G pixel data to file (raw) without loading..
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);
-
- DCMTK Developer
- Posts: 2506
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: Extracting 4G pixel data to file (raw) without loading..
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...
I'm still not sure why you use DcmWriteCache...
-
- Posts: 34
- Joined: Thu, 2014-07-17, 09:07
Re: Extracting 4G pixel data to file (raw) without loading..
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.
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.
-
- Posts: 34
- Joined: Thu, 2014-07-17, 09:07
Re: Extracting 4G pixel data to file (raw) without loading..
It fails because the pixel data element doesn't have the internal fLoadValue used to access the file again.
-
- DCMTK Developer
- Posts: 2506
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: Extracting 4G pixel data to file (raw) without loading..
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;
}
Who is online
Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot] and 1 guest