DICOM image shows up twisted

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
evanyftsai
Posts: 26
Joined: Fri, 2015-10-16, 09:18

DICOM image shows up twisted

#1 Post by evanyftsai »

Hi,

I have received a particular scan from Planmeca Promax where the DICOM image shows up twisted in DCMTK. All other scans work fine though. I am not sure what is special about this one. Can you help?

This is how I make the calls:


DJDecoderRegistration::registerCodecs();

OFString completeFileName = filePath + imageFileName;
DicomImage *image = new DicomImage(completeFileName.c_str());

DJDecoderRegistration::cleanup();



Which works fine until this case.

Thanks a lot!
Evan

evanyftsai
Posts: 26
Joined: Fri, 2015-10-16, 09:18

Re: DICOM image shows up twisted

#2 Post by evanyftsai »

Some more information. This is how I called createWindowsDIB:



DicomImage *pDcmImage = GetDicomImage(patientIndex, studyIndex, seriesIndex, imageIndex);
if ( !pDcmImage )
return NULL;

// Get width and height:
width = pDcmImage->getWidth();
height = pDcmImage->getHeight();

// Get device independent bitmap (DIB) pixel data:
pDcmImage->setMinMaxWindow();

void *data = NULL;
const int bits = ( pDcmImage->isMonochrome() ) ? 8 : 24;
const int upsideDown = 0;
const int padding = 1;
const unsigned long bytesAllocated = pDcmImage->createWindowsDIB(data, 0, pDcmImage->getFirstFrame(), bits, upsideDown, padding);
unsigned char *pPixelData = static_cast<unsigned char *>(data);
delete pDcmImage;
if ( !pPixelData )
return NULL;






Thanks,
Evan


evanyftsai wrote:Hi,

I have received a particular scan from Planmeca Promax where the DICOM image shows up twisted in DCMTK. All other scans work fine though. I am not sure what is special about this one. Can you help?

This is how I make the calls:


DJDecoderRegistration::registerCodecs();

OFString completeFileName = filePath + imageFileName;
DicomImage *image = new DicomImage(completeFileName.c_str());

DJDecoderRegistration::cleanup();



Which works fine until this case.

Thanks a lot!
Evan

evanyftsai
Posts: 26
Joined: Fri, 2015-10-16, 09:18

Re: DICOM image shows up twisted

#3 Post by evanyftsai »

Another piece of information - I tried dumping the image into a .bmp file:


// Dump .bmp:
int bmpMade = pDcmImage->writeBMP("C:\\Temp\\200.bmp", bits, 200);


And I got a 0KB .bmp file. The return value is 0.

Thanks,
Evan

evanyftsai wrote:Some more information. This is how I called createWindowsDIB:



DicomImage *pDcmImage = GetDicomImage(patientIndex, studyIndex, seriesIndex, imageIndex);
if ( !pDcmImage )
return NULL;

// Get width and height:
width = pDcmImage->getWidth();
height = pDcmImage->getHeight();

// Get device independent bitmap (DIB) pixel data:
pDcmImage->setMinMaxWindow();

void *data = NULL;
const int bits = ( pDcmImage->isMonochrome() ) ? 8 : 24;
const int upsideDown = 0;
const int padding = 1;
const unsigned long bytesAllocated = pDcmImage->createWindowsDIB(data, 0, pDcmImage->getFirstFrame(), bits, upsideDown, padding);
unsigned char *pPixelData = static_cast<unsigned char *>(data);
delete pDcmImage;
if ( !pPixelData )
return NULL;






Thanks,
Evan


evanyftsai wrote:Hi,

I have received a particular scan from Planmeca Promax where the DICOM image shows up twisted in DCMTK. All other scans work fine though. I am not sure what is special about this one. Can you help?

This is how I make the calls:


DJDecoderRegistration::registerCodecs();

OFString completeFileName = filePath + imageFileName;
DicomImage *image = new DicomImage(completeFileName.c_str());

DJDecoderRegistration::cleanup();



Which works fine until this case.

Thanks a lot!
Evan

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

Re: DICOM image shows up twisted

#4 Post by J. Riesmeier »

What does the logger say (when debug and/or trace mode is enabled)?

... and what do you mean by "twisted"? Do you have a screenshot of the result, somewhere?

evanyftsai
Posts: 26
Joined: Fri, 2015-10-16, 09:18

Re: DICOM image shows up twisted

#5 Post by evanyftsai »

How can I send the screenshot to you? Can I post it here?

Also, how can I enable trace mode? Where would I see the log files?

Thanks for your prompt response.

Evan
J. Riesmeier wrote:What does the logger say (when debug and/or trace mode is enabled)?

... and what do you mean by "twisted"? Do you have a screenshot of the result, somewhere?

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

Re: DICOM image shows up twisted

#6 Post by J. Riesmeier »

How can I send the screenshot to you? Can I post it here?
You can reference it using the "insert image" function. Alternatively, you could send it by email to bugs/at/dcmtk/dot/org.
Also, how can I enable trace mode? Where would I see the log files?
For your first question, see this Howto. By default, the log output is written to standard output/error but the aforementioned Howto also describes how to redirect the output to a file.

evanyftsai
Posts: 26
Joined: Fri, 2015-10-16, 09:18

Re: DICOM image shows up twisted

#7 Post by evanyftsai »

After some more research - and checking with OSG which handles the texture display in my program, it seems that the problem might be related to the setting of padding or packing. So - generally how should one select the padding parameter in calling createWindowsDIB? Is this parameter supposed to be a boolean or number of bytes? Is there a way to query from the DICOM data what padding is used in the bitmap?

Your help is very much appreciated.

Evan

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

Re: DICOM image shows up twisted

#8 Post by J. Riesmeier »

Whether you need padding or not depends on what you do with the created output, e.g. for the Windows API or the BMP image format you typically need padding to 32-bit addresses. That's why padding is enabled by default.

I guess you've read the documentation of DicomImage::createWindowDIB(). The "padding" parameter is described as "align each line to a 32-bit address if true (default)", so it's a boolean parameter. The reason why "int" is used instead of "bool" is simple: there was no standard "bool" type at the time when I wrote this class (more than twenty years ago) :wink:

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

Re: DICOM image shows up twisted

#9 Post by J. Riesmeier »

So from your suggestion it looks like it doesn't matter whether padding is set to be true or false? What is the general consideration here?
No, of course, it does matter. This is at least true for images where a line (row) of pixels in the rendered image does not allocated a multiple of 32 bit (4 bytes).
I guess my question is, as an application developer, do I need to set the padding state according to certain attribute in the DICOM data? Or is it safe for me to simply set it to false all the time?
The padding has nothing to do with the input image (DICOM) but with the output image (Windows BMP or DIB). If you still don't understand what the padding is about you should probably read the relevant parts of Microsoft's documentation (MSDN).

If you don't use Windows DIB format (with its special padding technique), createWindowsDIB() is not meant for you. Instead, you should have a look at DicomImage::getOutputData().
Another piece of information - I tried dumping the image into a .bmp file:

// Dump .bmp:
int bmpMade = pDcmImage->writeBMP("C:\\Temp\\200.bmp", bits, 200);

And I got a 0KB .bmp file. The return value is 0.
As I already asked (see above): what is the output to the logger? Are you sure that there are more than 200 frames in the image and that all these images are actually processed (see constructor of the DicomImage class)?

Post Reply

Who is online

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