spateo.alignment.methods.morpho_mesh_correction =============================================== .. py:module:: spateo.alignment.methods.morpho_mesh_correction Classes ------- .. autoapisummary:: spateo.alignment.methods.morpho_mesh_correction.Mesh_correction Module Contents --------------- .. py:class:: Mesh_correction(slices: List[anndata.AnnData], z_heights: Union[List, numpy.ndarray], mesh: pyvista.PolyData, spatial_key: str = 'spatial', key_added: str = 'align_spatial', normalize_spatial: bool = False, init_rotation: Optional[numpy.ndarray] = np.array([0.0, 0.0, 0.0]), init_translation: Optional[numpy.ndarray] = 0.0, init_scaling: Optional[numpy.ndarray] = 1.0, max_rotation_angle: float = 180, max_translation_scale: float = 0.5, max_scaling: float = 1.5, min_rotation_angle: float = 10, min_translation_scale: float = 1, min_scaling: float = 1.1, label_num: int = 15, fastpd_iter: int = 100, max_iter: int = 10, anneal_rate: float = 0.7, multi_processing: bool = False, subsample_slices: Optional[int] = None, verbose: bool = False) A class to perform 3D reconstruction correction from slices using a mesh. .. attribute:: slices A list of aligned slices by Spateo or other methods. :type: List[AnnData] .. attribute:: z_heights The z-coordinates for each slice. :type: Union[List, np.ndarray] .. attribute:: mesh The mesh used for correction. :type: PolyData .. attribute:: spatial_key The key to access spatial coordinates in the AnnData objects. The spatial coordinates under this key should be pre-aligned. :type: str .. attribute:: key_added The key under which the corrected spatial coordinates will be added. :type: str .. attribute:: normalize_spatial Flag indicating if spatial coordinates will be normalized. :type: bool .. attribute:: init_rotation Initial rotation angles (in degrees) for the correction. :type: np.ndarray .. attribute:: init_translation Initial translation vector for the correction. :type: np.ndarray .. attribute:: init_scaling Initial scaling factor for the correction. :type: np.ndarray .. attribute:: max_rotation_angle Maximum rotation angle allowed during the correction process. :type: float .. attribute:: max_translation_scale Maximum translation scale allowed during the correction process. :type: float .. attribute:: max_scaling Maximum scaling factor allowed during the correction process. :type: float .. attribute:: label_num Number of labels used for optimization. :type: int .. attribute:: fastpd_iter Number of iterations for the fastPD algorithm. :type: int .. attribute:: max_iter Maximum number of iterations for the correction process. :type: int .. attribute:: anneal_rate Annealing rate for the optimization process. :type: float .. attribute:: multi_processing Flag indicating if multiprocessing will be used for the correction process. :type: bool .. py:attribute:: n_slices .. py:attribute:: slices_spatial .. py:attribute:: z_heights .. py:attribute:: mesh .. py:attribute:: key_added :value: 'align_spatial' .. py:attribute:: normalize_spatial :value: False .. py:attribute:: max_rotation_angle :value: 180 .. py:attribute:: max_translation_scale :value: 0.5 .. py:attribute:: max_scaling :value: 1.5 .. py:attribute:: min_rotation_angle :value: 10 .. py:attribute:: min_translation_scale :value: 1 .. py:attribute:: min_scaling :value: 1.1 .. py:attribute:: label_num :value: 15 .. py:attribute:: fastpd_iter :value: 100 .. py:attribute:: max_iter :value: 10 .. py:attribute:: anneal_rate :value: 0.7 .. py:attribute:: multi_processing :value: False .. py:attribute:: subsample_slices :value: None .. py:attribute:: verbose :value: False .. py:attribute:: contours .. py:method:: set_init_parameters(init_rotation: Optional[numpy.ndarray] = np.array([0.0, 0.0, 0.0]), init_translation: Optional[numpy.ndarray] = 0.0, init_scaling: Optional[numpy.ndarray] = 1.0) Sets the initial transformation parameters for the mesh. :param init_rotation: Initial rotation angles (in degrees) for the mesh. Defaults to np.array([0., 0., 0.]). :type init_rotation: Optional[np.ndarray], optional :param init_translation: Initial translation vector for the mesh. Defaults to 0. :type init_translation: Optional[np.ndarray], optional :param init_scaling: Initial scaling factor for the mesh. Defaults to 1. :type init_scaling: Optional[np.ndarray], optional .. py:method:: normalize_mesh_spatial_coordinates() Normalizes the spatial coordinates of the mesh to align with the slices' spatial scale. This method calculates the scaling factor based on the maximum spatial extent of the slices and the z-height range, then applies this scaling to the mesh points. It also centers the mesh points along the z-axis to match the mean z-height of the slices. .. py:method:: extract_contours(method: Literal['opencv', 'alpha_shape'] = 'alpha_shape', n_sampling: Optional[int] = None, smoothing: bool = True, window_size: int = 5, filter_contours: bool = True, contour_filter_threshold: int = 20, opencv_kwargs: Optional[Dict] = None, alpha_shape_kwargs: Optional[Dict] = None) Extracts contours of slices using the specified method. :param method: Method to extract contours. Defaults to "alpha_shape". :type method: Literal["opencv", "alpha_shape"], optional :param n_sampling: Number of points to sample from each slice. Defaults to None. :type n_sampling: Optional[int], optional :param smoothing: Whether to smooth the contours. Defaults to True. :type smoothing: bool, optional :param window_size: Window size for contour smoothing. Defaults to 5. :type window_size: int, optional :param filter_contours: Whether to filter the contours based on the threshold. Defaults to True. :type filter_contours: bool, optional :param contour_filter_threshold: Threshold for filtering contours based on the number of points. Defaults to 20. :type contour_filter_threshold: int, optional :param opencv_kwargs: Additional arguments for the OpenCV method. Defaults to None. :type opencv_kwargs: Optional[Dict], optional :param alpha_shape_kwargs: Additional arguments for the alpha shape method. Defaults to None. :type alpha_shape_kwargs: Optional[Dict], optional .. py:method:: run_discrete_optimization() -> None Runs the discrete optimization process to find the best transformation parameters. .. py:method:: discrete_optimization_step() -> Tuple[float, numpy.ndarray] Performs a discrete optimization step to find the best transformation. :returns: The loss and the best transformation found. :rtype: Tuple[float, np.ndarray] .. py:method:: generate_labels() -> numpy.ndarray Generates discrete labels for rotation, translation, and scaling. :returns: An array of discrete transformation labels. :rtype: np.ndarray .. py:method:: perform_correction() Performs the correction using the best transformation found.