Image filtering method and device, computer equipment, storage medium and program product
Through sliding window templates and median filtering technology, the images collected by the electronic endoscope are filtered, solving the problem of poor image quality and improving image clarity and quality.
Patent Information
- Application Number
- CN202411993272.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-06-03
AI Technical Summary
During the image acquisition process, electronic endoscopes have poor image quality and reduced clarity and accuracy due to environmental complexity and noise interference.
Sliding window templates are used to slide on the original image, traversing each pixel and updating according to the size and pixel value of the sliding window template, and filtering the image through median filtering and discrete Gaussian convolution kernel calculation formulas.
It improves the clarity and quality of the images collected by the endoscopic, reduces the impact of noise, preserves the local details and characteristics of the image, and adapts to different image processing tasks and scene requirements.
Smart Images

Figure CN120091227A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of endoscopes, and particularly relates to an image filtering method, device, computer device, storage medium and program product. Background Art
[0002] An electronic endoscope is an electro-optical instrument integrating technologies such as optics, mechanics, and electricity, which is used to enter spaces that are not easily observable by the human eye for remote visual inspection. During the image acquisition process, since the electronic endoscope is often in a complex environment, the clarity and accuracy of the image are reduced. At the same time, the image signal is also interfered by various noises during the transmission process, resulting in image distortion and increased noise, which affects the quality and reliability of the image. Summary of the Invention
[0003] In view of this, the present invention provides an image filtering method, device, computer device, storage medium and program product to solve the problem of poor image quality collected by an electronic endoscope.
[0004] In a first aspect, the present invention provides an image filtering method, including: obtaining an original image collected by an endoscope and a preset sliding window template; controlling the sliding window template to slide on the original image in a preset order to traverse each pixel in the original image, and obtaining the original pixel value of each pixel; updating the original pixel value of each pixel in the original image according to the size of the sliding window template and each original pixel value to filter the original image.
[0005] The image filtering method provided by the embodiments of the present invention can adjust the size and shape of the sliding window template as needed to adapt to different types of images and filtering requirements. By traversing each pixel, each detail in the image can be processed, ensuring that the entire image is comprehensively processed during the filtering process. Since the filtering is calculated through the pixels in a local area, the local features of the image can be retained, which helps to maintain the details of the image. The shape and size of the sliding window template can be adjusted according to requirements to obtain different filtering effects, so as to meet different application requirements.
[0006] In an optional implementation manner, updating the original pixel value of each pixel in the original image according to the size of the sliding window template and each original pixel value includes: processing each first pixel value in a target window, and selecting a target median value in the first pixel values as the first target pixel value of the center point of the target window; where the target window is any area corresponding to the sliding window template during the sliding process on the original image; each first pixel value is the pixel value of each pixel point included in the target window; updating the original pixel value of each pixel in the original image according to the first target pixel value.
[0007] The image filtering method provided by the embodiments of the present invention updates the pixel values in the original image according to the size of the sliding window template and the pixel values in the target window, and can achieve the processing of local regions, which is beneficial to retaining the local details and features of the image. By selecting the median value in the target window as the target pixel value, the influence of noise can be effectively reduced, and the quality and clarity of the image can be improved. The size of the sliding window template and the selection strategy of the target window can be adjusted according to the actual situation to adapt to different image processing tasks and scene requirements. By selecting the median value as the target pixel value, complex pixel value calculations and filtering algorithms are avoided, the processing process is simplified, and the processing efficiency is improved. Median filtering can effectively retain the edge information in the image and will not produce excessive blurring effects, thus maintaining the clarity and recognition of the image.
[0008] In an alternative embodiment, processing the respective first pixel values in the target window and selecting the target median value among the first pixel values as the first target pixel value at the center point of the target window includes: sorting the multiple second pixel values corresponding to the respective target pixel rows in the target window from largest to smallest to obtain a sorting result; wherein the multiple second pixel values are the pixel values corresponding to the multiple first pixel points included in the target pixel row; comparing the multiple third pixel values corresponding to the respective target pixel columns in the sorting result to determine multiple candidate pixel values; wherein the multiple third pixel values are the pixel values corresponding to the multiple second pixel points included in the target pixel column; sorting the multiple candidate pixel values and determining the first median value among the multiple candidate pixel values as the first target pixel value.
[0009] The image filtering method provided by the embodiments of the present invention can compare and screen pixel values in multiple dimensions by sorting the pixel values corresponding to the respective target pixel rows and columns in the target window, improving the accuracy and reliability of the filtering effect. By performing multiple sorts and comparisons, determining multiple candidate pixel values, and then sorting the candidate pixel values, the most suitable target pixel value can be effectively screened out, improving the stability and robustness of the filtering algorithm. The parameters and behaviors of the filtering algorithm can be flexibly adjusted according to specific sorting rules and comparison strategies to adapt to different image processing tasks and application scenarios. By performing multiple sorts and comparisons, images with different complexities and noise levels can be adapted, having strong adaptability and generalization capabilities. Through a fine sorting and screening process, the target pixel value can be determined more accurately, thereby improving the filtering effect and making the quality of the processed image higher.
[0010] In an alternative embodiment, multiple third pixel values in each target pixel column in the sorting result are compared to determine multiple candidate pixel values, including: comparing multiple maximum pixel values corresponding to the first pixel column with the largest value in the sorting result, and determining the smallest pixel value among the multiple maximum pixel values as the first candidate pixel value; comparing multiple minimum pixel values corresponding to the second pixel column with the smallest value in the sorting result, and determining the largest pixel value among the multiple minimum pixel values as the second candidate pixel value; comparing multiple fourth pixel values corresponding to the third pixel column in the sorting result, and determining the second median value among the multiple fourth pixel values as the third candidate pixel value; wherein the third pixel column is any one of the pixel columns in the sorting result other than the first pixel column and the second pixel column.
[0011] The image filtering method provided by the embodiments of the present invention realizes the effect of multi-level screening by comparing the pixel columns with the largest and smallest values in the sorting result and selecting candidate pixel values therefrom, can more accurately determine the target pixel value, and improves the effect and performance of the filtering algorithm. By comparing the largest and smallest pixel values and selecting the most suitable candidate pixel value, outliers and noise can be effectively filtered out, and the stability and reliability of the filtering algorithm are improved. Through a fine comparison and selection process, the candidate pixel value can be more accurately determined, thereby improving the filtering effect and making the quality of the processed image higher.
[0012] In an alternative embodiment, according to the size of the sliding window template and each original pixel value, the original pixel values of each pixel in the original image are updated, including: determining the target discrete Gaussian convolution kernel corresponding to each pixel point in the target window according to the discrete Gaussian convolution kernel radius and the discrete Gaussian convolution kernel calculation formula; wherein the discrete Gaussian convolution kernel calculation formula is used to calculate the target discrete Gaussian convolution kernel according to the discrete Gaussian convolution kernel radius; the discrete Gaussian convolution kernel radius is determined according to the size of the sliding window template; multiplying the target discrete Gaussian convolution kernel by each first pixel value to obtain the second target pixel value of the center point of the target window; and updating the original pixel values of each pixel in the original image according to the second target pixel value.
[0013] The image filtering method provided by the embodiments of the present invention can accurately determine the target discrete Gaussian convolution kernel corresponding to each pixel point within the target window through the discrete Gaussian convolution kernel calculation formula, thereby ensuring the accuracy and stability of the convolution operation. Determining the radius of the discrete Gaussian convolution kernel according to the size of the sliding window template enables the algorithm to adapt to windows and images of different sizes, and has strong versatility and adaptability. Multiplying the target discrete Gaussian convolution kernel by each first pixel value to obtain the second target pixel value at the center point of the target window, and then updating the original pixel values of each pixel in the original image according to this pixel value can effectively achieve the filtering and enhancement effects of the image. Using the discrete Gaussian convolution kernel calculation formula and the convolution operation can effectively reduce the computational complexity and improve the running efficiency and performance of the algorithm.
[0014] In an alternative embodiment, when the size of the sliding window template is (2k + 1)×(2k + 1), the row and column sizes corresponding to the discrete Gaussian convolution kernel are (2k + 1)×(2k + 1), and the discrete Gaussian convolution kernel calculation formula is:
[0015]
[0016] where h i,j is the size of the discrete Gaussian convolution kernel, δ 2 is the variance, and k is the radius of the discrete Gaussian convolution kernel.
[0017] In an alternative embodiment, multiplying the target discrete Gaussian convolution kernel by each first pixel value to obtain the second target pixel value at the center point of the target window includes: normalizing the target discrete Gaussian convolution kernel to obtain the normalized convolution kernel corresponding to the target window; multiplying the normalized convolution kernel by each first pixel value to obtain the second target pixel value.
[0018] The image filtering method provided by the embodiments of the present invention, normalizing the target discrete Gaussian convolution kernel can ensure that the sum of the weights of the convolution kernel is 1, thereby maintaining the consistency of the image brightness in the convolution operation and avoiding the image brightness deviation introduced by the convolution operation. The normalized convolution kernel can make the convolution operation smoother and more stable, effectively enhance the convolution effect, and improve the quality and clarity of the image. Through the normalization operation, the influence of the target window size on the weights of the convolution kernel can be eliminated, making the convolution operation more scale-invariant, and improving the robustness and reliability of the algorithm. The normalization operation can simplify the calculation process of the convolution operation and improve the running efficiency and performance of the algorithm.
[0019] Second aspect, the present invention provides an image filtering device, comprising: an acquisition module, configured to acquire an original image collected by an endoscope and a preset sliding window template; a sliding module, configured to, in response to a user operation, control the sliding window template to slide on the original image to obtain the original pixel values of each pixel within a target window corresponding to the sliding window template; and an update module, configured to update the original pixel values of each pixel within the target window according to the target window size and each original pixel value, so as to filter the original image.
[0020] Third aspect, the present invention provides a computer device, comprising: a memory and a processor, which are communicatively connected to each other, wherein the memory stores computer instructions, and the processor executes the computer instructions to execute the image filtering method according to the first aspect or any corresponding embodiment thereof.
[0021] Fourth aspect, the present invention provides a computer-readable storage medium, on which computer instructions are stored, and the computer instructions are used to cause a computer to execute the image filtering method according to the first aspect or any corresponding embodiment thereof.
[0022] Fifth aspect, the present invention provides a computer program product, comprising computer instructions, and the computer instructions are used to cause a computer to execute the image filtering method according to the first aspect or any corresponding embodiment thereof. Description of the Drawings
[0023] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for use in the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0024] Figure 1 is a flowchart of an image filtering method according to an embodiment of the present invention;
[0025] Figure 2 is a flowchart of another image filtering method according to an embodiment of the present invention;
[0026] Figure 3 is a flowchart of determining a first target pixel value according to an embodiment of the present invention;
[0027] Figure 4 is a schematic diagram of realizing row and column alignment of each pixel within a target window according to an embodiment of the present invention;
[0028] Figure 5 is a schematic diagram of pixel mapping according to an embodiment of the present invention;
[0029] Figure 6 is a schematic flowchart of another image filtering method according to an embodiment of the present invention;
[0030] Figure 7 is a schematic diagram of filtering using Gaussian convolution according to an embodiment of the present invention;
[0031] Figure 8 is a structural block diagram of an image filtering device according to an embodiment of the present invention;
[0032] Figure 9 is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Detailed implementation manners
[0033] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some but not all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0034] An electronic endoscope is a high-tech electro-optical instrument, whose main function is to enter areas that cannot be directly observed by the human eye and obtain internal conditions through remote visual inspection. This device integrates advanced optical, mechanical, and electronic technologies and has a very wide range of application fields. In the medical field, electronic endoscopes are widely used in endoscopic examinations, such as gastroscopy and colonoscopy, to observe the internal conditions of the digestive tract and diagnose and treat digestive tract diseases.
[0035] Currently, during the image acquisition process, since the electronic endoscope is often in a complex environment, this leads to a decrease in the clarity and accuracy of the image. This environmental complexity may include factors such as changes in light conditions, instability of the instrument position, and interference from surrounding tissues, and these factors will all affect the quality of the image. In addition, the image signal is also subject to various noises during the transmission process, and these noises may come from electromagnetic interference, instability of the transmission line, or errors in the signal processing process. These noise interferences will cause image distortion, loss of details, and an increase in the noise level, thereby affecting the reliability and quality of the image.
[0036] In view of this, the technical solution of the present invention updates the original image collected by the endoscope by performing filtering processing on the original image, traversing the image pixels in a preset order using a sliding window template, and updating the original image according to the processing and sorting of the target pixel values and using a discrete Gaussian convolution kernel to update the pixel values, improving the clarity and quality of the image collected by the endoscope.
[0037] According to an embodiment of the present invention, an embodiment of an image filtering method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0038] In this embodiment, an image filtering method is provided, which can be used in a computer device. Figure 1 It is a flowchart of the image filtering method according to an embodiment of the present invention, as Figure 1 shown, the process includes the following steps:
[0039] Step S101, obtain the original image collected by the endoscope and a preset sliding window template.
[0040] The original image is the unprocessed or uncompressed image data obtained from the camera or sensor of the endoscope. Specifically, after the user inserts the endoscope into the examination area, the original image is directly captured through the control system connected to the endoscope.
[0041] The preset sliding window template is a rectangular area with a preset fixed size and shape, which slides on the entire original image to perform a certain calculation. For example, for a 3x3 sliding window, the window contains a sub-region with 3 rows and 3 columns.
[0042] Step S102, control the sliding window template to slide on the original image in a preset order to traverse each pixel in the original image and obtain the original pixel value of each pixel.
[0043] The sliding window template slides on the original image in a specific order. For example, it can be from left to right, from top to bottom, or other predefined ways to ensure a comprehensive traversal of the entire original image. Specifically, the sliding window moves on the image with a fixed size and shape (such as a 3x3 rectangle), usually row by row or column by column, until the entire image area is covered.
[0044] The original pixel value is used to characterize the characteristics of each pixel in the original image. Specifically, during the traversal process, by controlling the movement of the sliding window, it is ensured that each pixel is accessed. According to the preset order, the sliding window is gradually moved so as to traverse each pixel on the image in a specific direction and order. At each position covered by the sliding window, the pixel value at the corresponding position in the original image is obtained. These pixel values represent the brightness or color information at the corresponding positions in the image. By moving the sliding window, each pixel on the entire image is traversed and its original pixel value is obtained.
[0045] Step S103: Update the original pixel values of each pixel in the original image according to the size of the sliding window template and each original pixel value, so as to filter the original image.
[0046] According to the position and size of the sliding window template, slide on the original image in a preset order to obtain the original pixel values at each position. According to the filtering algorithm and each original pixel value, calculate the new pixel value at each position. Update the calculated new pixel value to the corresponding position of the original image to complete the filtering process of the original image. Among them, the filtering algorithm can be median filtering, Gaussian filtering, etc., which are not limited here.
[0047] The image filtering method provided by the embodiments of the present invention can adjust the size and shape of the sliding window template according to needs to adapt to different types of images and filtering requirements. By traversing each pixel, it can process each detail in the image to ensure that the filtering process comprehensively processes the entire image. Since the filtering is calculated through the pixels in the local area, the local features of the image can be retained, which helps to maintain the details of the image. The shape and size of the sliding window template can be adjusted according to needs to obtain different filtering effects, so as to meet different application requirements.
[0048] In this embodiment, an image filtering method is provided, which can be used in computer devices. Figure 2 It is a flowchart of the image filtering method according to the embodiments of the present invention, as Figure 2 shown, and this process includes the following steps:
[0049] Step S201: Obtain the original image collected by the endoscope and the preset sliding window template. For details, please refer to Figure 1 the steps of Embodiment shown in S101, which will not be elaborated here.
[0050] Step S202: Control the sliding window template to slide on the original image in a preset order to traverse each pixel in the original image and obtain the original pixel values of each pixel. For details, please refer to Figure 1 the steps of Embodiment shown in S102, which will not be elaborated here.
[0051] Step S203: Update the original pixel values of each pixel in the original image according to the size of the sliding window template and each original pixel value, so as to filter the original image.
[0052] Specifically, the above step S203 includes:
[0053] Step S2031: Process each first pixel value within the target window, and select the target median value among the first pixel values as the first target pixel value at the center point of the target window. Herein, the target window is any area corresponding to the sliding window template during its sliding process on the original image; each first pixel value is the pixel value of each pixel point included in the target window.
[0054] The target window is the area corresponding to the sliding window template during its movement on the original image. Specifically, the target window can have different sizes, such as 3x3, 5x5, etc. The size of the window usually affects the filtering result.
[0055] The first pixel value is the original value of all pixels included in the target window. For example, for a grayscale image, it may be the grayscale value of the pixel; for a color image, it may be the value of each channel, such as the RGB channels. For example, when the selected sliding window template is a 3*3 two-dimensional template, the 9 pixels within the target window are as shown in Figure 3 the A square in, and the corresponding first pixel values are f 11 、f 12 、f 13 、f 21 、f 22 、f 23 、f 31 、f 32 、f 33 .
[0056] The target median value is, within the target window, after sorting all the included first pixel values, taking the middle value after sorting. Specifically, slide the window on the original image to obtain the target window at each position. Sort the various first pixel values within this window, and then select the target median value. Take this median value as the first target pixel value at the center point of the target window. Slide the window across the entire image and repeat the above process. Whenever the window moves to a new position, the first pixel values within the target window will obtain a new median value according to the sorting. These median values are used to update the corresponding positions in the original image. Eventually, after all positions are processed, the pixel values in the original image will be updated.
[0057] In some alternative embodiments, the above step S2031 includes:
[0058] Step a1: Sort the multiple second pixel values corresponding to each target pixel row within the target window from largest to smallest to obtain a sorting result. Herein, the multiple second pixel values are the pixel values corresponding to the multiple first pixel points included in the target pixel row.
[0059] The target window contains multiple rows of pixels, and each row of pixels is called a target pixel row. A target pixel row corresponds to the pixel values of multiple first pixel points, so there are multiple second pixel values. The sorting result is the result obtained by arranging the multiple second pixel values in the target pixel row in descending order. Specifically, for each target pixel row, the multiple second pixel values corresponding to it are sorted according to the value size, which can be in descending order.
[0060] For example, when the selected sliding window template is a 3*3 two-dimensional template, FPGA parallel processing is used to sort three rows of pixel data simultaneously. For f 11 , f 12 , f 13 are respectively compared with a comparator to obtain f 1max , f 1med , f 1min sorted from large to small; for f 21 , f 22 , f 23 are respectively compared with a comparator to obtain f 2max , f 2med , f 2min sorted from large to small; for f 31 , f 32 , f 33 are respectively compared with a comparator to obtain f 3max , f 3med , f 3min , and the sorting result is obtained, as shown by the B square in Figure 3 .
[0061] Step a2: Compare the multiple third pixel values corresponding to each target pixel column in the sorting result to determine multiple candidate pixel values; among them, the multiple third pixel values are the pixel values corresponding to the multiple second pixel points included in the target pixel column.
[0062] The sorting result includes multiple columns of pixels, for example, the f Figure 3 in the B square in 1max -f 2max -f 3max pixel column. Candidate pixel values are used to characterize pixels with specific features or attributes in an image processing task. Specifically, by comparing the multiple third pixel values corresponding to each target pixel column in the sorting result, it can be determined which pixel values have sufficient features or information and can therefore be regarded as candidate pixel values.
[0063] In some alternative embodiments, step a2 above includes:
[0064] Step a21: Compare the multiple maximum pixel values corresponding to the first pixel column with the largest value in the sorting result, and determine the smallest pixel value among the multiple maximum pixel values as the first candidate pixel value.
[0065] The first pixel column is the pixel column with the largest value in the sorting result. For example Figure 3 f in block B in 1max -f 2max -f 3max pixel column. The maximum pixel value is the pixel value corresponding to each pixel in the first pixel column. Specifically, compare the multiple maximum pixel values in the first pixel column with the largest value. The purpose of the comparison is to find the pixel value with the smallest value among them. Among the multiple maximum pixel values, find the pixel value with the smallest value and determine it as the first candidate pixel value.
[0066] Step a22: Compare the multiple minimum pixel values corresponding to the second pixel column with the smallest value in the sorting result, and determine the largest pixel value among the multiple minimum pixel values as the second candidate pixel value.
[0067] The second pixel column is the pixel column with the smallest value in the sorting result. For example Figure 3 f in block B in 1min -f 2min -f 3min pixel column. The minimum pixel value is the pixel value corresponding to each pixel in the second pixel column. Specifically, in the sorting result, find the second pixel column with the smallest value. This is the group of pixel columns with the smallest value in the entire dataset. Compare the multiple minimum pixel values in this second pixel column with the smallest value to find the largest value among these minimum pixel values. Among these minimum pixel values, find the largest pixel value and determine it as the second candidate pixel value.
[0068] Step a23: Compare the multiple fourth pixel values corresponding to the third pixel column in the sorting result, and determine the second median value among the multiple fourth pixel values as the third candidate pixel value; where the third pixel column is any column among the pixel columns other than the first pixel column and the second pixel column in the sorting result.
[0069] The third pixel column is any column other than the first pixel column and the second pixel column, that is, in the sorted pixel columns, the third pixel column can be in any position, but it is not the smallest or the largest pixel column. For example Figure 3 f in block B in 1med -f 2med -f 3medThe pixel column. The fourth pixel value is the pixel value corresponding to each pixel in the third pixel column. The second median is the median determined after arranging multiple fourth pixel values from largest to smallest. Specifically, for the multiple fourth pixel values in the third pixel column, they are compared to find the median among these values. Among the multiple fourth pixel values, the second median is found and determined as the third candidate pixel value.
[0070] For example, as Figure 3 shown, when the selected sliding window template is a 3*3 two-dimensional template, using FPGA parallel processing, for the largest data f in the three columns within the sorting result 1max 、f 2max、 f 3max They are respectively compared by a comparator to obtain the minimum value data f in the largest data min_of_max , that is, the first candidate pixel value; for the middle data f in the three columns 1med 、f 2med 、f 3med They are respectively compared by a comparator to obtain the median value data f in the middle data med_of_med , that is, the third candidate pixel value; for the smallest data f in the three columns 1min 、f 2min 、f 3min They are respectively compared by a comparator to obtain the maximum value data f in the smallest data max_of_min , that is, the second candidate pixel value.
[0071] In the above embodiment, by comparing the pixel columns with the largest and smallest numerical values in the sorting result and selecting candidate pixel values therefrom, the effect of multi-level screening is achieved, the target pixel value can be determined more accurately, and the effect and performance of the filtering algorithm are improved. By comparing the largest and smallest pixel values and selecting the most suitable candidate pixel value, outliers and noise can be effectively filtered out, and the stability and reliability of the filtering algorithm are improved. Through a fine comparison and selection process, the candidate pixel value can be determined more accurately, thereby improving the filtering effect and making the quality of the processed image higher.
[0072] Step a3, sort multiple candidate pixel values, and determine the first median among the multiple candidate pixel values as the first target pixel value.
[0073] Sort these candidate pixel values. The sorting is usually carried out according to the size of the pixel values, and can be in ascending or descending order. Once the sorting is completed, find the first median in the sorted result. The first median is the pixel value located in the middle position after sorting multiple candidate pixel values. Determine the first median as the first target pixel value. This value is selected as the final target pixel value and can be used for subsequent image processing tasks.
[0074] For example, as Figure 3As shown by block C in, when the selected sliding window template is a 3*3 two-dimensional template, the minimum value f of the maximum data obtained min_of_max , the median value f of the intermediate data med_of_med , the maximum value f of the minimum data max_of_min are sorted to obtain the median pixel data f of the 9 pixel point data med .
[0075] In some alternative embodiments, such as Figure 4 shown, for the case where the sliding window template is a 3*3 two-dimensional template, at least two rows of row buffers are required to implement the 3*3 template window. Since the sliding window template requires strict row and column alignment, row and column alignment can be achieved through the method of row buffering. By simultaneously reading the first pixel of each row of the row buffer, column alignment can be achieved. The row and column alignment operation can then implement the 3*3 window template. The input image data din and row buffer 1 and row buffer 2 can be connected in a daisy chain. The output data of row buffer 1 is the input data of row buffer 2, and the read time of row buffer 1 is the write time of row buffer 2. When both row buffer 1 and row buffer 2 are filled with one row of image data, a pipelining operation can be performed at this time to complete row and column alignment.
[0076] In the above embodiment, by sorting the pixel values corresponding to each target pixel row and column in the target window, pixel value comparison and screening can be performed in multiple dimensions, improving the accuracy and reliability of the filtering effect. By performing multiple sorts and comparisons, multiple candidate pixel values are determined, and then the candidate pixel values are sorted again, which can effectively screen out the most suitable target pixel value, improving the stability and robustness of the filtering algorithm. The parameters and behaviors of the filtering algorithm can be flexibly adjusted according to specific sorting rules and comparison strategies to adapt to different image processing tasks and application scenarios. By performing multiple sorts and comparisons, images with different complexities and noise levels can be adapted, having strong adaptability and generalization ability. Through a fine sorting and screening process, the target pixel value can be more accurately determined, thereby improving the filtering effect and making the quality of the processed image higher.
[0077] Step S2032, update the original pixel values of each pixel in the original image according to the first target pixel value.
[0078] Replace the original pixel values of each pixel with the respective first target pixel values to update the original pixel values of each pixel in the original image, thereby implementing filtering of the original image.
[0079] Furthermore, for pixel points for which the first target pixel value cannot be obtained according to the above steps, such as Figure 5For the pixel point a, a mapping method can be adopted to map the pixel value of the pixel point located in the square f to the position of the square e, map the pixel value of the pixel point located in the square i to the positions of the square g and the square d, map the pixel value of the pixel point located in the square h to the position of the square c, and map the pixel value of the pixel point located in the square d to the position of the square b. After the mapping is completed, the first target pixel value corresponding to the pixel point a is determined according to the pixel value of the pixel point a and the pixel values of the surrounding 8 squares (b, c, d, e, f, g, h, i).
[0080] The image filtering method provided by the embodiments of the present invention can update the pixel values in the original image according to the size of the sliding window template and the pixel values in the target window, and can realize the processing of the local area, which is beneficial to retaining the local details and features of the image. By selecting the median value in the target window as the target pixel value, the influence of noise can be effectively reduced, and the quality and clarity of the image can be improved. The size of the sliding window template and the selection strategy of the target window can be adjusted according to the actual situation to adapt to different image processing tasks and scene requirements. By selecting the median value as the target pixel value, complex pixel value calculations and filtering algorithms are avoided, the processing process is simplified, and the processing efficiency is improved. Median filtering can effectively retain the edge information in the image and will not produce too much blurring effect, thus maintaining the clarity and recognition of the image.
[0081] In this embodiment, an image filtering method is provided, which can be used in a computer device, Figure 6 is a flowchart of the image filtering method according to the embodiments of the present invention, as Figure 6 shown, the process includes the following steps:
[0082] Step S301, obtain the original image collected by the endoscope and a preset sliding window template. For details, please refer to Figure 1 step S101 of the embodiment shown here, which will not be elaborated here.
[0083] Step S302, control the sliding window template to slide on the original image in a preset order to traverse each pixel in the original image, and obtain the original pixel value of each pixel. For details, please refer to Figure 1 step S102 of the embodiment shown here, which will not be elaborated here.
[0084] Step S303, update the original pixel values of each pixel in the original image according to the size of the sliding window template and each original pixel value to filter the original image.
[0085] Specifically, the above step S303 includes:
[0086] Step S3031: Determine the target discrete Gaussian convolution kernel corresponding to each pixel point within the target window according to the discrete Gaussian convolution kernel radius and the discrete Gaussian convolution kernel calculation formula. Among them, the discrete Gaussian convolution kernel calculation formula is used to calculate the target discrete Gaussian convolution kernel based on the discrete Gaussian convolution kernel radius, and the discrete Gaussian convolution kernel radius is determined according to the size of the sliding window template.
[0087] The discrete Gaussian convolution kernel radius refers to the standard deviation of the Gaussian filter, which is usually used to control the width of the Gaussian function. Specifically, when the size of the sliding window template is (2k + 1)×(2k + 1), the row and column sizes corresponding to the discrete Gaussian convolution kernel are (2k + 1)×(2k + 1), and the discrete Gaussian convolution kernel calculation formula is:
[0088]
[0089] where h i,j is the size of the discrete Gaussian convolution kernel, δ 2 is the variance, and k is the discrete Gaussian convolution kernel radius. The variance is set by the user according to experience or specific requirements, which determines the width of the Gaussian function and thus affects the weight distribution at each position in the convolution kernel.
[0090] According to the size of the sliding window template and the discrete Gaussian convolution kernel calculation formula, the target discrete Gaussian convolution kernel corresponding to each pixel point within the target window can be determined. Specifically, for each pixel point within the target window, according to its position in the window and the formula of the discrete Gaussian function, the weight value at the corresponding position is calculated, thereby obtaining the target discrete Gaussian convolution kernel.
[0091] Step S3032: Multiply the target discrete Gaussian convolution kernel by each first pixel value to obtain the second target pixel value at the center point of the target window.
[0092] As mentioned above, each pixel in the target window has an original pixel value, that is, the first pixel value. Specifically, each weight value in the target discrete Gaussian convolution kernel is multiplied by the first pixel value of the pixel at the corresponding position. This operation is equivalent to weighting each pixel in the window, and the pixel with a larger weight value contributes more to the final result.
[0093] In some alternative embodiments, the above Step S3032 includes:
[0094] Step b1: Normalize the target discrete Gaussian convolution kernel to obtain the normalized convolution kernel corresponding to the target window.
[0095] Normalize the calculated target discrete Gaussian convolution kernel to obtain a normalized convolution kernel such that the sum of all weights in the convolution kernel equals 1. This process helps ensure that when the convolution kernel smooths the image, it does not change the overall brightness or contrast of the image. Specifically, sum all the weights in the target discrete Gaussian convolution kernel to obtain the sum of the weights. Divide each weight by the sum of the weights, thereby normalizing all weights to a range between 0 and 1. The resulting normalized weights are the normalized convolution kernel corresponding to the target window, ensuring that the sum of all weights in the convolution kernel equals 1.
[0096] Step b2, multiply the normalized convolution kernel by each of the first pixel values to obtain second target pixel values.
[0097] Multiply each weight in the normalized convolution kernel by the first pixel value of the pixel at the corresponding position, that is, weight each pixel in the window. The larger the weight value, the greater the contribution of the pixel to the final result. Add up the results of all the multiplications to obtain the second target pixel value at the center point of the target window. This value is obtained by calculating the weighted average of all pixels within the window, where the weight values in the normalized convolution kernel are used to adjust the contribution of each pixel.
[0098] For example, as Figure 7 shown, when the sliding window template is a 3*3 two-dimensional template, the pixel values corresponding to the 9 pixel points are H1, H2, H3, H4, H5, H6, H7, H8, H9 respectively. After normalizing the convolution kernel, H is the value after normalization of the convolution kernel, that is
[0099]
[0100] Perform Gaussian convolution on the target window, that is, M5 = P1×H1 + P2×H2 + P3×H3 + P4×H4 + P5×H5 + P6×H6 + P7×H7 + P8×H8 + P9×H9, where M5 is the value after filtering and P5 is the value to be filtered (the first pixel value).
[0101] In the above embodiment, normalizing the target discrete Gaussian convolution kernel can ensure that the sum of the weights of the convolution kernel is 1, thereby maintaining the consistency of image brightness in the convolution operation and avoiding the image brightness deviation introduced by the convolution operation. The normalized convolution kernel can make the convolution operation smoother and more stable, effectively enhancing the convolution effect and improving the quality and clarity of the image. Through the normalization operation, the influence of the target window size on the weights of the convolution kernel can be eliminated, making the convolution operation more scale-invariant, improving the robustness and reliability of the algorithm. The normalization operation can simplify the calculation process of the convolution operation and improve the running efficiency and performance of the algorithm.
[0102] Step S3033: Update the original pixel values of each pixel in the original image according to the second target pixel value.
[0103] Replace the pixel value at the corresponding position in the original image with the second target pixel value, that is, update the value of each pixel in the original image to the second target pixel value. After the update operation, the pixel value at the corresponding position in the original image is replaced by the new value. The image obtained in this way is the result image after filtering, and the pixel values in it have been adjusted according to the second target pixel value of the center point of the target window.
[0104] The image filtering method provided by the embodiments of the present invention can accurately determine the target discrete Gaussian convolution kernel corresponding to each pixel point in the target window through the discrete Gaussian convolution kernel calculation formula, thus ensuring the accuracy and stability of the convolution operation. Determine the discrete Gaussian convolution kernel radius according to the size of the sliding window template, so that the algorithm can adapt to windows and images of different sizes, and has strong versatility and adaptability. Multiply the target discrete Gaussian convolution kernel by each first pixel value to obtain the second target pixel value of the center point of the target window, and then update the original pixel values of each pixel in the original image according to this pixel value, which can effectively achieve the filtering and enhancement effects of the image. Using the discrete Gaussian convolution kernel calculation formula and convolution operation can effectively reduce the computational complexity and improve the running efficiency and performance of the algorithm.
[0105] In this embodiment, an image filtering device is also provided. This device is used to implement the above embodiments and preferred implementation manners, and those that have been described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.
[0106] This embodiment provides an image filtering device, as Figure 8 shown, including:
[0107] An acquisition module 401, configured to acquire the original image collected by the endoscope and a preset sliding window template.
[0108] A sliding module 402, configured to control the sliding window template to slide on the original image in a preset order to traverse each pixel in the original image and obtain the original pixel value of each pixel.
[0109] An update module 403, configured to update the original pixel values of each pixel in the original image according to the size of the sliding window template and each original pixel value to filter the original image.
[0110] In some alternative implementation manners, the update module 403 includes:
[0111] A processing sub-module, configured to process each first pixel value within a target window, and select a target median value among the first pixel values as the first target pixel value at the center point of the target window; wherein, the target window is any area corresponding to the sliding window template during the sliding process on the original image; each first pixel value is the pixel value of each pixel point included in the target window.
[0112] A first update sub-module, configured to update the original pixel values of each pixel in the original image according to the first target pixel value.
[0113] In some alternative embodiments, the processing sub-module includes:
[0114] A first sorting unit, configured to sort, from largest to smallest, a plurality of second pixel values corresponding to each target pixel row within the target window to obtain a sorting result. Wherein, the plurality of second pixel values are the pixel values corresponding to a plurality of first pixel points included in the target pixel row.
[0115] A comparison unit, configured to compare a plurality of third pixel values corresponding to each target pixel column within the sorting result to determine a plurality of candidate pixel values. Wherein, the plurality of third pixel values are the pixel values corresponding to a plurality of second pixel points included in the target pixel column.
[0116] A second sorting unit, configured to sort the plurality of candidate pixel values, and determine the first median value among the plurality of candidate pixel values as the first target pixel value.
[0117] In some alternative embodiments, the comparison unit includes:
[0118] A first comparison sub-unit, configured to compare a plurality of maximum pixel values corresponding to the first pixel column with the largest value within the sorting result, and determine the smallest pixel value among the plurality of maximum pixel values as the first candidate pixel value.
[0119] A second comparison sub-unit, configured to compare a plurality of minimum pixel values corresponding to the second pixel column with the smallest value within the sorting result, and determine the largest pixel value among the plurality of minimum pixel values as the second candidate pixel value.
[0120] A third comparison sub-unit, configured to compare a plurality of fourth pixel values corresponding to the third pixel column within the sorting result, and determine the second median value among the plurality of fourth pixel values as the third candidate pixel value. Wherein, the third pixel column is any column among the pixel columns in the sorting result other than the first pixel column and the second pixel column.
[0121] In some alternative embodiments, the update module 403 includes:
[0122] A determination sub-module, configured to determine a target discrete Gaussian convolution kernel corresponding to each pixel point within a target window according to a discrete Gaussian convolution kernel radius and a discrete Gaussian convolution kernel calculation formula. The discrete Gaussian convolution kernel calculation formula is used to calculate the target discrete Gaussian convolution kernel according to the discrete Gaussian convolution kernel radius. The discrete Gaussian convolution kernel radius is determined according to the size of a sliding window template.
[0123] A calculation sub-module, configured to multiply the target discrete Gaussian convolution kernel by each first pixel value to obtain a second target pixel value at the center point of the target window.
[0124] A second update sub-module, configured to update the original pixel values of each pixel in the original image according to the second target pixel value.
[0125] In some alternative embodiments, the calculation sub-module includes:
[0126] A normalization unit, configured to normalize the target discrete Gaussian convolution kernel to obtain a normalized convolution kernel corresponding to the target window.
[0127] A calculation unit, configured to multiply the normalized convolution kernel by each first pixel value to obtain the second target pixel value.
[0128] The further function descriptions of the above-mentioned respective modules and units are the same as those in the corresponding foregoing embodiments, and will not be elaborated herein.
[0129] The image filtering device in this embodiment is presented in the form of functional units. Here, the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and a memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0130] The image filtering device provided by the embodiment of the present invention can adjust the size and shape of the sliding window template as needed to adapt to different types of images and filtering requirements. By traversing each pixel, it can process each detail in the image, ensuring that the filtering process comprehensively processes the entire image. Since the filtering is calculated through the pixels in a local area, the local features of the image can be retained, which helps to maintain the details of the image. The shape and size of the sliding window template can be adjusted according to requirements to obtain different filtering effects, so as to meet different application requirements.
[0131] The embodiment of the present invention further provides a computer device having the above-mentioned Figure 8 shown image filtering device.
[0132] Please refer to Figure 9 , Figure 9The following is a schematic structural diagram of a computer device provided by an alternative embodiment of the present invention. As Figure 9 shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including a high-speed interface and a low-speed interface. Each component communicates with each other using different buses and can be installed on a common motherboard or in other ways as needed. The processor can process instructions executed within the computer device, including instructions stored in the memory or on the memory to display graphical information of a GUI on an external input / output device (such as a display device coupled to the interface). In some alternative embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a set of blade servers, or a multi-processor system). Figure 9 In
[0133] FIG.
[0134] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiments.
[0135] The memory 20 can include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the computer device. In addition, the memory 20 can include high-speed random access memory and can also include non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state storage devices. In some alternative embodiments, the memory 20 can optionally include a memory remotely set relative to the processor 10, and these remote memories can be connected to the computer device through a network. Examples of the above networks include, but are not limited to, the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0136] The memory 20 can include volatile memory, such as random access memory; the memory can also include non-volatile memory, such as flash memory, a hard disk, or a solid-state drive; the memory 20 can also include a combination of the above types of memory.
[0137] The computer device further includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30, and the output device 40 may be connected by a bus or other means. Figure 9 Taking the connection through the bus as an example.
[0138] The input device 30 can receive input digital or character information, and generate key signal inputs related to the user settings and function controls of the computer device, such as a touch screen, a keypad, a mouse, a trackpad, a touchpad, a pointing stick, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED), and a haptic feedback device (e.g., a vibration motor), etc. The above display device includes but is not limited to a liquid crystal display, a light-emitting diode, a display, and a plasma display. In some alternative embodiments, the display device may be a touch screen.
[0139] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or be implemented as computer code that can be recorded on a storage medium, or be implemented as computer code that is originally stored in a remote storage medium or a non-transitory machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, or a solid-state drive, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by the computer, the processor, or the hardware, the method shown in the above embodiment is implemented.
[0140] A part of the present invention can be applied as a computer program product, such as computer program instructions. When executed by a computer, through the operation of the computer, the methods and / or technical solutions according to the present invention can be invoked or provided. Those skilled in the art should be able to understand that the forms of existence of computer program instructions in a computer-readable medium include but are not limited to source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include but are not limited to: the computer directly executes the instructions, or the computer compiles the instructions and then executes the corresponding compiled program, or the computer reads and executes the instructions, or the computer reads and installs the instructions and then executes the corresponding installed program. Herein, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible by the computer.
[0141] Although embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations fall within the scope defined by the appended claims.
Claims
1. An image filtering method, characterized in that: The method comprises: Obtaining the original image collected by the endoscope and the preset sliding window template; Controlling the sliding window template to slide on the original image in a preset order to traverse each pixel in the original image to obtain the original pixel value of each pixel; According to the sliding window template size and each of the original pixel values, the original pixel value of each pixel in the original image is updated to filter the original image.
2. The image filtering method according to claim 1, characterized in that: The updating of the original pixel value of each pixel in the original image according to the sliding window template size and each of the original pixel values comprises: Processing each first pixel value in the target window, selecting a target median value among the first pixel values as the first target pixel value of the center point of the target window; wherein the target window is any area corresponding to the sliding window template during the sliding process on the original image; and each first pixel value is a pixel value of each pixel point included in the target window; According to the first target pixel value, the original pixel value of each pixel in the original image is updated.
3. The image filtering method according to claim 2, characterized in that: The processing of each first pixel value in the target window and selecting a target median value among the first pixel values as a first target pixel value of a center point of the target window includes: Sorting a plurality of second pixel values corresponding to each target pixel row in the target window from large to small to obtain a sorting result; wherein the plurality of second pixel values are pixel values corresponding to a plurality of first pixel points included in the target pixel row; Comparing a plurality of third pixel values corresponding to each target pixel column in the sorting result to determine a plurality of candidate pixel values; wherein the plurality of third pixel values are pixel values corresponding to a plurality of second pixel points included in the target pixel column; The multiple candidate pixel values are sorted, and a first median value among the multiple candidate pixel values is determined as the first target pixel value.
4. The image filtering method according to claim 3, characterized in that: The step of comparing a plurality of third pixel values in each target pixel column in the sorting result to determine a plurality of candidate pixel values includes: Compare multiple maximum pixel values corresponding to the first pixel column with the largest value in the sorting result, and determine the smallest pixel value among the multiple maximum pixel values as the first candidate pixel value; Compare multiple minimum pixel values corresponding to the second pixel column with the smallest value in the sorting result, and determine the largest pixel value among the multiple minimum pixel values as the second candidate pixel value; Compare multiple fourth pixel values corresponding to the third pixel column in the sorting result, and determine the second median of the multiple fourth pixel values as the third candidate pixel value; wherein the third pixel column is any one of the pixel columns in the sorting result except the first pixel column and the second pixel column.
5. The image filtering method according to claim 1, characterized in that: The updating of the original pixel value of each pixel in the original image according to the sliding window template size and each of the original pixel values comprises: According to the discrete Gaussian convolution kernel radius and the discrete Gaussian convolution kernel calculation formula, determine the target discrete Gaussian convolution kernel corresponding to each pixel point in the target window; wherein the discrete Gaussian convolution kernel calculation formula is used to calculate the target discrete Gaussian convolution kernel according to the discrete Gaussian convolution kernel radius; the discrete Gaussian convolution kernel radius is determined according to the sliding window template size; Multiplying the target discrete Gaussian convolution kernel and each first pixel value to obtain a second target pixel value of the center point of the target window; According to the second target pixel value, the original pixel value of each pixel in the original image is updated.
6. The image filtering method according to claim 5, characterized in that: When the sliding window template size is (2k+1)×(2k+1), the row and column size corresponding to the discrete Gaussian convolution kernel is (2k+1)×(2k+1), and the calculation formula of the discrete Gaussian convolution kernel is: Among them, h i,j is the discrete Gaussian convolution kernel size, δ 2 is the variance, and k is the radius of the discrete Gaussian convolution kernel.
7. The image filtering method according to claim 5, characterized in that: The step of multiplying the target discrete Gaussian convolution kernel and each first pixel value to obtain a second target pixel value of the center point of the target window includes: Normalizing the target discrete Gaussian convolution kernel to obtain a normalized convolution kernel corresponding to the target window; The normalized convolution kernel is multiplied by each of the first pixel values to obtain the second target pixel value.
8. An image filtering device, characterized in that: The device comprises: An acquisition module, used to acquire the original image collected by the endoscope and a preset sliding window template; A sliding module, used to control the sliding window template to slide on the original image in a preset order, so as to traverse each pixel in the original image and obtain the original pixel value of each pixel; The updating module is used to update the original pixel value of each pixel in the original image according to the sliding window template size and each original pixel value, so as to filter the original image.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the image filtering method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the image filtering method according to any one of claims 1 to 7.
11. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the image filtering method according to any one of claims 1 to 7.
Citation Information
Cited By
Daytime running light color cast processing method
CN121616504A