cv2.resize() function changes 16 bit grayscale to 24 bit grayscale

Question:

When enlarging or shrinking with the cv2.resize function, 16-bit grayscale images are increased to 24 bits. Is there a way to resize them without changing the depth?

img=cv2.imread("16bitgray.tiff")

img512 = cv2.resize(img, (512,512), interpolation=cv2.INTER_NEAREST)
Asked By: eLigt

||

Answers:

If you read a 16-bit greyscale TIFF with:

img=cv2.imread("16bitgray.tiff")

you’ll get an RGB888 TIFF because that is the default. You need:

img=cv2.imread("16bitgray.tiff", cv2.IMREAD_UNCHANGED)
Answered By: Mark Setchell
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.