import numpy as np import utils.kernels as kernels import utils.vector_utils as vector_utils def estimate_light(normals,grey_levels, treshold = (0,1)): """Estimates the light directions using the given normals, grey levels, and mask. Args: normals (Array ..., n, dim): Normal vectors. grey_levels (Array ..., n): Grey levels corresponding to the normals. threshold (tuple, optional): Intensity threshold for valid grey levels. Defaults to (0, 1). Returns: Array ..., dim: Estimated light directions. """ validity_mask = np.logical_and(grey_levels>treshold[0],grey_levelsmin_grey_level,np.logical_and(computed_shading>min_dot_product,angular_factor>min_dot_product)) log_flux = np.log(np.maximum(grey_levels,min_grey_level)*np.square(distance)*np.reciprocal(np.maximum(computed_shading,min_dot_product))) log_factor = vector_utils.to_homogeneous(np.expand_dims(np.log(np.maximum(angular_factor,min_dot_product)),axis=-1)) eta = kernels.weighted_least_squares(log_factor,log_flux,validity_mask) mu,log_phi = eta[...,0], eta[...,1] estimated_flux = np.exp(log_phi) return mu,estimated_flux def light_conditions(light_point, principal_directions, points, mu, flux): distance, light_direction, angular_factor = geometric_shading_parameters(light_point, principal_directions, points) light_conditions = light_direction*(np.reciprocal(np.square(distance))*np.power(angular_factor,mu)*flux)[...,np.newaxis] return light_conditions