Source code for utils

import matplotlib.pyplot as plt
import sys
import numpy as np


[docs] def visualize_points(ZIP_object, save_path=None): """ Function for plotting the founded points on the image used for analysis :param object ZIP_object: ZeissImageProcessor Object :param str save_path: path to which the png will be saved :return: None """ plt.imshow(ZIP_object.image_to_analyze, cmap='gray') plt.colorbar() meas_points = ZIP_object.not_scaled_points for item in meas_points: point = item['position'] plt.scatter(point[0], point[1], s=10) plt.title('Points for measurement') if save_path is not None: plt.savefig(save_path) plt.close()
[docs] def parse_args_to_dict(): """ Parser of the arguments from the line command return: dict of the arguments """ args_dict = {} for arg in sys.argv[1:]: if arg.startswith("--"): # usuń początkowe '--' kv = arg[2:] # rozdziel pierwszy '=' if "=" in kv: key, value = kv.split("=", 1) # opcjonalnie usuń cudzysłowy, jeśli ktoś przekazał np. --'obj id'="42" key = key.strip("'\"") value = value.strip("'\"") args_dict[key] = value else: # argument flagowy bez wartości args_dict[kv] = True return args_dict
[docs] def choose_the_closest_point(measurement_points, stage_position): """ Function to choose the closest point from the founded to the stage position :param list measurement_points: list coordinates of the points which will be compared :param dict stage_position: position of the stage :return: list coordinates of the closest point """ stage = np.array([stage_position['x'], stage_position['y'], stage_position['z']]) distances = [np.linalg.norm(np.array(p["position"]) - stage) for p in measurement_points] closest_idx = int(np.argmin(distances)) return measurement_points[closest_idx]