Methods, apparatus, computer equipment, media and products for testing the quality of blister pack pharmaceuticals

By setting segmentation thresholds for each blister pack drug area and generating a preset segmentation threshold template, the problem of poor segmentation effect in blister pack drug detection is solved, achieving higher precision drug quality detection.

CN115439454BActive Publication Date: 2026-03-06SHANGHAI LIANYING ZHIYUAN MEDICAL TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211121701.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-15
Publication Date
2026-03-06
Estimated Expiration
2042-09-15

AI Technical Summary

Technical Problem

Traditional blister pack drug quality testing methods have the problem of poor testing results, especially the poor drug separation effect caused by the reflection effect in different areas of the blister pack aluminum plate.

Method used

An image segmentation method using template fusion and block thresholding is adopted. By determining the segmentation threshold for each drug region on the blister pack aluminum plate and generating a preset segmentation threshold template, the drug region can be accurately segmented and its quality detected.

Benefits of technology

It improves the accuracy of drug segmentation and the precision of quality inspection, avoids the problem of poor segmentation effect caused by aluminum plate reflection, and enhances the inspection effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115439454B_ABST
    Figure CN115439454B_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, computer equipment, medium, and product for quality inspection of blister pack pharmaceuticals. The method includes: dividing an image to be inspected into regions based on pharmaceutical particles to obtain multiple image blocks; segmenting the pharmaceutical regions in each image block according to a preset segmentation threshold template corresponding to a preset type of blister pack pharmaceutical to obtain the pharmaceutical regions corresponding to each image block; and performing quality inspection on the pharmaceutical regions corresponding to each image block to obtain the quality inspection result of the image to be inspected; wherein, the image to be inspected is an image corresponding to a preset type of blister pack pharmaceutical; the preset segmentation threshold template includes segmentation thresholds corresponding to each image block; that is, in this embodiment, by setting different segmentation thresholds for different regions of the blister pack pharmaceutical on the blister pack aluminum plate, and by using segmentation thresholds for different regions to segment the image of each region, the accuracy of pharmaceutical segmentation can be improved, thereby improving the precision and effectiveness of pharmaceutical inspection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of pharmaceutical quality testing technology, and in particular to a method, apparatus, computer equipment, medium, and product for testing the quality of blister pack pharmaceuticals. Background Technology

[0002] In the pharmaceutical production process, for blister pack drugs, defects such as missing, damaged, broken, or even discolored sugar coating may occur during the blister packaging process, leading to quality problems of the drugs.

[0003] Therefore, quality inspection of blister-packaged medicines is crucial. Traditionally, image processing methods are used for quality inspection of blister-packaged medicines, which improves inspection efficiency compared to manual inspection, but the inspection results are still unsatisfactory. Summary of the Invention

[0004] Therefore, it is necessary to provide a method, apparatus, computer equipment, computer-readable storage medium, and computer program product for testing the quality of blister packs, which can improve the quality testing effect of blister packs, in response to the above-mentioned technical problems.

[0005] Firstly, this application provides a method for quality testing of blister pack pharmaceutical products. The method includes:

[0006] The image to be detected is divided into regions according to the drug particles, resulting in multiple image blocks; among them, the image to be detected is the image corresponding to the preset type of blister drug;

[0007] Based on the preset segmentation threshold template corresponding to the preset type of blister pack medicine, the medicine region in each image block is segmented to obtain the medicine region corresponding to each image block; wherein, the preset segmentation threshold template includes the segmentation threshold corresponding to each image block respectively;

[0008] Quality inspection is performed on the drug region corresponding to each image block to obtain the quality inspection result of the image to be inspected.

[0009] In one embodiment, based on a preset segmentation threshold template corresponding to a preset type of blister pack drug, image segmentation is performed on the drug region in each image block to obtain the drug region corresponding to each image block, including:

[0010] For each image block, a segmentation threshold corresponding to the image block is determined from the preset segmentation threshold template of the image to be detected;

[0011] Based on the segmentation threshold corresponding to the image patch, the drug region in the image patch is segmented to obtain the drug region corresponding to the image patch.

[0012] In one embodiment, the method further includes:

[0013] Obtain sample images of blister packs of a preset type of medicine, and divide the sample images into regions according to the medicine particles to obtain multiple sample image blocks;

[0014] For each sample image patch, calculate the local mean of each pixel in the sample image patch;

[0015] For each pixel in the sample image block, the segmentation threshold corresponding to the pixel is calculated based on the local mean and gray value of the pixel.

[0016] Based on the segmentation threshold corresponding to each pixel in each sample image block, a preset segmentation threshold template corresponding to the preset type of blister pack medicine is generated.

[0017] In one embodiment, for each sample image block, the local mean of each pixel in the sample image block is calculated, including:

[0018] For each pixel in each sample image block, a preset local window corresponding to the pixel is determined according to the preset window size;

[0019] Calculate the sum of the grayscale values ​​of all pixels within a preset local window;

[0020] The quotient of the sum of gray values ​​and the area of ​​a preset local window is used as the local mean value of the pixel.

[0021] In one embodiment, a preset segmentation threshold template corresponding to a preset type of blister pack drug is generated based on the segmentation threshold corresponding to each pixel in each sample image block, including:

[0022] For each sample image block, determine whether the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions.

[0023] If the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions, the segmentation threshold corresponding to each pixel in the sample image block is added to the preset segmentation threshold template.

[0024] If the segmentation threshold corresponding to each pixel in the sample image block does not meet the preset conditions, the preset window size is updated, and the step of calculating the segmentation threshold of each pixel in the sample image block is re-executed until the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions. The segmentation threshold corresponding to each pixel in the sample image block that meets the preset conditions is added to the preset segmentation threshold template to obtain the preset segmentation threshold template corresponding to the preset type of blister drug.

[0025] In one embodiment, determining whether the segmentation threshold corresponding to each pixel in the sample image block meets a preset condition includes:

[0026] Based on the segmentation threshold corresponding to each pixel in the sample image block, the sample image block is segmented to obtain the segmented image corresponding to the sample image block.

[0027] Determine the number of connected components in the segmented image corresponding to the sample image patch;

[0028] When the number of connected components is equal to 1, the segmentation threshold corresponding to each pixel in the sample image block is determined to meet the preset conditions.

[0029] In one embodiment, quality inspection is performed on the drug region corresponding to each image block to obtain the quality inspection result of the image to be inspected, including:

[0030] For each image patch, determine the number of connected components in the corresponding drug region and the drug area of ​​the drug region;

[0031] The quality detection result of the image block is determined based on the number of connected components and the area of ​​the drug.

[0032] Based on the quality detection results of each image block, the quality detection results of the image to be detected are obtained.

[0033] In one embodiment, the quality detection result of the image patch is determined based on the number of connected components and the area of ​​the drug, including:

[0034] If the number of connected components is greater than 1 and the absolute value of the difference between the drug area and the preset area is less than the first threshold, it is determined that the image block has a crack-type defect.

[0035] If the number of connected components is greater than 1, and the absolute value of the difference between the area of ​​the drug and the preset area is greater than the second threshold, it is determined that the image block has a sugar coating fading defect; the second threshold is greater than the first threshold.

[0036] If the number of connected components is equal to 1, and the absolute value of the difference between the area of ​​the drug and the preset area is greater than the third threshold, it is determined that there is a defect in the image block.

[0037] Secondly, this application also provides a device for testing the quality of blister pack pharmaceuticals. The device includes:

[0038] The acquisition module is used to divide the image to be detected into regions according to the drug particles, and obtain multiple image blocks; among them, the image to be detected is the image corresponding to the preset type of blister drug;

[0039] The segmentation module is used to segment the drug region in each image block according to the preset segmentation threshold template corresponding to the preset type of blister drug, so as to obtain the drug region corresponding to each image block; wherein, the preset segmentation threshold template includes the segmentation threshold corresponding to each image block respectively;

[0040] The detection module is used to perform quality detection on the drug area corresponding to each image block and obtain the quality detection result of the image to be detected.

[0041] In one embodiment, the apparatus further includes a segmentation threshold template generation module, which includes:

[0042] The acquisition unit is used to acquire sample images of blister packs of a preset type of medicine, and to divide the sample images into regions according to the medicine particles to obtain multiple sample image blocks;

[0043] The first calculation unit is used to calculate the local mean of each pixel in each sample image block.

[0044] The second calculation unit is used to calculate the segmentation threshold corresponding to each pixel in the sample image block based on the local mean of the pixel and the gray value of the pixel.

[0045] The generation unit is used to generate a preset segmentation threshold template corresponding to a preset type of blister pack drug based on the segmentation threshold corresponding to each pixel in each sample image block.

[0046] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of any of the methods described in the first aspect above.

[0047] Fourthly, this application also provides a computer-readable storage medium. This computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the steps of any of the methods in the first aspect described above.

[0048] Fifthly, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of any of the methods in the first aspect described above.

[0049] The aforementioned blister pack drug quality testing method, apparatus, computer equipment, storage medium, and computer program product involve the computer equipment dividing the image to be tested into regions according to drug particles to obtain multiple image blocks; segmenting the drug region in each image block according to a preset segmentation threshold template corresponding to a preset type of blister pack drug to obtain the drug region corresponding to each image block; then, performing quality testing on the drug region corresponding to each image block to obtain the quality testing result of the image to be tested; wherein, the image to be tested is the image corresponding to a preset type of blister pack drug; the preset segmentation threshold template includes segmentation thresholds corresponding to each image block; that is, in this embodiment, by setting different segmentation thresholds for blister pack drugs in different regions on the blister pack aluminum plate, the problem of inaccurate segmentation results when using the same segmentation threshold to segment drugs in different regions is avoided. By using segmentation thresholds for different regions to segment the image of each region, the accuracy of drug segmentation can be improved, thereby improving the precision and detection effect of drug testing. Attached Figure Description

[0050] Figure 1 This is a diagram illustrating the application environment of a blister pack drug quality testing method in one embodiment.

[0051] Figure 2 This is a flowchart illustrating a method for testing the quality of blister packs in one embodiment;

[0052] Figure 3 This is a flowchart illustrating the blister pack drug quality testing method in another embodiment;

[0053] Figure 4 This is a flowchart illustrating the blister pack drug quality testing method in another embodiment;

[0054] Figure 5 This is a flowchart illustrating the blister pack drug quality testing method in another embodiment;

[0055] Figure 6 This is a flowchart illustrating a specific embodiment of a method for testing the quality of blister pack pharmaceuticals.

[0056] Figure 7 This is a flowchart illustrating the blister pack drug quality testing method in another specific embodiment;

[0057] Figure 8 This is a schematic diagram of the structure of sample image blocks in one embodiment;

[0058] Figure 9 This is a schematic diagram of the structure of the image block to be detected in one embodiment;

[0059] Figure 10 This is a schematic diagram of the image segmentation result corresponding to the image to be detected in one embodiment;

[0060] Figure 11 This is a schematic diagram of the image segmentation result achieved using the Canny operator in one embodiment;

[0061] Figure 12 This is a schematic diagram of the image segmentation result achieved using the region growing method in one embodiment;

[0062] Figure 13 This is a schematic diagram of the image segmentation result achieved using the adaptive iterative method in one embodiment;

[0063] Figure 14 This is a schematic diagram of an image segmentation result achieved using the template fusion block thresholding method of this application in one embodiment;

[0064] Figure 15 This is a schematic diagram of the drug quality testing results implemented using the template fusion block threshold method of this application in one embodiment;

[0065] Figure 16 This is a structural block diagram of a blister drug quality testing device in one embodiment;

[0066] Figure 17 This is a structural block diagram of the blister pack drug quality testing device in another embodiment;

[0067] Figure 18 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0068] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0069] First, before introducing the technical solutions of the embodiments of this disclosure in detail, the technical background or technical evolution on which the embodiments of this disclosure are based will be introduced. Typically, when performing quality inspection on blister packs of medicine, it is necessary to first segment the medicine within each blister on the blister pack aluminum plate, and then perform quality inspection on each segmented medicine. Traditional image segmentation algorithms include threshold-based, cluster-based, region-growing-based, edge-based, and deep learning-based methods. Using the complete blister pack aluminum plate as a basis, the above-mentioned image segmentation algorithms are employed to segment the medicine within the blister packs on the blister pack aluminum plate.

[0070] Taking threshold-based image segmentation algorithms as an example, this explanation focuses on how these algorithms divide image pixels into foreground and background regions using a specific threshold. The threshold is typically a grayscale value, but can also be a value in the tone space. Commonly used threshold segmentation algorithms include the Otsu's method (Otsu's method), which analyzes the entire blister pack to obtain a segmentation threshold. Then, based on this threshold, the blister pack is segmented to identify the region containing the medicine, thus achieving medicine segmentation.

[0071] However, due to the reflective effect of the blister pack aluminum plate, the pixel differences between the medicine and the background in different areas of the blister pack aluminum plate are different. This results in poor segmentation of medicine in areas with strong reflectivity based on the segmentation threshold determined by the complete blister pack aluminum plate, which in turn leads to poor drug quality detection results.

[0072] The difference between the background and the drug boundary within the same local area is not only reflected in the difference in grayscale, but also in the differences in local mean and local variance. The local mean and local standard deviation of the corresponding boundary pixels will change with the change in light distribution, and the same is true for the background. Therefore, it can be seen that the difference between the grayscale value and the local mean of the corresponding pixel in different areas will also change with the intensity of light distribution.

[0073] Based on this, this application proposes a method for quality inspection of blister pack medicines. It employs a template fusion and block thresholding image segmentation method to segment the medicine regions of the image to be inspected. A segmentation threshold template is obtained by fusing a defect-free medicine image (template image) with the block threshold segmentation. This template is then applied to the block images of the image to be inspected for thresholding. Specifically, the entire blister pack image is segmented according to the medicine particles, and a corresponding segmentation threshold is determined for each medicine region image within the blister pack image. Then, based on the segmentation threshold corresponding to each medicine region image, the corresponding region's medicine image is segmented. Finally, the segmentation results for each medicine region image are subjected to quality inspection. This method avoids the problem of poor segmentation results caused by aluminum plate reflection during image segmentation, improving the segmentation effect of blister pack medicines and thus improving the quality inspection effect of blister pack medicines.

[0074] The technical solutions involved in the embodiments of this disclosure will be described below in conjunction with the scenarios in which they are applied.

[0075] The blister pack drug quality testing method provided in this application embodiment can be applied to, for example... Figure 1The application environment shown includes computer equipment 120, which can be a blister drug quality testing device, or a server. The server can be a standalone server or a server cluster composed of multiple servers. It can also be a testing terminal, such as various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices.

[0076] In one embodiment, such as Figure 2 As shown, a method for quality testing of blister pack pharmaceuticals is provided, which is applied to... Figure 1 Taking a computer device as an example, the explanation includes the following steps:

[0077] Step 201: Divide the image to be detected into regions according to the drug particles to obtain multiple image blocks.

[0078] The image to be detected is the image corresponding to a preset type of blister pack medicine. The size, dimensions, and location distribution of the medicine area vary depending on the type of blister pack medicine.

[0079] Optionally, a preset region segmentation algorithm can be used to divide the image to be detected into regions based on the drug particles, resulting in multiple image blocks; the preset region segmentation algorithm is the segmentation algorithm corresponding to the preset type of blister pack drug. Optionally, each drug particle in the image to be detected can be identified, and based on the identified drug particles, the region where the drug particles are located can be divided to obtain multiple image blocks including the drug particles. Optionally, the center point of each drug particle in the image to be detected can be identified, and based on the center point of each drug particle and a preset size, the image to be detected can be divided into regions to obtain multiple image blocks; wherein, the preset size can be determined based on the preset type of blister pack drug. Of course, other methods can also be used, and this application embodiment does not specifically limit them.

[0080] Furthermore, the segmented image blocks may include at least one drug particle. That is, one drug particle can be segmented into one image block, two drug particles can be segmented into one image block, or multiple drug particles can be segmented into one image block, etc. This application does not specifically limit this. For example, when the image to be detected is an aluminum plate structure including multiple columns of drugs, the region can be segmented row by row to obtain multiple image blocks in each row, where the number of image blocks equals the number of rows.

[0081] Experimental studies have shown that when dividing a drug image into blocks, if the size of each image block is too large or too small, the threshold segmentation effect will be poor. However, if the drug image is divided into blocks according to the region where each drug particle is located, the problem of inaccurate segmentation of drug images due to the chaotic intermingling of high grayscale and low grayscale regions can be solved to a certain extent, and the threshold segmentation effect is better.

[0082] Step 202: Based on the preset segmentation threshold template corresponding to the preset type of blister drug, perform image segmentation on the drug region in each image block to obtain the drug region corresponding to each image block.

[0083] The preset segmentation threshold template includes segmentation thresholds corresponding to each image block. Optionally, the database may include preset segmentation threshold templates corresponding to different types of blister pack drugs, with each preset segmentation threshold template including the segmentation threshold for each image block corresponding to that type of blister pack drug. For the segmentation threshold of each image block, traditional thresholding algorithms, such as the maximum inter-class variance method, can be used to determine the segmentation threshold; alternatively, improved or optimized algorithms based on traditional thresholding algorithms can be used to determine the segmentation threshold. This application does not specifically limit the specific methods used in this embodiment.

[0084] Optionally, after obtaining a preset segmentation threshold template that matches the type of the image to be detected, the drug region in each image block can be segmented based on the preset segmentation threshold template to obtain the drug region corresponding to each image block; for example, for each image block, the segmentation threshold corresponding to the image block can be determined from the preset segmentation threshold template of the image to be detected, and then, the drug region in the image block can be segmented based on the segmentation threshold corresponding to the image block to obtain the drug region corresponding to the image block.

[0085] When segmenting the drug region within an image patch based on a segmentation threshold, if the pixel value of the drug region is less than the pixel value of the background region, then pixels in the image patch with values ​​less than (or equal to) the segmentation threshold can be designated as object points to obtain the drug region, while pixels with values ​​greater than or equal to (or greater than) the segmentation threshold can be designated as background points. Alternatively, if the pixel value of the drug region is greater than the pixel value of the background region, then pixels with values ​​greater than (or equal to) the segmentation threshold can also be designated as object points, while pixels with values ​​less than or equal to (or less than) the segmentation threshold can be designated as background points. It should be noted that in practical applications, the segmentation method can be determined based on the pixel differences between the background and object in the image; in other words, if the background pixels are greater than the object pixels, then pixels with values ​​less than or equal to the segmentation threshold are designated as object points; conversely, if the background pixels are less than the object pixels, then pixels with values ​​greater than or equal to the segmentation threshold are designated as object points.

[0086] Step 203: Perform quality inspection on the drug region corresponding to each image block to obtain the quality inspection result of the image to be inspected.

[0087] The quality inspection results may include whether the drug is defect-free, defective, or the type of defect. The type of defect may include cracks, missing parts, damage, discoloration of the sugar coating, etc. This embodiment does not specifically limit the content and type of defect of the quality inspection results.

[0088] Optionally, for the drug region corresponding to each image block, the drug region corresponding to the image block can be input into a preset quality detection algorithm to obtain the quality detection result of each image block. The preset quality detection algorithm can be a detection algorithm based on mathematical models, deep learning, neural networks, etc. In this embodiment, the type of quality detection algorithm is not specifically limited.

[0089] Next, based on the quality detection results of each image block, the quality detection result of the image to be detected is obtained; optionally, the quality detection results of each image block can be fused to obtain the quality detection result of the image to be detected; for example, the quality detection result may also include the number of defective drugs, the number of defective drugs, the proportion of defective drugs, the number and proportion of each type of defective drugs, etc.

[0090] In the above-mentioned method for detecting the quality of blister pack medicines, the computer equipment divides the image to be detected into regions according to the medicine particles to obtain multiple image blocks; according to the preset segmentation threshold template corresponding to the preset type of blister pack medicine, the medicine region in each image block is segmented to obtain the medicine region corresponding to each image block; then, the medicine region corresponding to each image block is subjected to quality detection to obtain the quality detection result of the image to be detected; wherein, the image to be detected is the image corresponding to the preset type of blister pack medicine; the preset segmentation threshold template includes the segmentation threshold corresponding to each image block; that is, in this embodiment, by setting different segmentation thresholds for the blister pack medicines in different regions on the blister pack aluminum plate, the problem of inaccurate segmentation results when using the same segmentation threshold to segment medicines in different regions is avoided. By using segmentation thresholds for different regions to segment the images of each region, the accuracy of medicine segmentation can be improved, thereby improving the precision and detection effect of medicine detection.

[0091] Figure 3 This is a flowchart illustrating a blister pack drug quality testing method in another embodiment. This embodiment relates to the establishment process of an optional preset segmentation threshold template, based on the above embodiments, such as... Figure 3 As shown, the above method also includes:

[0092] Step 301: Obtain sample images of blister packs of a preset type of medicine, and divide the sample images into regions according to the medicine particles to obtain multiple sample image blocks.

[0093] The sample images are images of blister packs of medicine of a preset type that are free of defects. There can be one or more sample images. If multiple sample images are included, each sample image is captured or scanned under the same environment and location to ensure consistency in brightness, sharpness, texture, etc., across all regions of each sample image. Optionally, the sample image can be a grayscale image obtained after performing a series of preprocessing steps on the original acquired image. These preprocessing operations may include, but are not limited to, filtering, color space conversion, and linear grayscale transformation. Filtering operations may include median filtering, mean filtering, and Kalman filtering.

[0094] Additionally, it should be noted that the sample image and the image to be detected should be images taken under the same environment and location.

[0095] Optionally, when there are multiple sample images, a segmentation threshold template corresponding to each sample image can be obtained. Then, the segmentation threshold templates corresponding to each sample image are fused to obtain a preset segmentation threshold template corresponding to the preset type of blister pack medicine. For example, the segmentation threshold templates corresponding to each sample image can be averaged, that is, the segmentation thresholds of the same image block in the segmentation threshold templates corresponding to each sample image are averaged, and the average segmentation threshold is used as the segmentation threshold corresponding to the image block. This yields the averaged segmentation threshold template, which is used as the preset segmentation threshold template corresponding to the preset type of blister pack medicine.

[0096] The process of obtaining the segmentation threshold template for the sample image is explained in detail below.

[0097] Optionally, after obtaining a sample image of a blister pack of medicine of a preset type, the sample image can be divided into regions according to a preset division rule to obtain multiple sample image blocks corresponding to the sample image; wherein, each sample image block may include at least one medicine particle, and the preset division rule is related to the number of medicine particles in the sample image block.

[0098] Step 302: For each sample image block, calculate the local mean of each pixel in the sample image block.

[0099] Wherein, the local mean of a pixel is the average value of all pixels within a local region including the pixel. This local region can be a region of a preset size centered on the pixel, a region of a preset size with the pixel as its origin, or a rectangular region extending from the image origin to the pixel. Alternatively, it can be any point within the region and a region defined by the preset size, etc., and this embodiment does not specifically limit this. Preferably, in this embodiment, the average value of all pixels within a local region of a preset size centered on the pixel is the local mean corresponding to that pixel.

[0100] In one implementation of this embodiment, the local mean of a pixel can be calculated as follows: for each pixel in the sample image block, a preset local window corresponding to the pixel is determined according to a preset window size; then, the sum of the gray values ​​of all pixels within the preset local window can be calculated; and the quotient of the sum of gray values ​​and the area of ​​the preset local window is taken as the local mean of the pixel. Optionally, the preset local window corresponding to the pixel can be a local window of a preset window size centered on the pixel.

[0101] For example, the local mean of a pixel can be calculated using an integral and an image, where the integral and image are defined as the sum of the gray values ​​of all points within a rectangular region formed by the origin of the image and the pixel. The calculation formula is shown in formula (1).

[0102]

[0103] Where ii(x,y) is the integral and image, and f(i,j) is the gray value of a pixel in the sample image.

[0104] In actual calculations, formulas (2) and (3) can be used to iteratively calculate the value of formula (1).

[0105] S(x,y)=s(x,y-1)+i(x,y) (2)

[0106] ii(x,y)=ii(x-1,y)+s(x,y) (3)

[0107] Here, s(x,y) is the integral of a sequence, and s(x,-1)=0, ii(-1,y)=0, and i(x,y) is the original image. Therefore, calculating the integral and the image only requires traversing the original image once, which can reduce the computational cost.

[0108] Then, the integral and image of a local window centered at pixel (x,y) with a preset size of w×w. w (x,y) can be represented as shown in formula (4).

[0109] ii w (x,y)=[ii(x+d-1,y+d-1)+i(xd,yd)]-[ii(xd,y+d-1)+ii(x+d-1,yd)] (4)

[0110] Where d = w / 2, and w is an odd number.

[0111] Furthermore, the local mean m(x,y) of a pixel can be expressed as:

[0112]

[0113] As can be seen from the definition of local mean, using integrals and images does not depend on the size of the local window, and the time complexity remains basically unchanged, thus shortening the computation time.

[0114] Step 303: For each pixel in the sample image block, calculate the segmentation threshold corresponding to the pixel based on the local mean and gray value of the pixel.

[0115] In this embodiment, an improved algorithm based on the traditional local binarization Sauvola algorithm is adopted. The calculation method of the segmentation threshold corresponding to a pixel point in the traditional Sauvola algorithm is shown in formula (6).

[0116]

[0117] Among them, T(x,y) is the segmentation threshold corresponding to the pixel point (x,y), s(x,y) is the standard variance of the local area of the pixel point, R is the dynamic range of the standard variance. If the input image is an 8-bit grayscale image, then R = 128, k is a correction parameter. Generally, 0 < k < 1. In this embodiment, k can be taken around 0.2.

[0118] It can be seen that the traditional Sauvola algorithm uses local mean and local variance to calculate the threshold. Due to the complexity of variance calculation, the complexity of threshold calculation is high and the calculation speed is slow. Furthermore, it may also lead to a slow image segmentation rate. In this embodiment, the local mean is used to replace the standard variance to reduce the calculation complexity. Similar to the classical local threshold selection idea, in this algorithm, a deviation value is also added to the grayscale mean of the local window. If the pixel point is in the tablet boundary area, the threshold size is usually between the grayscale value of the pixel point and the grayscale mean of its neighborhood.

[0119] In one implementation, the standard variance is replaced by the difference between the local mean of the pixel point and the grayscale value of the pixel point. Then, the calculation method of the segmentation threshold corresponding to the improved pixel point can be shown in formula (7).

[0120]

[0121] Among them, f(x,y) is the grayscale value of the pixel point, and m(x,y) is the local mean of the pixel point.

[0122] It should be noted that in formula (7), by is replaced by Its value range is (0,1). For an image with a gray level of 255, m(x,y) can be directly replaced by 255. However, when these two cases and other parameters are the same, the human eye cannot distinguish the difference in the segmentation results. In addition, due to local noise, shadows, highlights, etc., the size relationship between f(x,y) and m(x,y) cannot be determined. Therefore, the absolute value of the difference result between f(x,y) and m(x,y) is adopted.

[0123] In the improved algorithm, the computational cost of standard deviation is eliminated, and the threshold calculation rate is improved. In addition, the local mean of the pixel is calculated by using the above formulas (4) and (5), that is, by querying the integral image, the calculation method is used. This not only reduces the computational cost of the mean, but also further improves the calculation rate of the segmentation threshold and reduces the calculation time of the segmentation threshold.

[0124] Step 304: Generate a preset segmentation threshold template corresponding to a preset type of blister pack drug based on the segmentation threshold corresponding to each pixel in each sample image block.

[0125] When there is only one sample image, after obtaining the segmentation threshold corresponding to each pixel in each sample image block in the sample image, the segmentation thresholds corresponding to each pixel can be fused to generate the segmentation threshold template corresponding to the sample image, which can be used as the preset segmentation threshold template corresponding to the preset type of blister drug.

[0126] When there are multiple sample images, the average segmentation threshold of the corresponding pixel in each sample image can be used as the segmentation threshold of that pixel in the preset segmentation threshold template to generate a preset segmentation threshold template corresponding to the preset type of blister drug.

[0127] In this embodiment, the computer device acquires sample images of blister packs of a preset type of medicine and divides the sample images into regions according to the medicine particles to obtain multiple sample image blocks. For each sample image block, the local mean of each pixel in the sample image block is calculated. Then, for each pixel in the sample image block, the segmentation threshold corresponding to the pixel is calculated based on the local mean and the gray value of the pixel. Finally, based on the segmentation threshold corresponding to each pixel in each sample image block, a preset segmentation threshold template corresponding to the preset type of blister pack medicine is generated. Using the method in this embodiment, the acquisition speed of the preset segmentation threshold template can be greatly improved, and the amount of calculation for acquiring each segmentation threshold in the preset segmentation threshold template is small, resulting in low computational complexity.

[0128] Figure 4 This is a flowchart illustrating a blister pack drug quality inspection method in another embodiment. This embodiment involves an optional implementation process whereby a computer device generates a preset segmentation threshold template corresponding to a preset type of blister pack drug based on the segmentation threshold corresponding to each pixel in each sample image block. Based on the above embodiment, as... Figure 4 As shown, step 304 above includes:

[0129] Step 401: For each sample image block, determine whether the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions.

[0130] The preset condition can be used to characterize the image segmentation result, and this preset condition is related to the image segmentation result. For example, in blister pack drug segmentation, if segmentation is performed according to the drugs inside each blister pack, the segmentation result obtained is the region where a single blister pack drug is located, and this region can be regarded as a complete connected component. In obtaining the segmentation threshold template, in order to make the threshold segmentation of the image to be detected accurate, the number of connected components in the sample image after threshold segmentation must be 1. Experimental analysis shows that when the number of connected components is less than 1 or greater than 1, the threshold segmentation of the image to be detected is inaccurate.

[0131] Optionally, for each sample image block, the computer device can use the segmentation threshold corresponding to each pixel in the sample image block to perform image segmentation on the sample image block, obtain the segmented image corresponding to the sample image block, and then analyze the segmented image to determine whether the segmented image meets the preset conditions.

[0132] In an optional implementation of this embodiment, when the sample image block contains only one blister pack of medicine, the computer device can perform image segmentation on the sample image block according to the segmentation threshold corresponding to each pixel in the sample image block to obtain a segmented image corresponding to the sample image block; then, the number of connected components in the segmented image corresponding to the sample image block can be determined; and if the number of connected components is determined to be equal to 1, the segmentation threshold corresponding to each pixel in the sample image block is determined to satisfy a preset condition; that is, in this implementation, the preset condition is that the number of connected components in the segmented image is equal to 1.

[0133] In another optional implementation of this embodiment, when the sample image block includes multiple blister packs, the preset condition can be that the number of connected components in the segmented image is equal to the number of blister packs, and there is no intersection between the connected components corresponding to each blister pack, that is, each blister pack is independent, and the connected components corresponding to each blister pack should also be independent; for example, when the sample image block includes two medicines, the preset condition can be that the number of connected components in the segmented image is equal to 2, and the two connected components do not intersect.

[0134] Step 402: If the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions, add the segmentation threshold corresponding to each pixel in the sample image block to the preset segmentation threshold template.

[0135] The preset segmentation threshold template is either a segmentation threshold template corresponding to the sample image or a segmentation threshold template for the blister pack medicine type corresponding to the sample image. The preset segmentation threshold template includes the segmentation threshold corresponding to each pixel in each sample image block corresponding to the sample image.

[0136] Optionally, if the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions, it means that the segmentation threshold corresponding to each pixel in the sample image block can accurately segment the sample image block and obtain the drug region in the sample image block. Then, the segmentation threshold corresponding to each pixel in the sample image block can be used as the segmentation threshold of the image block region corresponding to the blister drug type. In other words, the segmentation threshold corresponding to each pixel in the sample image block can be added to the corresponding pixel position in the preset segmentation threshold template.

[0137] Step 403: If the segmentation threshold corresponding to each pixel in the sample image block does not meet the preset conditions, update the preset window size and re-execute the step of calculating the segmentation threshold of each pixel in the sample image block until the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions. Then, add the segmentation threshold corresponding to each pixel in the sample image block that meets the preset conditions to the preset segmentation threshold template to obtain the preset segmentation threshold template corresponding to the preset type of blister drug.

[0138] Optionally, if the segmentation threshold corresponding to each pixel in the sample image block does not meet the preset conditions, it indicates that using the segmentation threshold corresponding to each pixel in the sample image block to segment the drug region in the sample image block cannot accurately segment the drug region in the sample image block. In this case, the segmentation threshold corresponding to each pixel in the sample image block can be updated or re-determined. In one implementation, the preset window size used to determine the local mean of the pixel can be updated, and based on the updated preset window size, the steps of determining the local mean of the pixel and determining the segmentation threshold corresponding to the pixel based on the local mean can be re-executed to obtain the segmentation threshold corresponding to each pixel in the sample image block. Then, based on the re-obtained segmentation threshold corresponding to each pixel in the sample image block, image segmentation is performed on the sample image block, and the segmentation threshold corresponding to each pixel is judged based on the segmentation result to determine whether it meets the preset conditions. If it does not meet the conditions, the preset window size is updated again, and this process is repeated until the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions.

[0139] If the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions, then the segmentation threshold corresponding to each pixel in the sample image block that meets the preset conditions is added to the corresponding pixel position in the preset segmentation threshold template to obtain the preset segmentation threshold template corresponding to the preset type of blister drug.

[0140] It should be noted that during the iteration process of this embodiment, the preset window size can be updated in ascending order, such as 3, 5, 7, 9, etc. The preset window size can also be updated in descending order, such as 9, 7, 5, 3, etc. Of course, the preset window size can also be updated in other ways, and this application embodiment does not limit this.

[0141] In this embodiment, when generating a preset segmentation threshold template corresponding to a preset type of blister pack medicine based on the segmentation threshold corresponding to each pixel in each sample image block, for each sample image block, it is determined whether the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions. Only if the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions is the segmentation threshold added to the preset segmentation threshold template. If the segmentation threshold corresponding to each pixel in the sample image block does not meet the preset conditions, the preset window size is updated, and the step of calculating the segmentation threshold for each pixel in the sample image block is re-executed until the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions. Then, the segmentation threshold corresponding to each pixel in the sample image block that meets the preset conditions is added to the preset segmentation threshold template, resulting in a preset segmentation threshold template corresponding to the preset type of blister pack medicine. In other words, in this embodiment, before generating the preset segmentation threshold template, the accuracy of the segmentation threshold for each pixel in the sample image is first determined to ensure the accuracy of the threshold selection, thereby improving the accuracy of image segmentation and achieving better and higher precision segmentation results.

[0142] It should be noted that the generation process of the preset segmentation threshold template can be performed offline before the quality inspection of blister packs. When performing the quality inspection of blister packs, the pre-obtained preset segmentation threshold template can be directly used to perform image segmentation and quality inspection on the image to be inspected, which can improve the speed of quality inspection and meet the real-time requirements of blister pack quality inspection.

[0143] Figure 5 This is a flowchart illustrating a blister pack drug quality inspection method in another embodiment. This embodiment involves a computer device performing quality inspection on the drug regions corresponding to each image block to obtain the quality inspection results of the image to be inspected. Based on the above embodiment, as... Figure 5 As shown, step 203 above includes:

[0144] Step 501: For each image block, determine the number of connected components in the corresponding drug region and the drug area of ​​the drug region.

[0145] In this embodiment, for a single drug region in each image block, the number of connected components and the drug area of ​​each drug region are determined.

[0146] Step 502: Determine the quality detection result of the image block based on the number of connected components and the area of ​​the drug.

[0147] For each drug region in an image block, the drug quality inspection result of that drug region is determined based on the number of connected components and the drug area of ​​that drug region. Then, based on the quality inspection results of each drug region in the image block, the quality inspection result of the entire image block is determined.

[0148] Optionally, for a single drug region, if the number of connected components in the drug region is greater than 1, and the absolute value of the difference between the drug area and the preset area is less than a first threshold, it can be determined that the drug in the drug region of the image block has a crack-type defect, i.e., the drug has a crack; if the number of connected components is greater than 1, and the absolute value of the difference between the drug area and the preset area is greater than a second threshold, it can be determined that the image block has a sugar coating fading defect; the second threshold is greater than or equal to the first threshold; if the number of connected components is equal to 1, and the absolute value of the difference between the drug area and the preset area is greater than a third threshold, it can be determined that the image block has a defect-type defect.

[0149] For defects, multiple different third thresholds can be set to obtain multiple defects of different degrees, such as 10% defects, 20% defects, 50% defects, etc.

[0150] Step 503: Based on the quality detection results of each image block, obtain the quality detection results of the image to be detected.

[0151] Optionally, the quality detection results of the image to be detected can be obtained by fusing the quality detection results of each image block. The quality detection results of the image to be detected include the quality detection results of each image block and the quality detection results after fusion. The quality detection results after fusion can include the number and proportion of drugs of each defect type, the total number of defective drugs and their corresponding proportions, etc.

[0152] In this embodiment, the computer device analyzes each image block to determine the number of connected components and the area of ​​the drug region corresponding to each image block, and determines the quality detection result of each image block based on the number of connected components and the area of ​​the drug region. Then, based on the quality detection results of each image block, the quality detection result of the image to be detected is obtained. By using the method in this embodiment, the quality detection efficiency of the image to be detected can be improved, as well as the accuracy and diversity of the quality detection results.

[0153] In one specific embodiment of this application, such as Figure 6 As shown, a method for quality testing of blister pack pharmaceuticals is provided, the method comprising:

[0154] Step 601: Obtain a sample image of a blister pack of medicine of a preset type, and divide the sample image into regions according to individual medicine particles to obtain multiple sample image blocks.

[0155] Optionally, combined Figure 7 As shown, the sample image can be a defect-free tablet image after preprocessing operations such as median filtering, RGB color space conversion, and linear grayscale transformation of the original acquired image. For example, such as... Figure 8 As shown, the sample image can be a five-row, two-column image. Based on a single drug particle, the sample image can be divided into 10 sample image blocks, named from top to bottom as A1, B1, C1, D1, E1, F1, G1, H1, I1, and J1.

[0156] Step 602: For each pixel in each sample image block, determine the preset local window corresponding to the pixel according to the preset window size, and calculate the sum of the gray values ​​of all pixels within the preset local window.

[0157] Step 603: The quotient of the sum of gray values ​​and the area of ​​the preset local window is used as the local mean of the pixel.

[0158] Step 604: For each pixel in the sample image block, calculate the segmentation threshold corresponding to the pixel based on the local mean and gray value of the pixel.

[0159] Step 605: For each sample image block, perform image segmentation on the sample image block according to the segmentation threshold corresponding to each pixel in the sample image block to obtain the segmented image corresponding to the sample image block.

[0160] Optionally, combined Figure 7 As shown, for the preprocessed defect-free sample image, the template fusion block threshold is used to segment the sample image to obtain the segmented image corresponding to the sample image block; wherein, the template fusion block threshold is the segmentation threshold corresponding to each pixel point determined in steps 602 to 604 above.

[0161] Step 606: Determine the number of connected components in the segmented image corresponding to each sample image block.

[0162] Step 607: If the number of connected components is equal to 1, and the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions, then add the segmentation threshold corresponding to each pixel in the sample image block to the preset segmentation threshold template.

[0163] Step 608: If the number of connected components is not equal to 1, update the preset window size and return to step 602. Re-execute the step of calculating the segmentation threshold of each pixel in the sample image block until the segmentation threshold corresponding to each pixel in the sample image block meets the preset condition. Add the segmentation threshold corresponding to each pixel in the sample image block that meets the preset condition to the preset segmentation threshold template to obtain the preset segmentation threshold template corresponding to the preset type of blister drug.

[0164] Optionally, combined Figure 7 As shown, if the number of connected components is not equal to 1, the threshold segmentation continues to iterate until the number of connected components in the segmented image is equal to 1 after segmenting each sample image block by using the segmentation threshold corresponding to each pixel in each sample image block. Finally, the preset segmentation threshold template corresponding to the preset type of blister drug is obtained.

[0165] Step 609: Obtain the image to be detected of a preset type, and divide the image to be detected into regions according to individual drug particles to obtain multiple image blocks.

[0166] like Figure 9 As shown, according to the region where each drug particle is located in the image to be detected, the image to be detected after preprocessing operations such as median filtering and grayscale linear transformation is divided into 10 rectangular images, and named A2, B2, C2, D2, E2, F2, G2, H2, I2 and J2 respectively from left to right and from top to bottom.

[0167] Step 610: Obtain the preset segmentation threshold template corresponding to the preset type of blister drug, and determine the segmentation threshold corresponding to each image block from the preset segmentation threshold template.

[0168] Step 611: Based on the segmentation threshold corresponding to each image block, perform image segmentation on the drug region in each image block to obtain the drug region corresponding to each image block. That is, apply the segmentation thresholds corresponding to each image block A1, B1, C1, D1, E1, F1, G1, H1, I1, and J1 in the preset segmentation threshold template to the threshold segmentation of each image block A2, B2, C2, D2, E2, F2, G2, H2, I2, and J2 in the image to be detected. For example, using the segmentation threshold corresponding to A1 in the preset segmentation threshold template to segment image block A2 of the image to be detected, the resulting segmentation is as follows: Figure 10 As shown.

[0169] Step 612: Determine the number of connected components and the area of ​​the drug region corresponding to each image block.

[0170] Step 613: Determine the quality detection result of each image block based on the number of connected components in the drug region corresponding to each image block and the drug area.

[0171] Step 614: Based on the quality detection results of each image block, obtain the quality detection results of the image to be detected.

[0172] The following section will compare and analyze the quality inspection of blister packs using different image segmentation algorithms.

[0173] (1) When using edge detection to segment images of capsules or tablets, the Canny operator performs well. The Canny operator was used to process tablet images with cracks, missing parts, approximately 10% defects, and sugar coating fading defects, with the following results: Figure 11 As shown.

[0174] (2) The region growing method was used to segment tablet images with crack defects, missing defects, defects with approximately 10% loss, and sugar coating fading defects. The results are as follows: Figure 12 As shown.

[0175] (3) For capsule-type and tablet-type drug images that have undergone preprocessing operations such as median filtering, grayscale linear transformation, and color space conversion, thresholding is used for segmentation. Since the adaptive iterative method is an improved version of the bimodal method, its segmentation effect is slightly better than that of the bimodal method. The adaptive iterative method is used to segment tablet images with crack defects, missing defects, defects of about 10%, and sugar coating fading defects. The results are as follows: Figure 13 As shown.

[0176] (4) The template fusion and segmentation thresholding method proposed in this application is used to segment tablet images with crack defects, missing defects, defects with approximately 10% loss, and sugar coating fading defects. The results are as follows: Figure 14 As shown.

[0177] For tablet images with defects such as cracks, missing parts, approximately 10% defects, and sugar coating discoloration, after preprocessing, the images are segmented using the Canny operator, region growing method, adaptive iterative method, and the template fusion block thresholding method described in this application. The segmentation results show that the Canny operator, region growing method, and adaptive iterative method produce poor segmentation results for these types of tablets, failing to meet the requirements of actual drug testing. The template fusion block thresholding method described in this application achieves better segmentation results with higher accuracy and meets the real-time requirements for tablet packaging testing.

[0178] Finally, a template fusion and block thresholding method was adopted to detect tablet-type drug packaging. The detection results are as follows: Figure 15 As shown.

[0179] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0180] Based on the same inventive concept, this application also provides a blister drug quality testing device for implementing the above-mentioned blister drug quality testing method. The solution provided by this device is similar to the solution described in the above method; therefore, the specific limitations in one or more embodiments of the blister drug quality testing device provided below can be found in the limitations of the blister drug quality testing method described above, and will not be repeated here.

[0181] In one embodiment, such as Figure 16 As shown, a blister pack pharmaceutical quality testing device is provided, comprising: an acquisition module 1601, a segmentation module 1602, and a detection module 1603, wherein:

[0182] The acquisition module 1601 is used to divide the image to be detected into regions according to the drug particles to obtain multiple image blocks; wherein, the image to be detected is the image corresponding to a preset type of blister drug.

[0183] The segmentation module 1602 is used to segment the drug region in each image block according to the preset segmentation threshold template corresponding to the preset type of blister drug, so as to obtain the drug region corresponding to each image block; wherein, the preset segmentation threshold template includes the segmentation threshold corresponding to each image block respectively.

[0184] The detection module 1603 is used to perform quality detection on the drug area corresponding to each image block and obtain the quality detection result of the image to be detected.

[0185] In one embodiment, the segmentation module 1602 includes a determining unit and a segmentation unit; the determining unit is used to determine the segmentation threshold corresponding to each image block from a preset segmentation threshold template of the image to be detected; the segmentation unit is used to perform image segmentation on the drug region in the image block according to the segmentation threshold corresponding to the image block to obtain the drug region corresponding to the image block.

[0186] In one embodiment, such as Figure 17 As shown, the device also includes a segmentation threshold template generation module 1604, which includes:

[0187] The acquisition unit is used to acquire sample images of blister packs of a preset type of medicine, and to divide the sample images into regions according to the medicine particles to obtain multiple sample image blocks;

[0188] The first calculation unit is used to calculate the local mean of each pixel in each sample image block.

[0189] The second calculation unit is used to calculate the segmentation threshold corresponding to each pixel in the sample image block based on the local mean of the pixel and the gray value of the pixel.

[0190] The generation unit is used to generate a preset segmentation threshold template corresponding to a preset type of blister pack drug based on the segmentation threshold corresponding to each pixel in each sample image block.

[0191] In one embodiment, the first calculation unit is specifically used to determine a preset local window corresponding to each pixel in each sample image block according to a preset window size; calculate the sum of gray values ​​of all pixels within the preset local window; and use the quotient of the sum of gray values ​​and the area of ​​the preset local window as the local mean of the pixel.

[0192] In one embodiment, the generation unit is specifically used to determine whether the segmentation threshold corresponding to each pixel in each sample image block meets a preset condition for each sample image block; if it is determined that the segmentation threshold corresponding to each pixel in each sample image block meets the preset condition, the segmentation threshold corresponding to each pixel in each sample image block is added to a preset segmentation threshold template; if it is determined that the segmentation threshold corresponding to each pixel in each sample image block does not meet the preset condition, the preset window size is updated, and the step of calculating the segmentation threshold of each pixel in each sample image block is re-executed until the segmentation threshold corresponding to each pixel in each sample image block meets the preset condition, and the segmentation threshold corresponding to each pixel in the sample image block that meets the preset condition is added to the preset segmentation threshold template to obtain a preset segmentation threshold template corresponding to a preset type of blister drug.

[0193] In one embodiment, the generation unit is specifically used to perform image segmentation on the sample image block according to the segmentation threshold corresponding to each pixel in the sample image block to obtain a segmented image corresponding to the sample image block; determine the number of connected components in the segmented image corresponding to the sample image block; and determine that the segmentation threshold corresponding to each pixel in the sample image block satisfies a preset condition when the number of connected components is equal to 1.

[0194] In one embodiment, the detection module 1603 is specifically used to determine, for each image block, the number of connected components in the corresponding drug region and the drug area of ​​the drug region; determine the quality detection result of the image block based on the number of connected components and the drug area; and obtain the quality detection result of the image to be detected based on the quality detection result of each image block.

[0195] In one embodiment, the detection module 1603 is specifically used to determine that the image block has a crack-type defect when the number of connected components is greater than 1 and the absolute value of the difference between the drug area and the preset area is less than a first threshold; to determine that the image block has a sugar coating fading defect when the number of connected components is greater than 1 and the absolute value of the difference between the drug area and the preset area is greater than a second threshold; the second threshold is greater than the first threshold; and to determine that the image block has a missing defect when the number of connected components is equal to 1 and the absolute value of the difference between the drug area and the preset area is greater than a third threshold.

[0196] Each module in the aforementioned blister pack drug quality testing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the computer device's memory as software, so that the processor can call and execute the corresponding operations of each module.

[0197] In one embodiment, a computer device is provided, which can be a blister drug quality testing device, a server, or a testing terminal, etc., and its internal structure diagram can be as follows. Figure 18 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computational and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database stores preset segmentation threshold templates for different types of blister packs, image data to be detected, or quality inspection results corresponding to the images to be detected. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a method for quality inspection of blister packs.

[0198] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 18 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements a method for quality testing of blister pack pharmaceuticals. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.

[0199] Those skilled in the art will understand that Figure 18 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0200] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the blister drug detection method in the above embodiments.

[0201] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the blister drug detection method in the above embodiments.

[0202] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the blister drug detection method in the above embodiments.

[0203] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0204] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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.

[0205] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A blister medicine quality detection method characterized by, The method includes: The image to be detected is divided into regions according to the drug particles to obtain multiple image blocks; the image to be detected is the image corresponding to a preset type of blister drug, and each image block includes at least one of the drug particles. For each image block, a segmentation threshold corresponding to the image block is determined from a preset segmentation threshold template of the image to be detected; Based on the segmentation threshold corresponding to the image block, the drug region in the image block is segmented to obtain the drug region corresponding to the image block; Quality inspection is performed on the drug region corresponding to each image block to obtain the quality inspection result of the image to be inspected; the quality inspection result includes any one of the following: drug has no defects, drug has defects, or defect type.

2. The method of claim 1, wherein, The method further includes: Obtain sample images of the preset type of blister pack medicine, and divide the sample images into regions according to the medicine particles to obtain multiple sample image blocks; For each of the sample image blocks, calculate the local mean of each pixel in the sample image block; For each pixel in the sample image block, a segmentation threshold corresponding to the pixel is calculated based on the local mean of the pixel and the gray value of the pixel. Based on the segmentation threshold corresponding to each pixel in each sample image block, a preset segmentation threshold template corresponding to the preset type of blister drug is generated.

3. The method of claim 2, wherein, The step of calculating the local mean of each pixel in each sample image block includes: For each pixel in each of the sample image blocks, a preset local window corresponding to the pixel is determined according to a preset window size; Calculate the sum of the grayscale values ​​of all pixels within the preset local window; The quotient of the sum of the gray values ​​and the area of ​​the preset local window is used as the local mean of the pixel.

4. The method of claim 3, wherein, The step of generating a preset segmentation threshold template corresponding to the preset type of blister pack medicine based on the segmentation threshold corresponding to each pixel in each sample image block includes: For each of the sample image blocks, determine whether the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions; If so, the segmentation threshold corresponding to each pixel in the sample image block is added to the preset segmentation threshold template; If not, update the preset window size and re-execute the step of calculating the segmentation threshold of each pixel in the sample image block until the segmentation threshold corresponding to each pixel in the sample image block meets the preset condition. Then, add the segmentation threshold corresponding to each pixel in the sample image block that meets the preset condition to the preset segmentation threshold template to obtain the preset segmentation threshold template corresponding to the preset type of blister drug.

5. The method of claim 4, wherein, The step of determining whether the segmentation threshold corresponding to each pixel in the sample image block meets the preset conditions includes: Based on the segmentation threshold corresponding to each pixel in the sample image block, the sample image block is segmented to obtain the segmented image corresponding to the sample image block; Determine the number of connected components in the segmented image corresponding to the sample image block; If the number of the connected domains is equal to 1, it is determined that the segmentation threshold corresponding to each pixel point in the sample image block satisfies a preset condition.

6. The method of claim 1, wherein, The quality detection result of the image block is determined according to the number of the connected domains and the medicine area. For each image block, the number of connected domains of the medicine area corresponding to the image block and the medicine area of the medicine area are determined. The quality detection result of the image block is determined according to the number of the connected domains and the medicine area. The quality detection result of the image block is determined according to the number of the connected domains and the medicine area.

7. The method of claim 6, wherein, The quality detection result of the image block is determined according to the number of the connected domains and the medicine area. If the number of the connected domains is greater than 1, and the absolute value of the difference between the medicine area and the preset area is less than a first threshold, it is determined that the image block has a crack defect. If the number of the connected domains is greater than 1, and the absolute value of the difference between the medicine area and the preset area is greater than a second threshold, it is determined that the image block has a sugar coating discoloration defect; the second threshold is greater than the first threshold. If the number of the connected domains is equal to 1, and the absolute value of the difference between the medicine area and the preset area is greater than a third threshold, it is determined that the image block has a defect.

8. A blister medicine detection device, characterized in that, The device comprises: An acquisition module is configured to divide a to-be-detected image into a plurality of image blocks according to medicine particles, the to-be-detected image being an image corresponding to a bubble cap medicine of a preset type, and each image block comprising at least one medicine particle. A segmentation module is configured to determine, for each image block, a segmentation threshold corresponding to the image block from a preset segmentation threshold template of the to-be-detected image, and perform image segmentation on a medicine area in the image block according to the segmentation threshold corresponding to the image block to obtain a medicine area corresponding to the image block. A detection module is configured to perform quality detection on the medicine area corresponding to each image block to obtain a quality detection result of the to-be-detected image, the quality detection result comprising any one of no defect, defect, and defect type.

9. The apparatus of claim 8, wherein, The device further comprises a segmentation threshold template generation module, which comprises: An acquisition unit is configured to acquire a sample image of the bubble cap medicine of the preset type, and divide the sample image into a plurality of sample image blocks according to medicine particles. A first calculation unit is configured to calculate, for each sample image block, a local mean value of each pixel point in the sample image block. A second calculation unit is configured to calculate, for each pixel point in the sample image block, a segmentation threshold corresponding to the pixel point according to the local mean value of the pixel point and a gray value of the pixel point. A generation unit is configured to generate a preset segmentation threshold template corresponding to the bubble cap medicine of the preset type according to the segmentation threshold corresponding to each pixel point in each sample image block.

10. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that, The processor executes the computer program to implement the steps of the method of any one of claims 1 to 7.

11. A computer readable storage medium having stored thereon a computer program, characterized in that The computer program, which when executed by a processor, implements the steps of the method of any one of claims 1 to 7.

12. A computer program product comprising a computer program, characterized in that, The computer program, which when executed by a processor, implements the steps of the method of any one of claims 1 to 7.

Citation Information

Patent Citations

  • Defect detection method for electronic component

    CN115018828A