A method and device for extracting the appearance contour of assembly line products

By analyzing gradient and color changes in the CIELab image of medicinal glass bottles, dynamically adjusting the number of pieces and segmentation times of the superpixel segmentation algorithm, the problem of insufficient appearance contour extraction accuracy in traditional methods is solved, and the bottle body deformity is improved Extraction accuracy and overall detection efficiency.

CN118887240BActive Publication Date: 2024-11-26HUNAN ZHONGHONGHUIZHI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411337141.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-25
Publication Date
2024-11-26
Estimated Expiration
2044-09-25

AI Technical Summary

Technical Problem

When traditional superpixel segmentation algorithm extracts the appearance outline of a medicinal glass bottle, a fixed number of superpixel blocks have poor fit to the bottle body contour, resulting in insufficient extraction accuracy, especially inadequate or excessive segmentation in bottle body deformities.

Method used

By analyzing the gradient changes, color changes and spatial distances of pixel points in CIELab images, the superpixel segmentation algorithm is used to dynamically adjust the number of blocks and segmentation times of superpixel blocks, combining the pixel distribution chaos and block excellence, and optimizing the appearance contour Extraction.

Benefits of technology

It improves the extraction accuracy and accuracy of the appearance contour of the medicinal glass bottle, enhances the fit of the contours at the bottle body deformities, avoids excessive segmentation, and achieves more efficient quality inspection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118887240B_ABST
    Figure CN118887240B_ABST
Patent Text Reader

Abstract

The present application relates to the field of image processing technology, and specifically to a method and device for extracting the appearance contour of an assembly line product, the method comprising: obtaining a CIELab image of a medicinal glass bottle on the assembly line; obtaining each superpixel block in the CIELab image; determining the pixel distribution disorder of each superpixel block in the CIELab image, obtaining each superpixel block to be segmented; determining the number of blocks of each superpixel block to be segmented in the CIELab image; determining the number of blocks of the superpixel block after each segmentation and the superpixel block to be segmented; determining the block excellence of each segmentation, obtaining the appearance contour area, and extracting the appearance contour of the medicinal glass bottle. The present application can optimally segment the CIELab image and improve the extraction accuracy of the appearance contour of the deformed medicinal glass bottle.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to a method and device for extracting the appearance contour of an assembly line product. Background Art

[0002] Glass bottles are the most widely used packaging materials in pharmaceutical products. Since pharmaceutical products have extremely strong requirements for unit storage and measurement accuracy, pharmaceutical packaging materials need to have high dimensional accuracy and dimensional consistency. In recent years, the demand for pharmaceutical products in the medical industry has increased year by year, and the production capacity of pharmaceutical glass bottle production lines has gradually increased. In order to improve production efficiency while ensuring the quality of production line products, efficient and accurate quality testing of pharmaceutical glass bottles is essential.

[0003] The appearance contour of a pharmaceutical glass bottle not only determines the product's aesthetics and resistance to mechanical and thermal shocks, but also determines the accuracy of its storage and measurement. Extracting the appearance contour of a pharmaceutical glass bottle is an important part of quality inspection of assembly line products. At present, the industry uses superpixel segmentation algorithms to extract the appearance contour of pharmaceutical glass bottles. Since the appearance contour of a pharmaceutical glass bottle changes inconsistently at the deformed part of the bottle body, the fixed number of superpixel blocks in the traditional superpixel segmentation algorithm have poor fit to the bottle body contour, resulting in insufficient accuracy in extracting the appearance contour of deformed pharmaceutical glass bottles on the assembly line. Summary of the invention

[0004] In order to solve the above technical problems, a method and device for extracting the appearance contour of an assembly line product are provided to solve the existing problems.

[0005] The solution to the technical problem of the present application is to provide a method and device for extracting the appearance contour of a production line product, comprising the following steps:

[0006] In a first aspect, an embodiment of the present application provides a method for extracting the appearance contour of an assembly line product, the method comprising the following steps:

[0007] Get CIELab images of pharmaceutical glass bottles on the production line;

[0008] Analyze the gradient changes, color changes and spatial distance changes of different pixels in the CIELab image, and use the superpixel segmentation algorithm to obtain each superpixel block in the CIELab image;

[0009] Each L channel value of a pixel point in the CIELab image is recorded as an L channel level; according to the distribution discreteness and gradient change of the pixel points in each super pixel block in the CIELab image at different L channel levels, the pixel distribution disorder degree of each super pixel block in the CIELab image is determined, and each super pixel block to be segmented is obtained;

[0010] According to the difference between the horizontal distribution and the vertical distribution of the pixels in each super pixel block to be segmented, combined with the pixel distribution disorder, the number of blocks for each super pixel block to be segmented in the CIELab image is determined;

[0011] Based on the number of blocks, each superpixel block to be segmented is segmented using a superpixel segmentation algorithm, and the number of blocks of the superpixel block and the superpixel block to be segmented after each segmentation is determined; and the block excellence of each segmentation is determined;

[0012] The CIELab image is segmented based on the change of the segmentation excellence, the pixel distribution disorder of the super pixel block after the segmentation is analyzed, the appearance contour area is obtained, and the appearance contour of the medicinal glass bottle is extracted.

[0013] Preferably, obtaining each superpixel block in the CIELab image comprises:

[0014] Based on the L channel values ​​of all pixels in the CIELab image, a corresponding grayscale image is obtained; the lateral gradient and the longitudinal gradient of each pixel in the grayscale image are calculated, and the square root of the sum of the squares of the lateral gradient and the longitudinal gradient is used as the grayscale gradient of the corresponding pixel in the CIELab image;

[0015] The CIELab image is evenly divided into multiple rectangular grids, and the central pixel point of each rectangular grid is used as the initial seed point;

[0016] The difference in grayscale gradient between each initial seed point and each pixel in the CIELab image is recorded as the grayscale gradient distance;

[0017] Analyze the color distance, spatial distance and gray gradient distance between each initial seed point and each pixel in the CIELab image, and calculate the metric distance between each initial seed point and each pixel in the superpixel segmentation algorithm;

[0018] According to the initial seed point and the metric distance, a superpixel segmentation algorithm is used to segment the CIELab image to obtain a plurality of superpixel blocks.

[0019] Preferably, the metric distance between each initial seed point and each pixel point in the superpixel segmentation algorithm is calculated as follows: ,in, For the CIELab image The initial seed point and the The metric distance of pixels, For the CIELab image pixels, For the CIELab image Initial seed points, , and Calculate the color distance, spatial distance and grayscale gradient distance respectively; , S and G represent the maximum values ​​of the color distance, spatial distance and grayscale gradient distance between all calculated pixels and the initial seed point, respectively.

[0020] Preferably, determining the pixel distribution disorder of each super pixel block in the CIELab image and obtaining each super pixel block to be segmented includes:

[0021] Counting the frequency of occurrence of pixel points of each L channel level in each super pixel block; multiplying the product of a calculation result of a logarithmic function with base 2 and the frequency as the logarithm by the frequency of the corresponding L channel level as the first product;

[0022] Calculate the product of the mean value of the grayscale gradient of all pixels in each L channel level in each superpixel block and the first product, record it as a second product, and record the ratio of the second product to the corresponding L channel level as a first ratio;

[0023] The inverse of the sum of the first ratios of all L channel levels in each superpixel block is used as the pixel distribution disorder of each superpixel block;

[0024] The threshold segmentation algorithm is used to obtain the segmentation threshold of the pixel distribution disorder of all superpixel blocks in the CIELab image;

[0025] The super pixel block whose pixel distribution disorder degree is greater than the segmentation threshold is recorded as the super pixel block to be segmented.

[0026] Preferably, determining the number of blocks of each superpixel block to be segmented in the CIELab image comprises:

[0027] The frequency of the same horizontal coordinates of the pixels in each superpixel block to be segmented is counted, and a vertical histogram is constructed. The range of the frequency in the vertical histogram is used as the vertical range of each superpixel block to be segmented; for the vertical coordinates of the pixels in each superpixel block to be segmented, the horizontal range of each superpixel block to be segmented is obtained by the same method as the vertical range;

[0028] The calculation result of the square root of the sum of the squares of the horizontal extreme difference and the vertical extreme difference is used as the distribution difference of each super pixel block to be segmented;

[0029] Counting the number of all pixels in each superpixel block to be segmented; taking the normalized result of the product of the number, the pixel distribution disorder and the distribution difference as the block ratio of each superpixel block to be segmented;

[0030] The product of the preset maximum number of blocks and the block ratio is rounded up to an integer, which is used as the number of blocks of each super pixel block to be segmented.

[0031] Preferably, the determining of the number of blocks of the superpixel block after each segmentation and the superpixel block to be segmented comprises:

[0032] For each superpixel block to be segmented, seed points with the same number as the number of blocks are randomly selected in each superpixel block to be segmented, and the superpixel block to be segmented is iteratively segmented using a superpixel segmentation algorithm to obtain the superpixel blocks after each segmentation and the number of blocks of the superpixel block to be segmented.

[0033] Preferably, the calculation formula for determining the excellence of each segmentation is: ,in, For the The block excellence of the subdivision, For the The sum of the number of blocks of all superpixel blocks to be segmented after the first segmentation, For CIELab images After the second division The pixel distribution disorder of a super pixel block, For CIELab images The number of all superpixel blocks after segmentation, Represents an exponential function with a natural constant as base.

[0034] Preferably, the obtaining of the appearance contour area includes:

[0035] When the block excellence of each segmentation is less than the block excellence of the previous segmentation, the segmentation is stopped, and all super pixel blocks of the CIELab image after the segmentation is stopped are obtained;

[0036] A threshold segmentation algorithm is used to obtain the segmentation threshold of the pixel distribution disorder of all super-pixel blocks of the CIELab image after stopping segmentation;

[0037] The area composed of pixels in the superpixel block whose pixel distribution disorder is greater than the segmentation threshold is recorded as the appearance contour area.

[0038] Preferably, the extraction of the appearance contour of the medicinal glass bottle includes:

[0039] Perform image erosion operation on the appearance contour area to obtain the boundary pixel points of the appearance contour area, and connect the adjacent boundary pixel points in sequence to obtain each connected domain;

[0040] The closed boundary line of the connected domain with the largest area is used as the appearance outline of the medicinal glass bottle.

[0041] In the second aspect, an embodiment of the present application also provides an appearance contour extraction device for an assembly line product, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, the steps of the appearance contour extraction method for an assembly line product described in any one of the above items are implemented.

[0042] This application has at least the following beneficial effects:

[0043] The present application analyzes the gradient changes, color changes and spatial distance changes of different pixel points in the CIELab image, adopts the superpixel segmentation algorithm, obtains each superpixel block in the CIELab image, and has the beneficial effect that the gradient changes of the pixel points are taken into account when segmenting the CIELab image, so as to enhance the segmentation effect of the superpixel segmentation algorithm on the CIELab image; according to the distribution discreteness and gradient changes of the pixel points in each superpixel block in the CIELab image at different L channel levels, the pixel distribution disorder of each superpixel block in the CIELab image is determined, and each superpixel block to be segmented is obtained, and has the beneficial effect that the disorder of the pixel point distribution of different superpixel blocks is taken into account, so as to adopt different segmentation times for different superpixel blocks, improve the segmentation accuracy of the CIELab image at the appearance contour, and enhance the appearance contour extraction. Accuracy; according to the differences in the lateral and longitudinal distributions of the pixels in each superpixel block to be segmented, combined with the chaos of the pixel distribution, the number of blocks for each superpixel block to be segmented in the CIELab image is determined, which has the beneficial effect of taking into account the appearance contours of different deformed positions and adopting different numbers of blocks, thereby enhancing the fit of the superpixel block to the bottle contour and enhancing the accuracy of contour extraction at the deformed part of the bottle; determining the number of blocks of the superpixel block and the superpixel block to be segmented after each segmentation; determining the excellence of the blocks for each segmentation, obtaining the appearance contour area, and extracting the appearance contour of the medicinal glass bottle, which has the beneficial effect of analyzing the excellence of each segmentation, thereby stopping the segmentation of the CIELab image in time, avoiding over-segmentation, and being able to optimally segment the CIELab image of the medicinal glass bottle, thereby improving the accuracy of extracting the appearance contour of the deformed medicinal glass bottle. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The following is a further detailed description of a method for extracting the appearance contour of an assembly line product of the present application in conjunction with the accompanying drawings.

[0045] Figure 1 A flowchart of the steps of a method for extracting the appearance contour of an assembly line product provided in an embodiment of the present application;

[0046] Figure 2 A flowchart of the steps of a method for obtaining superpixel blocks to be segmented in a CIELab image provided in an embodiment of the present application;

[0047] Figure 3 A flowchart of the steps of a method for obtaining the number of blocks of each superpixel block to be segmented in a CIELab image provided in an embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solution and advantages of this application more clear, the following is a further detailed description of a method and device for extracting the appearance contour of a production line product proposed in this application in conjunction with the accompanying drawings and implementation examples. It should be understood that the specific embodiments described herein are only used to explain this application and are not used to limit this application.

[0049] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs.

[0050] See also Figure 1 , which shows a flowchart of a method for extracting the appearance contour of a production line product provided by an embodiment of the present application, the method comprising the following steps:

[0051] Step 1: Obtain CIELab images of pharmaceutical glass bottles on the production line.

[0052] The front of the pharmaceutical glass bottle is photographed by an industrial CCD camera, and the obtained RGB space image is preprocessed to eliminate the influence of noise and some external interference to enhance the accuracy of subsequent analysis. The denoised image is transformed from the RGB space to the CIELab space to obtain the CIELab image of the pharmaceutical glass bottle.

[0053] Preferably, in this embodiment, in order to remove noise while retaining boundary information, a Gaussian filtering algorithm is used to perform denoising processing on the RGB spatial image, wherein the Gaussian filtering algorithm is a well-known technology and will not be described in detail here.

[0054] At this point, the CIELab image of the pharmaceutical glass bottle is obtained.

[0055] Step 2: Analyze the gradient changes, color changes, and spatial distance changes of different pixel points in the CIELab image, and use the superpixel segmentation algorithm to obtain each superpixel block in the CIELab image.

[0056] When taking a photo of the front of a pharmaceutical glass bottle, the light transmittance of the glass bottle decays from the middle to the sides, resulting in a transition shadow at the outline of the glass bottle in the front-view image. The wall thickness of the pharmaceutical glass bottle changes rapidly at its outline, making its transition shadow band narrower, while the light transmittance of the middle area of ​​the glass bottle is stronger and the image features do not change much. In the traditional superpixel segmentation algorithm, the number of superpixel blocks remains unchanged, and the same segmentation degree is used for each area of ​​the pharmaceutical glass bottle, resulting in too much unnecessary segmentation of the central area of ​​the glass bottle, and insufficient segmentation of its appearance contour, resulting in errors in the subsequent extraction of the appearance contour. Based on the above analysis, the image needs to be re-segmented to extract the appearance contour.

[0057] First, compared with the middle area of ​​the pharmaceutical glass bottle, the gradient of the L channel value of the pixel point at the appearance contour is larger. Therefore, the gradient of each pixel point in the CIELab image of the pharmaceutical glass bottle is analyzed to determine the grayscale gradient to reflect the degree to which the pixel point in the CIELab image is close to the appearance contour of the pharmaceutical glass bottle, specifically:

[0058] Convert the L channel values ​​of all pixels in the CIELab image into grayscale values, and obtain the corresponding grayscale image based on the grayscale values ​​of all pixels;

[0059] Calculate the transverse gradient and the longitudinal gradient of each pixel in the grayscale image, and use the square root of the sum of the squares of the transverse gradient and the longitudinal gradient as the grayscale gradient of the corresponding pixel in the CIELab image;

[0060] Preferably, the Sobel operator is used to calculate the transverse gradient and the longitudinal gradient, wherein the Sobel operator is a well-known technique and will not be described in detail herein.

[0061] It should be noted that the brightness of the central area of ​​the medicinal glass bottle does not change much, and the smaller the change in the L channel value in the CIELab image, the smaller the grayscale gradient of the corresponding pixel point; the closer the pixel point in the CIELab image is to the appearance contour of the medicinal glass bottle, the greater the change in its L channel value, the greater the grayscale gradient, and the grayscale gradient of the pixel point reaches its maximum at the appearance contour.

[0062] Furthermore, the color distance and spatial distance in the superpixel segmentation algorithm are analyzed, and the gray gradient distance is combined to enhance the segmentation effect of the superpixel segmentation algorithm on the appearance contour of the medicinal glass bottle to reflect the distance between the pixels and further reflect the similarity between the pixels. Specifically:

[0063] The CIELab image is evenly divided into multiple rectangular grids, and the central pixel point of each rectangular grid is used as the initial seed point;

[0064] The difference in grayscale gradient between each initial seed point and each pixel in the CIELab image is recorded as the grayscale gradient distance;

[0065] Preferably, in this embodiment, the CIELab image is evenly divided into 100 rectangular grids, which can be set by the implementer according to actual conditions; the absolute value of the difference in grayscale gradient between each initial seed point and each pixel point in the CIELab image is recorded as the grayscale gradient distance.

[0066] The traditional superpixel segmentation algorithm calculates the metric distance between the pixel and the seed point through the color distance and the spatial distance. In order to enhance the segmentation effect of the superpixel segmentation algorithm on the appearance contour of the medicinal glass bottle, the metric distance between each initial seed point and each pixel in the superpixel segmentation algorithm is calculated based on the extreme difference of the traditional superpixel segmentation algorithm and the gray gradient of the pixel. The calculation formula is: ,in, For the CIELab image The initial seed point and The metric distance of pixels, For the CIELab image pixels, For the CIELab image Initial seed points, and To calculate the color distance and spatial distance respectively, Indicates the calculation of gray gradient distance; , S and G represent the maximum values ​​of the color distance, spatial distance and the calculated value between all pixel points and the initial seed point respectively, and G represents the maximum value of the grayscale gradient distance; wherein, the calculation of the color distance and the spatial distance is the step of the superpixel segmentation algorithm, and the superpixel segmentation algorithm and the calculation of the color distance and the spatial distance are well-known technologies and will not be repeated here.

[0067] According to the selected initial seed points and the metric distance between each initial seed and each pixel point in the superpixel segmentation algorithm, the CIELab image is segmented using the superpixel segmentation algorithm to obtain multiple superpixel blocks;

[0068] At this point, each superpixel block in the CIELab image is obtained.

[0069] Step 3, record each L channel value of the pixel point in the CIELab image as the L channel level; determine the pixel distribution disorder of each superpixel block in the CIELab image according to the distribution discreteness and gradient change of the pixel points in each superpixel block in the CIELab image at different L channel levels, and obtain each superpixel block to be segmented.

[0070] Furthermore, the transition shadow area formed by the appearance contour of the glass bottle is relatively narrow, and the segmented superpixel blocks need to be segmented again to obtain a more accurate appearance contour. Since the superpixel blocks in the center area of ​​the bottle body are irrelevant to the appearance contour extraction of the medicinal glass bottle, using the same number of blocks for different superpixel blocks will result in insufficient segmentation accuracy at the appearance contour, resulting in a decrease in the accuracy of subsequent appearance contour extraction.

[0071] Therefore, it is necessary to analyze the distribution of pixels in each superpixel block and construct the pixel distribution disorder to reflect the distribution disorder of pixels in the superpixel block, so as to reflect the degree of further segmentation. Specifically:

[0072] Each L channel value in the CIELab image is recorded as the L channel level;

[0073] Counting the frequency of occurrence of pixel points of each L channel level in each super pixel block; multiplying the product of a calculation result of a logarithmic function with base 2 and the frequency as the logarithm by the frequency of the corresponding L channel level as the first product;

[0074] Calculate the product of the mean value of the grayscale gradient of all pixels in each L channel level of each superpixel block and the first product, record it as a second product, and record the ratio of the second product to the corresponding L channel level as a first ratio;

[0075] The inverse of the sum of the first ratios of all L channel levels in each superpixel block is used as the pixel distribution disorder of each superpixel block;

[0076] It should be noted that the L channel value in the CIELab image ranges from 0 to 100, that is, there are 101 L channel levels.

[0077] In this embodiment, the calculation method of the pixel distribution disorder of each super pixel block is: ,in, For the The pixel distribution disorder of a super pixel block, For the The pixel point with the L channel value level is in the The frequency of occurrence in superpixel blocks, For the In the superpixel block The mean value of the grayscale gradient of all pixels at the L channel value level; For the The first superpixel block L channel value level, For the The number of all L channel value levels of superpixel blocks, is a preset value greater than 0. The value is 1. is the logarithmic function with base 2.

[0078] It should be noted that, affected by the change in bottle thickness, the L channel value of the pixel point at the appearance contour of the medicinal glass bottle is small, while the grayscale gradient is large. Therefore, the closer the superpixel block is to the appearance contour of the medicine bottle, the smaller the brightness of the superpixel block, the greater the change in brightness, and the greater the chaos of its pixel distribution. When the superpixel block is located in the center area of ​​the bottle, its pixel distribution chaos is small. In addition, the closer the superpixel block is to the contour, the more discrete the distribution of the pixel points in the L channel value, the greater the difference in the frequency of pixels of different L channel levels in each superpixel block, and the greater the resulting pixel distribution chaos.

[0079] Furthermore, since the super pixel blocks close to the appearance contour of the glass bottle need to be segmented to a higher degree, and the super pixel blocks located in the center area of ​​the bottle body do not need to be segmented further, the super pixel blocks that need to be segmented are determined as the super pixel blocks to be segmented, specifically:

[0080] The threshold segmentation algorithm is used to obtain the segmentation threshold of the pixel distribution disorder of all superpixel blocks in the CIELab image;

[0081] The super pixel block whose pixel distribution disorder degree is greater than the segmentation threshold is recorded as the super pixel block to be segmented;

[0082] Preferably, in this embodiment, the segmentation threshold is obtained by using the Otsu threshold segmentation algorithm, wherein the Otsu threshold segmentation algorithm will not be described in detail here.

[0083] It should be noted that, for superpixel blocks with a pixel distribution disorder less than or equal to the segmentation threshold, the corresponding superpixel block is close to the central area of ​​the bottle body and does not need to be further segmented; while for superpixel blocks with a pixel distribution disorder greater than the segmentation threshold, the corresponding superpixel block is close to the appearance contour of the glass bottle, and a superpixel segmentation algorithm is required to further segment it. By distinguishing the superpixel blocks and using different segmentation times, the segmentation accuracy of the CIELab image of the medicinal glass bottle at the appearance contour is improved, and the accuracy of appearance contour extraction is enhanced.

[0084] Further, the flowchart of the steps of the method for obtaining the super pixel block to be segmented in the CIELab image provided by the embodiment of the present application is as follows: Figure 2 shown.

[0085] At this point, the pixel distribution disorder of each superpixel block in the CIELab image is obtained, and the superpixel block to be segmented is obtained.

[0086] Step 4, according to the difference in the horizontal distribution and the vertical distribution of the pixels in each super pixel block to be segmented, combined with the pixel distribution disorder, determine the number of blocks for each super pixel block to be segmented in the CIELab image.

[0087] When the bottle body is deformed, the light transmittance of the appearance contour of the glass bottle is no longer uniform, the transition shadow becomes narrower at the concave part, and becomes wider at the convex part. If the same number of blocks is used for the appearance contours with different bottle body defects, part of the contour in the narrower area will be interrupted, resulting in the loss of the appearance contour, which reduces the accuracy of the appearance contour extraction. Therefore, it is necessary to use different numbers of blocks for the appearance contours of different deformed positions.

[0088] First, according to the position distribution of the pixels in the superpixel block to be segmented, the longitudinal range and the lateral range of the superpixel block to be segmented are calculated, specifically:

[0089] Count the frequencies of pixels with the same horizontal coordinates in each superpixel block to be segmented, construct a vertical histogram, and use the range of the frequency in the vertical histogram as the vertical range of each superpixel block to be segmented;

[0090] For the ordinate of the pixel point in each super pixel block to be segmented, the lateral range of each super pixel block to be segmented is obtained by using the same method as the longitudinal range;

[0091] It should be noted that the horizontal coordinates of the pixels in each superpixel block to be segmented are: ,and The frequencies of the same pixels are ,according to and Construct a vertical histogram, and the horizontal range is The difference between the maximum and minimum values ​​in .

[0092] It should be noted that the concave parts of the deformed area on the body of the medicinal glass bottle are thinner and the convex parts are thicker, and the body of the bottle is distributed vertically in the CIELab image of the medicinal glass bottle, resulting in uneven distribution of pixels of the corresponding super-pixel blocks to be segmented in the vertical direction. Therefore, the vertical range reflects the degree of deformity of the body of the medicinal glass bottle; secondly, the shoulder of the medicinal glass bottle is distributed horizontally in the CIELab image, and the pixel points of the super-pixel blocks to be segmented where the shoulder appears deformed are unevenly distributed in the horizontal direction. Therefore, the horizontal range reflects the degree of deformity of the shoulder of the medicinal glass bottle.

[0093] Further, based on the horizontal range and the vertical range, the block ratio of the super pixel block to be segmented is determined to reflect the degree to which the super pixel block to be segmented needs to be further segmented, specifically:

[0094] The calculation result of the square root of the sum of the squares of the horizontal extreme difference and the vertical extreme difference is used as the distribution difference of each super pixel block to be segmented;

[0095] Counting the number of all pixels in each superpixel block to be segmented; taking the normalized result of the product of the number, the pixel distribution disorder and the distribution difference as the block ratio of each superpixel block to be segmented;

[0096] In this embodiment, the calculation method of the block ratio of each super pixel block to be segmented is: ,in, For the The block ratio of the superpixel blocks to be segmented, For the The pixel distribution disorder of the super pixel block to be segmented, For the The number of all pixels in the superpixel block to be segmented, For the The horizontal range of the superpixel blocks to be segmented, For the The vertical range of the superpixel blocks to be segmented, is the normalization function.

[0097] It should be noted that, the closer the superpixel block to be segmented is to the appearance contour of the glass bottle, the greater the chaos of its pixel distribution, the greater the degree of segmentation required to obtain a more accurate contour, and the larger the proportion of the divided blocks obtained; on the other hand, the more pixels there are in the superpixel block to be segmented and the higher the degree of deformity of the shape, the greater the degree of segmentation required, the greater the lateral and longitudinal extremes, and the larger the proportion of the divided blocks obtained, so as to enhance the accuracy of contour extraction of the deformed part of the bottle body.

[0098] Further, based on the block ratio, the number of blocks of each super pixel block to be segmented is determined, specifically:

[0099] Rounding up the product of the preset maximum number of blocks and the block ratio as the number of blocks of each superpixel block to be segmented;

[0100] Preferably, in this embodiment, the method for calculating the number of blocks of each super pixel block to be divided is: ,in, For the The number of blocks of the superpixel block to be segmented, To preset the maximum number of blocks, in this embodiment, The value is 5. For the The block ratio of the superpixel blocks to be segmented, is the ceiling function.

[0101] It should be noted that the larger the block ratio of the super pixel block to be segmented, the more corresponding blocks are segmented, that is, the larger the number of blocks is.

[0102] Further, the flowchart of the method for obtaining the number of blocks of each super pixel block to be segmented in the CIELab image provided by the embodiment of the present application is as follows: Figure 3 shown.

[0103] At this point, the number of blocks of each superpixel block to be segmented in the CIELab image is obtained.

[0104] Step 5, based on the number of blocks, use a superpixel segmentation algorithm to segment each superpixel block to be segmented, determine the number of blocks of the superpixel blocks after each segmentation and the superpixel blocks to be segmented; determine the block excellence of each segmentation; stop segmenting the CIELab image based on the change of the block excellence, analyze the pixel distribution chaos of the superpixel block after stopping the segmentation, obtain the appearance contour area, and extract the appearance contour of the medicinal glass bottle.

[0105] Furthermore, each superpixel block to be segmented in the CIELab image is analyzed, specifically:

[0106] For each superpixel block to be segmented, randomly select seed points with the same number as the number of blocks in each superpixel block to be segmented, and use a superpixel segmentation algorithm to segment the superpixel block to obtain each superpixel block after the second segmentation;

[0107] It should be noted that the number of super pixel blocks after the second segmentation is the same as the number of blocks of the corresponding super pixel block to be segmented.

[0108] For each superpixel block after the second segmentation, the same method as the number of blocks for each superpixel block to be segmented is used to obtain the number of blocks of the superpixel block to be segmented after the second segmentation, and so on, the superpixel blocks are segmented iteratively continuously to obtain the number of blocks of the superpixel block after each segmentation and the superpixel block to be segmented;

[0109] Furthermore, due to the similarity of grayscale gradient and L channel value during the segmentation process, the pixels are continuously divided into the same superpixel block, and the pixel distribution disorder of each superpixel block is continuously reduced. In order to prevent the over-segmentation of the CIELab image of the medicinal glass bottle, the block segmentation excellence of the CIELab image is calculated to reflect the excellence of the pixel segmentation, specifically:

[0110] The block excellence of each segmentation is: ,in, For the The block excellence of the subdivision, For the The sum of the number of blocks of all superpixel blocks to be segmented after the first segmentation, For CIELab images After the second division The pixel distribution disorder of a super pixel block, For CIELab images The number of all superpixel blocks after segmentation, represents an exponential function with a natural constant as base, where is a preset value greater than 0. The value is 0.01.

[0111] It should be noted that when the number of blocks of the superpixel block to be segmented after each segmentation is large, the corresponding superpixel block to be segmented needs to be further segmented to a greater extent. At this time, the excellence of the superpixel block in dividing the pixels in the CIELab image is poor, and the segmentation excellence of the resulting CIELab image is smaller; secondly, the greater the chaos of the pixel distribution of the superpixel block, the greater the difference of the pixels within the superpixel block, the rougher the extraction of the appearance contour of the glass bottle, and the worse the excellence of the pixel division.

[0112] When the block excellence of each segmentation is less than the block excellence of the previous segmentation, the segmentation of the CIELab image is stopped to obtain each super pixel block of the CIELab image after the segmentation is stopped;

[0113] A threshold segmentation algorithm is used to obtain the segmentation threshold of the pixel distribution disorder of all super-pixel blocks of the CIELab image after stopping segmentation;

[0114] The area composed of pixels in the superpixel block whose pixel distribution disorder is greater than the segmentation threshold is recorded as the appearance contour area;

[0115] Preferably, in this embodiment, the Otsu threshold segmentation algorithm is used to obtain the segmentation threshold of the pixel distribution disorder degree of all superpixel blocks of the CIELab image, wherein the Otsu threshold segmentation algorithm is a well-known technology and will not be described in detail here.

[0116] It should be noted that since the L channel value of the pixel point at the contour in the CIELab image is smaller and the grayscale gradient is larger, the corresponding pixel distribution chaos is greater. Therefore, there are pixels containing the appearance contour in the superpixel block whose pixel distribution chaos is greater than the segmentation threshold. The appearance contour area is the transition shadow band of the medicinal glass bottle at the appearance contour.

[0117] Furthermore, since the outer boundary of the transition shadow band is the appearance contour of the medicinal glass bottle, that is, the outer boundary of the appearance contour area is the appearance contour of the medicinal glass bottle, it is necessary to perform contour extraction on the appearance contour area to obtain the appearance contour of the medicinal glass bottle, specifically:

[0118] Perform image erosion operation on the appearance contour area to obtain the boundary pixel points of the appearance contour area, and connect the adjacent boundary pixel points in sequence to obtain each connected domain;

[0119] The closed boundary line of the connected domain with the largest area is used as the appearance contour of the medicinal glass bottle, and the appearance contour of the medicinal glass bottle on the assembly line is extracted.

[0120] It should be noted that the appearance contour of the medicinal glass bottle is located at the outermost side of the entire appearance contour area, and the area of ​​the connected domain it encloses is the largest. The image corrosion operation and the calculation of the area of ​​the connected domain are well-known technologies and will not be repeated here.

[0121] Based on the same inventive concept as the above method, an embodiment of the present application also provides an appearance contour extraction device for an assembly line product, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor implements the steps of any one of the above-mentioned methods for extracting the appearance contour of an assembly line product when executing the computer program.

[0122] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.

[0123] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0124] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the present application. It should be pointed out that, for those of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application. Therefore, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present application without departing from the content of the technical solution of the present application, shall fall within the protection scope of the technical solution of the present application.

Claims

1. A method for extracting the appearance contour of a production line product, characterized in that: The method comprises the following steps: Get CIELab images of pharmaceutical glass bottles on the production line; Analyze the gradient changes, color changes and spatial distance changes of different pixels in the CIELab image, and use the superpixel segmentation algorithm to obtain each superpixel block in the CIELab image; Each L channel value of a pixel point in the CIELab image is recorded as an L channel level; according to the distribution discreteness and gradient change of the pixel points in each super pixel block in the CIELab image at different L channel levels, the pixel distribution disorder degree of each super pixel block in the CIELab image is determined, and each super pixel block to be segmented is obtained; According to the difference between the horizontal distribution and the vertical distribution of the pixels in each super pixel block to be segmented, combined with the pixel distribution disorder, the number of blocks for each super pixel block to be segmented in the CIELab image is determined; Based on the number of blocks, each superpixel block to be segmented is segmented using a superpixel segmentation algorithm, and the number of blocks of the superpixel block and the superpixel block to be segmented after each segmentation is determined; and the block excellence of each segmentation is determined; The CIELab image is segmented based on the change of the segmentation excellence, the pixel distribution disorder of the super pixel block after the segmentation is stopped is analyzed, the appearance contour area is obtained, and the appearance contour of the medicinal glass bottle is extracted; The step of determining the pixel distribution disorder of each super pixel block in the CIELab image and obtaining each super pixel block to be segmented includes: Counting the frequency of occurrence of pixel points of each L channel level in each super pixel block; multiplying the product of a calculation result of a logarithmic function with base 2 and the frequency as the logarithm by the frequency of the corresponding L channel level as the first product; Calculate the product of the mean value of the grayscale gradient of all pixels in each L channel level in each superpixel block and the first product, record it as a second product, and record the ratio of the second product to the corresponding L channel level as a first ratio; The inverse of the sum of the first ratios of all L channel levels in each superpixel block is used as the pixel distribution disorder of each superpixel block; The threshold segmentation algorithm is used to obtain the segmentation threshold of the pixel distribution disorder of all superpixel blocks in the CIELab image; The super pixel block whose pixel distribution disorder degree is greater than the segmentation threshold is recorded as the super pixel block to be segmented; The step of determining the number of blocks of each superpixel block to be segmented in the CIELab image comprises: The frequency of the same horizontal coordinates of the pixels in each superpixel block to be segmented is counted, and a vertical histogram is constructed. The range of the frequency in the vertical histogram is used as the vertical range of each superpixel block to be segmented; for the vertical coordinates of the pixels in each superpixel block to be segmented, the horizontal range of each superpixel block to be segmented is obtained by the same method as the vertical range; The calculation result of the square root of the sum of the squares of the horizontal extreme difference and the vertical extreme difference is used as the distribution difference of each super pixel block to be segmented; Counting the number of all pixels in each superpixel block to be segmented; taking the normalized result of the product of the number, the pixel distribution disorder and the distribution difference as the block ratio of each superpixel block to be segmented; Rounding up the product of the preset maximum number of blocks and the block ratio as the number of blocks of each superpixel block to be segmented; The calculation formula for determining the excellence of each segmentation is: ,in, For the The block excellence of the subdivision, For the The sum of the number of blocks of all superpixel blocks to be segmented after the first segmentation, For CIELab images After the second division The pixel distribution disorder of a super pixel block, For CIELab images The number of all superpixel blocks after segmentation, Represents an exponential function with a natural constant as base.

2. The method for extracting the appearance contour of an assembly line product according to claim 1, characterized in that: The step of obtaining each super pixel block in the CIELab image comprises: Based on the L channel values ​​of all pixels in the CIELab image, a corresponding grayscale image is obtained; the lateral gradient and the longitudinal gradient of each pixel in the grayscale image are calculated, and the square root of the sum of the squares of the lateral gradient and the longitudinal gradient is used as the grayscale gradient of the corresponding pixel in the CIELab image; The CIELab image is evenly divided into multiple rectangular grids, and the central pixel point of each rectangular grid is used as the initial seed point; The difference in grayscale gradient between each initial seed point and each pixel in the CIELab image is recorded as the grayscale gradient distance; Analyze the color distance, spatial distance and gray gradient distance between each initial seed point and each pixel in the CIELab image, and calculate the metric distance between each initial seed point and each pixel in the superpixel segmentation algorithm; According to the initial seed point and the metric distance, a superpixel segmentation algorithm is used to segment the CIELab image to obtain a plurality of superpixel blocks.

3. The method for extracting the appearance contour of an assembly line product according to claim 2, characterized in that: The metric distance between each initial seed point and each pixel in the superpixel segmentation algorithm is calculated as follows: ,in, For the CIELab image The initial seed point and the The metric distance of pixels, For the CIELab image pixels, For the CIELab image Initial seed points, , and Calculate the color distance, spatial distance and grayscale gradient distance respectively; , S and G represent the maximum values ​​of the color distance, spatial distance and gray gradient distance between all calculated pixels and the initial seed point, respectively.

4. The method for extracting the appearance contour of an assembly line product according to claim 1, characterized in that: The determining of the number of blocks of the super pixel block after each segmentation and the super pixel block to be segmented comprises: For each superpixel block to be segmented, seed points with the same number as the number of blocks are randomly selected in each superpixel block to be segmented, and the superpixel block to be segmented is iteratively segmented using a superpixel segmentation algorithm to obtain the superpixel blocks after each segmentation and the number of blocks of the superpixel block to be segmented.

5. The method for extracting the appearance contour of an assembly line product according to claim 1, characterized in that: The obtaining of the appearance contour area includes: When the block excellence of each segmentation is less than the block excellence of the previous segmentation, the segmentation is stopped, and all super pixel blocks of the CIELab image after the segmentation is stopped are obtained; A threshold segmentation algorithm is used to obtain the segmentation threshold of the pixel distribution disorder of all super-pixel blocks of the CIELab image after stopping segmentation; The area composed of pixels in the superpixel block whose pixel distribution disorder is greater than the segmentation threshold is recorded as the appearance contour area.

6. The method for extracting the appearance contour of an assembly line product according to claim 1, characterized in that: The extraction of the appearance contour of the medicinal glass bottle includes: Perform image erosion operation on the appearance contour area to obtain the boundary pixel points of the appearance contour area, and connect the adjacent boundary pixel points in sequence to obtain each connected domain; The closed boundary line of the connected domain with the largest area is used as the appearance outline of the medicinal glass bottle.

7. A device for extracting the appearance contour of a production line product, 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 steps of the method for extracting the appearance contour of an assembly line product as described in any one of claims 1-5 are implemented.