WriteFrameToDataset and getOutputData

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

WriteFrameToDataset and getOutputData

#1 Post by martinrame »

Hi, I'm trying to modify the contents of the buffer returned by getOutputData, then store the image again in the dataset by calling writeFrameToDataset.

I do this:

Code: Select all

void getBuffer(void * &myBuffer, DcmFileFormat * fileFormat, DicomImage * &image, DcmDataset * &dataset)
{
  image = new DicomImage(fileFormat, xfer, CIF_AcrNemaCompatibility, fstart, fcount);

  dataset = fileFormat->getDataset();
  myBuffer = image->getOutputData();
}

// modify the buffer in an external app
void saveOutput(DicomImage * image, DcmDataset * dataset)
{
  image->writeFrameToDataset(*dataset);
  dataset->saveFile("output.dcm");
}
If the buffer returned by getOutputData is the internal buffer, why it isn't changed?. If it's a copy, how can I replace that internal buffer?, I can't find a "setOutputData" or similar method.

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#2 Post by martinrame »

More info: here are a couple of screenshots of what happens if I get the buffer using getOutputData, modify it and then use putAndInsertUint16Array to store again in the dicom file. That's why I'm trying to use writeFrameToDataset instead of putAndInsertUint16Array.

Before:

Image

After:
Image

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#3 Post by Michael Onken »

Hi,

there is a DICOM pixel rendering pipeline which includes some grayscale operations until the image is shown on the screen. getOutputData() takes all those operations into account. So, the most important questions are:

- are you sure you consider any modality lut and voi luts that are in the file? If not, try to disable any modality luts and voi luts before calling getOutputData on your own modified pixel data.
- are you sure you consider that Pixel Representation is not pointing to unsigned pixel data. In that case, maybe changing polarity in DicomImage class may help (not sure).

There might be other things, e.g. that they were also overlays embededded into unused bits in Pixel Data and DcmImage still assumes they are inside. Displaying a DICOM image can be much than just taking the raw Pixel Data and displaying it on the screen.

Best regards,
Michael

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#4 Post by martinrame »

Thanks Michael, actually I've made some advances.

First of all, when I call getOutputData I must explicitly set the parameter bits, for example getOutputData(8).

Then, before calling putAndInsertUint8Array I have to set image parameters as follows

Code: Select all

lDataset->putAndInsertUint16(DCM_SamplesPerPixel, 1);
lDataset->putAndInsertString(DCM_PhotometricInterpretation, "MONOCHROME2");
lDataset->putAndInsertUint16(DCM_Rows, cols);
lDataset->putAndInsertUint16(DCM_Columns, rows);
lDataset->putAndInsertUint16(DCM_BitsAllocated, 8);
lDataset->putAndInsertUint16(DCM_BitsStored, 8);
lDataset->putAndInsertUint16(DCM_HighBit, 7);
lDataset->putAndInsertUint16(DCM_PixelRepresentation, 0);
lDataset->putAndInsertUint8Array(DCM_PixelData, (const Uint8 *)buffer, rows * cols);
With this code, I come to this image (not perfect but near):

Image

All dcmtk code is running in a shared library loaded from a FreePascal program in charge of loading the pixeldata into a 256 color palette canvas, adding the text, then copy the modified canvas to the buffer, and sending back the buffer to the shared library to save the new dicom image.

Before sending the buffer to the shared library, if I save the canvas as a bmp, I get this:

Image

That's the final result I want to get in my Dicom image.

Any hint?, do you see something wrong in my code, maybe the palette I'm using is not correct?.

Thanks in advance.

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

#5 Post by J. Riesmeier »

If the buffer returned by getOutputData is the internal buffer, why it isn't changed?
The term "Output" in the method name already suggests that it is not the so-called intermediate pixel data that is returned, it is just the resulting pixel matrix of the rendering process.
Also the documentation and other postings in this forum say: "The main purpose of these modules [i.e. dcmimgle/dcmimage] is image display." -- not image generation or modification.

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#6 Post by Michael Onken »

....However, of course, you can change the whole dicom dataset with the image information, feed it again into DicomImage and then let it render you the output.

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#7 Post by martinrame »

Can you help me find what's wrong with the palette I'm using, why the text on top of the image has that weird background?.

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#8 Post by martinrame »

I found a solution!.

I was using anti-aliased fonts, when I turned off the antialiasing it started to draw the text without issues.

Post Reply

Who is online

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