Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

My comment to berak is badly formatted, so I post it here again:

Mat image8, image16;
image8 = imread("c:\tmp\test.jpg", CV_LOAD_IMAGE_GRAYSCALE);
image8.convertTo(image16, CV_16UC1, 255);

bool result = imwrite("c:\tmp\test.jp2", image16);

Mat imageNew8, newImage16;
newImage16 = imread("c:\tmp\test.jp2", CV_LOAD_IMAGE_ANYDEPTH|CV_LOAD_IMAGE_ANYCOLOR);
newImage16.convertTo(imageNew8, CV_8UC1, 1.0/255);

results in a totally distorted image (both newImage16 and newImage8, the result variable indicates that the write went well).

The "c:\tmp\test.jp2" shown in IrfanView as just a black image (can not see the pixel values, but they are checked in the code via newImage16 to be totally wrong in something like half of the picture). That IrfanView can not display the image properly is not a problem for me, I am not the the decoder here is 100% compatible with libjasper.

My comment to berak is badly formatted, so I post it here again:

Mat image8, image16;
image8 = imread("c:\tmp\test.jpg", CV_LOAD_IMAGE_GRAYSCALE);
image8.convertTo(image16, CV_16UC1, 255);

bool result = imwrite("c:\tmp\test.jp2", image16);

Mat imageNew8, newImage16;
newImage16 = imread("c:\tmp\test.jp2", CV_LOAD_IMAGE_ANYDEPTH|CV_LOAD_IMAGE_ANYCOLOR);
newImage16.convertTo(imageNew8, CV_8UC1, 1.0/255);

results in a totally distorted image (both newImage16 and newImage8, the result variable indicates that the write went well).

The "c:\tmp\test.jp2" is shown in IrfanView as just a black image (can not see the pixel values, but they are checked in the code via newImage16 to be totally wrong in something like half of the picture). That IrfanView can not display the image properly is not a problem for me, I am not the sure whether the decoder here is 100% compatible with libjasper.