Image processing method, apparatus, device, storage medium and program product
By filtering edge pixels in the image and generating a distance image, the problem of contour deformation caused by uncertainty in the acquisition angle and position is solved, thus improving the accuracy of contour matching.
Patent Information
- Application Number
- CN202511319512.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-16
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2045-09-16
AI Technical Summary
In existing technologies, the uncertainty of the acquisition angle and position of the reference sample leads to the deformation of the reference sample in the reference image, which reduces the accuracy of the contour detection results.
By filtering edge pixels in the image of the first object and generating a distance image based on the pixel distance between the edge pixels and the background pixels, the accuracy of the contour matching results is improved by matching the image of the object to be detected.
It effectively avoids the influence of factors such as lens distortion and product placement tilt on the contour, thus improving the accuracy of contour matching results.
Smart Images

Figure CN120823134B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of image processing, and particularly relates to an image processing method, device, equipment, storage medium and program product. BACKGROUND
[0002] With the development of technology, in the product production process, each sample to be produced is detected, and samples meeting the factory conditions are selected therefrom to ensure the quality of products after leaving the factory, for example, by comparing the contour of a to-be-detected sample with the contour of a reference sample to determine whether the appearance contour of the to-be-detected sample meets the factory standard.
[0003] In the related art, a reference sample meeting the factory condition is manually selected from a plurality of samples, a reference image corresponding to the reference sample is generated, a reference contour image is generated after the reference image is manually cropped at the contour edge corresponding to the reference sample in the reference sample, and the contour detection result of the to-be-detected sample is determined by matching the contour edge of the to-be-detected sample.
[0004] However, due to the uncertainty of the collection angle and the collection position in the collection process of the reference image corresponding to the reference sample, the contour of the reference sample in the reference image is deformed, thereby reducing the matching degree between the reference image and the reference sample, and thus reducing the accuracy of the contour detection result. SUMMARY
[0005] Embodiments of the present application provide an image processing method, device, equipment, storage medium and program product, edge pixel points of a first object are screened out in a first image of the first object, a distance image is generated according to the pixel point distance between the edge pixel points and background pixel points of a background region in the first image, the distance image represents the geometric features of the contour of the first object in the first image, and the distance image is matched with an image of a to-be-detected object, so as to improve the accuracy of the contour matching result.
[0006] In a first aspect, an embodiment of the present application provides an image processing method, and the method comprises:
[0007] obtaining a first image corresponding to a first object, the first image comprising a plurality of candidate pixel points, and the first image comprising a first region and a second region;
[0008] determining a plurality of edge pixel points from the plurality of candidate pixel points based on the gradient intensity corresponding to each of the plurality of candidate pixel points, the plurality of edge pixel points being used to form a contour of the first object in the first image, the gradient intensity being used to indicate the change of the pixel value corresponding to the candidate pixel point in a specified gradient direction, and the plurality of edge pixel points being pixel points in the first region;
[0009] obtain a plurality of background pixel points in the first image, wherein a pixel distance between the plurality of edge pixel points and the plurality of background pixel points meets a first distance condition, and the background pixel points are candidate pixel points in the first image except the edge pixel points;
[0010] generate a distance image based on a plurality of pixel distances between the plurality of edge pixel points and the plurality of background pixel points, the distance image being used for matching a second image corresponding to a second object, and determining a contour matching result of the second object, wherein the first object and the second object are objects of the same type.
[0011] Optionally, the plurality of edge pixel points includes an ith edge pixel point, the ith edge pixel point corresponds to at least one background pixel point, and i is a positive integer.
[0012] The generating of the distance image based on the plurality of pixel distances between the plurality of edge pixel points and the plurality of background pixel points includes:
[0013] obtaining a candidate distance corresponding to the ith edge pixel point and the at least one background pixel point;
[0014] selecting one of at least one candidate distance with a minimum distance as the pixel distance corresponding to the ith edge pixel point;
[0015] determining the pixel distance corresponding to the ith edge pixel point as a pixel distance value corresponding to the ith edge pixel point;
[0016] generating the distance image based on pixel distance values respectively corresponding to the plurality of edge pixel points.
[0017] Optionally, the at least one background pixel point includes a jth background pixel point, and j is a positive integer.
[0018] The obtaining of the candidate distance corresponding to the ith edge pixel point and the at least one background pixel point includes:
[0019] obtaining a geometric distance between the ith edge pixel point and the jth background pixel point;
[0020] obtaining a preset propagation step length, the preset propagation step length being used to indicate a propagation attenuation between the ith edge pixel point and the jth background pixel point;
[0021] determining the candidate distance between the ith edge pixel point and the jth background pixel point based on the geometric distance and the preset propagation step length.
[0022] Optionally, the candidate distances include a first candidate distance and a second candidate distance.
[0023] The obtaining of the candidate distance corresponding to the ith edge pixel point and the at least one background pixel point comprises:
[0024] scanning the plurality of edge pixel points in a first scanning order to obtain the first candidate distance corresponding to the ith edge pixel point and the at least one background pixel point;
[0025] scanning the plurality of edge pixel points in a second scanning order to obtain the second candidate distance corresponding to the ith edge pixel point and the at least one background pixel point, the first scanning order being different from the second scanning order;
[0026] selecting a smaller distance value from the first candidate distance and the second candidate distance as the candidate distance.
[0027] Optionally, the plurality of candidate pixel points include an nth candidate pixel point, n being a positive integer.
[0028] The determining of the plurality of edge pixel points from the plurality of candidate pixel points based on the gradient intensities corresponding to the plurality of candidate pixel points comprises:
[0029] obtaining a plurality of reference pixel points of the nth candidate pixel point in the first image along the specified gradient direction, the reference pixel points and the nth candidate pixel point in the first image being at pixel positions meeting a second position condition, the plurality of reference pixel points corresponding to a plurality of reference gradients respectively;
[0030] In a case where a gradient difference between the gradient intensity corresponding to the nth candidate pixel point and the plurality of reference gradients meets a first gradient condition, the nth candidate pixel point is determined as the edge pixel point.
[0031] Optionally, the determining of the nth candidate pixel point as the edge pixel point in a case where a gradient difference between the gradient intensity corresponding to the nth candidate pixel point and the plurality of reference gradients meets a first gradient condition comprises:
[0032] In a case where a gradient difference between the gradient intensity corresponding to the nth candidate pixel point and the plurality of reference gradients meets a first gradient condition, the nth candidate pixel point is determined as a candidate edge pixel point.
[0033] In a case where the nth candidate pixel point reaches a first gradient threshold, the nth candidate pixel point is determined as the edge pixel point.
[0034] Optionally, the method further comprises:
[0035] If the nth candidate pixel does not reach the second gradient threshold, the nth candidate pixel is determined to be a non-edge pixel, and the second gradient threshold is less than the first gradient threshold.
[0036] Optionally, the plurality of candidate pixels includes the m-th candidate pixel, which is the edge pixel, where m is a positive integer and m is different from n;
[0037] The method further includes:
[0038] If the nth candidate pixel reaches the second gradient threshold but does not reach the first gradient threshold, obtain the pixel position distance between the mth candidate pixel and the nth pixel.
[0039] If the distance between the pixel locations meets the third location condition, the nth candidate pixel is determined as the edge pixel.
[0040] Optionally, the method further includes:
[0041] If the gradient difference between the gradient intensity corresponding to the nth candidate pixel and the plurality of reference gradients does not meet the first gradient condition, the gradient intensity corresponding to the nth candidate pixel is set to zero to obtain the zero intensity corresponding to the nth candidate pixel. The zero intensity is used to indicate that the nth candidate pixel is a non-edge pixel.
[0042] Secondly, embodiments of this application provide an image processing apparatus, including:
[0043] The acquisition module is used to acquire a first image corresponding to a first object, wherein the first image includes multiple candidate pixels;
[0044] The determining module is used to determine a plurality of edge pixels from the plurality of candidate pixels based on the gradient intensities corresponding to the plurality of candidate pixels respectively. The plurality of edge pixels are used to form the outline of the first object in the first image. The gradient intensities are used to indicate the changes in the pixel values corresponding to the candidate pixels in a specified gradient direction. The plurality of edge pixels are pixels within the first region.
[0045] The acquisition module is used to acquire multiple background pixels in the first image, wherein the pixel distance between the multiple edge pixels and the multiple background pixels meets a first distance condition, and the background pixels are candidate pixels in the first image other than the edge pixels;
[0046] The generation module is used to generate a distance image based on the distance between multiple edge pixels and multiple background pixels. The distance image is used to match with a second image corresponding to a second object to determine the contour matching result of the second object. The first object and the second object are objects of the same type.
[0047] Thirdly, embodiments of this application provide a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image processing method described in any one of the first aspects above.
[0048] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the image processing method described in any one of the first aspects.
[0049] Fifthly, embodiments of this application provide a computer program product that, when run on a computer device, causes the computer device to perform the image processing method described in any one of the first aspects.
[0050] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here.
[0051] The beneficial effects of the technical solutions provided in this application include at least the following:
[0052] After acquiring the first image of the first object, edge pixels of the first object in the first image are selected based on the gradient intensity of multiple candidate pixels. A distance image is then generated based on the pixel distance between the edge pixels and background pixels in the background region of the first image. Finally, the distance image is used as a reference for contour matching with images of other objects to be detected, yielding contour matching results for the other objects. In other words, by selecting edge pixels from the first image of the first object and generating a distance image based on the pixel distance between the edge pixels and background pixels in the background region of the first image, the geometric features of the first object's contour in the first image are characterized. This avoids the distortion of the first object's contour in the first image caused by lens distortion, product tilt, etc., during the acquisition of the first image, thus improving the accuracy of the first object's contour in the first image. Therefore, matching the distance image with the image of the object to be detected can improve the accuracy of the contour matching results. Attached Figure Description
[0053] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0054] Figure 1 This is a flowchart of an image processing method provided in an embodiment of this application;
[0055] Figure 2 This is a schematic diagram of the object outline provided in an embodiment of this application;
[0056] Figure 3 This is a flowchart of an image processing method provided in an embodiment of this application;
[0057] Figure 4 This is a schematic diagram of object outline selection provided in an embodiment of this application;
[0058] Figure 5 This is a schematic diagram of pixel distance provided in an embodiment of this application;
[0059] Figure 6 This is a schematic diagram of a distance image provided in an embodiment of this application;
[0060] Figure 7 This is a schematic diagram of grayscale matching provided in an embodiment of this application;
[0061] Figure 8 This is a structural diagram of the image processing apparatus provided in the embodiments of this application;
[0062] Figure 9 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0063] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0064] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0065] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0066] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0067] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0068] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0069] In related technologies, a reference image is generated by manually selecting a reference sample that meets the factory conditions from multiple samples. The corresponding contour edge of the reference image in the reference sample is then manually traced to generate a reference contour image, which is matched with the contour edge of the sample to be tested to determine the contour detection result of the sample to be tested. However, due to uncertainties in the acquisition angle and sample placement during the acquisition process, the contour of the reference sample in the reference image may be distorted, thereby reducing the matching degree between the reference image and the reference sample, and thus reducing the accuracy of the contour detection result.
[0070] Based on this, embodiments of this application provide an image processing method. After acquiring a first image of a first object, edge pixels of the first object in the first image are selected based on the gradient intensity of multiple candidate pixels. A distance image is generated based on the pixel distance between the edge pixels and the background pixels in the background region of the first image. Finally, the distance image is used as a reference to perform contour matching with images of other objects to be detected, thereby obtaining contour matching results for other objects to be detected. In other words, by selecting edge pixels of the first object in the first image and generating a distance image based on the pixel distance between the edge pixels and the background pixels in the background region of the first image, the geometric features of the contour of the first object in the first image are characterized. This avoids the influence of lens distortion, product tilt, and other factors on the contour distortion of the first object in the first image during the acquisition of the first image, thus improving the accuracy of the contour of the first object in the first image. Therefore, matching the distance image with the image of the object to be detected can improve the accuracy of the contour matching results.
[0071] The image processing method provided in the embodiments of this application will be described in detail below. For illustrative purposes, please refer to the following. Figure 1 The diagram illustrates an image processing method provided in an exemplary embodiment of this application, which includes steps 110 to 140.
[0072] Step 110: Obtain the first image corresponding to the first object. The first image includes multiple candidate pixels.
[0073] The first image includes a first region and a second region. The first region is the region where the first object is located, and the second region is the background region in the first image excluding the first region.
[0074] Indicatively, the first object refers to the sample to be tested; or, the first object is a sample that meets the pre-set sample conditions after preliminary sample testing.
[0075] In practical applications, the pre-set sample conditions can be implemented as good product conditions. For example, if sample 1 meets the good product conditions, it means that sample 1 is a good product, which is a product that meets the factory specifications. If sample 2 does not meet the good product conditions, it means that sample 2 is a defective product, which is a product that does not meet the factory rules.
[0076] Optionally, the pre-set sample conditions can be set from aspects such as product appearance, product performance, product component assembly, and product lifespan. This application embodiment does not limit this.
[0077] For example, regarding product appearance, the pre-set sample conditions can be determined by whether the sample has defects, scratches, grooves, marks, etc.; regarding product performance, the pre-set sample conditions can be determined by whether the sample can operate normally, the sample's operating time, operating power, etc.; regarding the assembly of product components, the pre-set sample conditions can be determined by whether the number of components meets the pre-set quantity threshold, whether the connection between components meets the pre-set connection conditions, and whether the type of components meets the pre-set type conditions; regarding product lifespan, the pre-set sample conditions can be determined by whether the product lifespan meets the pre-set usage time threshold.
[0078] In illustrative terms, the first image is an image obtained by acquiring an image of a first object through an image acquisition device. The image acquisition device includes at least one of the following types: film camera, digital camera, industrial camera (e.g., area scan camera, line scan camera, or smart camera), microscopic imaging device (e.g., optical microscope, electron microscope), astronomical imaging device (radio telescope), electromagnetic wave-based image acquisition device (e.g., infrared thermal imager, X-ray imaging device), three-dimensional imaging device, multispectral imaging device, embedded imaging device (e.g., mobile phone camera, drone-borne camera), and light field camera.
[0079] Optionally, the first image corresponding to the first object is a single image, or the first object corresponds to multiple images, so the first image is a collection of multiple images. This application embodiment does not limit this.
[0080] Indicatively, candidate pixels refer to the pixels that constitute the first image.
[0081] Optionally, multiple candidate pixels refer to all pixels in the first image, or multiple candidate pixels refer to pixels corresponding to a portion of the first image, wherein the portion of the image includes the first object.
[0082] Schematic, the first region in the first image refers to the region where the first object is located in the first image, and the second region refers to the region in the first image that does not include the first object.
[0083] Optionally, the rules for dividing the first region and the second region include at least one of the following rules:
[0084] The first method uses the edge of the first object as the boundary. The area inside the outermost edge of the first object is the first region, and the area outside the outermost edge of the first object is the second region. In other words, if there is a hollow part in the first object, and if the hollow part is also in the area inside the outermost edge of the first object in the first image, then the hollow part also belongs to the first region.
[0085] Second, taking the edge of the first object as the boundary, the area within the edge of the first object is the first area, and as long as it is outside the edge of the first object, it is the second area. Therefore, if there is a hollow part in the first object, the hollow part belongs to the second area. For example, the first object is a "hui" - shaped structure. Therefore, the first object includes the first - layer edge (the outermost frame edge) and the second - layer edge (the inner - frame edge). Therefore, the area outside the first - layer edge in the first image is the second area, the area outside the second - layer edge is also the second area, and the area between the first - layer edge and the second - layer edge is the first area.
[0086] It should be noted that the above - mentioned division rules for the first area and the second area are only illustrative examples, and the embodiments of the present application do not limit this.
[0087] Schematically, the first area and the second area are two independent areas in the first image.
[0088] Step 120: Determine multiple edge pixels from multiple candidate pixels based on the gradient intensities respectively corresponding to the multiple candidate pixels.
[0089] Among them, the multiple edge pixels are used to form the contour of the first object in the first image. The gradient intensity is used to indicate the change of the pixel value corresponding to the candidate pixel in the specified gradient direction. The multiple edge pixels are the pixels in the first area.
[0090] Schematically, the contour of the first object refers to the line part formed by the edge of the first object in the first image.
[0091] Schematically, an edge pixel refers to the pixel corresponding to the contour of the first object in the first image.
[0092] Among them, the thickness of the contour edge of the first object determines the number of edge pixels. That is to say, the thicker the contour edge of the first object, the more edge pixels corresponding to it in the first image. On the contrary, the thinner the contour edge of the first object, the fewer edge pixels corresponding to it in the first image.
[0093] Schematically, the gradient intensity of the candidate pixel reflects the change of the pixel value of the candidate pixel in the specified gradient direction. The higher the gradient intensity, the more剧烈 the change of the candidate pixel in the specified gradient direction. On the contrary, the lower the gradient intensity, the more平缓 the change of the candidate pixel in the specified gradient direction.
[0094] Optionally, the specified gradient direction includes the horizontal direction and / or the vertical direction.
[0095] Therefore, if the gradient direction is specified as horizontal, the corresponding gradient strength is horizontal gradient strength; if the gradient direction is specified as vertical, the corresponding gradient strength is vertical gradient strength; if the gradient direction includes both horizontal and vertical gradient directions, the gradient strength of the candidate pixel includes both horizontal and vertical gradient strength.
[0096] Optionally, the edge pixels can be determined using at least one of the following methods:
[0097] The first method involves pre-setting a gradient threshold, matching the gradient intensity of each candidate pixel in the first image based on the gradient threshold, and identifying candidate pixels whose gradient intensity reaches the gradient threshold as edge pixels.
[0098] The second method involves pre-setting a gradient threshold. After matching the gradient intensity of a single candidate pixel in the first image according to the gradient threshold, if the gradient intensity of the candidate pixel reaches the gradient threshold, the candidate pixel is determined to be an edge pixel. Furthermore, based on the candidate pixel, other candidate pixels adjacent to the candidate pixel are also determined to be edge pixels.
[0099] It is worth noting that the above-described method for determining edge pixels is merely an illustrative example, and the embodiments of this application do not limit it.
[0100] This is illustrative; please refer to it. Figure 2 It illustrates a schematic diagram of the object outline provided in an exemplary embodiment of this application, such as... Figure 2 As shown, the first object 210 is currently displayed. The edge pixels corresponding to the first object 210 are selected by the above method, thereby forming the outline 220 corresponding to the first object 210.
[0101] Step 130: Obtain multiple background pixels in the first image.
[0102] Among them, the pixel distance between multiple edge pixels and multiple background pixels meets the first distance condition, and the background pixels are candidate pixels in the first image other than edge pixels.
[0103] For illustration purposes, background pixels refer to candidate pixels in the first image that do not belong to the edge pixels.
[0104] Optionally, the background pixel belongs to the candidate pixel in the second region, or the background pixel belongs to the candidate pixel in the first region. This application embodiment does not limit this.
[0105] Optionally, for a single edge pixel, its corresponding background pixel may be one or more.
[0106] To illustrate, pixel distance refers to the geometric distance between edge pixels and background pixels. Geometric distance includes Euclidean distance, Manhattan distance, etc.
[0107] The method for calculating pixel distance will be explained in detail in subsequent embodiments.
[0108] Optionally, the background pixels can be obtained using at least one of the following methods:
[0109] The first method involves pre-setting a first distance condition, using the edge pixel as a reference, calculating the pixel distance between multiple candidate pixels within a specified area of the edge pixel and the edge pixel, and taking the candidate pixel whose pixel distance meets the first distance condition as the background pixel corresponding to the edge pixel.
[0110] The second method involves pre-setting a first distance condition, using the edge pixels as a reference, and generating a scanning range with the first distance condition as the scanning length. Candidate pixels within the scanning range are then used as background pixels corresponding to the edge pixels.
[0111] The third method involves pre-setting a first distance condition, using edge pixels as a reference, calculating the pixel distance between edge line pixels and candidate pixels in a specified direction, and taking candidate pixels whose pixel distance meets the first distance condition as background pixels corresponding to edge pixels. Furthermore, after obtaining multiple background pixels in a specified direction, other candidate pixels within the area enclosed by several background pixels are also taken as background pixels.
[0112] It is worth noting that the above-described method for obtaining background pixels is merely an illustrative example, and the embodiments of this application do not limit it.
[0113] Optionally, for different edge pixels, their corresponding background pixels may intersect, that is, the same background pixel may satisfy the first distance condition with different edge pixels at the same time, or for different edge pixels, their corresponding background pixels may not intersect. This application does not limit this.
[0114] Step 140: Generate a distance image based on the distance between multiple edge pixels and multiple background pixels.
[0115] The distance image is used to match the second image corresponding to the second object to determine the contour matching result of the second object. The first object and the second object are objects of the same type.
[0116] To illustrate, the methods for determining whether the first object and the second object belong to the same type of object include at least one of the following:
[0117] The first type is product process, that is, the first object and the second object are made by the same product process. For example, sample 1 and sample 2 are both printed circuit boards produced by spraying process (e.g., spraying glue). Therefore, sample 1 and sample 2 belong to the same type of sample.
[0118] The second type is product type, that is, the first object and the second object belong to the same product type. For example, both sample 3 and sample 4 belong to power conversion equipment (e.g., charging plug). Therefore, sample 3 and sample 4 belong to the same type of sample.
[0119] The third type is production specifications, that is, the first object and the second object correspond to the same production specifications. For example, sample 5 is a data cable with a length of 0.8 meters (m), and sample 6 is also a data cable with a length of 0.6 meters. Then sample 5 and sample 6 are products with different production specifications, that is, sample 5 and sample 6 are samples of different types.
[0120] The fourth type is product function, that is, the first object and the second object have the same product function. For example, sample 7 is used to power a specified device and provides a maximum current of 5 amps, and sample 8 is also used to power a specified device and provides a maximum current of 5 amps. Therefore, sample 7 and sample 8 belong to the same type of sample.
[0121] It is worth noting that the above-described method for determining whether the first object and the second object belong to the same type of object is merely an illustrative example, and the embodiments of this application do not limit this.
[0122] Indicatively, a distance image is an image generated based on the pixel distances between edge pixels and background pixels, used to characterize the geometric features of the outline of a first object.
[0123] Optionally, the distance image is a grayscale image, where a grayscale image means that each pixel in the distance image outputs a channel value, i.e., a grayscale value; or, the distance image is an RGB image, where an RGB image means that each pixel in the distance image outputs three channel values, namely a red (Red, R) channel value, a green (Green, G) channel value, and a blue (Blue, B) channel value.
[0124] Taking a grayscale distance image as an example, since the distance image describes the pixel distance between edge pixels and background pixels, even if the outline shape of the first object displayed in the first image is deformed compared to the actual outline shape of the first object, the outline in the distance image is similar to the actual outline shape of the first object because the distance image expresses the grayscale value distribution of the outline of the first object.
[0125] Optionally, the second image may be an RGB image or a grayscale image; this application does not limit the specific embodiment.
[0126] For illustrative purposes, the second image and the distance image correspond to the same image type; for example, both the distance image and the second image are grayscale images.
[0127] In a schematic way, when matching the distance image and the second image, the distance image is overlaid on the area where the second object is located in the second image, so that the outline shape of the first object in the distance image is aligned with the outline shape of the second object in the second image as much as possible. This is to detect whether the outline shape of the second object is consistent with the distance image. If there is a deviation, the second object is considered not to meet the preset object conditions (e.g., good product conditions). If the outline shape of the second object is consistent with the distance image, the second object is considered to meet the preset object conditions.
[0128] The image processing method provided in this application, after acquiring a first image of a first object, filters out edge pixels of the first object in the first image based on the gradient intensity of multiple candidate pixels in the first image, and generates a distance image based on the pixel distance between the edge pixels and the background pixels in the background region of the first image. Finally, the distance image is used as a reference to perform contour matching with images of other objects to be detected, and the contour matching results of other objects to be detected are obtained. In other words, by filtering out the edge pixels of the first object in the first image of the first object and generating a distance image based on the pixel distance between the edge pixels and the background pixels in the background region of the first image, the geometric features of the contour of the first object in the first image are characterized. This avoids the influence of lens distortion, product tilt, etc., on the contour distortion of the first object in the first image during the acquisition of the first image, and improves the accuracy of the contour of the first object in the first image. Therefore, matching the distance image with the image of the object to be detected can improve the accuracy of the contour matching results.
[0129] The image processing methods are explained in detail below. Please refer to the illustrative examples. Figure 3 This illustrates a flowchart of an image processing method provided by an exemplary embodiment of this application. Specifically, step 120 further includes steps 121 and 122, and step 140 further includes steps 141 to 144, as shown below. Figure 3 As shown, the method includes the following steps.
[0130] Step 121: Obtain multiple reference pixels along the specified gradient direction in the first image for the nth candidate pixel.
[0131] In this context, the distance between the reference pixel and the nth candidate pixel in the first image satisfies the second positional condition, and the multiple reference pixels correspond to multiple reference gradients. The multiple candidate pixels include the nth candidate pixel, where n is a positive integer.
[0132] To illustrate, after acquiring the first image, a Gaussian filter is used to smooth the first image and remove noise pixels. The Gaussian filter performs a weighted average of the pixels in the first image through a convolution operation based on the weights of the Gaussian function, thereby reducing high-frequency noise pixels in the image. At the same time, it retains as many pixels as possible that correspond to edge information. Pixels that are not removed after processing by the Gaussian filter are used as candidate pixels.
[0133] In this embodiment, the gradient intensity of the nth candidate pixel point in the specified gradient direction is calculated based on the specified gradient direction. The gradient intensity includes the horizontal gradient intensity and / or the vertical gradient intensity.
[0134] If the gradient intensity includes both horizontal and vertical gradient intensities, the one with the higher intensity is selected as the gradient intensity corresponding to the candidate pixel. Alternatively, the gradient intensity can be obtained based on the numerical relationship between the horizontal and vertical gradient intensities. The formula for calculating the gradient intensity is shown in Formula 1.
[0135] Formula 1:
[0136] in, I Represents candidate pixels (x, y) The corresponding pixel values (including grayscale values or channel values). G(x, y) Represents candidate pixels (x, y) gradient strength, Indicates the horizontal gradient strength. This represents the vertical gradient intensity.
[0137] Indicatively, the reference pixel and the nth candidate pixel in the first image meet the pre-set second position conditions. For example, with the gradient direction as the horizontal direction, the reference pixel is the pixel 1 to the left and the pixel 2 to the right of the nth candidate pixel. Or, with the gradient direction as the vertical direction, the reference pixel is the pixel 3 to the top and the pixel 4 to the bottom of the nth candidate pixel.
[0138] In this embodiment, taking the horizontal (or vertical) direction as an example, the two candidate pixels adjacent to the nth candidate pixel are selected as the reference pixel corresponding to the nth candidate pixel.
[0139] The method for obtaining the reference gradient intensity corresponding to the reference pixel is the same as the method for obtaining the gradient intensity corresponding to the nth candidate pixel, and will not be repeated here.
[0140] Step 122: If the gradient intensity corresponding to the nth candidate pixel and the gradient difference between multiple reference gradients meet the first gradient condition, the nth candidate pixel is determined as an edge pixel.
[0141] Indicatively, by pre-setting a first gradient condition, if the gradient intensity corresponding to the nth candidate pixel and the gradient difference between multiple reference gradients meet the first gradient condition, then the nth candidate pixel is determined to be an edge pixel of the first object in the first image; otherwise, the nth candidate pixel is a non-edge pixel. Here, a non-edge pixel means that the nth candidate pixel does not belong to the edge pixel of the first object in the first image.
[0142] In some embodiments, if the gradient difference between the gradient intensity corresponding to the nth candidate pixel and the multiple reference gradients does not meet the first gradient condition, the gradient intensity corresponding to the nth candidate pixel is set to zero to obtain the zero intensity corresponding to the nth candidate pixel. The zero intensity is used to indicate that the nth candidate pixel is a non-edge pixel.
[0143] In this embodiment, if the nth candidate pixel does not belong to the edge pixel of the first object in the first image, the gradient intensity corresponding to the nth candidate pixel is set to 0, thereby filtering out the nth candidate pixel as an edge pixel. That is, the gradient intensity of the edge pixel is greater than 0.
[0144] For each pixel, its gradient strength is compared with its two neighboring pixels along the gradient direction. If the gradient strength of the pixel is not the maximum among these three pixels (including the pixel itself), its gradient strength is set to 0. This refines the edges so that they are only one pixel wide while preserving the true edge pixels.
[0145] In some embodiments, if the gradient intensity corresponding to the nth candidate pixel and the gradient difference between the multiple reference gradients meet the first gradient condition, the nth candidate pixel is determined as a candidate edge pixel; if the nth candidate pixel reaches the first gradient threshold, the nth candidate pixel is determined as an edge pixel.
[0146] In this embodiment, the first gradient condition is used as the initial screening condition. If the nth candidate pixel is the maximum value of the gradient intensity of its reference pixel and itself, the nth candidate pixel is taken as the candidate edge pixel.
[0147] In this embodiment, a first gradient threshold is preset, and the relationship between the gradient intensity of the nth candidate pixel and the first gradient threshold is further determined. If the gradient intensity of the nth candidate pixel is greater than the first gradient threshold, the nth candidate pixel is determined as an edge pixel, which can also be called a strong edge pixel.
[0148] In some embodiments, if the nth candidate pixel does not reach the second gradient threshold, the nth candidate pixel is determined to be a non-edge pixel, and the second gradient threshold is less than the first gradient threshold.
[0149] In this embodiment, a second gradient threshold is preset, and the relationship between the gradient intensity of the nth candidate pixel and the second gradient threshold is further determined. If the gradient intensity of the nth candidate pixel is less than the second gradient threshold, the nth candidate pixel is determined as a non-edge pixel.
[0150] In some embodiments, the plurality of candidate pixels includes the m-th candidate pixel, which is an edge pixel, where m is a positive integer and m and n are different; if the n-th candidate pixel reaches the second gradient threshold but does not reach the first gradient threshold, the pixel position distance between the m-th candidate pixel and the n-th pixel is obtained; if the pixel position distance meets the third position condition, the n-th candidate pixel is determined to be an edge pixel.
[0151] Indicatively, using the first and second gradient thresholds mentioned above, if the nth candidate pixel reaches the second gradient threshold but does not reach the first gradient threshold, then the nth candidate pixel is considered a weak edge pixel. At this time, if the pixel distance between the mth candidate pixel and the nth candidate pixel meets the preset third position condition, and the mth candidate pixel is a strong edge pixel, then the nth candidate pixel is determined as an edge pixel.
[0152] In this embodiment, two thresholds are set: a high threshold (first gradient threshold) and a low threshold (second gradient threshold). The high threshold is used to identify strong edge pixels, and the low threshold is used to identify weak edge pixels. If the gradient intensity of a pixel is greater than the high threshold, the pixel is considered a strong edge pixel and belongs to the defined edge. If the gradient intensity is less than the low threshold, the pixel is considered not an edge pixel and is suppressed. For weak edge pixels with gradient intensities between the high and low thresholds, it is necessary to determine whether they are connected to strong edge pixels. If they are connected, they are retained as edge pixels; otherwise, they are suppressed as non-edge pixels. This processing method can effectively connect discontinuous parts of edges, making the edges more complete.
[0153] This is illustrative; please refer to it. Figure 4 This illustrates a schematic diagram of object contour selection provided in an exemplary embodiment of this application, such as...Figure 4 As shown, after the candidate edge pixels are selected, the first edge image 410 still contains noise (e.g., edge jaggedness). Therefore, after the final edge pixels are selected by the first threshold intensity and the second threshold intensity, the noise in the second edge image 420 can be reduced, making the outline more complete and clear.
[0154] To illustrate, the coordinate distance between two candidate pixels is calculated by obtaining the pixel coordinates of the candidate pixels in the first image.
[0155] Step 141: Obtain the candidate distance between the i-th edge pixel and at least one background pixel.
[0156] Among the multiple edge pixels, the i-th edge pixel corresponds to at least one background pixel, and i is a positive integer.
[0157] Indicatively, by obtaining the pixel coordinates of candidate pixels (including edge pixels and background pixels) in the first image, the coordinate distance between two candidate pixels is calculated as the pixel distance, that is, the candidate distance between the i-th edge pixel and at least one background pixel.
[0158] In some embodiments, at least one background pixel includes a j-th background pixel, where j is a positive integer; the geometric distance between the i-th edge pixel and the j-th background pixel is obtained; a preset propagation step size is obtained, which is used to indicate the propagation attenuation from the i-th edge pixel to the j-th background pixel; and a candidate distance between the i-th edge pixel and the j-th background pixel is determined based on the geometric distance and the preset propagation step size.
[0159] In this embodiment, taking the j-th background pixel as an example, the geometric distance between the i-th edge pixel and the j-th background pixel is calculated, and a propagation step size is preset (which can be 0 or a very small value). The geometric distance and the preset propagation step size are added together as the candidate distance between the i-th edge pixel and the j-th background pixel.
[0160] In some embodiments, the candidate distance includes a first candidate distance and a second candidate distance; multiple edge pixels are scanned in a first scanning order to obtain a first candidate distance between the i-th edge pixel and at least one background pixel; multiple edge pixels are scanned in a second scanning order to obtain a second candidate distance between the i-th edge pixel and at least one background pixel, wherein the first scanning order and the second scanning order are different; the smaller distance value is selected from the first candidate distance and the second candidate distance as the candidate distance.
[0161] In this embodiment, a first scanning order and a second scanning order are preset. The first scanning order and the second scanning order are different. For example, the first scanning order is to scan all candidate pixels in the first image from the top left to the bottom right, and the second scanning order is to scan all candidate pixels in the first image from the bottom right to the top left.
[0162] In this embodiment, a first candidate distance and a second candidate distance are obtained between the same background pixel and candidate pixel based on two different scanning sequences, and the smaller one is selected as the candidate distance.
[0163] Step 142: Select the minimum distance from at least one candidate distance as the pixel distance corresponding to the background pixel.
[0164] The minimum distance among multiple candidate distances corresponding to background pixels is determined as the pixel distance corresponding to the i-th edge pixel, and this background pixel is also the target background pixel corresponding to the i-th edge pixel.
[0165] Step 143: Determine the pixel distance corresponding to the background pixel as the pixel distance value corresponding to the background pixel.
[0166] The background pixels are assigned values based on the pixel distance; that is, the assigned value of each background pixel represents the pixel distance to the corresponding edge pixel.
[0167] This is illustrative; please refer to it. Figure 5 This illustrates a pixel distance diagram provided in an exemplary embodiment of this application, such as... Figure 5 As shown, the current display shows multiple edge pixels 510 in the first image, where "0" indicates a gradient intensity of 0 and "255" indicates the channel value of the edge pixel. Based on the pixel distance between the multiple edge pixels 510 and the background pixels, the pixel assignment results are obtained. The pixel assignment results include the assignment results 520 of the multiple edge pixels 510 (which is 0 because the distance between the edge pixels themselves and their own pixels is 0), and the assignment results of the background pixels, including 1, 2, etc.
[0168] Step 144: Generate a distance image based on the pixel distance values corresponding to multiple background pixels.
[0169] A grayscale image is generated based on the assigned values of each background pixel, serving as the distance image.
[0170] In this embodiment, a forward scan is first performed: from the top left to the bottom right, the distance of each pixel is updated using a local template (such as a 3×3 neighborhood), and the minimum value of the current pixel value, the neighborhood distance, and the propagation step size is taken. Next, a reverse scan is performed: from the bottom right to the top left, the same operation is repeated to ensure that the distance values propagate from all directions. Finally, a distance map is returned, where the value of each pixel represents the nearest Euclidean distance to the background.
[0171] This is illustrative; please refer to it. Figure 6 It illustrates a distance image schematic diagram provided in an exemplary embodiment of this application, such as Figure 6 As shown, the first distance image 610 corresponding to the first image is generated. The first distance image 610 is a grayscale image. The larger the Euclidean distance, the higher the value of the pixel, because the area corresponding to the pixel is closer to white. Conversely, the smaller the Euclidean distance, the lower the value of the pixel, because the area corresponding to the pixel is closer to black.
[0172] In this embodiment, the image to be matched is compared with a distance image generated from the first image using grayscale matching. By comparing the grayscale similarity of the distance images, the degree of contour matching between the two images is determined, thus achieving contour matching. Since the distance image can reflect the geometric features of the contour to a certain extent, even if the contour has slight deformation, the overall grayscale distribution of the distance image still has a certain similarity, thereby reducing the adverse effect of contour deformation on the matching result and improving the accuracy of matching. (Illustrative example, please refer to...) Figure 7 It illustrates a grayscale matching diagram provided by an exemplary embodiment of this application, such as... Figure 7 As shown, the second distance image 710 and the second image 720 are currently being matched. It is detected that the contour portion 730 does not match (that is, the edges of some regions in the second distance image 710 and the second image 720 cannot be aligned). Therefore, the contour matching result of the second image 720 is used.
[0173] Among them, in order to distinguish Figure 6 and Figure 7 The distance image in the image, therefore Figure 6 The distance image in the image is called the first distance image 610. Figure 7 The distance image in the image is called the second distance image 710.
[0174] The image processing method provided in this application, after acquiring a first image of a first object, filters out edge pixels of the first object in the first image based on the gradient intensity of multiple candidate pixels in the first image, and generates a distance image based on the pixel distance between the edge pixels and the background pixels in the background region of the first image. Finally, the distance image is used as a reference to perform contour matching with images of other objects to be detected, and the contour matching results of other objects to be detected are obtained. In other words, by filtering out the edge pixels of the first object in the first image of the first object and generating a distance image based on the pixel distance between the edge pixels and the background pixels in the background region of the first image, the geometric features of the contour of the first object in the first image are characterized. This avoids the influence of lens distortion, product tilt, etc., on the contour distortion of the first object in the first image during the acquisition of the first image, and improves the accuracy of the contour of the first object in the first image. Therefore, matching the distance image with the image of the object to be detected can improve the accuracy of the contour matching results.
[0175] In this application, contour matching is performed using a contour distance map, which can avoid contour matching failures caused by camera distortion, product misalignment, and contour differences caused by product tolerances.
[0176] This application proposes a contour matching-based method to improve the accuracy and robustness of image matching. The method extracts image contours using an algorithm, filters the contours to remove unsuitable parts, calculates the distance from each point on the contour to generate a distance image, and finally performs grayscale matching based on this distance image to achieve contour matching. This method effectively prevents matching errors caused by slight contour deformations and is widely used in image processing and pattern recognition fields, such as industrial inspection and target recognition, improving the reliability and stability of matching results.
[0177] This is illustrative; please refer to it. Figure 8 The diagram illustrates an image processing apparatus provided in an exemplary embodiment of this application, wherein the image processing apparatus may specifically include the following modules:
[0178] The acquisition module 810 is used to acquire a first image corresponding to the first object, wherein the first image includes multiple candidate pixels.
[0179] The determining module 820 is used to determine a plurality of edge pixels from the plurality of candidate pixels based on the gradient intensities corresponding to the plurality of candidate pixels respectively. The plurality of edge pixels are used to form the outline of the first object in the first image. The gradient intensities are used to indicate the changes in the pixel values corresponding to the candidate pixels in a specified gradient direction. The plurality of edge pixels are pixels in the first region.
[0180] The acquisition module 810 is used to acquire multiple background pixels in the second region, wherein the pixel distance between the multiple edge pixels and the multiple background pixels meets a first distance condition.
[0181] The generation module 830 is used to generate a distance image based on the distance between multiple edge pixels and multiple background pixels. The distance image is used to match with a second image corresponding to a second object to determine the contour matching result of the second object. The first object and the second object are objects of the same type.
[0182] Optionally, the plurality of edge pixels includes the i-th edge pixel, which corresponds to at least one background pixel, where i is a positive integer;
[0183] The generation module 830 is further configured to obtain candidate distances between the i-th edge pixel and the at least one background pixel; select the minimum distance from the at least one candidate distance as the pixel distance corresponding to the i-th edge pixel; determine the pixel distance corresponding to the i-th edge pixel as the pixel distance value corresponding to the i-th edge pixel; and generate the distance image based on the pixel distance values corresponding to the plurality of edge pixels respectively.
[0184] Optionally, the at least one background pixel includes the j-th background pixel, where j is a positive integer;
[0185] The acquisition module 810 is further configured to acquire the geometric distance between the i-th edge pixel and the j-th background pixel; acquire a preset propagation step size, the preset propagation step size being used to indicate the propagation attenuation from the i-th edge pixel to the j-th background pixel; and determine the candidate distance between the i-th edge pixel and the j-th background pixel based on the geometric distance and the preset propagation step size.
[0186] Optionally, the candidate distances include a first candidate distance and a second candidate distance;
[0187] The acquisition module 810 is further configured to scan the plurality of edge pixels in a first scanning order to obtain the first candidate distance between the i-th edge pixel and the at least one background pixel; scan the plurality of edge pixels in a second scanning order to obtain the second candidate distance between the i-th edge pixel and the at least one background pixel, wherein the first scanning order and the second scanning order are different; and select the smaller distance value from the first candidate distance and the second candidate distance as the candidate distance.
[0188] Optionally, the plurality of candidate pixels includes the nth candidate pixel, where n is a positive integer;
[0189] The determining module 820 is further configured to acquire multiple reference pixels in the first image along the specified gradient direction of the nth candidate pixel, wherein the distance between the reference pixels and the pixel position of the nth candidate pixel in the first image meets a second position condition, and the multiple reference pixels correspond to multiple reference gradients respectively; and if the gradient intensity corresponding to the nth candidate pixel and the gradient difference between the multiple reference gradients meet a first gradient condition, the nth candidate pixel is determined to be the edge pixel.
[0190] Optionally, the determining module 820 is further configured to: determine the nth candidate pixel as a candidate edge pixel when the gradient difference between the gradient intensity corresponding to the nth candidate pixel and the plurality of reference gradients meets the first gradient condition; and determine the nth candidate pixel as the edge pixel when the nth candidate pixel reaches the first gradient threshold.
[0191] Optionally, the determining module 820 is further configured to determine that the nth candidate pixel is a non-edge pixel when the nth candidate pixel does not reach the second gradient threshold, wherein the second gradient threshold is less than the first gradient threshold.
[0192] Optionally, the plurality of candidate pixels includes the m-th candidate pixel, which is the edge pixel, where m is a positive integer and m is different from n;
[0193] The determining module 820 is further configured to: obtain the pixel position distance between the m-th candidate pixel and the n-th pixel when the n-th candidate pixel reaches the second gradient threshold but does not reach the first gradient threshold; and determine the n-th candidate pixel as the edge pixel when the pixel position distance meets the third position condition.
[0194] Optionally, the determining module 820 is further configured to, when the gradient difference between the gradient intensity corresponding to the nth candidate pixel and the plurality of reference gradients does not meet the first gradient condition, set the gradient intensity corresponding to the nth candidate pixel to zero, thereby obtaining the zero intensity corresponding to the nth candidate pixel, wherein the zero intensity is used to indicate that the nth candidate pixel is a non-edge pixel.
[0195] The image processing apparatus provided in this application acquires a first image of a first object, filters out edge pixels of the first object in the first image based on the gradient intensity of multiple candidate pixels, and generates a distance image based on the pixel distance between the edge pixels and background pixels in the background region of the first image. Finally, the distance image is used as a reference to perform contour matching with images of other objects to be detected, obtaining contour matching results for the other objects. In other words, by filtering out edge pixels of the first object in the first image and generating a distance image based on the pixel distance between the edge pixels and background pixels in the background region of the first image, the geometric features of the first object's contour in the first image are characterized. This avoids the distortion of the first object's contour in the first image caused by lens distortion, product tilt, etc., during the acquisition of the first image, thus improving the accuracy of the first object's contour in the first image. Therefore, matching the distance image with the image of the object to be detected can improve the accuracy of the contour matching results.
[0196] See Figure 9 This illustration shows a schematic diagram of the structure of a computer device provided in an embodiment of this application. Figure 9 As shown, the computer device 1000 of this embodiment includes: at least one processor 1010 ( Figure 9 (Only one is shown in the image) A processor, a memory 1020, and a computer program 1021 stored in the memory 1020 and executable on at least one processor 1010. When the processor 1010 executes the computer program 1021, it implements the steps in the above-described image processing method embodiments.
[0197] Computer device 1000 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. This terminal device may include, but is not limited to, processor 1010 and memory 1020. Those skilled in the art will understand that... Figure 9 This is merely an example of computer device 1000 and does not constitute a limitation on computer device 1000. It may include more or fewer components than shown in the figure, or combine certain components, or different components, such as input / output devices, network access devices, etc.
[0198] The processor 1010 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0199] In some embodiments, memory 1020 may be an internal storage unit of computer device 1000, such as a hard disk or memory of computer device 1000. In other embodiments, memory 1020 may be an external storage device of computer device 1000, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., provided on computer device 1000. Furthermore, memory 1020 may include both internal and external storage units of computer device 1000. Memory 1020 is used to store operating systems, applications, boot loaders, data, and other programs, such as program code for computer programs. Memory 1020 may also be used to temporarily store data that has been output or will be output.
[0200] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0201] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0202] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0203] In the embodiments provided in this application, it should be understood that the disclosed apparatus / computer devices and methods can be implemented in other ways. For example, the apparatus / computer device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0204] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0205] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0206] If an integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, swivel hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.
[0207] The implementation of all or part of the processes in the methods of the above embodiments can also be accomplished by a computer program product. When the computer program product is run on a computer device, the computer device can implement the steps in the various method embodiments described above.
[0208] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. An image processing method, characterized in that, The method includes: Obtain the first image corresponding to the first object, wherein the first image includes multiple candidate pixels, and the multiple candidate pixels include the nth candidate pixel, where n is a positive integer; Obtain multiple reference pixels in the first image along a specified gradient direction for the nth candidate pixel. The distance between the reference pixels and the pixel position of the nth candidate pixel in the first image meets a second position condition. The multiple reference pixels correspond to multiple reference gradients respectively. If the gradient difference between the gradient intensity corresponding to the nth candidate pixel and the plurality of reference gradients meets the first gradient condition, the nth candidate pixel is determined to be an edge pixel. The edge pixel is used to form the outline of the first object in the first image. The gradient intensity is used to indicate the change of the pixel value corresponding to the candidate pixel in the specified gradient direction. The edge pixel is a pixel in the first region of the first image. Multiple background pixels in the first image are obtained, wherein the pixel distance between the edge pixels and the multiple background pixels meets a first distance condition, the background pixels are candidate pixels in the first image other than the edge pixels, the edge pixels include the i-th edge pixel, the i-th edge pixel corresponds to at least one background pixel, and i is a positive integer; Obtain the candidate distance between the i-th edge pixel and the at least one background pixel; Select the minimum distance from at least one candidate distance as the pixel distance corresponding to the background pixel; The pixel distance corresponding to the background pixel is determined as the pixel distance value corresponding to the background pixel; A distance image is generated based on the pixel distance values corresponding to the plurality of background pixels. The distance image is used to match the second image corresponding to the second object to determine the contour matching result of the second object. The first object and the second object are objects of the same type.
2. The method according to claim 1, characterized in that, The at least one background pixel includes the j-th background pixel, where j is a positive integer; The step of obtaining the candidate distance between the i-th edge pixel and the at least one background pixel includes: Obtain the geometric distance between the i-th edge pixel and the j-th background pixel; Obtain a preset propagation step size, which is used to indicate the propagation attenuation from the i-th edge pixel to the j-th background pixel; The candidate distance between the i-th edge pixel and the j-th background pixel is determined based on the geometric distance and the preset propagation step size.
3. The method according to claim 1, characterized in that, The candidate distance includes a first candidate distance and a second candidate distance; The step of obtaining the candidate distance between the i-th edge pixel and the at least one background pixel includes: The plurality of edge pixels are scanned in a first scanning order to obtain the first candidate distance between the i-th edge pixel and the at least one background pixel; The plurality of edge pixels are scanned in a second scanning order to obtain the second candidate distance between the i-th edge pixel and the at least one background pixel, wherein the first scanning order is different from the second scanning order. The candidate distance is selected from the first candidate distance and the second candidate distance, with the smaller distance value being the candidate distance.
4. The method according to claim 1, characterized in that, The step of determining the nth candidate pixel as the edge pixel when the gradient difference between the gradient intensity corresponding to the nth candidate pixel and the plurality of reference gradients meets the first gradient condition includes: If the gradient difference between the gradient intensity corresponding to the nth candidate pixel and the plurality of reference gradients meets the first gradient condition, the nth candidate pixel is determined as a candidate edge pixel. If the nth candidate pixel reaches the first gradient threshold, the nth candidate pixel is determined to be the edge pixel.
5. An image processing apparatus, characterized in that, The device includes: The acquisition module is used to acquire a first image corresponding to a first object, the first image including multiple candidate pixels, the multiple candidate pixels including an nth candidate pixel, where n is a positive integer; acquire multiple reference pixels of the nth candidate pixel in the first image along a specified gradient direction, the distance between the reference pixels and the nth candidate pixel in the first image meets a second position condition, and the multiple reference pixels correspond to multiple reference gradients respectively; The determining module is configured to determine the nth candidate pixel as an edge pixel when the gradient difference between the gradient intensity corresponding to the nth candidate pixel and the plurality of reference gradients meets the first gradient condition. The edge pixel is used to form the outline of the first object in the first image. The gradient intensity is used to indicate the change of the pixel value corresponding to the candidate pixel in the specified gradient direction. The edge pixel is a pixel in a first region in the first image. The acquisition module is configured to acquire multiple background pixels in the first image, wherein the pixel distance between the edge pixels and the multiple background pixels meets a first distance condition, the background pixels are candidate pixels in the first image excluding the edge pixels, the edge pixels include an i-th edge pixel, the i-th edge pixel corresponds to at least one background pixel, and i is a positive integer; acquire candidate distances between the i-th edge pixel and the at least one background pixel; select the minimum distance from the at least one candidate distance as the pixel distance corresponding to the background pixel; and determine the pixel distance corresponding to the background pixel as the pixel distance value corresponding to the background pixel. The generation module is used to generate a distance image based on the pixel distance values corresponding to the plurality of background pixels respectively. The distance image is used to match with the second image corresponding to the second object to determine the contour matching result of the second object. The first object and the second object are objects of the same type.
6. A computer device, characterized in that, The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image processing method as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the image processing method as described in any one of claims 1 to 4.
8. A computer program product, characterized in that, Includes a computer program, which, when run, causes the image processing method as described in any one of claims 1 to 4 to be performed.
Citation Information
Patent Citations
Contour data feature point detection method and device
CN113658153A