A pneumonia image edge detection method based on an improved Canny algorithm
By improving the Canny algorithm and combining it with the CLAHE and Otsu algorithms, the problem of unclear edge recognition in lung CT images of COVID-19 patients was solved, achieving higher detection accuracy and efficiency, and providing clear image edge information to support doctors' diagnosis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WUXI UNIV
- Filing Date
- 2022-11-04
- Publication Date
- 2026-05-15
AI Technical Summary
Existing deep learning algorithms are not clear enough in edge recognition of lung CT images of COVID-19 patients, resulting in low detection accuracy and affecting the accuracy of doctors' diagnoses.
An improved Canny algorithm is adopted, which enhances the image through the contrast-limited CLAHE algorithm, combines a bilateral filter to remove noise, and uses the Otsu algorithm to adaptively select the threshold, thereby improving the adaptability and accuracy of edge detection.
It significantly improves the accuracy and efficiency of edge detection in pneumonia images, and the detected edges are clearer and more complete, meeting the needs of doctors for lung CT image diagnosis.
Smart Images

Figure CN115631179B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image detection technology, and in particular to a method for edge detection of pneumonia images based on an improved Canny algorithm. Background Technology
[0002] Lung CT imaging is an examination that needs to be performed multiple times during the screening, diagnosis and treatment of COVID-19 patients. The results of lung CT imaging can distinguish between normal lungs, ordinary pneumonia and COVID-19, thereby monitoring the recovery of COVID-19 patients. By comparing the lesion data in multiple lung CT images, the condition of the lesions can be judged, thereby obtaining the patient's disease progression and determining their degree of recovery.
[0003] At present, the diagnosis and treatment of COVID-19 patients still mainly rely on doctors to judge the lesions in the lung CT images. Doctors give diagnostic results based on their professional knowledge and experience. In order to ensure that doctors give correct and reliable diagnostic results, it is necessary to provide doctors with accurate and clear lung CT images of patients. A lung image with clear edges and a high signal-to-noise ratio is a key step in the diagnosis and treatment of COVID-19 patients.
[0004] There has been relevant research on the technology of recognizing chest CT images of COVID-19 based on deep learning. It mainly uses deep learning algorithms to enable optimized convolutional models to automatically identify lesions in lung images of COVID-19 patients, thereby determining whether the patient has COVID-19 and the progression of the disease. However, the edge recognition results of the current recognition methods are not clear enough and the detection accuracy is low. Summary of the Invention
[0005] This invention provides a pneumonia image edge detection method based on an improved Canny algorithm, which can achieve clear detection of pneumonia image edges and improve the accuracy of pneumonia image edge detection.
[0006] To achieve the above effects, the technical solution of the present invention is as follows:
[0007] A method for edge detection in pneumonia images based on an improved Canny algorithm includes the following steps:
[0008] Step S1: Perform contrast enhancement processing on the input original pneumonia image to obtain an enhanced image;
[0009] Step S2: Perform bilateral filtering on the enhanced image to obtain a denoised image;
[0010] Step S3: Perform Gaussian filtering on the denoised image to obtain the filtered image;
[0011] Step S4: Calculate the gradient of the filtered image to obtain the gradient image;
[0012] Step S5: Apply non-maximum suppression to the gradient image and use the Otsu algorithm to find the optimal point for the segmentation threshold to obtain the edge image.
[0013] It should be noted that the gradient of the filtered image in step S4 is calculated using the CLAHE algorithm.
[0014] Furthermore, in step S1, the contrast enhancement uses the contrast-limited CLAHE algorithm to enhance the contrast of the original pneumonia image.
[0015] Furthermore, step S1 specifically involves:
[0016] Step S1.1: Segment the input original pneumonia image into sub-blocks of the same size that are adjacent but do not overlap;
[0017] Step S1.2: Based on the pixel information contained in each sub-block image, calculate the gray-level histogram H(i) of each sub-block image, where i represents the gray level;
[0018] Step S1.3: Calculate the average pixel value N for the sub-block image. Aver This makes the number of pixels with the same gray level in the sub-block image equal;
[0019] Step S1.4: Set a clipping limit coefficient γ, based on the average pixel value N. Aver Obtain the actual shear limit value N CL ;
[0020] Step S1.5: Extract the values of N from the grayscale histogram H(i) that exceed the actual shearing limit. CL The pixels are extracted and redistributed evenly to the gray levels of each sub-block image to obtain a new local histogram W(i).
[0021] Step S1.6: Perform equalization processing on the local new histogram W(i) of each sub-block image;
[0022] Step S1.7: Use bilinear interpolation to obtain new gray values from the new local histogram W(i) after equalization to obtain the enhanced image.
[0023] Furthermore, in step S1.3, the pixel average value N Aver Represented as:
[0024]
[0025] Where, δ x δ represents the number of pixels in the sub-block image in the horizontal direction; y L represents the number of pixels in the vertical direction of the sub-block image; GrayThis indicates the number of gray levels in the sub-block image.
[0026] Furthermore, in step S1.4, the shear limit coefficient γ ranges from 0 to 1, with a default value of 0.01.
[0027] Furthermore, in step S1.4, the actual shear limit value N CL Represented as:
[0028] N CL =N Aver +[γ×(δ x ×δ y -N Aver )).
[0029] Furthermore, step S1.5 specifically involves assuming that the total number of pixels extracted is N. Clip Calculate the number of pixels N assigned to each gray level i. Acp for:
[0030]
[0031] Where, N Clip =∑ i {max[H(i)-N CL ]}
[0032] Let W(i) represent the new local histogram obtained after the allocation, and W(i) be the piecewise function, expressed as:
[0033]
[0034] At this point, the total number of pixels N after cropping is... Clip for:
[0035]
[0036] If there are any pixels remaining after allocation, these remaining pixels are then cyclically allocated. During this cyclical allocation, the remaining pixels are evenly distributed to areas smaller than the clipping limit value N. CL In the grayscale levels, until the remaining pixels are fully allocated.
[0037] This invention proposes an improvement to the Canny algorithm. First, it utilizes the contrast-limited CLAHE algorithm to enhance image contrast. Then, it employs a bilateral filter to remove salt-and-pepper noise and uses the Otsu algorithm to adaptively select the threshold, enhancing the adaptability of the Canny algorithm. The improved Canny algorithm, when used in pneumonia image detection, extracts clearer and more complete image edges, making it easier to distinguish between normal lungs, ordinary pneumonia, and COVID-19 through the output image. It can be effectively applied to pneumonia image detection, meeting the needs of doctors in their actual work.
[0038] Furthermore, step S2 specifically involves assuming that the grayscale value of the enhanced image at coordinate point p = (x, y) is I. p Bilateral filtering is applied to the enhanced image to remove salt-and-pepper noise, resulting in a denoised image BI. The gray value of the denoised image BI at coordinate point p is defined as BI. P The bilateral filtering formula for a bilateral filter is as follows:
[0039]
[0040]
[0041] In the above formula, q = (u, v) represents the neighborhood pixels of coordinate point p, and I q Let W be the gray value of a neighboring pixel q, S be the set of neighboring pixels q, and W be the gray value of a neighboring pixel q. p Normalization factor;
[0042] The spatial proximity factor is expressed as follows:
[0043]
[0044] In the above formula, σ s It is based on the standard deviation of the distance using a Gaussian function.
[0045] The gray-scale similarity factor is expressed as follows:
[0046]
[0047] In the above formula, σ r It is the gray standard deviation based on the Gaussian function.
[0048] It should be noted that σ s and σ r The spatial domain filtering kernel function was controlled separately. and grayscale filtering kernel function The radial range of action is a selectable parameter that directly determines the performance of the bilateral filter. The weighting value of the pixel is adjusted by controlling the relative space of the pixel position and the range of grayscale variation.
[0049] Further, step S5 specifically involves performing non-maximum suppression on the gradient of each pixel in the gradient image along the gradient direction to obtain a suppressed image; let F represent the suppressed image, with a total grayscale value of (0, M-1) and grayscale levels of M. The resolution of the suppressed image F is R×S, and let n... i For a pixel with gray level i, P i Let P be the probability of a pixel with gray level i appearing. i Represented as:
[0050]
[0051] Set the segmentation threshold The Otsu algorithm divides the suppressed image F into foreground C0 and background C1 according to the segmentation threshold k. The segmentation result of the suppressed image F is expressed as:
[0052]
[0053] In the formula, the suppressed image F with a gray level less than k is included in the image foreground C0, and vice versa, it is included in the image background C1;
[0054] The variance of the image foreground C0 was calculated separately. The variance of the image background C1 and They are represented as follows:
[0055]
[0056]
[0057] In the formula, ω0 and ω1 represent the probabilities of the image foreground C0 and the image background C1 appearing, respectively; μ0 and μ1 represent the mean gray levels of the image foreground C0 and the image background C1, respectively.
[0058] Calculate the inter-class variance for the foreground C0 and the background C1 of the image. When inter-class variance When the value is at its maximum, the optimal point for the suppression image F segmentation threshold k is obtained, which is the edge image;
[0059] Wherein, the segmentation threshold k is expressed as:
[0060]
[0061] Furthermore, inter-class variance Represented as:
[0062]
[0063] in:
[0064] It should be noted that the variance between classes... The value indicates the degree of pixel difference between the image foreground C0 and the image background C1, as well as the quality of the separation effect. This invention selects the optimal point for the segmentation threshold, making the extracted edge contours of the pneumonia image more accurate and clearer. Selecting the optimal point for the segmentation threshold means choosing from the threshold values.
[0065] In the above scheme, the interception in step S5 is also called cutting.
[0066] This invention employs the contrast-limited CLAHE algorithm and bilateral filtering to preprocess the original pneumonia image, thereby improving image contrast and filtering out salt-and-pepper noise. To further enhance adaptability, the Otsu algorithm is used to select a threshold, and the Canny algorithm is used to perform image edge detection.
[0067] The contrast-limited CLAHE algorithm evolved from the AHE algorithm. While AHE is suitable for improving local image contrast and capturing more image details, it suffers from over-amplifying noise in relevant regions. The CLAHE algorithm, by limiting the histogram of each region, effectively overcomes the shortcomings of AHE. The CLAHE algorithm improves local image contrast and suppresses noise amplification.
[0068] Compared with the prior art, the beneficial effects of the technical solution of the present invention are:
[0069] This invention primarily aims to enable physicians to quickly and accurately interpret lung images when diagnosing patients using CT scans. By improving the Canny algorithm, the contrast-limited CLAHE algorithm is used to enhance the contrast of the original pneumonia image, and a bilateral filter removes salt-and-pepper noise, thus not only enhancing image contrast but also achieving edge-preserving denoising. The Otsu algorithm is used to select a threshold, enhancing the adaptability of the Canny algorithm. The improved Canny algorithm is applied to edge detection in images of normal lungs, ordinary pneumonia, and COVID-19, extracting clearer and more complete image edges. The edges detected by the improved Canny algorithm in pneumonia images have more detail and more distinct contours, significantly improving detection efficiency and accuracy, increasing PSNR (Peak Signal-to-Noise Ratio), and addressing the problem of low accuracy in pneumonia image edge detection in existing edge detection methods. Attached Figure Description
[0070] The accompanying drawings are for illustrative purposes only and should not be construed as limiting the invention. To better illustrate this embodiment, some components in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understood by those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0071] Figure 1 This is a flowchart of the detection method provided in an embodiment of the present invention;
[0072] Figure 2 This is a schematic diagram of pixel allocation in step S1.5 provided in an embodiment of the present invention;
[0073] Figure 3 This is a schematic diagram of the input image provided in an embodiment of the present invention;
[0074] Figure 4This is a schematic diagram illustrating the detection results of the traditional Canny algorithm for normal lungs, pneumonia, and COVID-19 provided in this embodiment of the invention.
[0075] Figure 5 This is a schematic diagram illustrating the detection results of the improved Canny algorithm in this invention on normal lungs, pneumonia, and COVID-19. Detailed Implementation
[0076] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0077] Example 1
[0078] For easier understanding, please refer to Figures 1-2 This invention provides an embodiment of a pneumonia image edge detection method based on an improved Canny algorithm, comprising the following steps:
[0079] Step S1: Apply the contrast-limited CLAHE algorithm to the input original pneumonia image to enhance its contrast and obtain an enhanced image;
[0080] Step S2: Apply a bilateral filter to the enhanced image to obtain a denoised image;
[0081] Step S3: Perform Gaussian filtering on the denoised image to obtain the filtered image;
[0082] Step S4: Calculate the gradient of the filtered image to obtain the gradient image;
[0083] Step S5: Apply non-maximum suppression to the gradient image and use the Otsu algorithm to find the optimal point for the segmentation threshold to obtain the edge image.
[0084] Contrast enhancement and bilateral filtering can be understood as preprocessing the original input pneumonia image.
[0085] This invention can be applied to edge detection in images of normal lungs, common pneumonia, and COVID-19. The improved Canny algorithm detects image edges with more detail and clearer contours, significantly improving detection efficiency and accuracy. It provides doctors with clearer and more detailed images of patients' lungs, enabling them to accurately assess patients' conditions and improve work efficiency. It is of great significance for the diagnosis, monitoring, treatment, and analysis of COVID-19.
[0086] Example 2
[0087] Specifically, based on Example 1, the solution will be described in conjunction with specific embodiments to further demonstrate its technical effects. Specifically:
[0088] Step S1: Apply the contrast-limited CLAHE algorithm to the input original pneumonia image to enhance its contrast and obtain an enhanced image;
[0089] Step S1.1: Segment the input original pneumonia image into sub-blocks of the same size that are adjacent but do not overlap;
[0090] Step S1.2: Based on the pixel information contained in each sub-block image, calculate the gray-level histogram H(i) of each sub-block image, where i represents the gray level;
[0091] Step S1.3: Calculate the average pixel value N for the sub-block image. Aver This makes the number of pixels with the same gray level in the sub-block image equal;
[0092] Pixel average value N Aver Represented as:
[0093]
[0094] Where, δ x δ represents the number of pixels in the sub-block image in the horizontal direction; y L represents the number of pixels in the vertical direction of the sub-block image; Gray This indicates the number of gray levels in the sub-block image.
[0095] Step S1.4: Set a clipping limit coefficient γ, based on the average pixel value N. Aver Obtain the actual shear limit value N CL The value of γ ranges from 0 to 1, with a default value of 0.01.
[0096] N CL Represented as:
[0097] N CL =N Aver +[γ×(δ x ×δ y -N Aver )];
[0098] Step S1.5: Extract the values of N from the grayscale histogram H(i) that exceed the actual shearing limit. CL The pixels are extracted and redistributed evenly to the gray levels of each sub-block image to obtain a new local histogram W(i).
[0099] Assume the total number of pixels extracted is N. Clip Calculate the number of pixels N assigned to each gray level i. Acp for:
[0100]
[0101] Where, N Clip =∑ i {max[H(i)-N CL ]}
[0102] Let W(i) represent the new local histogram obtained after the allocation, and W(i) be the piecewise function, expressed as:
[0103]
[0104] At this point, the total number of pixels N after cropping is... Clip for:
[0105]
[0106] If there are any pixels remaining after allocation, these remaining pixels are then cyclically allocated. During this cyclical allocation, the remaining pixels are evenly distributed to areas smaller than the clipping limit value N. CL In the grayscale levels, until the remaining pixels are fully allocated.
[0107] Step S1.6: Perform equalization processing on the local new histogram W(i) of each sub-block image;
[0108] Step S1.7: Use bilinear interpolation to obtain new gray values from the new local histogram W(i) after equalization to obtain the enhanced image.
[0109] Step S2: Apply a bilateral filter to the enhanced image to obtain a denoised image;
[0110] Suppose the gray value of the enhanced image at coordinate point p = (x, y) is I. p Bilateral filtering is applied to the enhanced image to remove salt-and-pepper noise, resulting in a denoised image BI. The gray value of the denoised image BI at coordinate point p is defined as BI. P The bilateral filtering formula for a bilateral filter is as follows:
[0111]
[0112]
[0113] In the above formula, q = (u, v) represents the neighborhood pixels of coordinate point p, and I q Let W be the gray value of a neighboring pixel q, S be the set of neighboring pixels q, and W be the gray value of a neighboring pixel q.p Normalization factor;
[0114] The spatial proximity factor is expressed as follows:
[0115]
[0116] In the above formula, σ s It is based on the standard deviation of the distance using a Gaussian function.
[0117] The gray-scale similarity factor is expressed as follows:
[0118]
[0119] In the above formula, σ r It is the gray standard deviation based on the Gaussian function.
[0120] Step S3: Perform Gaussian filtering on the denoised image to obtain the filtered image;
[0121] Step S4: Calculate the gradient of the filtered image to obtain the gradient image;
[0122] Step S5: A threshold is selected for the gradient image using non-maximum suppression and the Otsu algorithm. The gradient of each pixel in the gradient image is subjected to non-maximum suppression along the gradient direction to obtain a suppressed image. Let F represent the suppressed image, with a total grayscale value of (0, M-1) and grayscale levels of M. The resolution of the suppressed image F is R×S. Let n... i For a pixel with gray level i, P i Let P be the probability of a pixel with gray level i appearing. i Represented as:
[0123]
[0124] Set the segmentation threshold The Otsu algorithm divides the suppressed image F into foreground C0 and background C1 according to the segmentation threshold k. The segmentation result of the suppressed image F is expressed as:
[0125]
[0126] In the formula, the suppressed image F with a gray level less than k is included in the image foreground C0, and vice versa, it is included in the image background C1;
[0127] The variance of the image foreground C0 was calculated separately. The variance of the image background C1 and They are represented as follows:
[0128]
[0129]
[0130] In the formula, ω0 and ω1 represent the probabilities of the image foreground C0 and the image background C1 appearing, respectively; μ0 and μ1 represent the mean gray levels of the image foreground C0 and the image background C1, respectively.
[0131] Calculate the inter-class variance for the foreground C0 and the background C1 of the image. When inter-class variance When the value is at its maximum, the optimal point for the suppression image F segmentation threshold k is obtained, which is the edge image;
[0132] Wherein, the segmentation threshold k is expressed as:
[0133]
[0134] Between-class variance Represented as:
[0135]
[0136] in:
[0137] In the specific implementation process, the experimental environment of this invention uses Win10 Home Chinese version as the operating system, Matlab2017 and Python3.9 as the compilation language, and PyCharm 2021 as the IDE.
[0138] Figure 3 These are six original pneumonia images to be examined, among which... Figure 3 (a) Figure 3 (b) are normal lung samples n0001 and n0002, respectively; Figure 3 (c) Figure 3 (d) are pneumonia samples f0001 and f0002, respectively; Figure 3 (e) Figure 3 (f) are COVID-19 samples p0001 and p0002, respectively.
[0139] Figure 4 The results of testing normal lungs, pneumonia, and COVID-19 using the traditional Canny algorithm are shown in Figure 4(a). Figure 4 (b) The test results for normal lung samples n0001 and n0002, respectively; Figure 4 (c) Figure 4 (d) These are the test results for pneumonia samples f0001 and f0002, respectively; Figure 4 (e) Figure 4 (f) shows the test results of COVID-19 samples p0001 and p0002, respectively.
[0140] Figure 5 Figure 5(a) shows the detection results of the improved Canny algorithm of this invention on normal lungs, pneumonia, and COVID-19. Figure 5 (b) The test results for normal lung samples n0001 and n0002, respectively; Figure 5 (c) Figure 5 (d) These are the test results for pneumonia samples f0001 and f0002, respectively; Figure 5 (e) Figure 5 (f) These are the test results for COVID-19 samples p0001 and p0002, respectively.
[0141] By comparison, it can be seen that compared with the traditional Canny algorithm, the improved Canny algorithm of this invention can detect more edges and more details in pneumonia images when applied to the detection of normal lungs, pneumonia and COVID-19, and the detection accuracy is higher.
[0142] The improved Canny algorithm of this invention is compared with the traditional Canny algorithm based on the PSNR image quality evaluation index. The results are summarized in Table 1. Compared with the traditional algorithm, the improved Canny algorithm of this invention improves the PSNR by 7%-15%.
[0143] Table 1. Comparison of PSNR results between the improved Canny algorithm of this invention and the traditional algorithm.
[0144]
[0145] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the implementation of the present invention. Those skilled in the art will recognize that other variations or modifications can be made based on the above description. It is neither necessary nor possible to exhaustively describe all embodiments here. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the claims of the present invention.
Claims
1. A method for edge detection of pneumonia images based on an improved Canny algorithm, characterized in that, Includes the following steps: Step S1: Perform contrast enhancement processing on the input original pneumonia image to obtain an enhanced image; Step S2: Perform bilateral filtering on the enhanced image to obtain a denoised image; Step S3: Perform Gaussian filtering on the denoised image to obtain the filtered image; Step S4: Calculate the gradient of the filtered image to obtain the gradient image; Step S5: Apply non-maximum suppression to the gradient image and use the Otsu algorithm to find the optimal point for the segmentation threshold to obtain the edge image; In step S1, the contrast enhancement uses the contrast-limited CLAHE algorithm to enhance the contrast of the original pneumonia image; The contrast enhancement of the original pneumonia image using the contrast-limited CLAHE algorithm is specifically as follows: Step S1.1: Segment the input original pneumonia image into sub-blocks of the same size that are adjacent but do not overlap; Step S1.2: Calculate the grayscale histogram of each sub-block image based on the pixel information contained in each sub-block image. H ( i ), i Indicates grayscale level; Step S1.3: Calculate the average pixel value for the sub-block image. NAver This makes the number of pixels with the same gray level in the sub-block image equal; Step S1.4: Set a shear limit coefficient γ Based on the average pixel value NAver Obtain the actual shear limit value NCL ; Step S1.5: Extract the grayscale histogram H ( i (Exceeding the actual shear limit value) NCL The pixels are extracted and then redistributed evenly to the gray levels of each sub-block of the image to obtain a new local histogram. W ( i ); Step S1.6: Create a new local histogram for each sub-block image. W ( i Perform equalization processing; Step S1.7: Apply equalization to the new local histogram. W ( i The new grayscale value is obtained using bilinear interpolation to obtain the enhanced image; Average pixel value in step S1.3 NAver Represented as: in, δx This indicates the number of pixels in the sub-block image in the horizontal direction; δy This indicates the number of pixels in the vertical direction of the sub-block image; LGray Indicates the number of gray levels in the sub-block image; Shear constraint coefficient in step S1.4 γ The value range is from 0 to 1, and the default value is 0.01; Actual shear limit value in step S1.4 NCL Represented as: ; Step S1.5 specifically involves assuming the total number of pixels extracted is... NClip Calculate each gray level i Number of pixels allocated NAcp for: in, ; use W ( i () represents the new local histogram obtained after allocation. W ( i Let ) be a piecewise function, expressed as: At this point, the total number of pixels after cropping. NClip for: If there are pixels remaining after allocation, these remaining pixels are then allocated cyclically. During this cyclical allocation, the remaining pixels are evenly distributed to areas smaller than the clipping limit. NCL In the grayscale levels, until the remaining pixels are fully allocated; Step S2 specifically involves assuming the enhanced image is at coordinate point p =( x , y The grayscale value of ) Ip Bilateral filtering is applied to the enhanced image to remove salt-and-pepper noise, resulting in a denoised image. BI Denoising images BI At coordinate point p The grayscale value is defined as BIP The bilateral filtering formula for a bilateral filter is as follows: In the above formula, q =( u , v () represents the coordinates of the point. p The neighboring pixels, Iq For neighboring pixels q grayscale value, S For neighboring pixels q The set, Wp Normalization factor; The spatial proximity factor is expressed as follows: In the above formula, σs It is based on the standard deviation of the distance using a Gaussian function. The gray-scale similarity factor is expressed as follows: In the above formula, σr It is based on the gray standard deviation of the Gaussian function; Step S5 specifically involves performing non-maximum suppression on the gradient of each pixel in the gradient image along the gradient direction to obtain a suppressed image; using... F This represents a suppressed image, where the overall grayscale value is (0, ...). M -1), grayscale level is M Suppress image F The resolution is R × S ,set up ni grayscale i pixels, Pi grayscale i The probability of a pixel appearing. Pi Represented as: Set the segmentation threshold The Otsu algorithm is based on the segmentation threshold. k Suppress image F Divided into image foreground C 0 and image background C 1. Suppress image F The segmentation result is represented as: In the formula, the gray level is less than k Suppressed image F Contained in the foreground of the image C 0 in, and conversely, contained in the image background. C 1 in; The image foreground was calculated separately. C variance of 0 and image background C variance of 1 , and They are represented as follows: In the formula, ω 0 and ω 1 represents the foreground of the image. C 0 and image background C The probability of 1 appearing; μ 0 and μ 1 represents the foreground of the image. C 0 and image background C The average gray level of 1; Foreground of the image C 0 and image background C 1. Calculate the inter-class variance. When the inter-class variance reaches its maximum value, the suppressed image is obtained. F Segmentation threshold k The optimal point is where the edge image is obtained; Among them, the segmentation threshold k Represented as: ; Between-class variance Represented as: in: .