Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from cv2_45 import cv2
- import numpy as np
- img_cv = cv2.imread('example_image.tiff', cv2.IMREAD_ANYDEPTH)
- img_cv = img_cv.view(np.int32)
- print(img_cv.max()) # 40950
- # Since the max_value is less than 2^16, let's cast it to 16bit
- img_cv_16bit = img_cv.astype(np.uint16)
- cv2.imwrite('output_cv_16bit.png', img_cv_16bit)
- # Actually, it looks like those max values are just spurious extra bright spots.
- # We can probably clip it to 8bit range... if we scale it down by 16
- img_cv_8bit = np.clip(img_cv_16bit // 16, 0, 255).astype(np.uint8)
- cv2.imwrite('output_cv_8bit.png', img_cv_8bit)
- # =========
- # And just for demonstration, PIL reads it as int32 with the same max
- from PIL import Image
- img_pil = Image.open('example_image.tiff')
- img_pil_cv = np.array(img_pil)
- print(img_pil_cv.dtype) # int32
- print(img_pil_cv.max()) # 40950
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement