Method and device for detecting overlapped ellipses in image processing and electronic equipment

By pre-processing, segmentation fitting, distance matrix calculation and optimization processing of overlapping ellipses in the image, the problem of insufficient detection accuracy and stability of overlapping ellipses in the prior art is solved, and higher detection accuracy and stability are achieved.

CN120198366APending Publication Date: 2025-06-24CHINA MOBILE M2M +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510212684.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-25
Publication Date
2025-06-24

AI Technical Summary

Technical Problem

The prior art uses the following to significantly reduce accuracy and stability when processing overlapping ellipses in images, resulting in the occurrence of false detection and missed detection.

Method used

By preprocessing the input image, extracting the complete contour and segmenting and fitting, the candidate ellipse is obtained. Then, the distance matrix of each candidate ellipse is calculated, and optimized based on the global distance matrix to obtain the optimal ellipse combination, thereby outputting the ellipse detection result.

Benefits of technology

The accuracy and stability of object detection and counting in overlapping elliptical scenes are improved, and elliptical objects in the image can be more accurately identified and counted, especially when there is an occlusion or partial overlap of ellipticals.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120198366A_ABST
    Figure CN120198366A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computer vision, and provides a detection method and device for an overlapped ellipse in image processing and electronic equipment, and the detection method for the overlapped ellipse in the image processing comprises the steps: carrying out the preprocessing of an input image comprising the overlapped ellipse, and obtaining a to-be-detected image; wherein the to-be-detected image comprises at least one complete contour of a connected region generated by an overlapped ellipse; segmenting and fitting the complete contour to obtain a plurality of candidate ellipses; calculating a distance matrix representing the minimum distance from the contour point to the ellipse boundary in each candidate ellipse to obtain a global distance matrix; and performing optimization based on the global distance matrix to obtain an optimal ellipse combination, and outputting an ellipse detection result based on the optimal ellipse combination. The method can more accurately adapt to the diversity and complexity of the ellipse in the image, and can more accurately detect the ellipse in the image especially when shielding or partial overlapping of the ellipse exists.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer vision technology, and particularly to a method, device and electronic device for detecting overlapping ellipses in image processing. Background Art

[0002] In the fields of image processing and computer vision, the application of object detection and counting technologies is very extensive. Traditional object detection and counting methods usually rely on technologies such as image preprocessing, image segmentation, connected component analysis, and morphological operations.

[0003] Among them, image preprocessing covers steps such as image grayscale conversion, noise removal, and edge detection. Image segmentation uses threshold methods (such as Otsu threshold method) to divide the image into foreground and background, and this method has better effects when the lighting conditions are uniform. Connected component analysis is to detect and count the number of objects in the image through relevant analysis of the image. Morphological operations are performed on binary images using operations such as dilation, erosion, opening operation, and closing operation to achieve the purpose of removing noise and filling holes.

[0004] Although these traditional technologies can meet the basic requirements of object detection and counting to a certain extent, when encountering the situation of overlapping objects, their accuracy and stability will be significantly reduced. Taking the existing object detection and counting methods based on image segmentation and Hough transform as an example, they cannot effectively handle the situation of overlapping ellipses. When multiple ellipses share edge points, it is difficult for these methods to accurately distinguish and detect each ellipse, resulting in false detection and missed detection. Summary of the Invention

[0005] The present invention provides a method, device and electronic device for detecting overlapping ellipses in image processing, aiming to improve the problems of ineffective processing of overlapping ellipses and resulting in false detection and missed detection in existing image processing, so as to improve the accuracy and stability of object detection and counting in the overlapping ellipse scenario, and provide more reliable technical support for applications in related fields.

[0006] The present invention provides a method for detecting overlapping ellipses in image processing, including: preprocessing an input image including overlapping ellipses to obtain a to-be-detected image; wherein the to-be-detected image includes at least one complete contour of a connected region generated by the overlapping ellipses; segmenting and fitting the complete contour to obtain a plurality of candidate ellipses; calculating a distance matrix representing the minimum distance from contour points to the ellipse boundary in each candidate ellipse to obtain a global distance matrix; optimizing based on the global distance matrix to obtain an optimal ellipse combination, and outputting an ellipse detection result based on the optimal ellipse combination.

[0007] A method for counting overlapping ellipses in image processing according to the present invention performs segmentation and fitting on a complete contour to obtain a plurality of candidate ellipses, including: simplifying the complete contour using a polygon approximation algorithm; segmenting the simplified complete contour using a concave point detection algorithm to obtain a plurality of sub-contours; generating ellipse fitting parameters for each sub-contour using an affine transformation algorithm, and taking the sub-contour corresponding to the ellipse fitting parameters that meet the preset requirements as a candidate ellipse.

[0008] A method for counting overlapping ellipses in image processing according to the present invention takes the sub-contour corresponding to the ellipse fitting parameters that meet the preset requirements as a candidate ellipse, including: calculating the distance transformation value of the internal region of the ellipse corresponding to each sub-contour according to the ellipse fitting parameters; determining a score matrix, an area matrix, and a coverage matrix according to the percentile score and the coverage area of the distance transformation value; taking the sub-contour with a coverage area greater than the minimum coverage area as a candidate ellipse according to the score matrix, the area matrix, and the coverage matrix.

[0009] A method for counting overlapping ellipses in image processing according to the present invention optimizes based on a global distance matrix to obtain an optimal ellipse combination, including: processing the global distance matrix according to an optimization algorithm to obtain an optimal ellipse combination; wherein, the optimization algorithm is to minimize the weighted sum of the total distance between the ellipse and the contour points and the number of ellipses.

[0010] A method for counting overlapping ellipses in image processing according to the present invention preprocesses an input image including overlapping ellipses to obtain an image to be detected, including: converting the input image including overlapping ellipses into a grayscale image; performing binarization processing on the grayscale image to generate a binarized image; performing connected component analysis on the binarized image to obtain at least one connected region generated by the overlapping ellipses; using an edge detection algorithm to extract edges from the binarized image sub-regions of each connected region to form at least one complete contour.

[0011] A method for counting overlapping ellipses in image processing according to the present invention outputs an ellipse detection result based on the optimal ellipse combination, including: drawing an ellipse in the input image according to the ellipse detection result; and / or, outputting the number of detected ellipses according to the ellipse detection result.

[0012] The present invention also provides a detection device for overlapping ellipses in image processing, comprising: a preprocessing module, configured to preprocess an input image including overlapping ellipses to obtain a to-be-detected image; wherein the to-be-detected image includes at least one complete contour of a connected region generated by the overlapping ellipses; a candidate ellipse obtaining module, configured to segment and fit the complete contour to obtain a plurality of candidate ellipses; a distance calculation module, configured to calculate a distance matrix representing the minimum distance from a contour point to the ellipse boundary in each candidate ellipse to obtain a global distance matrix; and an ellipse optimization module, configured to optimize based on the global distance matrix to obtain an optimal ellipse combination, and output an ellipse detection result based on the optimal ellipse combination.

[0013] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor executes the program, it implements the detection method for overlapping ellipses in image processing as described in any one of the above.

[0014] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the detection method for overlapping ellipses in image processing as described in any one of the above.

[0015] The present invention also provides a computer program product, comprising a computer program, and when the computer program is executed by a processor, it implements the detection method for overlapping ellipses in image processing as described in any one of the above.

[0016] The detection method, device, and electronic device for overlapping ellipses in image processing provided by the present invention, the method comprising: preprocessing an input image including overlapping ellipses to obtain a to-be-detected image; wherein the to-be-detected image includes at least one complete contour of a connected region generated by the overlapping ellipses; segmenting and fitting the complete contour to obtain a plurality of candidate ellipses; calculating a distance matrix representing the minimum distance from a contour point to the ellipse boundary in each candidate ellipse to obtain a global distance matrix; optimizing based on the global distance matrix to obtain an optimal ellipse combination, and outputting an ellipse detection result based on the optimal ellipse combination. By the above method, the present invention can more precisely adapt to the diversity and complexity of ellipses in an image, and combine an optimization strategy based on a distance matrix and global information to effectively identify and count elliptical objects in the image, especially when there is occlusion or partial overlap of ellipses, it can more accurately detect ellipses in the image. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] To more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on these drawings.

[0018] Figure 1 It is a schematic flowchart of a method for detecting overlapping ellipses in image processing provided by an embodiment of the present invention.

[0019] Figure 2 It is a schematic diagram of the detection result of overlapping ellipses in the related art.

[0020] Figure 3 It is a schematic diagram of the detection result of overlapping ellipses provided by an embodiment of the present invention.

[0021] Figure 4 It is a schematic structural diagram of a device for detecting overlapping ellipses in image processing provided by an embodiment of the present invention.

[0022] Figure 5 It is a schematic physical structure diagram of an electronic device provided by an embodiment of the present invention. Detailed implementation manners

[0023] To make the objectives, technical solutions and advantages of the present invention clearer, the following will clearly and completely describe the technical solutions in the present invention with reference to the accompanying drawings in the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art without creative efforts based on the embodiments in the present invention belong to the scope of protection of the present invention.

[0024] In the description of this specification, the descriptions referring to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the embodiments of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without conflict, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0025] Ellipse detection is a fundamental and important task in many application fields, playing an indispensable role in scenarios such as medical imaging, industrial inspection, robot vision, and autonomous driving. With the increasing complexity of application scenarios, higher requirements are placed on the accuracy and efficiency of ellipse detection in overlapping and complex scenarios.

[0026] Based on this, the present invention provides a method for detecting overlapping ellipses in image processing. This method has significant advantages in computational efficiency and can meet application scenarios with high requirements for real-time processing, such as autonomous driving, medical imaging, real-time monitoring, and industrial automation. Moreover, compared with the traditional Hough transform method, the present invention reduces memory consumption, making it more suitable for resource-constrained application scenarios such as embedded systems and mobile devices.

[0027] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of the method for detecting overlapping ellipses in image processing provided by an embodiment of the present invention. In this embodiment, the method for detecting overlapping ellipses in image processing includes steps S110 to S140, and the specific steps are as follows: S110: Preprocess the input image including overlapping ellipses to obtain a to-be-detected image; wherein the to-be-detected image includes at least one complete contour of a connected region generated by the overlapping ellipses.

[0028] In actual image processing tasks, the input image often contains various noises, interferences, and complex background information, which will all have an adverse impact on the accuracy of ellipse detection. Therefore, it is first necessary to preprocess the input image including overlapping ellipses to obtain a to-be-detected image.

[0029] The preprocessing process can include multiple sub-steps, such as grayscale processing of the image, image filtering operations, and image binarization processing, etc.

[0030] Grayscale processing of the image is to convert a color image into a grayscale image, which can reduce the amount of data and also facilitate subsequent processing operations. Image filtering operations include but are not limited to Gaussian filtering, median filtering, etc. Image binarization processing is to convert a grayscale image into a binary image, so that the target objects (ellipses) and the background in the image can be more clearly separated.

[0031] Exemplarily, the binarization method can adopt the global threshold method and the adaptive threshold method. The global threshold method uses a fixed threshold for the entire image for binarization, while the adaptive threshold method dynamically determines the threshold according to the local region characteristics of the image, and can better adapt to the situation of uneven image brightness.

[0032] After the above preprocessing steps, combined with an edge recognition algorithm, the resulting image to be detected should include at least one complete contour of a connected region generated by overlapping ellipses. The complete contour is the boundary of these connected regions, which contains the shape information of the ellipses and provides a basis for subsequent ellipse detection.

[0033] In some embodiments, the step of preprocessing an input image including overlapping ellipses to obtain an image to be detected may specifically include: Convert the input image including overlapping ellipses into a grayscale image; perform binarization processing on the grayscale image to generate a binary image; perform connected component analysis on the binary image to obtain at least one connected region generated by overlapping ellipses; use an edge detection algorithm to extract edges from the binary image sub-regions of each connected region to form at least one complete contour.

[0034] Based on this, in this embodiment, the preprocessing steps can be simplified by directly reading the image and converting it into a grayscale image, followed by binarization processing.

[0035] S120: Segment and fit the complete contour to obtain multiple candidate ellipses.

[0036] After obtaining the complete contour of the image to be detected, it is necessary to segment and fit it to obtain multiple candidate ellipses.

[0037] Contour segmentation is the process of dividing a complete contour into multiple sub-contours. Since the contours of overlapping ellipses may be intertwined with each other, it is necessary to separate them through a suitable segmentation algorithm. Exemplarily, the segmentation position can be determined according to the characteristics of the edge points of the complete contour (such as gradient direction, curvature, etc.).

[0038] After completing the contour segmentation, it is necessary to perform ellipse fitting on each sub-contour. The purpose of ellipse fitting is to find an ellipse that best matches the sub-contour. For example, the parameters of the ellipse can be determined by minimizing the sum of the squares of the distances from the points on the sub-contour to the ellipse. The parameters of the ellipse can include the center position, major axis, minor axis, rotation angle, etc.

[0039] S130: Calculate the distance matrix representing the minimum distance from the contour points to the ellipse boundary for each candidate ellipse to obtain a global distance matrix.

[0040] In order to screen out the most realistic ellipse combination from multiple candidate ellipses, the calculation of the distance matrix is added in this embodiment. The distance matrix can represent the minimum distance from the contour points to the ellipse boundary in each candidate ellipse.

[0041] Describe the standard ellipse equation for each candidate ellipse, and calculate the minimum distance from the contour points to the ellipse boundary to obtain the distance matrix for each sub - contour. Combine the distance matrix results of all sub - contours to form a global distance matrix. The global distance matrix contains the distance information between all candidate ellipses and contour points, providing data support for subsequent optimization.

[0042] S140: Optimize based on the global distance matrix to obtain the best ellipse combination, and output the ellipse detection result based on the best ellipse combination.

[0043] In this embodiment, an optimal ellipse combination is selected through an optimization algorithm to ensure that each contour point is covered by the best ellipse. Finally, the final ellipse detection result is generated according to the best ellipse combination.

[0044] Optionally, during the optimization process, for the global distance matrix, an integer programming algorithm can be used to optimize the selection of the best ellipse combination, minimizing the weighted sum of the total distance between the ellipses and contour points and the number of ellipses.

[0045] In some embodiments, the step of outputting the ellipse detection result based on the best ellipse combination may specifically include at least one of the following: ① Draw an ellipse in the input image according to the ellipse detection result.

[0046] ② Output the number of detected ellipses according to the ellipse detection result.

[0047] Above, the method for detecting overlapping ellipses in image processing proposed in the embodiments of the present invention aims to solve the problem of more accurately and precisely detecting ellipses in an image in a complex image scene, especially when there are ellipse overlaps, occlusions, etc. The method mainly includes four key steps: image pre - processing, contour segmentation and fitting, distance matrix calculation, and optimization output. Through the above method, the embodiments of the present invention can more precisely adapt to the diversity and complexity of ellipses in the image, and combine the optimization strategies based on the distance matrix and the global situation to effectively identify and count elliptical objects in the image. Especially when there are occlusions or partial overlaps of ellipses, the ellipses in the image can be detected more accurately.

[0048] Please refer to Figures 2 - 3 , Figure 2 which is a schematic diagram of the overlapping ellipse detection result in the related art. Figure 3 which is a schematic diagram of the overlapping ellipse detection result provided by the embodiments of the present invention.

[0049] As Figure 2 shown, in the overlapping ellipse detection result of the related art, overlapping ellipses cannot be recognized, and only multiple overlapping ellipses can be recognized as a large ellipse, with relatively low recognition accuracy. In contrast, as Figure 3After adopting the overlapping ellipse detection method provided by the embodiments of the present application, the most realistic ellipse combination can be screened out in the overlapping ellipse region. Therefore, in the obtained overlapping ellipse detection result, the overlapping ellipses can be separated and the contours of each ellipse can be accurately fitted, improving the accuracy of ellipse detection.

[0050] Based on any of the above embodiments, the step of segmenting and fitting the complete contour to obtain multiple candidate ellipses may specifically include: Using a polygon approximation algorithm to simplify the complete contour; using a concave point detection algorithm to segment the simplified complete contour to obtain multiple sub-contours; using an affine transformation algorithm to generate ellipse fitting parameters for each sub-contour, and taking the sub-contour corresponding to the ellipse fitting parameters that meet the preset requirements as a candidate ellipse.

[0051] In this embodiment, while simplifying the contour, the polygon approximation algorithm can better retain the main shape features of the original contour. It can adjust the degree of approximation according to the preset accuracy requirements, so that the simplified polygon is similar to the original contour in shape. Ensure that key ellipse feature information will not be lost during the simplification process, thereby improving the accuracy of ellipse detection.

[0052] Concave points are key feature points of the overlapping ellipse contour, representing the overlapping area between ellipses. In this embodiment, by using a concave point detection algorithm to segment the simplified contour, the overlapping ellipse contours can be accurately separated into multiple sub-contours.

[0053] The affine transformation algorithm has strong adaptability and can handle sub-contours of different shapes and postures. It can convert the sub-contour into a standard ellipse form through transformation operations such as translation, rotation, and scaling, so as to generate accurate ellipse fitting parameters. For ellipses that may have rotation, scaling, etc. in the image, the affine transformation can effectively capture their features and improve the accuracy of ellipse detection in complex scenarios.

[0054] Above, in this embodiment, the edges in the image are extracted by polygon approximation and concave point detection methods. By using affine transformation and considering ellipses of different ratios and angles, it can more precisely adapt to the diversity and complexity of ellipses in the image.

[0055] Based on any of the above embodiments, the step of taking the sub-contour corresponding to the ellipse fitting parameters that meet the preset requirements as a candidate ellipse may specifically include: Calculating the distance transformation value of the ellipse internal region corresponding to each sub-contour according to the ellipse fitting parameters; determining the score matrix, area matrix, and coverage matrix according to the percentile score and coverage area of the distance transformation value; taking the sub-contour with a coverage area greater than the minimum coverage area as a candidate ellipse according to the score matrix, area matrix, and coverage matrix.

[0056] The distance transformation values in the inner region of the ellipse can accurately reflect the internal structure and shape characteristics of the ellipse corresponding to the sub - contour. In this embodiment, the distance transformation values are used to describe the distance from each point inside the ellipse to the ellipse boundary. By calculating these values, a more detailed understanding of the ellipse's morphology can be obtained.

[0057] And in this embodiment, the characteristics of the ellipse are also quantified by percentile scores. Combining multi - matrix comprehensive evaluation, the score matrix is based on percentile scores and reflects the characteristic quality of the ellipse; the area matrix records the area size of the ellipse; the coverage matrix reflects the coverage relationship between ellipses. By comprehensively considering these three matrices, the possibility of each sub - contour being an ellipse can be comprehensively evaluated.

[0058] Finally, the sub - contours with a coverage area greater than the minimum coverage area are used as candidate ellipses, which can effectively exclude those sub - contours with too small an area or unreasonable coverage range. For example, some small noise regions or incomplete ellipses may be misidentified as ellipses. By setting a threshold for the minimum coverage area, these invalid sub - contours can be filtered out, and only those ellipses with sufficient coverage range and practical significance are retained as candidates, improving the quality and reliability of the candidate ellipses.

[0059] Based on any of the above - mentioned embodiments, the steps of optimizing based on the global distance matrix to obtain the optimal ellipse combination may specifically include: Processing the global distance matrix according to the optimization algorithm to obtain the optimal ellipse combination; wherein, the optimization algorithm is to minimize the weighted sum of the total distance between the ellipse and the contour points and the number of ellipses.

[0060] In this embodiment, the distance matrix results of all sub - contours are combined to form a global distance matrix. The optimal ellipse combination is selected through the optimization algorithm to ensure that each contour point is covered by the best ellipse. By minimizing the weighted sum of the total distance between the ellipse and the contour points and the number of ellipses: .

[0061] Where is a binary variable indicating whether candidate ellipse i covers contour point j. is a binary variable indicating whether candidate ellipse i is selected. λ is a weight parameter used to balance the distance and the number of ellipses.

[0062] There are four constraint conditions, specifically as follows: (1)Coverage constraint ; The coverage constraint ensures that each contour point j is covered by at least one ellipse i. is a binary variable indicating whether contour point j is covered by any ellipse.

[0063] (2) Selection Constraint ; The selection constraint ensures that each candidate ellipse i covers at most M contour points, where M is a large number, usually set to the total number of contour points.

[0064] (3) Coverage Consistency Constraint ; The coverage consistency constraint ensures that if candidate ellipse i is selected ( ), then it can cover contour point j. If , that is, ellipse i is not selected, then must be 0, indicating that ellipse i cannot cover any contour points.

[0065] (4) Unique Coverage Constraint ; The unique coverage constraint ensures that each contour point j is covered by at most one ellipse i. This can avoid multiple ellipses overlapping to cover the same contour point and ensure the uniqueness of coverage. An integer programming solver is used to solve the optimization problem, and the optimal ellipse combination is extracted according to the optimization result.

[0066] Based on the above method, this embodiment combines the optimization strategy based on the distance matrix and integer programming to effectively identify and count elliptical objects in the image. This embodiment introduces a fractional mechanism, evaluates the matching degree between each candidate ellipse and the edge contour by calculating the distance matrix, and then uses the integer programming method to select the optimal ellipse object. This method ensures the accuracy and reliability of the detection result, ensuring that the ellipse not only conforms in shape but also is efficient in covering the actual image area.

[0067] To better illustrate the content of the method for detecting overlapping ellipses in the image processing of the present invention, the following provides a specific step flow for reference.

[0068] Step 1: Image loading and preprocessing.

[0069] Load the color image from the specified path and convert it to a grayscale image to simplify the subsequent processing steps. Perform binarization on the grayscale image, set the threshold to 127, and generate a binary image to distinguish the foreground and the background. Among them, the pixel value of 0 represents the background, and the pixel value of 255 represents the foreground.

[0070] Step 2: Connected component analysis of the binary image.

[0071] Perform connected component analysis on the obtained binary image to obtain the number, label, statistical information, and centroid of the connected regions.

[0072] Exemplarily, create a label image label of the same size as the input binary image, initialized to zero. Initialize a list of equivalence classes to record equivalent labels. Set the current label current_label to 1. Starting from the upper left corner of the image, traverse each pixel row by row and column by column. For each foreground pixel (value 255), check its neighboring pixels according to the 8-connectivity method, that is, the pixels in the eight directions of up, left, right, down, upper left, upper right, lower left, and lower right. If there are labeled foreground pixels among the neighboring pixels, label the current pixel with the same label. If there are no labeled foreground pixels among the neighboring pixels, label the current pixel with current_label and increment current_label by 1. If multiple neighboring pixels have different labels, record the equivalence relationship of these labels. Use the union-find data structure to manage the equivalence classes and merge the equivalent labels. Traverse the image again and replace all equivalent labels with a unified root label. Calculate the statistical information of each connected component, including area, centroid, and bounding box.

[0073] Step 3: Contour detection and processing.

[0074] Extract the edges of the binary image sub-region of each connected region to form a complete contour. Use the polygon approximation algorithm to simplify the contour and detect concave points. According to the marked concave points, split the contour into multiple sub-contours.

[0075] Specifically, for each connected region, extract its corresponding binary image sub-region. Traverse each connected region and use the edge detection algorithm to detect the contour. First, find the edge pixels (pixels with value 255) in the binary image. Starting from each found edge pixel, track its adjacent edge pixels until returning to the starting point to form a complete contour.

[0076] The tracking direction is 8-connectivity. Store each found contour as a set of points to extract its contour. For the detected contour point set, use the polygon approximation algorithm to simplify the contour. Then detect the positions of its concave points and generate a list of concave point indices.

[0077] Polygon approximation algorithm: Given a point set and a threshold , where the threshold is set to 1, calculate the distance of each point to the line . Find the point farthest from the line. If no point's distance is greater than the threshold, delete all points on the curve and only keep the first point and the last point. If the distance of this point is greater than the preset threshold, keep this point and split the curve into two segments at this point, and recursively process each segment to reduce the number of vertices and smooth the contour to obtain a new set poly.

[0078] Concave point detection algorithm: Calculate the difference vector between each vertex and its previous vertex to obtain the first difference vector array Calculate the rolling difference of the first difference vector to obtain the second difference vector array .

[0079] Determine the concave point position by calculating the cross product: If the cross product is greater than 0, then this point is a concave point. Store the coordinates of the concave points in a set. For each vertex, calculate the cross product of its first difference vector and second difference vector. The sign of the cross product is used to determine whether the vertex is a convex point or a concave point. If the cross product is greater than zero, then this vertex is a concave point and is stored in the concave point set

[0080] Step 4: Generate ellipse candidate parameters

[0081] Calculate the ellipse fitting parameters for each obtained sub - contour. According to the given different ratios and angles, use affine transformation to generate ellipse parameters with different ratios and angles, including the center point, major axis radius, and minor axis radius

[0082] Specifically, generate a contour image for each connected region. According to the marked concave points, divide the contour into multiple sub - contours. Each sub - contour corresponds to a simpler shape, which is convenient for individual processing

[0083] Calculate the ellipse fitting parameters for each sub - contour separately. There are five ellipse parameters: the center coordinates (x, y), the major axis radius a, the minor axis radius b, the angle θ between the x - axis and the major axis of the ellipse, and the ratio ratio of a to b

[0084] Initialize the ellipse detection parameters, including the angle and the ratio of the major and minor axes. The ratio ranges from 1 to 4 with an interval of 0.2, and the angle ranges from 0 to 180 with an interval of 5. Use affine transformation to generate ellipse parameters with different ratios and angles. According to different angles and ratios, calculate the affine transformation matrix T and its inverse matrix Tinv

[0085] .

[0086] .

[0087] Where , .

[0088] Applying an affine transformation matrix to the coordinates (x, y) of the original image yields the transformed coordinates. Perform a distance transformation on the transformed coordinates, and find the local maximum on the distance transformation graph as the center point of the candidate ellipse. The distance transformation method is to calculate the distance DT from each point to the nearest contour point, and find the point on the distance transformation graph that maximizes DT locally as the center point of the candidate ellipse. Based on the local maximum of the distance transformation graph, calculate the major and minor axes of the ellipse. The minor axis minor = DT(peak), that is, the local maximum of DT, and the major axis major = minor × ratio, where ratio is the predefined ratio of the major axis to the minor axis. Map the transformed center point coordinates back to the original image space through the inverse transformation matrix. The rotation angle θ of the ellipse is directly determined by the predefined angle range.

[0089] Affine transformation can generate a series of different ellipse shapes, covering various ellipse shapes that may appear in the image, ensuring that the algorithm can adapt to the diversity of elliptical objects in the image.

[0090] Step 5: Screen candidate ellipses.

[0091] Calculate the distance transformation values of the internal regions of each candidate ellipse according to the obtained parameters. Update the score matrix, area matrix, and coverage matrix according to the percentile scores and coverage areas of the distance transformation values. Traverse each percentile layer and count the coverage area of each ellipse. Retain the ellipses whose coverage area is greater than the minimum coverage area.

[0092] Specifically, for each candidate ellipse, calculate the distance transformation value of its internal region. First, invert the foreground and background of the entire binary image and calculate the distance transformation graph using the Euclidean distance. The internal region represents the set of pixel points inside the ellipse, and the external region represents the set of pixel points outside the ellipse but adjacent to the internal region. The formula for the internal region: 。

[0093] Extract the distance transformation values of the internal region of the ellipse, which represent the distances from the pixels inside the ellipse to the nearest foreground (contour) pixels. Sort the distance transformation values from smallest to largest, and calculate the corresponding positions according to the required percentiles (e.g., 30%, 50%, 70%).

[0094] If the calculated position is an integer, directly take the value at that position from the sorted data. If the position is a decimal, use linear interpolation to calculate to determine the accurate percentile value as the final score. The distance transformation is used to evaluate the matching degree of the candidate ellipse.

[0095] Record the percentile scores and coverage areas of each candidate ellipse in the score matrix and coverage matrix. Update the score matrix, area matrix, and coverage matrix according to the calculated scores and areas.

[0096] If the current ellipse provides a better score or a larger area at a specific pixel point than the previously recorded ellipse, then the three matrices will be updated.

[0097] Update the score matrix: Compare the new score and the current score, and keep the smaller score.

[0098] Update the area matrix: Compare the new ellipse area and the current area, and keep the larger area.

[0099] Update the coverage matrix: Record which ellipse covers each pixel point.

[0100] The score matrix records the scores of each pixel point at different percentiles. The coverage matrix records which candidate ellipse covers each pixel point. Calculate the minimum coverage area according to the coverage rate threshold of 0.95 (obtained by multiplying the coverage rate by the theoretical area of the ellipse).

[0101] Traverse each percentile layer, which reflects different distance transformation score criteria, and count the number of pixels covered by each ellipse according to the coverage matrix. Compare this statistical result with the minimum area array. In the end, only when the actual coverage area of the ellipse is greater than or equal to this minimum value, it will be included in the final ellipse list. Count the coverage area of each ellipse. Keep the ellipses whose coverage area is greater than the minimum coverage area.

[0102] Step 6: Distance matrix calculation.

[0103] For each filtered candidate ellipse, describe its standard ellipse equation and calculate the minimum distance from the contour points to the ellipse boundary. Combine the distance matrix results of all sub - contours to form a global distance matrix.

[0104] Specifically, for each candidate ellipse, it is described using the standard ellipse equation: .

[0105] (cx, cy) is the center point coordinates. For the given ellipse parameters, calculate the set of points on the ellipse boundary. Use the angle parameter t to parameterize the points on the ellipse boundary: ; where t is uniformly taken from 0 to 2π. For each contour point (x, y), calculate its distance to all points on the ellipse boundary and take the minimum value as the distance from the contour point to the ellipse. Traverse all contour points to construct the distance matrix. The element represents the minimum distance between the i - th candidate ellipse and the j - th contour point.

[0106] Step 7: Ellipse optimization.

[0107] According to the obtained distance matrix, use the integer programming algorithm to optimally select the best combination of ellipses, minimizing the weighted sum of the total distance between the ellipses and the contour points and the number of ellipses. The specific optimization method has been introduced in the above embodiments and will not be elaborated here.

[0108] Step 8: Draw the results and count.

[0109] Generate the final ellipse detection result according to the obtained optimal ellipse combination, draw it on the image, and output the number of detected ellipses at the same time.

[0110] Based on the above steps, in this embodiment, by directly reading the image and converting it into a grayscale image, and then performing binarization processing, the preprocessing steps are simplified. Next, the edges in the image are extracted by polygon approximation and concave point detection methods. By using affine transformation, ellipses with different scales and angles are considered, and the diversity and complexity of ellipses in the image can be more precisely adapted. Combined with the optimization strategy based on the distance matrix and integer programming, oval objects in the image can be effectively identified and counted. The present invention introduces a scoring mechanism, evaluates the matching degree between each candidate ellipse and the edge contour by calculating the distance matrix, and then uses the integer programming method to select the optimal ellipse object. This method ensures the accuracy and reliability of the detection results, ensuring that the ellipses not only conform in shape but also are efficient in covering the actual image area. The present invention not only simplifies the image processing process, reduces the dependence on parameter adjustment, but also effectively retains the important features in the image while accelerating the processing speed. This method allows for a finer fitting of the ellipses, especially when there is occlusion or partial overlap of the ellipses, and can more accurately count the ellipses.

[0111] In some other embodiments, for interference factors such as image noise and illumination changes, the algorithm can be further optimized to improve its robustness. For example, by introducing more advanced image preprocessing techniques to reduce the influence of noise and illumination changes.

[0112] In some other embodiments, in order to reduce the dependence of the algorithm on parameters, an adaptive parameter adjustment mechanism can be designed. Dynamically adjust the parameters according to the image features and detection results to improve the generalization ability of the algorithm.

[0113] In some other embodiments, an error detection and processing mechanism is introduced to identify and correct possible misdetections or missed detections. For example, by comparing the matching degrees and covered areas of multiple candidate ellipses, select the optimal detection result.

[0114] In some other embodiments, when processing images containing sensitive information, privacy protection issues need to be considered. User privacy can be protected by encrypting image data, restricting algorithm access rights, etc.

[0115] In some other embodiments, to ensure the compatibility of the algorithm across different platforms and devices, cross-platform testing and optimization can be performed on it. This includes testing and adjustment in different operating systems, hardware configurations, and programming language environments.

[0116] The present invention also provides a detection device for overlapping ellipses in image processing. The detection device for overlapping ellipses in image processing provided by the present invention will be described below. The detection device for overlapping ellipses in image processing described below can be correspondingly referred to the detection method for overlapping ellipses in image processing described above.

[0117] Please refer to Figure 4 , Figure 4 FIG. is a schematic structural diagram of the detection device for overlapping ellipses in image processing provided by an embodiment of the present invention. In this embodiment, the detection device for overlapping ellipses in image processing may include a preprocessing module 410, a candidate ellipse acquisition module 420, a distance calculation module 430, and an ellipse optimization module 440.

[0118] The preprocessing module 410 is configured to preprocess an input image including overlapping ellipses to obtain a to-be-detected image; wherein the to-be-detected image includes at least one complete contour of a connected region generated by the overlapping ellipses.

[0119] The candidate ellipse acquisition module 420 is configured to segment and fit the complete contour to obtain a plurality of candidate ellipses.

[0120] The distance calculation module 430 is configured to calculate a distance matrix representing the minimum distance from contour points to the ellipse boundary in each candidate ellipse to obtain a global distance matrix.

[0121] The ellipse optimization module 440 is configured to perform optimization based on the global distance matrix to obtain an optimal ellipse combination, and output an ellipse detection result based on the optimal ellipse combination.

[0122] In some embodiments, the candidate ellipse acquisition module 420 is specifically configured to: Use a polygon approximation algorithm to simplify the complete contour; use a concave point detection algorithm to segment the simplified complete contour to obtain a plurality of sub-contours; use an affine transformation algorithm to generate ellipse fitting parameters for each sub-contour, and use the sub-contour corresponding to the ellipse fitting parameters meeting the preset requirements as candidate ellipses.

[0123] In some embodiments, the candidate ellipse acquisition module 420 is specifically configured to: Calculate the distance transformation values of the inner regions of the ellipses corresponding to each sub - contour according to the ellipse fitting parameters; determine the score matrix, area matrix, and coverage matrix according to the percentile scores of the distance transformation values and the coverage regions; and take the sub - contours with a coverage area greater than the minimum coverage area as candidate ellipses according to the score matrix, area matrix, and coverage matrix.

[0124] In some embodiments, the ellipse optimization module 440 is specifically configured to: Process the global distance matrix according to an optimization algorithm to obtain the optimal ellipse combination; wherein, the optimization algorithm is to minimize the weighted sum of the total distance between the ellipses and the contour points and the number of ellipses.

[0125] In some embodiments, the pre - processing module 410 is specifically further configured to: Convert the input image including overlapping ellipses into a grayscale image; perform binarization processing on the grayscale image to generate a binary image; perform connected - component analysis on the binary image to obtain at least one connected region generated by the overlapping ellipses; and use an edge - detection algorithm to extract edges from the binary - image sub - regions of each connected region to form at least one complete contour.

[0126] In some embodiments, the ellipse optimization module 440 is specifically further configured to: Draw ellipses in the input image according to the ellipse detection results; and / or output the number of detected ellipses according to the ellipse detection results.

[0127] On the other hand, an embodiment of the present invention further provides an electronic device. Please refer to Figure 5 , Figure 5 is a schematic physical structure diagram of the electronic device provided by the embodiment of the present invention. As Figure 5 shown, the electronic device may include a memory 520, a processor 510, and a computer program stored on the memory 520 and executable on the processor 510. When the processor 510 executes the program, it implements the detection method for overlapping ellipses in the image processing provided by the above - mentioned various methods.

[0128] Optionally, the electronic device may further include a communication bus 530 and a communication interface 540. Among them, the processor 510, the communication interface 540, and the memory 520 complete mutual communication through the communication bus 530. The processor 510 may call the computer program in the memory 520 to execute the detection method for overlapping ellipses in the image processing. The method may include: Preprocess the input image including overlapping ellipses to obtain the image to be detected; wherein the image to be detected includes the complete contours of at least one connected region generated by the overlapping ellipses; segment and fit the complete contours to obtain multiple candidate ellipses; calculate the distance matrix representing the minimum distance from the contour points to the ellipse boundary in each candidate ellipse to obtain the global distance matrix; optimize based on the global distance matrix to obtain the optimal ellipse combination, and output the ellipse detection result based on the optimal ellipse combination.

[0129] In addition, when the logical instructions in the above-mentioned memory 520 are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical disks and other various media that can store program codes.

[0130] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the detection method for overlapping ellipses in the image processing provided by the above-mentioned various methods. The steps and principles have been introduced in detail in the above methods and will not be elaborated here.

[0131] On yet another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is implemented to execute the detection method for overlapping ellipses in the image processing provided by the above-mentioned various methods. The steps and principles have been introduced in detail in the above methods and will not be elaborated here.

[0132] The non-transitory computer-readable storage medium can be any available medium or data storage device accessible by the processor, including but not limited to magnetic memories (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical memories (such as CDs, DVDs, BDs, HVDs, etc.), and semiconductor memories (such as ROM, EPROM, EEPROM, non-volatile memories (NANDFLASH), solid-state drives (SSD)), etc.

[0133] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative labor.

[0134] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0135] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features. And these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for detecting overlapping ellipses in image processing, characterized in that: include: Preprocessing the input image including the overlapping ellipses to obtain an image to be detected; wherein the image to be detected includes at least one complete outline of a connected region generated by overlapping ellipses; Segmenting and fitting the complete contour to obtain a plurality of candidate ellipses; Calculate the distance matrix representing the minimum distance from the contour point to the ellipse boundary in each candidate ellipse to obtain a global distance matrix; Optimization is performed based on the global distance matrix to obtain an optimal ellipse combination, and an ellipse detection result is output based on the optimal ellipse combination.

2. The method for detecting overlapping ellipses in image processing according to claim 1, characterized in that: The complete contour is segmented and fitted to obtain a plurality of candidate ellipses, including: Simplifying the complete outline using a polygonal approximation algorithm; Use the concave point detection algorithm to segment the simplified complete contour to obtain multiple sub-contours; An affine transformation algorithm is used to generate ellipse fitting parameters for each sub-contour, and the sub-contour corresponding to the ellipse fitting parameters that meet preset requirements is used as the candidate ellipse.

3. The method for detecting overlapping ellipses in image processing according to claim 2, characterized in that: The step of taking the sub-contour corresponding to the ellipse fitting parameters that meet the preset requirements as the candidate ellipse includes: Calculate the distance transformation value of the inner area of ​​the ellipse corresponding to each sub-contour according to the ellipse fitting parameters; Determining a score matrix, an area matrix, and a coverage matrix based on the percentile scores and coverage areas of the distance transform values; According to the score matrix, the area matrix and the coverage matrix, the sub-contour with a coverage area greater than the minimum coverage area is taken as the candidate ellipse.

4. The method for detecting overlapping ellipses in image processing according to claim 1, characterized in that: The optimization based on the global distance matrix to obtain the best ellipse combination includes: Processing the global distance matrix according to an optimization algorithm to obtain the optimal ellipse combination; The optimization algorithm is implemented by minimizing the weighted sum of the total distance between the ellipse and the contour points and the number of ellipses.

5. The method for detecting overlapping ellipses in image processing according to claim 1, characterized in that: The step of preprocessing the input image including the overlapping ellipses to obtain the image to be detected comprises: Convert the input image including the overlapping ellipses to a grayscale image; Binarizing the grayscale image to generate a binary image; Performing connected domain analysis on the binary image to obtain at least one connected region generated by overlapping ellipses; An edge detection algorithm is used to extract edges from the binary image sub-regions of each connected region to form at least one complete contour.

6. The method for detecting overlapping ellipses in image processing according to any one of claims 1 to 5, characterized in that: The outputting of the ellipse detection result based on the optimal ellipse combination comprises: Drawing an ellipse in the input image according to the ellipse detection result; And / or, outputting the number of detected ellipses according to the ellipse detection result.

7. A detection device for overlapping ellipses in image processing, characterized in that: include: A preprocessing module, used for preprocessing the input image including the overlapping ellipses to obtain an image to be detected; wherein the image to be detected includes at least one complete outline of a connected region generated by overlapping ellipses; A candidate ellipse acquisition module is used to segment and fit the complete contour to obtain multiple candidate ellipses; A distance calculation module is used to calculate a distance matrix representing the minimum distance from the contour point to the ellipse boundary in each candidate ellipse to obtain a global distance matrix; The ellipse optimization module is used to optimize based on the global distance matrix to obtain the best ellipse combination, and output the ellipse detection result based on the best ellipse combination.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the method for detecting overlapping ellipses in image processing according to any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for detecting overlapping ellipses in image processing according to any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for detecting overlapping ellipses in image processing according to any one of claims 1 to 6 is implemented.