Skip to content

Instantly share code, notes, and snippets.

@jmpinit
Last active June 28, 2023 20:18
Show Gist options
  • Save jmpinit/cda931a4759b1790f7bdd9d3aee28d29 to your computer and use it in GitHub Desktop.
Save jmpinit/cda931a4759b1790f7bdd9d3aee28d29 to your computer and use it in GitHub Desktop.
Fast image export from Houdini using a Python node. Assumes a grid of points (one per pixel) with Cd set to the pixel color.
from pathlib import Path
import numpy as np
from PIL import Image
node = hou.pwd()
geo = node.geometry()
hip_path = Path(hou.hipFile.path())
render_dir = hip_path.parent / 'render'
image_path = hou.parm('image_out_filename').eval()
width = hou.parm('width_in_pixels').eval()
height = hou.parm('height_in_pixels').eval()
width_in_m = hou.parm('width_in_m').eval()
height_in_m = hou.parm('height_in_m').eval()
dpi = hou.parm('dpi').eval()
point_colors = np.uint8(np.array(geo.pointFloatAttribValues('Cd')) * 255).reshape((height, width, 3))
image_out = Image.fromarray(point_colors, mode='RGB')
image_out.save(image_path, dpi=(dpi, dpi))
import numpy as np
from PIL import Image
node = hou.pwd()
geo = node.geometry()
image_path = hou.parm('image_path').eval()
image = Image.open(image_path)
image_array = np.array(image)
height, width, channel_count = image_array.shape
assert channel_count == 3
cd_values = image_array.flatten()[:len(geo.points()) * 3].astype(np.float) / 255.0
geo.setPointFloatAttribValues('Cd', cd_values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment