JPEG 2000 compression for 16 bit images does not work for me

classic Classic list List threaded Threaded
3 messages Options
ttn
Reply | Threaded
Open this post in threaded view
|

JPEG 2000 compression for 16 bit images does not work for me

ttn
Hi,

according to the OpenCV documentation, I should be able to save a 16 bit (unsigned) image to
a JPEG 2000 image, and then later read it again from the file.

I am using OpenCV 2.3.1 on a Windows 7 computer (PC) with the C++ interface.
And I need to save 16 bit images with a fairly compression (so loosy compression is accepted). This should be easy using JPEG 2000 according to documentation.

The following code snippet shows the problem (I start by loading a simple 8 bit JPG image as I asume not every body reading this have a 16 bit image available - also I am working on gray level images only):

--------------------------------
  Mat image8 = imread("c:\\tmp\\about.jpg", 0);
  Mat image16;
  image8.convertTo(image16, CV_16UC1);

  imwrite("c:\\tmp\\test16.jp2", image16);

  Mat newImage16 = imread("c:\\tmp\\test16.jp2", 0), imageNew8;
  newImage16.convertTo(imageNew8, CV_8UC1);

  namedWindow("About", 0);
  imshow("About", imageNew8);
  waitKey(0);
  destroyWindow("About");
--------------------------------

The same code snippet works if I only use 8 bit JPEG 2000 compression (changing only one line):

--------------------------------
  Mat image8 = imread("c:\\tmp\\about.jpg", 0);
  Mat image16;
  image8.convertTo(image16, CV_8UC1);

  imwrite("c:\\tmp\\test16.jp2", image16);

  Mat newImage16 = imread("c:\\tmp\\test16.jp2", 0), imageNew8;
  newImage16.convertTo(imageNew8, CV_8UC1);

  namedWindow("About", 0);
  imshow("About", imageNew8);
  waitKey(0);
  destroyWindow("About");
--------------------------------


Can anyone help me on this. Am I doing something wrong or does the described 16 bit JPEG 2000 compression not work in OpenCV (a bug)?

Or do I need a special JPEG 2000 compression DLL than what OpenCV delivers (libjpg)?

Thanks in advance, Torben.

ttn
Reply | Threaded
Open this post in threaded view
|

Re: JPEG 2000 compression for 16 bit images does not work for me

ttn
Hi again,

I am now sure this must be a bug in OpenCV, it neither work when using imencode and imdecode.
So I gave up and is now using the compression library JPG-LS (in case anybody is interested :-).

Regards Torben.
ttn
Reply | Threaded
Open this post in threaded view
|

Re: JPEG 2000 compression for 16 bit images does not work for me

ttn