pandora2d.memory_estimation =========================== .. py:module:: pandora2d.memory_estimation .. autoapi-nested-parse:: This module contains methods associated to the pandora2d memory estimation Attributes ---------- .. autoapisummary:: pandora2d.memory_estimation.BYTE_TO_MB pandora2d.memory_estimation.RELATIVE_ESTIMATION_MARGIN pandora2d.memory_estimation.IMG_DATA_VAR pandora2d.memory_estimation.IMG_DATA_VAR_MASK pandora2d.memory_estimation.CV_FLOAT_DATA_VAR pandora2d.memory_estimation.CV_DOUBLE_DATA_VAR pandora2d.memory_estimation.DATA_VARS_TYPE_SIZE Classes ------- .. autoapisummary:: pandora2d.memory_estimation.RoiRange pandora2d.memory_estimation.Roi Functions --------- .. autoapisummary:: pandora2d.memory_estimation.estimate_total_consumption pandora2d.memory_estimation.compute_effective_image_size pandora2d.memory_estimation.get_img_size pandora2d.memory_estimation.get_nb_disp pandora2d.memory_estimation.get_roi_margins pandora2d.memory_estimation.img_dataset_size pandora2d.memory_estimation.estimate_input_size pandora2d.memory_estimation.estimate_cost_volumes_size pandora2d.memory_estimation.estimate_shifted_right_images_size pandora2d.memory_estimation.estimate_pandora_cost_volume_size pandora2d.memory_estimation.estimate_dataset_disp_map_size pandora2d.memory_estimation.segment_image_by_rows Module Contents --------------- .. py:data:: BYTE_TO_MB :value: 1048576 .. py:data:: RELATIVE_ESTIMATION_MARGIN :value: 0.25 .. py:data:: IMG_DATA_VAR :value: ['im', 'row_disparity_min', 'row_disparity_max', 'col_disparity_min', 'col_disparity_max'] .. py:data:: IMG_DATA_VAR_MASK :value: ['im', 'row_disparity_min', 'row_disparity_max', 'col_disparity_min', 'col_disparity_max', 'msk'] .. py:data:: CV_FLOAT_DATA_VAR :value: ['cost_volumes_float', 'criteria'] .. py:data:: CV_DOUBLE_DATA_VAR :value: ['cost_volumes_double', 'criteria'] .. py:data:: DATA_VARS_TYPE_SIZE .. py:function:: estimate_total_consumption(config: dict, height: int, width: int, margin_disp: pandora2d.margins.Margins = NullMargins()) -> float Estimate the total memory consumption of all objects that will be allocated. :param config: configuration with ROI margins if necessary. :param height: Image height including any ROI adjustments. :param width: Image width including any ROI adjustments. :param margin_disp: Disparity margins. :return: Memory consumption estimate in megabytes. .. py:function:: compute_effective_image_size(config: dict, image_margins: pandora2d.margins.Margins) -> tuple[int, int] Compute the effective image size (height, width), including ROI and global margins. :param config: Configuration dictionary containing the image path and optional ROI information. :param image_margins: Margins to apply around the ROI to ensure the full region is processed. Used only when a ROI is defined. Defaults to None. :return: Image dimensions as (height, width) including margins. .. py:function:: get_img_size(img_path: str, roi: dict = None) -> tuple[int, int] Get width and height from an image path. If a ROI is given, its width and height are returned without taking margins into account. :param img_path: img path :return: width and height of the image .. py:function:: get_nb_disp(disparity: dict, before_margins: int = 0, after_margins: int = 0, subpix: int = 1) -> int Get number of disparities. :param disparity: init and range for disparities. :param before_margins: Margins before the minimum disparity. :param after_margins: Margins after the maximum disparity. :param subpix: subpix :return: number of disparities .. py:function:: get_roi_margins(row_disparity: dict, col_disparity: dict, global_margins: pandora2d.margins.Margins) -> pandora2d.margins.Margins Get ROI margins according to row and col disparities and global margins calculated in the check conf step. :param row_disparity: init and range for disparities in rows. :param col_disparity: init and range for disparities in columns. :param global_margins: global image margins computed in the check conf :return: ROI margins updated according to disparity values .. py:function:: img_dataset_size(height: int, width: int, nb_bytes: int) -> float Return image dataset size (MB) according to width, height and sum of the number of bytes corresponding to the different data types contained in the image dataset. :param height: image or ROI number of rows :param width: image or ROI number of columns :param nb_bytes: sum of the number of bytes. :return: size of image dataset in MB .. py:function:: estimate_input_size(height: int, width: int, data_vars: list[str]) -> float Estimate input configuration size (MB) according to image width, height and data variables contained in the image dataset. :param height: image or ROI number of rows :param width: image or ROI number of columns :param data_vars: data variables contained in the image dataset. :return: size of image dataset in MB .. py:function:: estimate_cost_volumes_size(user_cfg: dict, height: int, width: int, margins_disp: pandora2d.margins.Margins, data_vars: list[str]) -> float Estimate 4D cost volumes size (MB) according to image width, height, number of disparities, subpix, step and data variables contained in the cost volumes dataset. :param user_cfg: user configuration :param height: image or ROI number of rows :param width: image or ROI number of columns :param margins_disp: disparity margins computed in the check conf :param data_vars: data variables contained in the cost_volumes dataset. :return: size of image dataset in MB .. py:function:: estimate_shifted_right_images_size(height: int, width: int, subpix: int) -> float Estimate the size in MB of the list of shifted right images (excluding the original right image itself). :param height: height of image :param width: width of image :param subpix: subpixel :return: estimated size in MB .. py:function:: estimate_pandora_cost_volume_size(config: dict, height: int, width: int, margins: pandora2d.margins.Margins) -> float Estimate the size in MB of the cost volume according to image width, height, and refinement margins. :param config: user configuration. :param height: image or ROI number of rows :param width: image or ROI number of columns :param margins: Refinement margins. :return: estimated size in MB. .. py:function:: estimate_dataset_disp_map_size(height: int, width: int, step: list, dtype: numpy.typing.DTypeLike, cost_volume_confidence_step: bool) -> float Estimate the size in MB of the disparity map dataset. :param height: image or ROI number of rows. :param width: image or ROI number of columns. :param step: step. :param dtype: dtype of the disparity map (should be same as cost volumes dataset). :param cost_volume_confidence_step: whether to include the cost volume confidence step. :return: estimated size in MB. .. py:class:: RoiRange Bases: :py:obj:`TypedDict` Represents the range of rows or columns in a region of interest (ROI). :param first: Index of the first row or column. :param last: Index of the last row or column (inclusive). .. py:attribute:: first :type: int .. py:attribute:: last :type: int .. py:class:: Roi Bases: :py:obj:`TypedDict` Represents a 2D region of interest, defined by row and column bounds. :param row: Row range of the ROI. :param col: Column range of the ROI. .. py:attribute:: row :type: RoiRange .. py:attribute:: col :type: RoiRange .. py:function:: segment_image_by_rows(config: dict, disp_margins: pandora2d.margins.Margins, image_margins: pandora2d.margins.Margins) -> list[Roi] Split an image into multiple horizontal ROI segments that fit within memory constraints. This function estimates the memory required to process the full image with the provided disparity margins. If the memory requirement exceeds the configured `memory_per_work`, the image is split into horizontal segments whose individual memory usage remains within the allowed limit. :param config: Configuration dictionary containing keys such as 'segment_mode' and 'pipeline'. :param disp_margins: Margins applied during disparity computation. Defaults to NullMargins. :param image_margins: Margins applied to image. :return: List of segment dictionaries with row and column bounds. :raises ValueError: If the minimum memory required for processing a basic segment exceeds the configured `memory_per_work`.