OpenvCV JPEG2000 compression error

Hi, I have a problem to compress greyscale image with JPEG2000. I have 3000x3000 , 16-bits, uint16, Little Edian raw-image. After compression(raw->jp2)-decompression(jp2->raw) , I can see compression loss. Any suggestions?
I’m using opencv-python (4.4.046)

precisely what code do you use to compress the picture?

can you quantify the issue? take the cv::absdiff of the decoded picture and calculate some statistics on that

i’m using cv2:imwrite(“file_name.jp2”, img_array)… the images are not equal.

by how much are they not equal? a screenshot of a window showing a mostly gray picture doesn’t illustrate your point very well. jpeg2000 is not necessarily lossless and you didn’t configure a quality value to imwrite (although the default for jpeg2000 is “1.0”).

right, but as I understood… there is NO option to change the default setting. Am I wrong?

Yes. the IMWRITE_JPEG2000_COMPRESSION_X1000 option. it doesn’t appear to force lossless compression for any value, at least on my system with somewhat outdated OpenCV.

cv::imwrite documentation
cv::ImwriteFlags documentation

cv.absdiff(im1, im2).max() # maximum difference between pictures

OpenCV seems to still use the Jasper library, which is sadly unmaintained, so it will be replaced in the future. There is a contribution for OpenJPEG. What’s used depends on how OpenCV was built.

I don’t know what Jasper needs for lossless operation. Jasper docs are very lacking.

feel free to open an issue on OpenCV’s github, requesting the option/default of lossless JPEG2000 operation. I can certainly reproduce lossy compression (deviation at most 1/255) for default settings.

Thank you very much for helping