update calibration

This commit is contained in:
Nicolas Bertrand 2025-10-09 19:39:28 +02:00
parent 80d259e519
commit 35b039a39a
1 changed files with 7 additions and 6 deletions

View File

@ -28,7 +28,7 @@ def calibrate(input_dir: str):
# Camera parameters
nu, nv, nc = images[0].shape
nspheres = 5
nspheres = 4
focal_mm = 35
matrix_size = 24
focal_pix = nu * focal_mm / matrix_size
@ -41,14 +41,15 @@ def calibrate(input_dir: str):
pixels = np.reshape(max_image / 255.0, (-1, 3))
# Initialize parameters for GMM
init_params = np.ones(2), np.broadcast_to(np.eye(3) * 0.1, (2, 3, 3)), np.asarray([[0, 0, 0], [1, 1, 1]])
# init_params = np.ones(2), np.broadcast_to(np.eye(3) * 0.1, (2, 3, 3)), np.asarray([[0, 0, 0], [1, 1, 1]])
# Estimate GMM parameters and classify pixels
estimated_params = math_utils.gaussian_mixture_estimation(pixels, init_params, it=10)
classif = np.asarray(math_utils.maximum_likelihood(pixels, estimated_params), dtype=bool)
# estimated_params = math_utils.gaussian_mixture_estimation(pixels, init_params, it=10)
# classif = np.asarray(math_utils.maximum_likelihood(pixels, estimated_params), dtype=bool)
# Refine classification to select the appropriate binary mask
rectified_classif = math_utils.select_binary_mask(classif, lambda mask: np.mean(pixels[mask]))
# rectified_classif = math_utils.select_binary_mask(classif, lambda mask: np.mean(pixels[mask]))
rectified_classif = np.mean(pixels, axis=-1) > 0.03
# Identify the largest connected components (spheres) and extract their borders
sphere_masks = math_utils.get_greatest_components(np.reshape(rectified_classif, (nu, nv)), nspheres)
@ -79,7 +80,7 @@ def calibrate(input_dir: str):
# Load grey values from images for the identified sphere regions
def to_grayscale(image):
return [np.mean(image, axis=-1)[sphere_geometric_masks[i]] / 255.0 for i in range(nspheres)]
return [np.power(np.mean(image, axis=-1)[sphere_geometric_masks[i]] / 255.0, 1.0) for i in range(nspheres)]
grey_values = np.asarray(list(map(to_grayscale, images)), dtype=object)