# Revision history [back]

### 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);

newImage16.convertTo(imageNew8, CV_8UC1);

waitKey(0);


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);

newImage16.convertTo(imageNew8, CV_8UC1);