xrf_explorer.server.image_to_cube_selection package¶
Submodules¶
xrf_explorer.server.image_to_cube_selection.image_to_cube_selection module¶
- class CubeType(value)[source]¶
Bases:
Enum
An enumeration to represent different types of datacubes.
- Attributes:
Raw: Represents the raw datacube (i.e. the .raw or .rpl file) Elemental: Represents the elemental datacube (i.e. the .dms file)
- Elemental = 'elemental'¶
- Raw = 'raw'¶
- class SelectionType(value)[source]¶
Bases:
str
,Enum
An enumeration to represent different selection tools.
- Attributes:
Rectangle: Represents the rectangle selection tool. Polygon: Represents the polygon selection tool.
- Polygon = 'polygon'¶
- Rectangle = 'rectangle'¶
- compute_selection_mask(selection_type: SelectionType, selection: list[tuple[int, int]], cube_width: int, cube_height: int)[source]¶
Compute the selection mask of a given selection.
- Parameters:
selection_type – The type of selection the mask being computed is for.
selection – List of points that define the selection.
cube_width – Width of the elemental datacube.
cube_height – Height of the elemental datacube.
- Returns:
2D mask of the datacube, where mask[y, x]==True means the point at (x, y) is in the selection,
False means it is not.
- convexHull(points[, hull[, clockwise[, returnPoints]]]) hull ¶
. @brief Finds the convex hull of a point set. . . The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky’s algorithm @cite Sklansky82 . that has O(N logN) complexity in the current implementation. . . @param points Input 2D point set, stored in std::vector or Mat. . @param hull Output convex hull. It is either an integer vector of indices or vector of points. In . the first case, the hull elements are 0-based indices of the convex hull points in the original . array (since the set of convex hull points is a subset of the original point set). In the second . case, hull elements are the convex hull points themselves. . @param clockwise Orientation flag. If it is true, the output convex hull is oriented clockwise. . Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing . to the right, and its Y axis pointing upwards. . @param returnPoints Operation flag. In case of a matrix, when the flag is true, the function . returns convex hull points. Otherwise, it returns indices of the convex hull points. When the . output array is std::vector, the flag is ignored, and the output depends on the type of the . vector: std::vector<int> implies returnPoints=false, std::vector<Point> implies . returnPoints=true. . . @note points and hull should be different arrays, inplace processing isn’t supported. . . Check @ref tutorial_hull “the corresponding tutorial” for more details. . . useful links: . . https://www.learnopencv.com/convex-hull-using-opencv-in-python-and-c/
- deregister_coord(coord: tuple[int, int], cube_recipe_path: str, base_img_height: int, base_img_width: int, cube_height: int, cube_width: int) tuple[int, int] [source]¶
Translates an (x, y) coordinate to its (x’, y’) counterpart in the cube coordinate system. The function assumes that the cube recipe maps cube coordinates to the base image coordinates.
- Parameters:
coord – The (x, y) coordinate to be translated.
cube_recipe_path – The path to the cube recipe.
base_img_height – The height of the base image in pixels.
base_img_width – The width of the base image in pixels.
cube_height – The height of the cube.
cube_width – The width of the cube.
- Returns:
A (x’, y’) tuple representing the translated coordinate to the cube’s coordinates.
- fillPoly(img, pts, color[, lineType[, shift[, offset]]]) img ¶
. @brief Fills the area bounded by one or more polygons. . . The function cv::fillPoly fills an area bounded by several polygonal contours. The function can fill . complex areas, for example, areas with holes, contours with self-intersections (some of their . parts), and so forth. . . @param img Image. . @param pts Array of polygons where each polygon is represented as an array of points. . @param color Polygon color. . @param lineType Type of the polygon boundaries. See #LineTypes . @param shift Number of fractional bits in the vertex coordinates. . @param offset Optional offset of all points of the contours.
- getPerspectiveTransform(src, dst[, solveMethod]) retval ¶
. @brief Calculates a perspective transform from four pairs of the corresponding points. . . The function calculates the f$3 times 3f$ matrix of a perspective transform so that: . . f[begin{bmatrix} t_i x’_i \ t_i y’_i \ t_i end{bmatrix} = texttt{map_matrix} cdot begin{bmatrix} x_i \ y_i \ 1 end{bmatrix}f] . . where . . f[dst(i)=(x’_i,y’_i), src(i)=(x_i, y_i), i=0,1,2,3f] . . @param src Coordinates of quadrangle vertices in the source image. . @param dst Coordinates of the corresponding quadrangle vertices in the destination image. . @param solveMethod method passed to cv::solve (#DecompTypes) . . @sa findHomography, warpPerspective, perspectiveTransform
- get_scaled_cube_coordinates(coords: list[tuple[int, int]], base_img_width: int, base_img_height: int, cube_width: int, cube_height: int) list[tuple[int, int]] [source]¶
Calculates and returns the coordinates of a list of points within the data cube, scaled from the coordinates of a base image.
- Parameters:
coords – List of points/coordinates within the data cube.
base_img_width – The width of the base image in pixels.
base_img_height – The height of the base image in pixels.
cube_width – The width of the cube.
cube_height – The height of the cube.
- Returns:
A list of all the scaled coordinates, in the same order as they were input.
- get_selection(data_source_folder: str, selection_coords: list[tuple[int, int]], selection_type: SelectionType, cube_type: CubeType) ndarray | None [source]¶
Extracts and returns a 2D representation of a data cube region, based on the selection coordinates on the base image. If the specified data source contains a recipe for the data cube, the selection made on the base image is “deregistered” so that the returned data from the function correctly represents the selected pixels on the image. If the data cube does not have a recipe, the selection made on the base image is simply scaled to match the data cube’s dimensions.
- Parameters:
data_source_folder – The data source folder name.
selection_coords – The coordinates tuples (x, y), in order, of the selection. In case of a rectangle
selection_type – The type of selection being performed. selection, the list must contain the two opposite
corners of the selection rectangle. In case of polygon selection, the list must contain the points in the order in which they form the selection area. :param cube_type: The type of the cube the selection is made on. :return: A boolean mask over the data cube indicating which pixels are part of the selection.
- imread(filename[, flags]) retval ¶
. @brief Loads an image from a file. . . @anchor imread . . The function imread loads an image from the specified file and returns it. If the image cannot be . read (because of missing file, improper permissions, unsupported or invalid format), the function . returns an empty matrix ( Mat::data==NULL ). . . Currently, the following file formats are supported: . . - Windows bitmaps - *.bmp, *.dib (always supported) . - JPEG files - *.jpeg, *.jpg, *.jpe (see the Note section) . - JPEG 2000 files - *.jp2 (see the Note section) . - Portable Network Graphics - *.png (see the Note section) . - WebP - *.webp (see the Note section) . - AVIF - *.avif (see the Note section) . - Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported) . - PFM files - *.pfm (see the Note section) . - Sun rasters - *.sr, *.ras (always supported) . - TIFF files - *.tiff, *.tif (see the Note section) . - OpenEXR Image files - *.exr (see the Note section) . - Radiance HDR - *.hdr, *.pic (always supported) . - Raster and Vector geospatial data supported by GDAL (see the Note section) . . @note . - The function determines the type of an image by the content, not by the file extension. . - In the case of color images, the decoded images will have the channels stored in B G R order. . - When using IMREAD_GRAYSCALE, the codec’s internal grayscale conversion will be used, if available. . Results may differ to the output of cvtColor() . - On Microsoft Windows* OS and MacOSX*, the codecs shipped with an OpenCV image (libjpeg, . libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, . and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware . that currently these native image loaders give images with different pixel values because of . the color management embedded into MacOSX. . - On Linux*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for . codecs supplied with an OS image. Install the relevant packages (do not forget the development . files, for example, “libjpeg-dev”, in Debian* and Ubuntu*) to get the codec support or turn . on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. . - In the case you set WITH_GDAL flag to true in CMake and @ref IMREAD_LOAD_GDAL to load the image, . then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting . the following formats: [Raster](http://www.gdal.org/formats_list.html), . [Vector](http://www.gdal.org/ogr_formats.html). . - If EXIF information is embedded in the image file, the EXIF orientation will be taken into account . and thus the image will be rotated accordingly except if the flags @ref IMREAD_IGNORE_ORIENTATION . or @ref IMREAD_UNCHANGED are passed. . - Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. . - By default number of pixels must be less than 2^30. Limit can be set using system . variable OPENCV_IO_MAX_IMAGE_PIXELS . . @param filename Name of file to be loaded. . @param flags Flag that can take values of cv::ImreadModes
- perspectiveTransform(src, m[, dst]) dst ¶
. @brief Performs the perspective matrix transformation of vectors. . . The function cv::perspectiveTransform transforms every element of src by . treating it as a 2D or 3D vector, in the following way: . f[(x, y, z) rightarrow (x’/w, y’/w, z’/w)f] . where . f[(x’, y’, z’, w’) = texttt{mat} cdot begin{bmatrix} x & y & z & 1 end{bmatrix}f] . and . f[w = fork{w’}{if (w’ ne 0)}{infty}{otherwise}f] . . Here a 3D vector transformation is shown. In case of a 2D vector . transformation, the z component is omitted. . . @note The function transforms a sparse set of 2D or 3D vectors. If you . want to transform an image using perspective transformation, use . warpPerspective . If you have an inverse problem, that is, you want to . compute the most probable perspective transformation out of several . pairs of corresponding points, you can use getPerspectiveTransform or . findHomography . . @param src input two-channel or three-channel floating-point array; each . element is a 2D/3D vector to be transformed. . @param dst output array of the same size and type as src. . @param m 3x3 or 4x4 floating-point transformation matrix. . @sa transform, warpPerspective, getPerspectiveTransform, findHomography
- perspective_transform_coord(coord: tuple[int, int], transform_matrix: ndarray) tuple[float, float] [source]¶
Transforms the perspective of a coordinate (x, y) to (x’, y’) based on a transformation matrix.
- Parameters:
coord – The (x, y) coordinate to be transformed.
transform_matrix – The transformation matrix.
- Returns:
A (x’, y’) perspective transformed coordinate.