src.image.analyze package¶
Submodules¶
src.image.analyze.histogram module¶
- class src.image.analyze.histogram.HistGraphical(title, *args, **kwargs)¶
Bases:
PyQt5.QtWidgets.QMdiSubWindow,src.image.analyze.histogram_ui.HistGraphicalUIThe HistGraphical class implements a graphical representation of the image histogram.
- closeEvent(event)¶
Mark close event by setting
window_is_openedtoFalse.
- create_histogram_plot(hist)¶
Create a histogram plot of the image.
Initialize user interface. Connect list and changing-channel buttons. Create a histogram for grayscale or color image.
- Parameters
hist (dict[str, list[int]]) – The histogram data of the image. Taken from
image.Image.calc_histogram(){channel_char: [number_of_pixels]}
- set_title(title)¶
Set the histogram graphical window title.
- Parameters
title – The new title
- class src.image.analyze.histogram.HistList(title, *args, **kwargs)¶
Bases:
PyQt5.QtWidgets.QMdiSubWindow,src.image.analyze.histogram_ui.HistListUIThe HistList class implements a list representation of the image histogram.
- create_histogram_list(hist)¶
Create a histogram list of the image.
Initialize user interface. Create a table with two columns:
pixel value;
number of pixels.
- Parameters
hist (list[int]) – The histogram data of the image without specifying channel
- set_title(title)¶
Set the histogram list window title.
- Parameters
title – The new title
src.image.analyze.histogram_ui module¶
- class src.image.analyze.histogram_ui.HistGraphicalUI¶
Bases:
objectBuild UI for
hist_window.HistGraphical.- init_ui(hist_sub_window)¶
Create user interface for
hist_window.HistGraphical.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
hist_sub_window (
hist_window.HistGraphical) – The window for graphical representation of histogram
- class src.image.analyze.histogram_ui.HistListUI¶
Bases:
objectBuild UI for
hist_window.HistList.- init_ui(hist_sub_window, row_count)¶
Create user interface for
hist_window.HistList.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
hist_sub_window (
hist_window.HistList) – The window for list representation of histogramrow_count (int) – The number of rows in list
- class src.image.analyze.histogram_ui.MplCanvas(parent=None, width=5, height=4, dpi=100)¶
Bases:
matplotlib.backends.backend_qt5agg.FigureCanvasQTAggBuild base canvas for plotting.
src.image.analyze.intensity_profile module¶
- class src.image.analyze.intensity_profile.IntensityProfile(title, *args, **kwargs)¶
Bases:
PyQt5.QtWidgets.QMdiSubWindow,src.image.analyze.intensity_profile_ui.IntensityProfileUIThe IntensityProfile class implements a graphical representation of the profile line.
- closeEvent(event)¶
Mark close event by setting
window_is_closedtoTrue.
- create_profile(points, img_data)¶
Create intensity profile window.
Calculate pixel intensities between two
points.For one-channel image the intensities are the same as original.
For three-channel image the intensities are calculated using the formula: 0.24*R + 0.69*G + 0.07*B.
Clear a previous plot. Plot and draw the intensities data.
- Parameters
points (list[
PyQt5.QtCore.QPoint,PyQt5.QtCore.QPoint]) – The begin-end point of the drawn profile lineimg_data (
numpy.ndarray) – The image data. Taken from cv2.imread
- set_title(title)¶
Set the intensity profile window title.
- Parameters
title – The new title
src.image.analyze.intensity_profile_ui module¶
- class src.image.analyze.intensity_profile_ui.IntensityProfileUI¶
Bases:
objectBuild UI for
intensity_profile.IntensityProfile.- init_ui(profile)¶
Create user interface for
intensity_profile.IntensityProfile.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
profile (
intensity_profile.IntensityProfile) – The window for graphical representation of profile
src.image.analyze.object_features module¶
- class src.image.analyze.object_features.ObjectFeatures(parent)¶
Bases:
PyQt5.QtWidgets.QDialog,src.image.analyze.object_features_ui.ObjectFeaturesUI- calc_division(dividend, divisor)¶
Calculate division between two numbers.
- calc_features()¶
Calculate object features based on selected object contour.
- Calculated object features:
area;
perimeter;
aspect radio;
extent;
solidity;
equivalent diameter;
moments (up to the 3rd order).
- Returns
The object features
- Return type
dict
- calc_moments()¶
Calculate all the moments in sorted order.
- find_contours()¶
Calculate objects’ contours.
- update_features()¶
Update the features table whenever the form changed.
- update_img_preview()¶
Update image preview window.
Draw contours for the selected object.
Convert new image data to
PyQt5.QtGui.QImage.Reload the image to the preview window.
- update_selected_object()¶
Update the contour of the selected object whenever changed.
- src.image.analyze.object_features.arcLength(curve, closed) → retval¶
. @brief Calculates a contour perimeter or a curve length. . . The function computes a curve length or a closed contour perimeter. . . @param curve Input vector of 2D points, stored in std::vector or Mat. . @param closed Flag indicating whether the curve is closed or not.
- src.image.analyze.object_features.boundingRect(array) → retval¶
. @brief Calculates the up-right bounding rectangle of a point set or non-zero pixels of gray-scale image. . . The function calculates and returns the minimal up-right bounding rectangle for the specified point set or . non-zero pixels of gray-scale image. . . @param array Input gray-scale image or 2D point set, stored in std::vector or Mat.
- src.image.analyze.object_features.contourArea(contour[, oriented]) → retval¶
. @brief Calculates a contour area. . . The function computes a contour area. Similarly to moments , the area is computed using the Green . formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using . #drawContours or #fillPoly , can be different. Also, the function will most certainly give a wrong . results for contours with self-intersections. . . Example: . @code . vector<Point> contour; . contour.push_back(Point2f(0, 0)); . contour.push_back(Point2f(10, 0)); . contour.push_back(Point2f(10, 10)); . contour.push_back(Point2f(5, 4)); . . double area0 = contourArea(contour); . vector<Point> approx; . approxPolyDP(contour, approx, 5, true); . double area1 = contourArea(approx); . . cout << “area0 =” << area0 << endl << . “area1 =” << area1 << endl << . “approx poly vertices” << approx.size() << endl; . @endcode . @param contour Input vector of 2D points (contour vertices), stored in std::vector or Mat. . @param oriented Oriented area flag. If it is true, the function returns a signed area value, . depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can . determine orientation of a contour by taking the sign of an area. By default, the parameter is . false, which means that the absolute value is returned.
- src.image.analyze.object_features.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/
- src.image.analyze.object_features.cvtColor(src, code[, dst[, dstCn]]) → dst¶
. @brief Converts an image from one color space to another. . . The function converts an input image from one color space to another. In case of a transformation . to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note . that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the . bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue . component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and . sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on. . . The conventional ranges for R, G, and B channel values are: . - 0 to 255 for CV_8U images . - 0 to 65535 for CV_16U images . - 0 to 1 for CV_32F images . . In case of linear transformations, the range does not matter. But in case of a non-linear . transformation, an input RGB image should be normalized to the proper value range to get the correct . results, for example, for RGB f$rightarrowf$ L*u*v* transformation. For example, if you have a . 32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will . have the 0..255 value range instead of 0..1 assumed by the function. So, before calling #cvtColor , . you need first to scale the image down: . @code . img *= 1./255; . cvtColor(img, img, COLOR_BGR2Luv); . @endcode . If you use #cvtColor with 8-bit images, the conversion will have some information lost. For many . applications, this will not be noticeable but it is recommended to use 32-bit images in applications . that need the full range of colors or that convert an image before an operation and then convert . back. . . If conversion adds the alpha channel, its value will set to the maximum of corresponding channel . range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F. . . @param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC… ), or single-precision . floating-point. . @param dst output image of the same size and depth as src. . @param code color space conversion code (see #ColorConversionCodes). . @param dstCn number of channels in the destination image; if the parameter is 0, the number of the . channels is derived automatically from src and code. . . @see @ref imgproc_color_conversions
- src.image.analyze.object_features.drawContours(image, contours, contourIdx, color[, thickness[, lineType[, hierarchy[, maxLevel[, offset]]]]]) → image¶
. @brief Draws contours outlines or filled contours. . . The function draws contour outlines in the image if f$texttt{thickness} ge 0f$ or fills the area . bounded by the contours if f$texttt{thickness}<0f$ . The example below shows how to retrieve . connected components from the binary image and label them: : . @include snippets/imgproc_drawContours.cpp . . @param image Destination image. . @param contours All the input contours. Each contour is stored as a point vector. . @param contourIdx Parameter indicating a contour to draw. If it is negative, all the contours are drawn. . @param color Color of the contours. . @param thickness Thickness of lines the contours are drawn with. If it is negative (for example, . thickness=#FILLED ), the contour interiors are drawn. . @param lineType Line connectivity. See #LineTypes . @param hierarchy Optional information about hierarchy. It is only needed if you want to draw only . some of the contours (see maxLevel ). . @param maxLevel Maximal level for drawn contours. If it is 0, only the specified contour is drawn. . If it is 1, the function draws the contour(s) and all the nested contours. If it is 2, the function . draws the contours, all the nested contours, all the nested-to-nested contours, and so on. This . parameter is only taken into account when there is hierarchy available. . @param offset Optional contour shift parameter. Shift all the drawn contours by the specified . f$texttt{offset}=(dx,dy)f$ . . @note When thickness=#FILLED, the function is designed to handle connected components with holes correctly . even when no hierarchy date is provided. This is done by analyzing all the outlines together . using even-odd rule. This may give incorrect results if you have a joint collection of separately retrieved . contours. In order to solve this problem, you need to call #drawContours separately for each sub-group . of contours, or iterate over the collection using contourIdx parameter.
- src.image.analyze.object_features.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) → contours, hierarchy¶
. @brief Finds contours in a binary image. . . The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours . are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the . OpenCV sample directory. . @note Since opencv 3.2 source image is not modified by this function. . . @param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1’s. Zero . pixels remain 0’s, so the image is treated as binary . You can use #compare, #inRange, #threshold , . #adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one. . If mode equals to #RETR_CCOMP or #RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1). . @param contours Detected contours. Each contour is stored as a vector of points (e.g. . std::vector<std::vector<cv::Point> >). . @param hierarchy Optional output vector (e.g. std::vector<cv::Vec4i>), containing information about the image topology. It has . as many elements as the number of contours. For each i-th contour contours[i], the elements . hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based indices . in contours of the next and previous contours at the same hierarchical level, the first child . contour and the parent contour, respectively. If for the contour i there are no next, previous, . parent, or nested contours, the corresponding elements of hierarchy[i] will be negative. . @param mode Contour retrieval mode, see #RetrievalModes . @param method Contour approximation method, see #ContourApproximationModes . @param offset Optional offset by which every contour point is shifted. This is useful if the . contours are extracted from the image ROI and then they should be analyzed in the whole image . context.
- src.image.analyze.object_features.moments(array[, binaryImage]) → retval¶
. @brief Calculates all of the moments up to the third order of a polygon or rasterized shape. . . The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. The . results are returned in the structure cv::Moments. . . @param array Raster image (single-channel, 8-bit or floating-point 2D array) or an array ( . f$1 times Nf$ or f$N times 1f$ ) of 2D points (Point or Point2f ). . @param binaryImage If it is true, all non-zero image pixels are treated as 1’s. The parameter is . used for images only. . @returns moments. . . @note Only applicable to contour moments calculations from Python bindings: Note that the numpy . type for the input array should be either np.int32 or np.float32. . . @sa contourArea, arcLength
- src.image.analyze.object_features.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.image.analyze.object_features_ui module¶
- class src.image.analyze.object_features_ui.ObjectFeaturesUI¶
Bases:
src.operations.form_ui.FormUIBuild UI for
object_features.ObjectFeatures.- init_ui(object_features, height)¶
Create user interface for
object_features.ObjectFeatures.The method creates the widget objects in the proper containers and assigns the object names to them.
- Parameters
object_features (
object_features.ObjectFeatures) – The dialog object features windowheight (int) – The height of the image