Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- print('Loading CSV...')
- raw = np.loadtxt('HEA_515_01.csv', delimiter=';', skiprows=1)
- print('Loaded %d rows.' % len(raw))
- # Split the array for convenience...
- x = raw[:,0]
- y = raw[:,1]
- value = raw[:,2]
- min_x, max_x = x.min(), x.max()
- min_y, max_y = y.min(), y.max()
- min_val, max_val = value.min(), value.max()
- # Determine output image size....
- count_x = len(np.unique(x))
- count_y = len(np.unique(y))
- # Calculate accurate step sizes
- step_x = (max_x - min_x) / (count_x - 1)
- step_y = (max_y - min_y) / (count_y - 1)
- # Remap x and y to pixel coordinates
- x = np.int32(np.rint((x - min_x) / step_x))
- y = np.int32(np.rint((y - min_y) / step_y))
- # Normalize values to range [0.0, 1.0]
- value = (value - min_val) / max_val
- # Create destination array...
- result = np.full((count_y, count_x), np.nan)
- # Assign the values...
- result[y,x] = value
- assert(np.count_nonzero(np.isnan(result)) == 0)
- cv2.imwrite('output.png', np.uint8(result * 255))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement