I have inherited a project that originally only saved memory based 8 bits per pixel grayscale images into DICOM files and that all still works. Now however i have requirement to save 24 bit per pixel color images as DICOM files as well, and am trying to figure out all the various parameters, but have not been successful. I tried looking through the various examples but none appear to use the encoders explicitly the way this code does.
Everything works just great for Gray Scale images, but the cond = m_pEncoder->encode comes back with an OFCondition
+ theText {theCString=0x0102b858 "Bogus input colorspace" theCapacity=22 } OFString
Input nCompressMode = 21
nQuality = 0
eInpConvType = EPI_RGB
The init Function that is throwing this error is
{
DcmRLEDecoderRegistration::registerCodecs(OFFalse /*pCreateSOPInstanceUID*/, OFFalse);
unsigned int bytesPerPixel = 1; // Default is Monochrome
// register decompression codecs
DJDecoderRegistration::registerCodecs(
EDC_photometricInterpretation,
EUC_default,
EPC_default,
OFFalse);
// register compression codecs
DJEncoderRegistration::registerCodecs(
ECC_lossyRGB,//ECC_monochrome, //pCompressionCSConversion color conversion mode for compression
EUC_default, //pCreateSOPInstanceUID mode for SOP Instance UID creation
OFFalse, //pVerbose verbose mode flag
OFFalse, //pOptimizeHuffman perform huffman table optimization for 8 bits/pixel compression?
0, //pSmoothingFactor smoothing factor for image compression, 0..100
8, //pForcedBitDepth forced bit depth for image compression, 0 (auto) or 8/12/16
0, //pFragmentSize maximum fragment size (in kbytes) for compression, 0 for unlimited.
OFTrue, //pCreateOffsetTable create offset table during image compression?
ESS_444, //pSampleFactors subsampling mode for color image compression
OFFalse, //pWriteYBR422 flag
OFFalse, //pConvertToSC flag should image be converted to Secondary Capture upon compression
0, //pWindowType mode for VOI transformation of monochrome images
0, //pWindowParameter parameter for VOI transform of monochrome images, used in modes 1, 2, 4, 6
0, //pVoiCenter VOI window center for mode 5
0, //pVoiWidth VOI window width for mode 5
0, //pRoiLeft Region of Interest left corner for for VOI transform of monochrome images, mode 7
0, //pRoiTop Region of Interest upper corner for for VOI transform of monochrome images, mode 7
0, //pRoiWidth Region of Interest width for for VOI transform of monochrome images, mode 7
0, //pRoiHeight Region of Interest height for for VOI transform of monochrome images, mode 7
OFFalse, //pUsePixelValues Check smallest and largest pixel value and optimize compression, mode 0 only
OFFalse); //pUseModalityRescale Create Rescale Slope/Intercept to scale back to original pixel range, mode 0 only
// EXS_JPEG2000LosslessOnly = 26, EXS_JPEG2000 = 27,
DJ_RPLossy rp_lossy (nQuality);
DJ_RPLossless rp_lossless (6, 0);
const DcmRepresentationParameter *rp = &rp_lossless;
switch (nCompressMode) {
case EXS_JPEGProcess1TransferSyntax: // lossy JPEG compression
case EXS_JPEG2000:
rp = &rp_lossy;
}
//eConvType = EPI_Monochrome2;
eConvType = eInpConvType;
if(eInpConvType == EPI_RGB)
bytesPerPixel = 3;
// Get the pointer to the codec that will do our encoding
DcmCodec * Codec = NULL;
//DcmCodecParameter * CodecParam = NULL;
//DJEncoderBaseline * JpegCodec = NULL;
m_pCodecParam = NULL;
m_pCodec = NULL;
DcmCodecList::getCanChangeCoding(EXS_LittleEndianExplicit, (const E_TransferSyntax) nCompressMode, Codec, m_pCodecParam);
//JpegCodec = (DJEncoderP14SV1*)Codec;
//JpegCodec = (DJEncoderBaseline*)Codec;
m_pCodec = (DJEncoderBaseline*)Codec;
m_pEncoder = m_pCodec->getCreateEncoderInstance(rp, (const class DJCodecParameter*)m_pCodecParam, ;
//create a blank frame
m_pScaledInput = new Uint8 [nTargetSize * nTargetSize*bytesPerPixel];
memset (m_pScaledInput, nBlankByte, nTargetSize * nTargetSize);
OFCondition cond = m_pEncoder->encode(nTargetSize, nTargetSize, eConvType, 1, m_pScaledInput, m_pBlank, m_nBlankLen);
return 0;
}
I have tried a bunch of different things like changing the
getCreateEncoderInstance to use 24 bits per sample for Color etc, but there is always some error.
Any help would be appreciated.
Trying to Write Class to Compress MonoChrome2 and RGB
Moderator: Moderator Team
-
- DCMTK Developer
- Posts: 2049
- Joined: Fri, 2004-11-05, 13:47
- Location: Oldenburg, Germany
- Contact:
Hi MicroFace,
The error comes from the IJG libraries stating that the number of pixel components does not match the defined colorspare (look into jccolor.c). I did not check the code completely, but at "first sight" :
Does this line:
does not have to look like this?
Because you reserve "nTargetSize * nTargetSize*bytesPerPixel" bytes in the line above for m_pScaledInput. I don't know whether this is crucial or if only your pixel data will be non-blank if you don't clear the input data.
Regards,
Michael
The error comes from the IJG libraries stating that the number of pixel components does not match the defined colorspare (look into jccolor.c). I did not check the code completely, but at "first sight" :
Does this line:
Code: Select all
memset (m_pScaledInput, nBlankByte, nTargetSize * nTargetSize);
Code: Select all
memset (m_pScaledInput, nBlankByte, nTargetSize * nTargetSize * bytesPerPixel);
Regards,
Michael
Yes thank you I allocate using the
nTargetSize * nTargetSize*bytesPerPixel
But forgot the memset.
so I have allocated teh correct amount of space in my code,
but I am still setting the described error.
I have tried chnging the registerCodecs to use various parameters
ECC_MONOCHROME, ECC_lossyRGB etc etc.
I am beginning to think I would be better off just figuring out how to use no compression, and take the hit on disk space, and time to save the files to the disk.
Any further suggestions ?
nTargetSize * nTargetSize*bytesPerPixel
But forgot the memset.
so I have allocated teh correct amount of space in my code,
but I am still setting the described error.
I have tried chnging the registerCodecs to use various parameters
ECC_MONOCHROME, ECC_lossyRGB etc etc.
I am beginning to think I would be better off just figuring out how to use no compression, and take the hit on disk space, and time to save the files to the disk.
Any further suggestions ?
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest