Skip to content

Instantly share code, notes, and snippets.

@decrispell
decrispell / normals_from_xyz.py
Created September 26, 2019 19:11
Compute surface normals from 3-plane "xyz" image data
import numpy as np
def normals_from_xyz(xyz, smooth_sigma=None):
"""
Given a 3-plane float image containing x,y,z coordinates,
compute the surface normals at each pixel.
Returns a 3-plane floating point image with nx,ny,nz per pixel.
"""
if smooth_sigma is not None:
xyz = np.array(xyz) # make copy of input
@decrispell
decrispell / crop_geotiff.py
Last active January 7, 2023 15:56
quick and dirty geotiff crop using rasterio
import rasterio
# load the geotiff (a DSM in this case) and read the data - only one index in this case
dsm = rasterio.open(dsm_fname)
dsm_data = dsm.read()[0]
# crop the data
dsm_crop = dsm_data[min_y:min_y+height, min_x:min_x+width]
# make a copy of the geotiff metadata
@decrispell
decrispell / make_vtk_camera.cpp
Last active March 1, 2024 02:47
Convert standard camera intrinsic (focal length, principal point) and extrinsic parameters (rotation and translation) into a vtkCamera for rendering. Assume square pixels and 0 skew for now.
/**
* Convert standard camera intrinsic and extrinsic parameters to a vtkCamera instance for rendering
* Assume square pixels and 0 skew (for now).
*
* focal_len : camera focal length (units pixels)
* nx,ny : image dimensions in pixels
* principal_pt: camera principal point,
* i.e. the intersection of the principal ray with the image plane (units pixels)
* camera_rot, camera_trans : rotation, translation matrix mapping world points to camera coordinates
* depth_min, depth_max : needed to set the clipping range