src.operations.local package¶
Submodules¶
src.operations.local.convolve module¶
- class src.operations.local.convolve.Convolve(parent)¶
Bases:
PyQt5.QtWidgets.QDialog,src.operations.operation.Operation,src.operations.local.convolve_ui.ConvolveUIThe Convolve class implements a local convolve operation.
- calc_convolve(border, kernel_values)¶
Convolve an image based on border type and kernel values.
- Parameters
border (str) – The border type for convolution, defined in BORDER_TYPES
kernel_values (class:numpy.ndarray) – The values of kernel matrix to convolve
- Returns
The new convolved image data
- Return type
class:numpy.ndarray
- merge_kernels()¶
Merge two input kernels 3x3 to single kernel 5x5.
- Returns
The new merged kernel of size 5x5
- Return type
class:numpy.ndarray
- update_form()¶
Update the second kernel grid access whenever
rbtn_two_stage_convolveclicked.
- update_img_preview()¶
Update image preview window.
Calculate convolve based on border and kernel input values.
Reload image preview using the base
operation.Operationmethod.
- update_kernel_value(index, value, first_kernel)¶
Update kernel values whenever changed.
- Parameters
index (tuple[int]) – The index of kernel cell, e.g. (1, 2)
value (int) – The new value of kernel cell
first_kernel (bool) – The flag to indicate whether the first or second kernel need to update
- src.operations.local.convolve.filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]) → dst¶
. @brief Convolves an image with the kernel. . . The function applies an arbitrary linear filter to an image. In-place operation is supported. When . the aperture is partially outside the image, the function interpolates outlier pixel values . according to the specified border mode. . . The function does actually compute correlation, not the convolution: . . f[texttt{dst} (x,y) = sum _{ substack{0leq x’ < texttt{kernel.cols}\{0leq y’ < texttt{kernel.rows}}}} texttt{kernel} (x’,y’)* texttt{src} (x+x’- texttt{anchor.x} ,y+y’- texttt{anchor.y} )f] . . That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip . the kernel using #flip and set the new anchor to (kernel.cols - anchor.x - 1, kernel.rows - . anchor.y - 1). . . The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or . larger) and the direct algorithm for small kernels. . . @param src input image. . @param dst output image of the same size and the same number of channels as src. . @param ddepth desired depth of the destination image, see @ref filter_depths “combinations” . @param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point . matrix; if you want to apply different kernels to different channels, split the image into . separate color planes using split and process them individually. . @param anchor anchor of the kernel that indicates the relative position of a filtered point within . the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor . is at the kernel center. . @param delta optional value added to the filtered pixels before storing them in dst. . @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. . @sa sepFilter2D, dft, matchTemplate
- src.operations.local.convolve.normalize(src, dst[, alpha[, beta[, norm_type[, dtype[, mask]]]]]) → dst¶
. @brief Normalizes the norm or value range of an array. . . The function cv::normalize normalizes scale and shift the input array elements so that . f[| texttt{dst} | _{L_p}= texttt{alpha}f] . (where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that . f[min _I texttt{dst} (I)= texttt{alpha} , , , max _I texttt{dst} (I)= texttt{beta}f] . . when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be . normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this . sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or . min-max but modify the whole array, you can use norm and Mat::convertTo. . . In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, . the range transformation for sparse matrices is not allowed since it can shift the zero level. . . Possible usage with some positive example data: . @code{.cpp} . vector<double> positiveData = { 2.0, 8.0, 10.0 }; . vector<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax; . . // Norm to probability (total count) . // sum(numbers) = 20.0 . // 2.0 0.1 (2.0/20.0) . // 8.0 0.4 (8.0/20.0) . // 10.0 0.5 (10.0/20.0) . normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1); . . // Norm to unit vector: ||positiveData|| = 1.0 . // 2.0 0.15 . // 8.0 0.62 . // 10.0 0.77 . normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2); . . // Norm to max element . // 2.0 0.2 (2.0/10.0) . // 8.0 0.8 (8.0/10.0) . // 10.0 1.0 (10.0/10.0) . normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF); . . // Norm to range [0.0;1.0] . // 2.0 0.0 (shift to left border) . // 8.0 0.75 (6.0/8.0) . // 10.0 1.0 (shift to right border) . normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX); . @endcode . . @param src input array. . @param dst output array of the same size as src . . @param alpha norm value to normalize to or the lower range boundary in case of the range . normalization. . @param beta upper range boundary in case of the range normalization; it is not used for the norm . normalization. . @param norm_type normalization type (see cv::NormTypes). . @param dtype when negative, the output array has the same type as src; otherwise, it has the same . number of channels as src and the depth =CV_MAT_DEPTH(dtype). . @param mask optional operation mask. . @sa norm, Mat::convertTo, SparseMat::convertTo
src.operations.local.convolve_ui module¶
- class src.operations.local.convolve_ui.ConvolveUI¶
Bases:
src.operations.operation_ui.OperationUI,src.operations.local.local_ui.LocalUIBuild UI for
convolve.Convolve.- create_layout_grid(convolve, first_kernel)¶
Create layout grid 3x3 of spin boxes to input kernel values.
- Parameters
convolve (
convolve.Convolve) – The dialog convolve windowfirst_kernel – The flag to indicate whether the layout is for first or second kernel
- Returns
bool
- init_ui(convolve)¶
Create user interface for
convolve.Convolve.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
convolve (
convolve.Convolve) – The dialog convolve window
src.operations.local.edge_detection module¶
- src.operations.local.edge_detection.Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]]) → edges¶
. @brief Finds edges in an image using the Canny algorithm @cite Canny86 . . . The function finds edges in the input image and marks them in the output map edges using the . Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The . largest value is used to find initial segments of strong edges. See . <http://en.wikipedia.org/wiki/Canny_edge_detector> . . @param image 8-bit input image. . @param edges output edge map; single channels 8-bit image, which has the same size as image . . @param threshold1 first threshold for the hysteresis procedure. . @param threshold2 second threshold for the hysteresis procedure. . @param apertureSize aperture size for the Sobel operator. . @param L2gradient a flag, indicating whether a more accurate f$L_2f$ norm . f$=sqrt{(dI/dx)^2 + (dI/dy)^2}f$ should be used to calculate the image gradient magnitude ( . L2gradient=true ), or whether the default f$L_1f$ norm f$=|dI/dx|+|dI/dy|f$ is enough ( . L2gradient=false ).
Canny(dx, dy, threshold1, threshold2[, edges[, L2gradient]]) -> edges . overload . . Finds edges in an image using the Canny algorithm with custom image gradient. . . @param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3). . @param dy 16-bit y derivative of input image (same type as dx). . @param edges output edge map; single channels 8-bit image, which has the same size as image . . @param threshold1 first threshold for the hysteresis procedure. . @param threshold2 second threshold for the hysteresis procedure. . @param L2gradient a flag, indicating whether a more accurate f$L_2f$ norm . f$=sqrt{(dI/dx)^2 + (dI/dy)^2}f$ should be used to calculate the image gradient magnitude ( . L2gradient=true ), or whether the default f$L_1f$ norm f$=|dI/dx|+|dI/dy|f$ is enough ( . L2gradient=false ).
- class src.operations.local.edge_detection.DirectionalEdgeDetection(parent)¶
Bases:
PyQt5.QtWidgets.QDialog,src.operations.operation.Operation,src.operations.local.edge_detection_ui.DirectionalEdgeDetectionUIThe DirectionalEdgeDetection class implements a local direction edge detection operation.
- DIRECTION_MASKS = {'E': array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]]), 'N': array([[ 1, 1, 1], [ 0, 0, 0], [-1, -1, -1]]), 'NE': array([[ 0, 1, 1], [-1, 0, 1], [-1, -1, 0]]), 'NW': array([[ 1, 1, 0], [ 1, 0, -1], [ 0, -1, -1]]), 'S': array([[-1, -1, -1], [ 0, 0, 0], [ 1, 1, 1]]), 'SE': array([[-1, -1, 0], [-1, 0, 1], [ 0, 1, 1]]), 'SW': array([[ 0, -1, -1], [ 1, 0, -1], [ 1, 1, 0]]), 'W': array([[ 1, 0, -1], [ 1, 0, -1], [ 1, 0, -1]])}¶
- calc_edges(direction, border)¶
Detect image edges for selected direction. Direction specifies Prewitt mask.
- Parameters
direction – The Prewitt mask direction, defined in DIRECTION_MASKS
border (str) – The border type for edge detection, defined in BORDER_TYPES
- Returns
The new image data with detected edges
- Return type
class:numpy.ndarray
- update_img_preview()¶
Update image preview window.
Calculate image edges based on chosen direction and border.
Reload image preview using the base
operation.Operationmethod.
- class src.operations.local.edge_detection.EdgeDetection(parent)¶
Bases:
PyQt5.QtWidgets.QDialog,src.operations.operation.Operation,src.operations.local.edge_detection_ui.EdgeDetectionUIThe EdgeDetection class implements a local edge detection operation.
- calc_edges(edge_type, border, ksize, threshold)¶
Detect image edges for selected edge type.
To get better results, Sobel and Laplacian methods perform edge detection in int16 data type.
- Parameters
edge_type (str) – The type of edge detecting, can be “Sobel”, “Laplacian”, “Canny”
border (str) – The border type for edge detection, defined in BORDER_TYPES
ksize (int) – The number for NxN kernel
threshold (tuple[int]) – The lower:upper threshold values for Canny detection
- Returns
The new image data with detected edges
- Return type
class:numpy.ndarray
- update_form()¶
Update lower:upper threshold spin box, border, and kernel size access.
The threshold range is available only for Canny detection. Border type and kernel size are available for other methods.
- update_img_preview()¶
Update image preview window.
Calculate image edges based on form parameters.
Reload image preview using the base
operation.Operationmethod.
- validate_high_value()¶
Filter threshold range to be valid for the upper value.
- validate_low_value()¶
Filter threshold range to be valid for the lower value.
- src.operations.local.edge_detection.Laplacian(src, ddepth[, dst[, ksize[, scale[, delta[, borderType]]]]]) → dst¶
. @brief Calculates the Laplacian of an image. . . The function calculates the Laplacian of the source image by adding up the second x and y . derivatives calculated using the Sobel operator: . . f[texttt{dst} = Delta texttt{src} = frac{partial^2 texttt{src}}{partial x^2} + frac{partial^2 texttt{src}}{partial y^2}f] . . This is done when ksize > 1. When ksize == 1, the Laplacian is computed by filtering the image . with the following f$3 times 3f$ aperture: . . f[vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}f] . . @param src Source image. . @param dst Destination image of the same size and the same number of channels as src . . @param ddepth Desired depth of the destination image. . @param ksize Aperture size used to compute the second-derivative filters. See #getDerivKernels for . details. The size must be positive and odd. . @param scale Optional scale factor for the computed Laplacian values. By default, no scaling is . applied. See #getDerivKernels for details. . @param delta Optional delta value that is added to the results prior to storing them in dst . . @param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. . @sa Sobel, Scharr
- src.operations.local.edge_detection.Sobel(src, ddepth, dx, dy[, dst[, ksize[, scale[, delta[, borderType]]]]]) → dst¶
. @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. . . In all cases except one, the f$texttt{ksize} times texttt{ksize}f$ separable kernel is used to . calculate the derivative. When f$texttt{ksize = 1}f$, the f$3 times 1f$ or f$1 times 3f$ . kernel is used (that is, no Gaussian smoothing is done). ksize = 1 can only be used for the first . or the second x- or y- derivatives. . . There is also the special value ksize = #FILTER_SCHARR (-1) that corresponds to the f$3times3f$ Scharr . filter that may give more accurate results than the f$3times3f$ Sobel. The Scharr aperture is . . f[vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}f] . . for the x-derivative, or transposed for the y-derivative. . . The function calculates an image derivative by convolving the image with the appropriate kernel: . . f[texttt{dst} = frac{partial^{xorder+yorder} texttt{src}}{partial x^{xorder} partial y^{yorder}}f] . . The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less . resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) . or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first . case corresponds to a kernel of: . . f[vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}f] . . The second case corresponds to a kernel of: . . f[vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}f] . . @param src input image. . @param dst output image of the same size and the same number of channels as src . . @param ddepth output image depth, see @ref filter_depths “combinations”; in the case of . 8-bit input images it will result in truncated derivatives. . @param dx order of the derivative x. . @param dy order of the derivative y. . @param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7. . @param scale optional scale factor for the computed derivative values; by default, no scaling is . applied (see #getDerivKernels for details). . @param delta optional delta value that is added to the results prior to storing them in dst. . @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. . @sa Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar
- src.operations.local.edge_detection.add(src1, src2[, dst[, mask[, dtype]]]) → dst¶
. @brief Calculates the per-element sum of two arrays or an array and a scalar. . . The function add calculates: . - Sum of two arrays when both input arrays have the same size and the same number of channels: . f[texttt{dst}(I) = texttt{saturate} ( texttt{src1}(I) + texttt{src2}(I)) quad texttt{if mask}(I) ne0f] . - Sum of an array and a scalar when src2 is constructed from Scalar or has the same number of . elements as src1.channels(): . f[texttt{dst}(I) = texttt{saturate} ( texttt{src1}(I) + texttt{src2} ) quad texttt{if mask}(I) ne0f] . - Sum of a scalar and an array when src1 is constructed from Scalar or has the same number of . elements as src2.channels(): . f[texttt{dst}(I) = texttt{saturate} ( texttt{src1} + texttt{src2}(I) ) quad texttt{if mask}(I) ne0f] . where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each . channel is processed independently. . . The first function in the list above can be replaced with matrix expressions: . @code{.cpp} . dst = src1 + src2; . dst += src1; // equivalent to add(dst, src1, dst); . @endcode . The input arrays and the output array can all have the same or different depths. For example, you . can add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit . floating-point array. Depth of the output array is determined by the dtype parameter. In the second . and third cases above, as well as in the first case, when src1.depth() == src2.depth(), dtype can . be set to the default -1. In this case, the output array will have the same depth as the input . array, be it src1, src2 or both. . @note Saturation is not applied when the output array has the depth CV_32S. You may even get . result of an incorrect sign in the case of overflow. . @param src1 first input array or a scalar. . @param src2 second input array or a scalar. . @param dst output array that has the same size and number of channels as the input array(s); the . depth is defined by dtype or src1/src2. . @param mask optional operation mask - 8-bit single channel array, that specifies elements of the . output array to be changed. . @param dtype optional depth of the output array (see the discussion below). . @sa subtract, addWeighted, scaleAdd, Mat::convertTo
- src.operations.local.edge_detection.filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]) → dst¶
. @brief Convolves an image with the kernel. . . The function applies an arbitrary linear filter to an image. In-place operation is supported. When . the aperture is partially outside the image, the function interpolates outlier pixel values . according to the specified border mode. . . The function does actually compute correlation, not the convolution: . . f[texttt{dst} (x,y) = sum _{ substack{0leq x’ < texttt{kernel.cols}\{0leq y’ < texttt{kernel.rows}}}} texttt{kernel} (x’,y’)* texttt{src} (x+x’- texttt{anchor.x} ,y+y’- texttt{anchor.y} )f] . . That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip . the kernel using #flip and set the new anchor to (kernel.cols - anchor.x - 1, kernel.rows - . anchor.y - 1). . . The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or . larger) and the direct algorithm for small kernels. . . @param src input image. . @param dst output image of the same size and the same number of channels as src. . @param ddepth desired depth of the destination image, see @ref filter_depths “combinations” . @param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point . matrix; if you want to apply different kernels to different channels, split the image into . separate color planes using split and process them individually. . @param anchor anchor of the kernel that indicates the relative position of a filtered point within . the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor . is at the kernel center. . @param delta optional value added to the filtered pixels before storing them in dst. . @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. . @sa sepFilter2D, dft, matchTemplate
- src.operations.local.edge_detection.normalize(src, dst[, alpha[, beta[, norm_type[, dtype[, mask]]]]]) → dst¶
. @brief Normalizes the norm or value range of an array. . . The function cv::normalize normalizes scale and shift the input array elements so that . f[| texttt{dst} | _{L_p}= texttt{alpha}f] . (where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that . f[min _I texttt{dst} (I)= texttt{alpha} , , , max _I texttt{dst} (I)= texttt{beta}f] . . when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be . normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this . sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or . min-max but modify the whole array, you can use norm and Mat::convertTo. . . In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, . the range transformation for sparse matrices is not allowed since it can shift the zero level. . . Possible usage with some positive example data: . @code{.cpp} . vector<double> positiveData = { 2.0, 8.0, 10.0 }; . vector<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax; . . // Norm to probability (total count) . // sum(numbers) = 20.0 . // 2.0 0.1 (2.0/20.0) . // 8.0 0.4 (8.0/20.0) . // 10.0 0.5 (10.0/20.0) . normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1); . . // Norm to unit vector: ||positiveData|| = 1.0 . // 2.0 0.15 . // 8.0 0.62 . // 10.0 0.77 . normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2); . . // Norm to max element . // 2.0 0.2 (2.0/10.0) . // 8.0 0.8 (8.0/10.0) . // 10.0 1.0 (10.0/10.0) . normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF); . . // Norm to range [0.0;1.0] . // 2.0 0.0 (shift to left border) . // 8.0 0.75 (6.0/8.0) . // 10.0 1.0 (shift to right border) . normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX); . @endcode . . @param src input array. . @param dst output array of the same size as src . . @param alpha norm value to normalize to or the lower range boundary in case of the range . normalization. . @param beta upper range boundary in case of the range normalization; it is not used for the norm . normalization. . @param norm_type normalization type (see cv::NormTypes). . @param dtype when negative, the output array has the same type as src; otherwise, it has the same . number of channels as src and the depth =CV_MAT_DEPTH(dtype). . @param mask optional operation mask. . @sa norm, Mat::convertTo, SparseMat::convertTo
src.operations.local.edge_detection_ui module¶
- class src.operations.local.edge_detection_ui.DirectionalEdgeDetectionUI¶
Bases:
src.operations.operation_ui.OperationUI,src.operations.local.local_ui.LocalUIBuild UI for
edge_detection.DirectionalEdgeDetection.- init_ui(edge_dt_dir)¶
Create user interface for
edge_detection.DirectionalEdgeDetection.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
edge_dt_dir (
edge_detection.DirectionalEdgeDetection) – The dialog directional edge detection window
- class src.operations.local.edge_detection_ui.EdgeDetectionUI¶
Bases:
src.operations.operation_ui.OperationUI,src.operations.local.local_ui.LocalUIBuild UI for
edge_detection.EdgeDetection.- init_ui(edge_dt)¶
Create user interface for
edge_detection.EdgeDetection.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
edge_dt (
edge_detection.EdgeDetection) – The dialog edge detection window
src.operations.local.local_ui module¶
- class src.operations.local.local_ui.LocalUI¶
Bases:
src.operations.form_ui.FormUIThe LocalUI class represents the base UI for local operation UI classes.
- local_ui(child_ui)¶
Create a base user interface for local operation UI classes.
The method creates main widget objects in the proper containers and assigns the object names to them.
- Parameters
child_ui – The local operation UI class
src.operations.local.morphology module¶
- class src.operations.local.morphology.Morphology(parent)¶
Bases:
PyQt5.QtWidgets.QDialog,src.operations.operation.Operation,src.operations.local.morphology_ui.MorphologyUIThe Morphology class implements a morphological transformation.
- calc_edges(border)¶
Calculate edges based on morphological dilate and erode operations
- Parameters
border (str) – The border type for morphology, defined in BORDER_TYPES
- Returns
The new image data with detected edges
- Return type
class:numpy.ndarray
- calc_morphology(operation_name, border, iterations)¶
Calculate morphological transformation based on structuring element, operation and border type
- Parameters
operation_name (str) – The type of morphological operation
border (str) – The border type for morphology, defined in BORDER_TYPES
iterations (str) – The number of times to execute operation
- Returns
The new morphological transformed image data
- Return type
class:numpy.ndarray
- calc_skeletonize(border)¶
Calculate skeletonization of the image
- Parameters
border (str) – The border type for morphology, defined in BORDER_TYPES
- Returns
The new skeletonized image data
- Return type
class:numpy.ndarray
- update_img_preview()¶
Update image preview window.
Calculate morphological transformation.
Reload histogram preview.
Reload image preview using the base
operation.Operationmethod.
- update_structuring_element()¶
Update structuring element whenever shape or kernel size changed.
- src.operations.local.morphology.bitwise_or(src1, src2[, dst[, mask]]) → dst¶
. @brief Calculates the per-element bit-wise disjunction of two arrays or an . array and a scalar. . . The function cv::bitwise_or calculates the per-element bit-wise logical disjunction for: . * Two arrays when src1 and src2 have the same size: . f[texttt{dst} (I) = texttt{src1} (I) vee texttt{src2} (I) quad texttt{if mask} (I) ne0f] . * An array and a scalar when src2 is constructed from Scalar or has . the same number of elements as src1.channels(): . f[texttt{dst} (I) = texttt{src1} (I) vee texttt{src2} quad texttt{if mask} (I) ne0f] . * A scalar and an array when src1 is constructed from Scalar or has . the same number of elements as src2.channels(): . f[texttt{dst} (I) = texttt{src1} vee texttt{src2} (I) quad texttt{if mask} (I) ne0f] . In case of floating-point arrays, their machine-specific bit . representations (usually IEEE754-compliant) are used for the operation. . In case of multi-channel arrays, each channel is processed . independently. In the second and third cases above, the scalar is first . converted to the array type. . @param src1 first input array or a scalar. . @param src2 second input array or a scalar. . @param dst output array that has the same size and type as the input . arrays. . @param mask optional operation mask, 8-bit single channel array, that . specifies elements of the output array to be changed.
- src.operations.local.morphology.countNonZero(src) → retval¶
. @brief Counts non-zero array elements. . . The function returns the number of non-zero elements in src : . f[sum _{I: ; texttt{src} (I) ne0 } 1f] . @param src single-channel array. . @sa mean, meanStdDev, norm, minMaxLoc, calcCovarMatrix
- src.operations.local.morphology.getStructuringElement(shape, ksize[, anchor]) → retval¶
. @brief Returns a structuring element of the specified size and shape for morphological operations. . . The function constructs and returns the structuring element that can be further passed to #erode, . #dilate or #morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as . the structuring element. . . @param shape Element shape that could be one of #MorphShapes . @param ksize Size of the structuring element. . @param anchor Anchor position within the element. The default value f$(-1, -1)f$ means that the . anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor . position. In other cases the anchor just regulates how much the result of the morphological . operation is shifted.
- src.operations.local.morphology.morphologyEx(src, op, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) → dst¶
. @brief Performs advanced morphological transformations. . . The function cv::morphologyEx can perform advanced morphological transformations using an erosion and dilation as . basic operations. . . Any of the operations can be done in-place. In case of multi-channel images, each channel is . processed independently. . . @param src Source image. The number of channels can be arbitrary. The depth should be one of . CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. . @param dst Destination image of the same size and type as source image. . @param op Type of a morphological operation, see #MorphTypes . @param kernel Structuring element. It can be created using #getStructuringElement. . @param anchor Anchor position with the kernel. Negative values mean that the anchor is at the . kernel center. . @param iterations Number of times erosion and dilation are applied. . @param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. . @param borderValue Border value in case of a constant border. The default value has a special . meaning. . @sa dilate, erode, getStructuringElement . @note The number of iterations is the number of times erosion or dilatation operation will be applied. . For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to apply . successively: erode -> erode -> dilate -> dilate (and not erode -> dilate -> erode -> dilate).
- src.operations.local.morphology.subtract(src1, src2[, dst[, mask[, dtype]]]) → dst¶
. @brief Calculates the per-element difference between two arrays or array and a scalar. . . The function subtract calculates: . - Difference between two arrays, when both input arrays have the same size and the same number of . channels: . f[texttt{dst}(I) = texttt{saturate} ( texttt{src1}(I) - texttt{src2}(I)) quad texttt{if mask}(I) ne0f] . - Difference between an array and a scalar, when src2 is constructed from Scalar or has the same . number of elements as src1.channels(): . f[texttt{dst}(I) = texttt{saturate} ( texttt{src1}(I) - texttt{src2} ) quad texttt{if mask}(I) ne0f] . - Difference between a scalar and an array, when src1 is constructed from Scalar or has the same . number of elements as src2.channels(): . f[texttt{dst}(I) = texttt{saturate} ( texttt{src1} - texttt{src2}(I) ) quad texttt{if mask}(I) ne0f] . - The reverse difference between a scalar and an array in the case of SubRS: . f[texttt{dst}(I) = texttt{saturate} ( texttt{src2} - texttt{src1}(I) ) quad texttt{if mask}(I) ne0f] . where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each . channel is processed independently. . . The first function in the list above can be replaced with matrix expressions: . @code{.cpp} . dst = src1 - src2; . dst -= src1; // equivalent to subtract(dst, src1, dst); . @endcode . The input arrays and the output array can all have the same or different depths. For example, you . can subtract to 8-bit unsigned arrays and store the difference in a 16-bit signed array. Depth of . the output array is determined by dtype parameter. In the second and third cases above, as well as . in the first case, when src1.depth() == src2.depth(), dtype can be set to the default -1. In this . case the output array will have the same depth as the input array, be it src1, src2 or both. . @note Saturation is not applied when the output array has the depth CV_32S. You may even get . result of an incorrect sign in the case of overflow. . @param src1 first input array or a scalar. . @param src2 second input array or a scalar. . @param dst output array of the same size and the same number of channels as the input array. . @param mask optional operation mask; this is an 8-bit single channel array that specifies elements . of the output array to be changed. . @param dtype optional depth of the output array . @sa add, addWeighted, scaleAdd, Mat::convertTo
- src.operations.local.morphology.threshold(src, thresh, maxval, type[, dst]) → retval, dst¶
. @brief Applies a fixed-level threshold to each array element. . . The function applies fixed-level thresholding to a multiple-channel array. The function is typically . used to get a bi-level (binary) image out of a grayscale image ( #compare could be also used for . this purpose) or for removing a noise, that is, filtering out pixels with too small or too large . values. There are several types of thresholding supported by the function. They are determined by . type parameter. . . Also, the special values #THRESH_OTSU or #THRESH_TRIANGLE may be combined with one of the . above values. In these cases, the function determines the optimal threshold value using the Otsu’s . or Triangle algorithm and uses it instead of the specified thresh. . . @note Currently, the Otsu’s and Triangle methods are implemented only for 8-bit single-channel images. . . @param src input array (multiple-channel, 8-bit or 32-bit floating point). . @param dst output array of the same size and type and the same number of channels as src. . @param thresh threshold value. . @param maxval maximum value to use with the #THRESH_BINARY and #THRESH_BINARY_INV thresholding . types. . @param type thresholding type (see #ThresholdTypes). . @return the computed threshold value if Otsu’s or Triangle methods used. . . @sa adaptiveThreshold, findContours, compare, min, max
src.operations.local.morphology_ui module¶
- class src.operations.local.morphology_ui.MorphologyUI¶
Bases:
src.operations.operation_ui.OperationUI,src.operations.local.local_ui.LocalUIBuild UI for
morphology.Morphology.- init_ui(morphology)¶
Create user interface for
morphology.Morphology.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
morphology (
morphology.Morphology) – The dialog morphology window
src.operations.local.sharpen module¶
- class src.operations.local.sharpen.Sharpen(parent)¶
Bases:
PyQt5.QtWidgets.QDialog,src.operations.operation.Operation,src.operations.local.sharpen_ui.SharpenUIThe Sharpen class implements a local sharpen operation.
- calc_sharpen(border)¶
Sharpen an image based on chosen Laplacian mask.
- Parameters
border (str) – The border type for sharpening, defined in BORDER_TYPES
- Returns
The image sharpening
- Return type
class:numpy.ndarray
- update_img_preview()¶
Update image preview window.
Calculate image sharpen.
Reload image preview using the base
operation.Operationmethod.
- src.operations.local.sharpen.filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]) → dst¶
. @brief Convolves an image with the kernel. . . The function applies an arbitrary linear filter to an image. In-place operation is supported. When . the aperture is partially outside the image, the function interpolates outlier pixel values . according to the specified border mode. . . The function does actually compute correlation, not the convolution: . . f[texttt{dst} (x,y) = sum _{ substack{0leq x’ < texttt{kernel.cols}\{0leq y’ < texttt{kernel.rows}}}} texttt{kernel} (x’,y’)* texttt{src} (x+x’- texttt{anchor.x} ,y+y’- texttt{anchor.y} )f] . . That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip . the kernel using #flip and set the new anchor to (kernel.cols - anchor.x - 1, kernel.rows - . anchor.y - 1). . . The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or . larger) and the direct algorithm for small kernels. . . @param src input image. . @param dst output image of the same size and the same number of channels as src. . @param ddepth desired depth of the destination image, see @ref filter_depths “combinations” . @param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point . matrix; if you want to apply different kernels to different channels, split the image into . separate color planes using split and process them individually. . @param anchor anchor of the kernel that indicates the relative position of a filtered point within . the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor . is at the kernel center. . @param delta optional value added to the filtered pixels before storing them in dst. . @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. . @sa sepFilter2D, dft, matchTemplate
- src.operations.local.sharpen.normalize(src, dst[, alpha[, beta[, norm_type[, dtype[, mask]]]]]) → dst¶
. @brief Normalizes the norm or value range of an array. . . The function cv::normalize normalizes scale and shift the input array elements so that . f[| texttt{dst} | _{L_p}= texttt{alpha}f] . (where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that . f[min _I texttt{dst} (I)= texttt{alpha} , , , max _I texttt{dst} (I)= texttt{beta}f] . . when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be . normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this . sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or . min-max but modify the whole array, you can use norm and Mat::convertTo. . . In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, . the range transformation for sparse matrices is not allowed since it can shift the zero level. . . Possible usage with some positive example data: . @code{.cpp} . vector<double> positiveData = { 2.0, 8.0, 10.0 }; . vector<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax; . . // Norm to probability (total count) . // sum(numbers) = 20.0 . // 2.0 0.1 (2.0/20.0) . // 8.0 0.4 (8.0/20.0) . // 10.0 0.5 (10.0/20.0) . normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1); . . // Norm to unit vector: ||positiveData|| = 1.0 . // 2.0 0.15 . // 8.0 0.62 . // 10.0 0.77 . normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2); . . // Norm to max element . // 2.0 0.2 (2.0/10.0) . // 8.0 0.8 (8.0/10.0) . // 10.0 1.0 (10.0/10.0) . normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF); . . // Norm to range [0.0;1.0] . // 2.0 0.0 (shift to left border) . // 8.0 0.75 (6.0/8.0) . // 10.0 1.0 (shift to right border) . normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX); . @endcode . . @param src input array. . @param dst output array of the same size as src . . @param alpha norm value to normalize to or the lower range boundary in case of the range . normalization. . @param beta upper range boundary in case of the range normalization; it is not used for the norm . normalization. . @param norm_type normalization type (see cv::NormTypes). . @param dtype when negative, the output array has the same type as src; otherwise, it has the same . number of channels as src and the depth =CV_MAT_DEPTH(dtype). . @param mask optional operation mask. . @sa norm, Mat::convertTo, SparseMat::convertTo
src.operations.local.sharpen_ui module¶
- class src.operations.local.sharpen_ui.SharpenUI¶
Bases:
src.operations.operation_ui.OperationUI,src.operations.local.local_ui.LocalUIBuild UI for
sharpen.Sharpen.- init_ui(sharpen)¶
Create user interface for
sharpen.Sharpen.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
sharpen (
sharpen.Sharpen) – The dialog sharpen window
src.operations.local.smooth module¶
- src.operations.local.smooth.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType]]]) → dst¶
. @brief Blurs an image using a Gaussian filter. . . The function convolves the source image with the specified Gaussian kernel. In-place filtering is . supported. . . @param src input image; the image can have any number of channels, which are processed . independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. . @param dst output image of the same size and type as src. . @param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be . positive and odd. Or, they can be zero’s and then they are computed from sigma. . @param sigmaX Gaussian kernel standard deviation in X direction. . @param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be . equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, . respectively (see #getGaussianKernel for details); to fully control the result regardless of . possible future modifications of all this semantics, it is recommended to specify all of ksize, . sigmaX, and sigmaY. . @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported. . . @sa sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur
- class src.operations.local.smooth.Smooth(parent)¶
Bases:
PyQt5.QtWidgets.QDialog,src.operations.operation.Operation,src.operations.local.smooth_ui.SmoothUIThe Smooth class implements a local smoothing operation.
- calc_smooth(smooth, border, ksize)¶
Calculate the smoothing of the selected type.
- Parameters
smooth (str) – The smooth type to calculate, can be “Blur”, “Gaussian Blur” or “Median Blur”
border (str) – The border type for smoothing, defined in BORDER_TYPES
ksize (int) – The number for NxN kernel
- Returns
The smoothed image data
- Return type
class:numpy.ndarray
- update_form()¶
Update the border type access, which isn’t available for Median Blur.
- update_img_preview()¶
Update image preview window.
Calculate image smoothing based on kernel size, smooth and border type.
Reload image preview using the base
operation.Operationmethod.
- src.operations.local.smooth.blur(src, ksize[, dst[, anchor[, borderType]]]) → dst¶
. @brief Blurs an image using the normalized box filter. . . The function smooths an image using the kernel: . . f[texttt{K} = frac{1}{texttt{ksize.width*ksize.height}} begin{bmatrix} 1 & 1 & 1 & cdots & 1 & 1 \ 1 & 1 & 1 & cdots & 1 & 1 \ hdotsfor{6} \ 1 & 1 & 1 & cdots & 1 & 1 \ end{bmatrix}f] . . The call blur(src, dst, ksize, anchor, borderType) is equivalent to boxFilter(src, dst, src.type(), ksize, . anchor, true, borderType). . . @param src input image; it can have any number of channels, which are processed independently, but . the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. . @param dst output image of the same size and type as src. . @param ksize blurring kernel size. . @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel . center. . @param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes. #BORDER_WRAP is not supported. . @sa boxFilter, bilateralFilter, GaussianBlur, medianBlur
- src.operations.local.smooth.medianBlur(src, ksize[, dst]) → dst¶
. @brief Blurs an image using the median filter. . . The function smoothes an image using the median filter with the f$texttt{ksize} times . texttt{ksize}f$ aperture. Each channel of a multi-channel image is processed independently. . In-place operation is supported. . . @note The median filter uses #BORDER_REPLICATE internally to cope with border pixels, see #BorderTypes . . @param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be . CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U. . @param dst destination array of the same size and type as src. . @param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 … . @sa bilateralFilter, blur, boxFilter, GaussianBlur
src.operations.local.smooth_ui module¶
- class src.operations.local.smooth_ui.SmoothUI¶
Bases:
src.operations.operation_ui.OperationUI,src.operations.local.local_ui.LocalUIBuild UI for
smooth.SmoothUI.- init_ui(smooth)¶
Create user interface for
smooth.SmoothUI.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
smooth (
smooth.SmoothUI) – The dialog smooth window