Advertisement
dan-masek

Interpret SICK Trispector PNG

Mar 25th, 2020
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. img = cv2.imread('combined.png', cv2.IMREAD_GRAYSCALE)
  5. height, width = img.shape
  6.  
  7. # Determine the actual height of the component images
  8. real_height = height/3
  9.  
  10. # Extract the top (intensity) part
  11. intensity_img = img[:real_height,...]
  12.  
  13. # Extract the botton (heightmap) part
  14. # Since this has two values per pixel, also reshape it to have the correct number of rows
  15. heightmap_raw = img[real_height:,...].reshape(real_height,-1)
  16.  
  17. # The heightmap is 16 bit, two subsequent 8 bit pixels need to be combined
  18. # ABCD -> A+256*B, C+256*D
  19.  
  20. # Quick but non-portable (needs little-endian architecture)
  21. heightmap_img = heightmap_raw.view(np.uint16)
  22.  
  23. # Slower but portable
  24. heightmap_a = heightmap_raw[...,::2].astype(np.uint16)
  25. heightmap_b = heightmap_raw[...,1::2].astype(np.uint16)
  26. heightmap_img = heightmap_a + 256 * heightmap_b
  27.  
  28. # Note: intensity is np.uint8, heightmap is np.uint16
  29.  
  30. cv2.imwrite('intensity.png', intensity_img)
  31. 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