Set window center / width for multi-frame DICOM image

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Hualei.Shen
Posts: 4
Joined: Wed, 2017-03-01, 13:42

Set window center / width for multi-frame DICOM image

#1 Post by Hualei.Shen »

Dear friends,

I have a multi-frame DICOM image. I want to set window center and window width for all frames, then save each frame as single image file.

My routine is:
(1) Use "DicomImage::setWindow()" method to the DICOM image;
(2) Use "DicomImage::getOutputData()" method to obtain the rendered pixel data;
(3) Save the rendered pixel data as single image file, frame by frame.

My trouble is: The "DicomImage::setWindow()" method in (1) only takes effect on the first frame. Because in (3), only the first frame is clear, and all others are dark.

Could you please give some hints on how to solve my trouble?

Many thanks!

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

Re: Set window center / width for multi-frame DICOM image

#2 Post by J. Riesmeier »

How do you access the individual frames? Do you have a code fragment that shows this behavior?

Hualei.Shen
Posts: 4
Joined: Wed, 2017-03-01, 13:42

Re: Set window center / width for multi-frame DICOM image

#3 Post by Hualei.Shen »

J. Riesmeier wrote:How do you access the individual frames? Do you have a code fragment that shows this behavior?
Many thanks for your kind reply!

I access the individual frame via step (3) in the following code:

//(0.1) load DICOM header from file "strDICOMPath"
DcmFileFormat dicomFileFormat;
OFCondition status = dicomFileFormat.loadFile(strDICOMPath);

//(0.2) load DICOM pixel data from file "strTiffPair", employing LIBTIFF package
uint16 *pDICOMPixel = LoadFromTiff(strTiffPair);

//(0.3) equip DICOM image, based on DICOM header and DICOM pixel data, obtained in (0.1) and (0.2), respectively.
DcmDataset* dicomDataSet = dicomFileFormat.getDataset();
E_TransferSyntax xfer = dicomDataSet->getOriginalXfer();
dicomDataSet->findAndGetFloat64(DCM_WindowCenter, dbWindowCenter); //get window center
dicomDataSet->findAndGetFloat64(DCM_WindowWidth, dbWindowWidth); //get window width

OFCondition statusEquip = dicomDataSet->putAndInsertUint16Array(DCM_PixelData,
pDICOMPixel,
sizeof(pDICOMPixel)/2
);
DicomImage dicomImage(dicomDataSet,
xfer,
CIF_UseAbsolutePixelRange,
0,
0);

//(1) set window width / window center
dicomImage.setWindow(dbWindowCenter, dbWindowWidth);

//(2) obtain the rendered pixel data
uint16* pRenderedPixel = (uint16*)_TIFFmalloc(sizeof(dicomImage));
dicomImage.getOutputData(pRenderedPixel ,
sizeof(dicomImage),
16,
0,
0);

//(3) save the rendered pixle data to individual image, frame by frame
for (int slice = 0; slice < dicomImage.getFrameCount(); slice++)
{
uint16* pSliceBuff = pRenderedPixel + slice * dicomImage.getFrameSize();
saveBuff2PNG(pSliceBuff, dicomImage.getFrameSize()); //save current frame as PNG file, employing LIBPNG package
}

Hualei.Shen
Posts: 4
Joined: Wed, 2017-03-01, 13:42

Re: Set window center / width for multi-frame DICOM image

#4 Post by Hualei.Shen »

Now there is some advance...

I replace

//(1) set window width / window center
dicomImage.setWindow(dbWindowCenter, dbWindowWidth);

with the following code:

//(1) set window width / window center, frame by frame
int valReturn = 0;
for (int frame = 0; frame < GetImgDepth(); frame++)
{
valReturn = dicomImage.setRoiWindow(0, 0, GetImgWidth(), GetImgHeight(), frame);
}

Then I can obtain images with low brightness.

Could you please give me some hints on how to make these images brighter?

Thanks a lot!

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

Re: Set window center / width for multi-frame DICOM image

#5 Post by J. Riesmeier »

To be honest, I still don't know what you intend to do... and, actually, I also don't understand what the purpose of step "0.1" to "0.3" is.

Anyway, here are my questions and comments regarding step "1" to "3":
  1. Where are the values for "dbWindowCenter" and "dbWindowWidth" coming from? Are you sure that they are appropriate for the particular image?
  2. Passing "sizeof(dicomImage)" is certainly wrong in the call of "getOutputData()". You have to pass the size of the "buffer" and not the size of the DicomImage instance.
  3. As far as I can see, "pRenderedPixel" only contains the pixel data of a single frame only...
Sorry, but could you please provide a minimal and self-contained example. I mean something like what is described here: http://stackoverflow.com/help/mcve

Hualei.Shen
Posts: 4
Joined: Wed, 2017-03-01, 13:42

Re: Set window center / width for multi-frame DICOM image

#6 Post by Hualei.Shen »

Now I get the right results.
I paste the key pseudo-codes here. And I hope this will help others who encounter the same problem.
*****************************************************************
//pRenderedData points to a buffer, which is used to store the rendered pixel data, frame by frame
for (int frame = 0; frame < dicomImage->depth(); frame++)
{
dicomImage->getOutputData((uint16*)pRenderedData + frame * bytes_per_slice / 2,
bytes_entire_image,
16,//16-bits per pixel
frame,//number of current frame, being rendered
0);
}
*****************************************************************

Many thanks for all of you!

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest