Skip to content

Instantly share code, notes, and snippets.

@Don-Moahskarton
Created May 29, 2020 17:51
Show Gist options
  • Save Don-Moahskarton/287abd17b7ad33a7dada45429c3a93ae to your computer and use it in GitHub Desktop.
Save Don-Moahskarton/287abd17b7ad33a7dada45429c3a93ae to your computer and use it in GitHub Desktop.
import cv2
import sys
import numpy as np
#config
outputSize = 1017
image = cv2.imread('in.png', cv2.IMREAD_UNCHANGED)
dimensions = image.shape
# height, width, number of channels in image
height = image.shape[0]
width = image.shape[1]
print('heightmap Height : ',height)
print('heightmap Width : ',width)
#imS = cv2.resize(image, (512, 512))
#cv2.imshow("original (512 resize)", imS)
x_name = 0
x = 0
while x+outputSize < width:
y = 0
y_name = 0
while y+outputSize < height:
out_file_name = "IMG_X" + str(x_name) + "_Y" + str(y_name) + ".png"
print("Currently rendering " + out_file_name)
crop_image = image[y:y+outputSize, x:x+outputSize]
cv2.imwrite(out_file_name, crop_image.astype(np.uint16))
y+=outputSize-1
y_name+=1
x+=outputSize-1
x_name+=1
cv2.waitKey(0)
@cyber-speed
Copy link

This is a great find, but i have another question, is there a way to use same script but in reverse?
Meaning i have the tiles in RAW format of 32-bit floating points, and I'd like to merge them back to a single height map and then to slice them for UE using script above since i no longer have the original large single height map.
Is there a way you could help at all?
The tiles i have are 257x257 and must overlap by 1 pixel.
The end result will not be a power of 2 height map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment