I have a (basically working) program which inputs several 8-bit three colour channel .png images and blends them using a Laplacian pyramid method. The processing is done in float values, so I use input_image = cv2.imread('file_name', cv2.IMREAD_UNCHANGED) then convert the format with image=input_image.astype(np.float64) and the result is a 3-colour float array with pixel values nominally 0.0-255.0. Now I want to save the result to file so I do: cv2.imwrite('file.png', image) and all is well - the resulting file is an 8-bit image, correctly rendered by other programs. If I do cv2.imwrite('file.png', image.astype(np.uint8)) the colours in certain areas of the image are corrupted. I find this difficult to understand, but it hardly matters in this case as I can simply use the first form and get the result I need. However, I now want to input 16-bit colour images and output a corresponding 16-bit 3-colour result. Indeed, my routine outputs a float array with nominal data range 0.0-65535.0. If I use cv2.imwrite('file.png', image) in this case, I get a burnt-out 8-bit image. And if I do cv2.imwrite('file.png', image.astype(np.uint16)) then the result is a 16-bit image with the same corrupted colours as in the 8-bit case. I can use cv2.imwrite('file.png', image/256) to output a correctly coloured image - but of course it is 8-bit. Can anyone recommend a better way to output a 16-bit png image? The docs are clear that this should work, but thin on details how. I am using opencv 4.6.0 with Python 3.12.3 on Ubuntu 24.4. Thanks! Continue reading...