Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6749 Discussions

Problem with Encoding a 16 bit image to Grayscale jpeg image with JPEG_LOSSLESS option

Dhruba_Mahanta
Beginner
1,253 Views

Hi,

I am new to IPP UIC codecs. My requirement is to encode a 16 bit pixel image to grayscale jpeg format. I need to maintain high quality with lossless compression.

Here is what I am doing:

***********************************************************

CIppImage imageIn;

PARAMS_JPEG param ;

param.nthreads = 1;

param.quality = 100;

param.color = IC_GRAY;

param.mode = JPEG_LOSSLESS;

param.sampling = IS_444;

param.restart_interval = 0;

param.huffman_opt = 0;

param.point_transform = 0;

param.predictor = 1;

param.dct_scale = JD_1_1;

param.comment_size = 0;

CMy16BitImage sourceImg;

//Get the source image

int nHeight(sourceImg.Height()), nWidth(sourceImg.Width());

unsigned short* pSourceImgBuff = sourceImg.GetImageBuffer();

unsigned char* pImageBuffer = new unsigned char[nHeight*nWidth];

//Construct the destination image buffer

unsigned char* pTempBuff = pSourceImgBuff;

for(int i = 0; i < nHeight; ++i)

{

for(int j = 0; j < nWidth; ++j)

{

*pTempBuff = *pSourceImgBuff ;

++pTempBuff ;

++pSourceImgBuff ;

}

}

imageIn.Attach(nHeight, nWidth, 1, 8, (void*)pSourceImgBuff, 0);

CStdFileOutput foJPEG;

if(!BaseStream::IsOk(foJPEG.Open("C:\\\\testOut.jpeg")))

return 1;

imageIn.Sampling(IS_444);

imageIn.Color(IC_GRAY);

SaveImageJPEG(imageIn, param, foJPEG);

*************************************************************

Result: JPEG Image has generated but unable to view in any image viewer including mspaint.

Format is not recognised and errors out.

But if I change the mode as below, I can see some image.

param.mode = JPEG_BASELINE

What am I looking for:

1. Some help to correct the above code so that the image can be viewed.

2. The best param settings for GRAYSCALE LOSSLESS encoding

3. Can I directly attach the 16 bit image buffer to CIppImage without converting to a unsigned char*. I know that for this to happen the precesion param should be 16.

Thanks in advance.

Regards

Dhruba

0 Kudos
8 Replies
Vladimir_Dudnik
Employee
1,253 Views
Hi Dhruba,

according your code it seems you have created a valid lossless JPEG file. Note, the most of popular imaging software does not support lossless JPEG format or 16-bit per color channel images. As lossless JPEG format is widely used in medical-orientedsoftware you may want look for any of those applications to view a lossless JPEG image.

Another option you may use IPP picnic demo application.

Regards,
Vladimir
0 Kudos
Dhruba_Mahanta
Beginner
1,253 Views
Hi Vladimir

Thanks for your reply.
I am using Windows Photo Viewer, MS Paint, which supposed to have support for LOSSLESS JPEG.
I will also try with picnic demo application.


Regards
Dhruba
0 Kudos
levicki
Valued Contributor I
1,253 Views
If I remember correctly, standard JPEG format does not support more than 12 bits of precision. Not a single image viewer/editor can support more than 12 bits and very few of them support 12 bits.

16-bit gray can only be encoded and shown using JPEG2000 format, TIFF format, or PNG format.
0 Kudos
Thomas_Jensen1
Beginner
1,253 Views
No, Jpeg has three compression domains:
- Baseline
- Extended
- Lossless

Baseline = 8 bits per channel lossy or uncompressed.
Extended = 12 bits per channel lossy or uncompressed.
Lossless = 2-16 bits per channel lossless.

(If I'm right)

0 Kudos
Dhruba_Mahanta
Beginner
1,253 Views

Hi Vladimir

I have tried with couple of jpeg viewer such as IrfanView, Picasa, JPEGCrop etc.
None of them can understand the file format.
I am not able to launch picnic application as it is linked with IPP dlls. I have only static IPP libs.
Also it requires some other QT libraries too.

I have attached a lossless JPEG file. Can you please see if you can open in picnic.

Regards
Dhruba

0 Kudos
levicki
Valued Contributor I
1,253 Views
Your file does not contain a picture -- apart from the short header the rest of the file are all zeros.

If I am not mistaken, more than 12 bits is not possible with JPEG in any mode, only with JPEG2000.

My assumption is based on the IJG JPEG library source code which is the basis for all JPEG encoders/decoders used in all image viewing and editing applications.
0 Kudos
Dhruba_Mahanta
Beginner
1,253 Views
Thanks Levicki to giving a hint that the all image bytes are zeros.
I am not sure about the 16 bit support for JPEG Lossless.

But, I have the same issue even for 8 bit imahges.
Can somebody able toencode any Lossless JPEG image using IPP codecs and view inany common image viewer.
Please share the image and basic header configurations.


Regards
Dhruba
0 Kudos
Vladimir_Dudnik
Employee
1,253 Views

IPP JPEG supportsfollowing compression modes defined by JPEG ISO/IEC 10918:
1. Baseline, 8-bits, DCT based process, huffman entropy coding
2. Extended baseline, 8- and 12-bits, DCT based process, huffman entropy coding
3. Lossless, 1..16 bits, prediction based, huffman entropy coding

Most of widely available image viewers and editors only support Baseline and Extended Baseline modes with 8-bits per color component.
To test lossless image created by IPP JPEG encoder you need to look for a specialized software (frequently medical related image vievers do support lossless compression modes as it required by DICOM specification)

Regards,
Vladimir

0 Kudos
Reply