Convert YCbCr to RGB

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
procuris
Posts: 8
Joined: Thu, 2012-03-01, 12:19

Convert YCbCr to RGB

#1 Post by procuris »

I am trying to create a Windows DIB using createWindowsDIB. This works for LittleEndianImplicit, but not for JPEGLSLossless (as createWindowsDIB does not work if original YCbCr color model is retained).

How do I convert YCbCr to RGB?
(I have found the method DiYBRPixelTemplate< T1, T2 >::convert() in diybrpxt.h but I don´t manage how to use it.)

------------------------------------------------------
Here is my code:

STDMETHODIMP CDicomDataSet::CreateDIBFast(BYTE** pData, ULONG size, ULONG frame, SHORT bits, SHORT upsideDown, SHORT padding, ULONG* result)
{
DJDecoderRegistration::registerCodecs(); // register global JPEG decompression codecs
DJEncoderRegistration::registerCodecs(); // register global JPEG compression codecs
DcmRLEEncoderRegistration::registerCodecs(); // register RLE compression codec
DcmRLEDecoderRegistration::registerCodecs(); // register RLE decompression codec

DicomImage image(m_pData,m_pData->getOriginalXfer());
image.setMinMaxWindow();
InvertedPresentationFix(image);

*result = image.createWindowsDIB((void*&)(*pData),size, frame, bits, upsideDown, padding);

// deregister JPEG codecs
DJDecoderRegistration::cleanup();
DJEncoderRegistration::cleanup();
// deregister RLE codecs
DcmRLEDecoderRegistration::cleanup();
DcmRLEEncoderRegistration::cleanup();

return S_OK;
}

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

#2 Post by J. Riesmeier »

So, you are using CIF_KeepYCbCrColorModel? For what reason?

procuris
Posts: 8
Joined: Thu, 2012-03-01, 12:19

#3 Post by procuris »

The person who started the project has left our company, so I don´t know. But I can´t find setting CIF_KeepYCbCrColorModel in any of the project files.

How do I change it to RGB?

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

#4 Post by J. Riesmeier »

Then, what you mean by "as createWindowsDIB does not work if original YCbCr color model is retained"? The color model of color images is always converted into RGB (if the above mentioned flag is not used).

procuris
Posts: 8
Joined: Thu, 2012-03-01, 12:19

#5 Post by procuris »

I believed YCbCr was the default mode. Then I found in a document that "createWindowsDIB does not work if original YCbCr color model is retained".

My question now is how I can disable CIF_KeepYCbCrColorModel.

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

#6 Post by J. Riesmeier »

As I tried to explain in my previous posting: This is the default. So, if CIF_KeepYCbCrColorModel is not used in the DicomImage constructor, the internal representation is RGB (for color images) and createWindowsDIB() should work. Of course, you should always check whether the DICOM image could be processed at all (using getStatus()) and whether createWindowsDIB() was successful (see return value).

Btw, I don't think that it is a good idea to register and deregister the codecs for each images. This should be done only once for an application.

procuris
Posts: 8
Joined: Thu, 2012-03-01, 12:19

#7 Post by procuris »

Aha! I didn´t realized it was in the constructor.
I will also change the register/deregister for codecs.

Thanks :-)

Post Reply

Who is online

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