CN119399157A - A drug image detection method based on improved Canny operator - Google Patents
A drug image detection method based on improved Canny operator Download PDFInfo
- Publication number
- CN119399157A CN119399157A CN202411484262.XA CN202411484262A CN119399157A CN 119399157 A CN119399157 A CN 119399157A CN 202411484262 A CN202411484262 A CN 202411484262A CN 119399157 A CN119399157 A CN 119399157A
- Authority
- CN
- China
- Prior art keywords
- gradient
- improved
- edge
- points
- value
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/0002—Inspection of images, e.g. flaw detection
- G06T7/0004—Industrial image inspection
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T5/00—Image enhancement or restoration
- G06T5/20—Image enhancement or restoration using local operators
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Quality & Reliability (AREA)
- Image Analysis (AREA)
Abstract
The invention discloses a medicine image detection method based on an improved Canny operator, which comprises the steps of 1) collecting medicine images, carrying out gray processing on the medicine images, 2) adopting an improved bilateral filter to filter the medicine images after gray processing to restrain noise, 3) adopting a four-way Soble operator to extract gradient amplitude values and phases of the medicine images, 4) adopting improved non-maximum value restraining to carry out non-maximum value restraining on the extracted gradient amplitude values and phases to accurately position target edges, 5) adopting Otsu based on gradient edge information to carry out self-adaptive threshold extraction to obtain medicine image edge contours, and 6) outputting medicine image edge contours. The interference to the central pixel point is effectively reduced by adjusting the weight value of the edge pixel point recognized by the bilateral filter to zero, so that the target edge and detail characteristics of the image are reserved to the maximum extent.
Description
Technical Field
The invention relates to a medicine image detection method based on an improved Canny operator.
Background
The quality control of the medicines is important, and the medicine production qualification rate can be improved through the detection of the medicines, so that the possibility that consumers buy medicines with quality problems is avoided.
Image edge detection technology is one of the important technologies in digital image processing for detecting and enhancing object edges and contours in images. Image edges refer to places in the image where grey values are abrupt, typically corresponding to edges or contours between objects. The edge information has key effects on applications such as target detection, image segmentation, feature extraction and the like. In the image edge processing, the common first-order differential operators include Roberts operator, kirsch operator, sobel operator and the like, and the second-order differential operators include Laplace operator, log operator, doG operator and the like. The first-order operator has stronger universality, but cannot meet the requirements for processing images with complex noise and more edge details. However, the second order operator commonly adopts gaussian filtering, which has a good filtering effect on gaussian noise, and when an image contains a plurality of noise fusion, the gaussian filtering can cause edge blurring. Based on the detection method, the invention designs a medicine image detection method based on an improved Canny operator.
Disclosure of Invention
The invention aims to solve the problems in the prior art and provides a medicine image detection method based on an improved Canny operator.
The invention adopts the technical scheme that:
a medicine image detection method based on an improved Canny operator comprises the following steps:
1) Collecting a medicine image, and carrying out gray-scale treatment on the medicine image;
2) Filtering the medicine image after graying treatment by adopting an improved bilateral filter, and inhibiting noise;
3) Carrying out gradient amplitude and phase extraction on the medicine image by adopting a four-direction Soble operator;
4) Performing non-maximum suppression on the extracted gradient amplitude and phase by adopting improved non-maximum suppression, and accurately positioning the edge of the target;
5) Performing adaptive threshold extraction by using Otsu improved based on gradient edge information to obtain an edge profile of a medicine image;
6) And outputting the medicine image.
Further, in step 2), the improvement of the bilateral filter is to improve the weighting function coefficient in the bilateral filter, and the process is as follows:
in the bilateral filter, the weighted value of the neighborhood pixel value determines the value of the output pixel, and the expression is as follows:
Wherein,
(I, j) is a coordinate point of other coefficients of the template window, (k, l) is a central coordinate point of the template window, f (i, j) is a pixel value of the point (i, j), f (k, l) is a pixel value of the point (k, l), ω (i, j, k, l) is a weighting coefficient, σ d is a spatial standard deviation, and σ r is a gray standard deviation;
the weighting function coefficient ω (i, j, k, l) is obtained by multiplying a domain kernel by an improved value domain kernel, the domain kernel being as follows:
The improvement of the value domain core is as follows:
constructing a bilateral filtering threshold value:
T=exp(-σ)
t is a bilateral filtering threshold value, and sigma is the standard deviation of the image;
the modified value range kernel function is as follows:
Delta is the difference between the gray values of the central pixel point and other pixel points, and L is the gray level of the image;
the weighting function coefficient ω (i, j, k, l) is specifically as follows:
further, the specific process of the step 3) is as follows:
Expanding a 2X 2 convolution template in a Canny operator into a Soble convolution template of 3X 3, and adding two gradient directions of 45 degrees and 135 degrees on the basis of the original two gradient directions of horizontal and vertical, wherein matrix templates in the four directions are as follows:
traversing the pixel gray value f (x, y) through four matrix templates, wherein the calculation formula is as follows:
Gx=(f(x+1,y-1)+2f(x+1,y)+f(x+1,y+1))-
(f(x-1,y-1)+2f(x-1,y)+f(x-1,y+1))
Gy=(f(x-1,y-1)+2f(x,y-1)+f(x+1,y-1))-
(f(x-1,y+1)+2f(x,y+1)+f(x+1,y+1))
G45°=(f(x,y-1)+2f(x+1,y-1)+f(x+1,y))-
(f(x-1,y)+2f(x-1,y+1)+f(x,y+1))
G135°=(f(x-1,y)+2f(x-1,y-1)+f(x,y-1))-
(f(x+1,y)+2f(x+1,y+1)+f(x,y+1))
Gradient components in 4 directions are obtained, denoted G x,Gy,G45° and G 135°, respectively, and finally the gradient magnitude and gradient direction are calculated from these 4 gradient components:
Further, in step 4), the improvement of the non-maximum suppression method includes:
In the non-maximum value inhibition process of the Canny operator, expanding the 8 neighborhood to the 16 neighborhood, and lifting the pixel points corresponding to the gradient direction angles from 4 to 8, wherein the following conditions are satisfied:
P(x,y)>M(x+i,y+j)+D(x+i,y+j)
P(x,y)>M(x-i,y-j)+D(x-i,y-j)
Wherein,
P (x, y) is the coordinate of the pixel point to be judged, D is the average value of the local neighborhood deviation values of each point in the 3X 3 neighborhood, and M is the average value in the neighborhood to replace the corresponding point.
Further, in step 5), the improvement Otsu adaptive threshold extraction is specifically:
dividing all the uninhibited edge points into foreground target classes and background classes according to gray values, and uniformly dividing the uninhibited points into 64 stages at intervals according to gradient amplitude values;
s is the number of all pixel points which are not inhibited;
n i -the number of i-th level pixel points;
probability of p i -ith level in all extreme points;
The target gradient mean value and the background gradient mean value correspond to:
T-distinguishing a target point from a background point threshold;
-a target gradient probability;
-background gradient probability;
All non-suppressed edge point gradient means are:
u=ub(T)ωb(T)+uo(T)ωo(T)
The variance between the target point and the background point is as follows:
σ2(T)=ωb(T)[ub(T)-u]2+ωo(T)[uo(T)-u]2
when the inter-class variance is maximum, the misclassification probability of the background point and the target point is minimum;
Selecting a gradient amplitude T h corresponding to the maximum inter-class variance as a high threshold;
If the number of T h is larger than 1, selecting the minimum value of T h as a high threshold value, and selecting the low threshold value T l to be T l=Th x 0.4.
The invention has the following beneficial effects:
1) The improved bilateral filter filters the image, and the interference to the central pixel point is effectively reduced by adjusting the weight value of the edge pixel point recognized by the bilateral filter to zero, so that the target edge and detail characteristics of the image are reserved to the maximum extent;
2) The improved non-maximum value suppression method improves the accuracy of judging the non-edge points and avoids suppressing the edge points;
3) The improved Otsu self-adaptive threshold selection improves the segmentation precision of image details and edges, and retains rich weak edge information.
Drawings
FIG. 1 is a flow chart of the present invention.
Fig. 2 shows the gradient direction corresponding (3×3) neighborhood.
Fig. 3 shows the number of the neighborhood center point corresponding to the gradient direction θ.
Fig. 4 is a filtered drug image.
FIG. 5 is an edge contour map extracted after non-maximum suppression and thresholding.
Detailed Description
The invention is further described below with reference to the accompanying drawings.
As shown in FIG. 1, the medicine image detection method based on the improved Canny operator comprises the following steps:
1) After the medicine processing is finished, the medicine is conveyed to the lower part of the CCD camera through the conveying belt to collect pictures, and the pictures are fed back to the PC end for gray processing.
2) And filtering the medicine image after the graying treatment by adopting an improved bilateral filter, and inhibiting noise.
In the bilateral filter, the weighted value of the neighborhood pixel value determines the value of the output pixel, and the expression is as follows:
Wherein,
(I, j) is a coordinate point of other coefficients of the template window, (k, l) is a center coordinate point of the template window, f (i, j) is a pixel value of the point (i, j), f (k, l) is a pixel value of the point (k, l), ω (i, j, k, l) is a weighting coefficient, σ d is a spatial standard deviation, and σ r is a gray standard deviation.
The weighting function coefficient ω (i, j, k, l) is obtained by multiplying a domain kernel by an improved value domain kernel, the domain kernel being as follows:
because the bilateral filter considers the weight of the gray information of the pixel points, the value domain kernel function is improved in order to avoid that each pixel point participates in filtering with a certain weight, thereby causing adverse effect on the center point.
Constructing a bilateral filtering threshold value:
T=exp(-σ)
T is the bilateral filtering threshold and sigma is the standard deviation of the image.
The modified value range kernel function is as follows:
Delta is the difference between the gray value of the central pixel point and the gray value of other pixel points, and L is the gray level of the image.
The definition domain kernel is multiplied by the modified value domain kernel to obtain a weighting function coefficient ω (i, j, k, l), which is specifically shown as follows:
The interference to the central pixel point is effectively reduced by adjusting the weight value of the edge pixel point recognized by the bilateral filter to zero, so that the target edge and detail characteristics of the image are reserved to the maximum extent.
3) Gradient amplitude and phase extraction are carried out on the medicine image by adopting a four-direction Soble operator;
The 2X 2 convolution template in the traditional Canny edge detection algorithm is expanded into a 3X 3 Soble convolution template, and two gradient directions of 45 degrees and 135 degrees are added on the basis of the original horizontal gradient direction and the original vertical gradient direction, so that more edge information is reserved. The matrix templates for the four directions are as follows:
traversing the pixel gray value f (x, y) through the four matrix templates, wherein the specific calculation formula is as follows:
Gx=(f(x+1,y-1)+2f(x+1,y)+f(x+1,y+1))-
(f(x-1,y-1)+2f(x-1,y)+f(x-1,y+1))
Gy=(f(x-1,y-1)+2f(x,y-1)+f(x+1,y-1))-
(f(x-1,y+1)+2f(x,y+1)+f(x+1,y+1))
G45°=(f(x,y-1)+2f(x+1,y-1)+f(x+1,y))-
(f(x-1,y)+2f(x-1,y+1)+f(x,y+1))
G135°=(f(x-1,y)+2f(x-1,y-1)+f(x,y-1))-
(f(x+1,y)+2f(x+1,y+1)+f(x,y+1))
Gradient components in 4 directions are obtained, denoted G x,Gy,G45° and G 135°, respectively, and finally the gradient magnitude and gradient direction are calculated from these 4 components:
4) And performing non-maximum suppression on the gradient amplitude by adopting improved non-maximum suppression, eliminating part of non-edge points, and accurately positioning the target edge.
As shown in fig. 2 and 3, partial non-edge points can be eliminated by using non-maximum suppression, and edge points are easily suppressed by noise gradient points in the 8-neighborhood region, so that erroneous judgment is caused. For this problem, the 8 neighborhood is expanded to the 16 neighborhood. The invention promotes the corresponding pixel points of the gradient direction angles from 4 to 8. And replacing the corresponding point by using the average value M in the neighborhood (shown in figure 2) of the corresponding pixel point (3 multiplied by 3), and calculating the local neighborhood deviation value average value D of each point in the neighborhood of the corresponding point (3 multiplied by 3).
And comparing the edge point to be judged with the sum of the multi-point mean value in the gradient direction neighborhood and the local neighborhood deviation mean value, and retaining the edge point when the edge point to be judged is the maximum value.
P(x,y)>M(x+i,y+j)+D(x+i,y+j)
P(x,y)>M(x-i,y-j)+D(x-i,y-j)
Wherein,
5) And (3) performing adaptive threshold extraction by using Otsu improved based on gradient edge information to obtain a medicine image edge profile, and finally performing medicine image output. Fig. 4 is a medicine image, and fig. 5 is an extracted edge profile after non-maximum suppression and thresholding.
Dividing all the uninhibited edge points into foreground target classes and background classes according to gray values. The uninhibited points are evenly spaced apart into 64 stages according to gradient magnitude.
In the formula, S is the number of all pixel points which are not inhibited
N i -the number of i-th level pixel points;
p i -probability of the ith stage in all extreme points.
The target gradient mean value and the background gradient mean value are as follows:
T-distinguishing a target point from a background point threshold;
-a target gradient probability;
-background gradient probability.
All non-suppressed edge point gradient means are:
u=ub(T)ωb(T)+uo(T)ωo(T)
The variance between the target point and the background point is as follows:
σ2(T)=ωb(T)[ub(T)-u]2+ωo(T)[uo(T)-u]2
When the inter-class variance is maximum, the misclassification probability of the background point and the target point is minimum.
The maximum inter-class variance corresponds to the gradient magnitude T h as the high threshold.
If the number of T h is greater than 1, the minimum value of T h is selected as the high threshold value in order to obtain rich weak edge information. The low threshold T l selects T l=Th x 0.4.
The foregoing is merely a preferred embodiment of the invention, and it should be noted that modifications could be made by those skilled in the art without departing from the principles of the invention, which modifications would also be considered to be within the scope of the invention.
Claims (5)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202411484262.XA CN119399157A (en) | 2024-10-23 | 2024-10-23 | A drug image detection method based on improved Canny operator |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202411484262.XA CN119399157A (en) | 2024-10-23 | 2024-10-23 | A drug image detection method based on improved Canny operator |
Publications (1)
Publication Number | Publication Date |
---|---|
CN119399157A true CN119399157A (en) | 2025-02-07 |
Family
ID=94423548
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202411484262.XA Pending CN119399157A (en) | 2024-10-23 | 2024-10-23 | A drug image detection method based on improved Canny operator |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN119399157A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN120088262A (en) * | 2025-05-06 | 2025-06-03 | 陕西六川通汇智能科技有限公司 | A method for detecting image quality of silver electrode substrate based on machine vision |
-
2024
- 2024-10-23 CN CN202411484262.XA patent/CN119399157A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN120088262A (en) * | 2025-05-06 | 2025-06-03 | 陕西六川通汇智能科技有限公司 | A method for detecting image quality of silver electrode substrate based on machine vision |
CN120088262B (en) * | 2025-05-06 | 2025-07-18 | 陕西六川通汇智能科技有限公司 | Silver electrode substrate image quality detection method based on machine vision |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112819772B (en) | High-precision rapid pattern detection and recognition method | |
CN114529459B (en) | Method, system and medium for enhancing image edge | |
Bieniecki et al. | Image preprocessing for improving ocr accuracy | |
CN105740876B (en) | A kind of image pre-processing method and device | |
CN104268872B (en) | Consistency-based edge detection method | |
CN115063421B (en) | Pole piece region detection method, system and device, medium and defect detection method | |
CN109377450B (en) | Edge protection denoising method | |
CN117853510A (en) | Canny edge detection method based on bilateral filtering and self-adaptive threshold | |
CN108346148B (en) | A system and method for detecting oxidized area of high-density flexible IC substrate | |
CN119399157A (en) | A drug image detection method based on improved Canny operator | |
CN105139391B (en) | A kind of haze weather traffic image edge detection method | |
CN115909353B (en) | Image binarization processing method and device | |
CN109903254B (en) | An Improved Bilateral Filtering Method Based on Poisson Kernel | |
CN111429372A (en) | Method for enhancing edge detection effect of low-contrast image | |
CN103778613A (en) | Polarization SAR image filtering method for window self-adaptation | |
CN113554695A (en) | Intelligent part hole site identification and positioning method | |
CN114092468A (en) | Standard target counting method based on machine vision | |
CN112967304A (en) | Edge detection algorithm for multi-edge window collaborative filtering | |
Wu et al. | An Improved canny edge detection algorithm with iteration gradient filter | |
CN115984863A (en) | Image processing method, device, equipment and storage medium | |
CN113887477A (en) | A method of parcel extraction based on UAV high-score images | |
Kusnik et al. | On the robust technique of mixed Gaussian and impulsive noise reduction in color digital images | |
CN111539877A (en) | Cartoon style edge enhancement image sharpening method | |
CN117710287A (en) | Material detection method and device, electronic equipment and storage medium | |
CN104966271A (en) | Image denoising method based on biological vision receptive field mechanism |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |