Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

JPEG 2000 compression for 16 bit images does not work

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.

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", CV_LOAD_IMAGE_GRAYSCALE);
  Mat image16;
  image8.convertTo(image16, CV_16UC1);

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

  Mat newImage16 = imread("c:\\tmp\\test16.jp2", CV_LOAD_IMAGE_GRAYSCALE), 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", CV_LOAD_IMAGE_GRAYSCALE);
  Mat image16;
  image8.convertTo(image16, CV_8UC1);

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

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

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

I have posted this about a year ago in another forum, using at that time OpenCV 2.3.1 on a 32 bit Window system using Microsoft Visual Studio 2010.

I am now working at a 64 bit Window system using Visual Studio 2012 and made my own build of OpenCV 2.4.6.1 using among other stuff the GPU module (CUDA).

I have the same problem with JPEG2000 again. Am I doing something wrong or is this a bug in OpenCV I should report?

PS: My image is a small one a 640x480 pixels only.

Thansk in advance, Torben.