Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- img = cv2.imread('combined.png', cv2.IMREAD_GRAYSCALE)
- height, width = img.shape
- # Determine the actual height of the component images
- real_height = height/3
- # Extract the top (intensity) part
- intensity_img = img[:real_height,...]
- # Extract the botton (heightmap) part
- # Since this has two values per pixel, also reshape it to have the correct number of rows
- heightmap_raw = img[real_height:,...].reshape(real_height,-1)
- # The heightmap is 16 bit, two subsequent 8 bit pixels need to be combined
- # ABCD -> A+256*B, C+256*D
- # Quick but non-portable (needs little-endian architecture)
- heightmap_img = heightmap_raw.view(np.uint16)
- # Slower but portable
- heightmap_a = heightmap_raw[...,::2].astype(np.uint16)
- heightmap_b = heightmap_raw[...,1::2].astype(np.uint16)
- heightmap_img = heightmap_a + 256 * heightmap_b
- # Note: intensity is np.uint8, heightmap is np.uint16
- cv2.imwrite('intensity.png', intensity_img)
- cv2.imwrite('heightmap.png', heightmap_img) # This is just an example so I can show the image, writing as PNG will convert to 8bit, losing detail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement