Image processing method and related equipment

By using the sliding window and image gradient value calculation method in image processing, the problem of poor stability and low accuracy of sharpness evaluation in the existing technology is solved, a more accurate focus height determination is achieved, and the image processing effect and applicable scenarios are improved. .

CN118945275BActive Publication Date: 2025-01-21HANGZHOU XINO INTELLIGENT MEDICINE CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411423604.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-01-21
Estimated Expiration
2044-10-11

AI Technical Summary

Technical Problem

The clarity evaluation method in the prior art image processing scheme has poor stability, low accuracy of clarity evaluation, poor image processing effect, and narrow applicable scenes, especially in linear scanning devices, it is difficult to accurately identify the clearest row images, affecting focus. operate.

Method used

By obtaining the grayscale image obtained by linear scanning of the target object, setting the sliding window to slide along the height direction of the image, calculating the image gradient value of each window image, and determining the window image corresponding to the maximum gradient value in the image gradient value as the target window image. , determine the target focus height based on its sliding window position.

Benefits of technology

It significantly improves the accuracy and stability of sharpness evaluation, improves image processing effects, expands applicable scenarios, and can more accurately determine the clearest line of a linear image, thereby supporting effective focusing operations of linear scanning equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118945275B_ABST
    Figure CN118945275B_ABST
Patent Text Reader

Abstract

The present application relates to an image processing method and related equipment, and to the field of image processing technology. A specific implementation of the method includes: obtaining a grayscale image obtained after linear scanning of a target object, setting a sliding window, and sliding the sliding window along the image height direction to obtain multiple window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value; respectively calculating the image gradient values ​​corresponding to each window image; determining the window image corresponding to the maximum gradient value in the image gradient value as the target window image, and determining the target focus height according to the sliding window position corresponding to the target window image. This implementation solves the problem that the accuracy and stability of the existing clarity evaluation function are poor and it is difficult to determine the optimal focus height due to too few pixels contained in the scanning line, and achieves the effect of providing strong support for the focusing operation of linear scanning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to an image processing method and related equipment. Background Art

[0002] A linear scanner is a device that can scan an object line by line and generate an image. It moves the light source and sensor to scan and take pictures of lines with a pixel width each time. The focusing process scans multiple times at different heights, and then stitches these lines together to form a complete linear image. For a linear image stitched together from multiple lines of images, it is a technical challenge to accurately identify which line of image is the clearest and then focus the linear scanning device based on the clearest line of image, because the linear image has problems such as color cast, noise interference, blurred edges, and skewed lines caused by skewed stitching.

[0003] In the image processing solutions provided by the related technology, the Brenner gradient function (spatial gradient evaluation algorithm) is generally used to evaluate the clarity of linear images. However, this solution is only suitable for the clarity evaluation of the entire image. When applied to the clarity evaluation of scanned lines in the image, due to the small number of pixels contained in the scanned lines, the accuracy and stability of the evaluation function are poor, and it is difficult to determine the clearest line in the linear image, and thus it is impossible to determine the optimal focus height, and it is impossible to provide data support for subsequent focusing operations. There are problems such as poor stability of the clarity evaluation method and low clarity evaluation accuracy, and there is a lack of a mechanism for adaptively identifying noise, poor anti-noise ability, and poor image processing effect, which in turn affects the focusing operation of the linear image during the scanning and photographing process, and the applicable scenarios are narrow.

[0004] With respect to the above-mentioned problems in the related technologies, no effective solution has been proposed yet. Summary of the invention

[0005] An image processing method and related equipment provided by an embodiment of the present invention at least solve the problems of poor stability of the clarity evaluation method, low clarity evaluation accuracy, poor image processing effect, and narrow application scenarios existing in the image processing scheme in the related art.

[0006] In order to solve the above problem, one aspect of an embodiment of the present invention provides an image processing method, including:

[0007] Obtain a grayscale image of the target object after linear scanning, set a sliding window, and slide the sliding window along the image height direction to obtain multiple window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value;

[0008] Calculate the image gradient value corresponding to each window image respectively;

[0009] The window image corresponding to the maximum gradient value in the image gradient values ​​is determined as the target window image, and the target focus height is determined according to the sliding window position corresponding to the target window image.

[0010] In some embodiments, the step of calculating the image gradient value corresponding to each window image includes:

[0011] For any window image: calculate the square of the grayscale difference between each pixel in the window image and the associated pixel in the image width direction to obtain the gradient value corresponding to the pixel; where the pixel and the associated pixel are spaced K pixels apart in the image width direction, K is an interval number parameter, and K is a positive integer greater than or equal to 2;

[0012] The gradient value corresponding to each pixel in the window image is summed to obtain the image gradient value corresponding to the window image.

[0013] In some of the embodiments, the method further comprises the step of calculating an optimal combination of parameter values:

[0014] Acquire a plurality of sample grayscale images of known clearest rows, and determine, based on a plurality of sliding windows corresponding to different preset window parameter values, a plurality of window images corresponding to each sample grayscale image under different preset window parameter values;

[0015] Based on different preset values ​​of the interval number parameter, the image gradient values ​​corresponding to each window image under different preset values ​​of the interval number parameter are calculated respectively, and the target window image corresponding to each sample grayscale image under different parameter value combinations and the target row where the center line of the target window image is located are determined according to the maximum gradient value in the image gradient values;

[0016] Under different parameter value combinations, the row error is calculated based on the known clearest row and the target row corresponding to the sample grayscale image, and the average of the row errors of multiple sample grayscale images is calculated as the total error. The window parameter preset value and the interval number preset value corresponding to the minimum total error are determined as the optimal parameter value combination.

[0017] In some embodiments, the step of calculating the total error of the plurality of sample grayscale images comprises:

[0018] The row error corresponding to the defocus is set as the error threshold, and the row errors calculated under different parameter value combinations of multiple sample grayscale images are screened according to the error threshold, and the average value of the multiple row errors after the screening is calculated as the total error.

[0019] In some embodiments, the step of obtaining a grayscale image of the target object after linear scanning includes:

[0020] Acquire multiple line images corresponding to the target object, and stitch the multiple line images along the image height direction to obtain an RGB color image; wherein the line image is obtained by linearly scanning and photographing the target object based on different preset focus heights by a linear scanning device;

[0021] Perform image conversion on the RGB color image to obtain a grayscale image.

[0022] In some of the embodiments, the step of determining the target focus height according to the sliding window position corresponding to the target window image includes:

[0023] The target position of the window center line of the target window image in the image height direction is determined, and the focus height corresponding to the target position is used as the target focus height.

[0024] In some of these embodiments, the method further comprises:

[0025] The focus height of the linear scanning device is set according to the target focus height, so that the target object is scanned and photographed based on the set linear scanning device to obtain a target linear scanning image.

[0026] In order to solve the above problem, one aspect of an embodiment of the present invention provides an image processing device, including:

[0027] The window image determination module is used to obtain a grayscale image of the target object after linear scanning, set a sliding window, and slide the sliding window along the image height direction to obtain multiple window images corresponding to the grayscale image; wherein the set sliding window includes window parameters of a target window height value and a target sliding step value;

[0028] A gradient value calculation module is used to calculate the image gradient value corresponding to each window image respectively;

[0029] The focus height determination module is used to determine that the window image corresponding to the maximum gradient value in the image gradient values ​​is the target window image, and determine the target focus height according to the sliding window position corresponding to the target window image.

[0030] In some of the embodiments, the apparatus further comprises a parameter optimization module for:

[0031] Acquire a plurality of sample grayscale images of known clearest rows, and determine, based on a plurality of sliding windows corresponding to different preset window parameter values, a plurality of window images corresponding to each sample grayscale image under different preset window parameter values;

[0032] Based on different preset values ​​of the interval number parameter, the image gradient values ​​corresponding to each window image under different preset values ​​of the interval number parameter are calculated respectively, and the target window image corresponding to each sample grayscale image under different parameter value combinations and the target row where the center line of the target window image is located are determined according to the maximum gradient value in the image gradient values;

[0033] Under different parameter value combinations, the row error is calculated based on the known clearest row and the target row corresponding to the sample grayscale image, and the average of the row errors of multiple sample grayscale images is calculated as the total error. The window parameter preset value and the interval number preset value corresponding to the minimum total error are determined as the optimal parameter value combination.

[0034] In order to solve the above problems, one aspect of an embodiment of the present invention provides an electronic device, including: a processor, and a memory storing a program, wherein the program includes instructions, and when the instructions are executed by the processor, the processor executes any one of the above image processing methods.

[0035] In order to solve the above problems, one aspect of an embodiment of the present invention provides a non-transitory machine-readable medium storing computer instructions, where the computer instructions are used to enable a computer to execute any one of the above image processing methods.

[0036] In order to solve the above problems, one aspect of an embodiment of the present invention provides a computer program product, including a computer program / instruction, which implements any of the above image processing methods when executed by a processor.

[0037] The beneficial effects of the embodiments of the present invention are as follows: by adopting the method of obtaining a grayscale image obtained after linear scanning of a target object, setting a sliding window, and sliding the sliding window along the image height direction to obtain a plurality of window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value; respectively calculating the image gradient values ​​corresponding to each window image; determining the window image corresponding to the maximum gradient value in the image gradient values ​​as the target window image, and determining the target focus height according to the sliding window position corresponding to the target window image, the technical means overcomes the problems of poor stability, low clarity evaluation accuracy, poor image processing effect, and narrow applicable scenes of the clarity evaluation method existing in the related art, realizes dividing the linear image into a plurality of window images based on the sliding window, and determines the target window image with the highest clarity by comparing the image gradient values ​​corresponding to the plurality of window images, and then determines the target focus height, thereby achieving the determination of the clarity of the local image, significantly improving the clarity evaluation accuracy, improving the stability of the clarity evaluation method, and improving the image processing effect, thereby providing support for the focusing operation of the linear scanning in the scanning and photographing process, and expanding the applicable scenes of the image processing method.

[0038] The details of one or more embodiments of the invention are set forth in the following drawings and description so that other features, objects, and advantages of the invention are more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other embodiments can be obtained based on these drawings without creative work.

[0040] Figure 1 It is a main flow chart of an image processing method according to an embodiment of the present invention.

[0041] Figure 2 It is a schematic diagram of a linear image having problems of splicing skew and noise in an embodiment of the present invention.

[0042] Figure 3 It is a schematic diagram of determining multiple window images corresponding to a grayscale image according to an embodiment of the present invention.

[0043] Figure 4 It is a main framework diagram of an image processing device according to an embodiment of the present invention.

[0044] Figure 5 It is a structural schematic diagram of the electronic device of the present invention. DETAILED DESCRIPTION

[0045] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.

[0046] Since a linear scanner can only acquire one line of image data at a time, it is necessary to stitch multiple single-line images together into a complete linear image. This usually requires positioning and aligning each line of images to ensure that the final image has no obvious seams or misalignments. However, the final stitched linear image still has problems such as color cast (due to changes in light source intensity or inconsistencies in sensor response, images in different lines may have color deviations), noise interference (random noise introduced during the scanning process may affect image quality), edge blur (if the focus setting of the scanner at different heights is inaccurate, the edges of some lines of the image may be blurred), and stitching skew (due to the inaccuracy of mechanical movement, there may be slight angle deviations between different lines, causing the lines in the final image to appear skewed), making it difficult to identify the clearest lines in the linear image. Figure 2 As shown, Figure 2 The figure shows the problems of stitching skew and noise in a stitched linear image.

[0047] In the image processing solutions provided by the related art, the Brenner gradient function (spatial gradient evaluation algorithm) is generally used to evaluate the clarity of linear images. The Brenner gradient is the square of the grayscale difference (difference in grayscale value) between two pixels separated by two pixels in the x direction (image width direction). The sum of the Brenner gradients of all pixels in the linear image is the image evaluation value, which can be used as a clarity indicator. However, this method can only characterize the overall clarity of the linear image. When applied to the clarity evaluation of the scanned lines in the image, due to the small number of pixels in the scanned lines, the accuracy and stability of the evaluation function are poor, so it is impossible to accurately determine the clearest line in the linear image, and thus it is impossible to determine the optimal focus height. According to the definition of the Brenner gradient clarity evaluation algorithm, the clear image at the focus position has the largest evaluation value. Therefore, during the focusing process, the image evaluation values ​​at different positions can be compared to determine the moving direction of the image receiving device, thereby achieving focusing.

[0048] At the same time, the above scheme has fewer pixels representing the image height (the height of the scanning line is 1) when evaluating the clarity of linear images, resulting in poor stability of the clarity evaluation method, low clarity evaluation accuracy, and a lack of a mechanism for adaptively identifying noise. It has poor noise resistance and poor image processing effects, which in turn affects the focusing operation of the linear image during the scanning and photographing process and has a narrow range of applicable scenarios.

[0049] In order to solve the above problems, an embodiment of the present invention provides an image processing method, such as Figure 1 As shown, the image processing method mainly includes:

[0050] Step S101, obtain a grayscale image of the target object after linear scanning, set a sliding window, and slide the sliding window along the image height direction to obtain multiple window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value.

[0051] The grayscale image provided in the embodiment of the present invention is a grayscale image corresponding to the linear image obtained by stitching. Since the grayscale value of each pixel in the image needs to be applied when calculating the image gradient value later, a grayscale image with only grayscale information is used here. In the pixel matrix corresponding to the grayscale image, each element is the grayscale value f (x, y) of each pixel.

[0052] Through the above settings, the embodiment of the present invention divides the grayscale image corresponding to the linear image into multiple window images through a preset sliding window (the preset sliding window is determined according to the preset window parameters including the target window height value and the target sliding step value), so as to facilitate the subsequent calculation of the image gradient values ​​of each window image, and then determine the clearest window image, which helps to accurately determine the optimal focus height and provide data support for the subsequent focusing operation on the linear image. It can be understood that the setting of the window parameters is related to the target object being scanned, and is the optimal parameter for the target object. The window parameters can be set based on experience, or they can be set in combination with a representative sample image (covering different types of noise) to set a learning mechanism and obtain them through calculation.

[0053] Specifically, by using a sliding window, not only can each part of the image be analyzed more carefully, but it can also help reduce the impact of noise on clarity assessment, help accurately assess the clarity of each window image, and then determine the clearest part of the image. In addition, the height and step size of the sliding window (i.e., the above-mentioned target window height value, target sliding step size value) can be flexibly adjusted according to actual conditions (different image content, noise conditions, etc.), so that the image processing method provided by the embodiment of the present invention can adapt to different types of images and application scenarios. According to a specific implementation of the embodiment of the present invention, Figure 3 As shown, a sliding window design is provided:

[0054] Assume that the image height of the grayscale image is h and the image width is w. Assume that the height of the sliding window (i.e. the target window height value) ) is d, the width of the sliding window ( , which is consistent with the width of the grayscale image) is w, and the sliding step value of the sliding window (that is, the target sliding step value ) is set to 1 (this value is only an example and is not intended to limit this application. The target sliding step value can be adjusted according to actual conditions). That is, the size of the sliding window and the sliding step are:

[0055]

[0056] like Figure 3 As shown, along the height direction of the image, the sliding window slides from the starting position of the image to the end position of the image, thereby obtaining multiple window images corresponding to the grayscale image.

[0057] In some of the embodiments, the step of obtaining a grayscale image of the target object after linear scanning includes: obtaining multiple row images corresponding to the target object, and splicing the multiple row images along the image height direction to obtain an RGB color image; wherein the row image is obtained by linearly scanning and photographing the target object based on different preset focusing heights using a linear scanning device; and performing image conversion processing on the RGB color image to obtain a grayscale image.

[0058] Through linear scanning and stitching, it can be ensured that each line in the image is fully evaluated, which can help quickly find the best focus position, achieve automatic focus, and thus improve the focus accuracy. By evaluating the complete stitched image, and in the stitching process, the influence of noise on clarity evaluation can be reduced through preprocessing methods (such as filtering). After conversion to a grayscale image, it is helpful for subsequent calculation of the image gradient value, and then determine the clearest line and the best focus height.

[0059] Step S102, respectively calculating the image gradient values ​​corresponding to each window image.

[0060] According to an embodiment of the present invention, the image gradient value can be calculated according to the existing Brenner gradient function, that is, the Brenner gradient value of each pixel is first determined, that is, for each pixel, the square of the grayscale difference between two pixels in the width direction of the image is calculated, and then the Brenner gradient values ​​of all pixels in each window image are summed to obtain the image gradient values ​​corresponding to each window image.

[0061] By combining the sliding window and the Brenner gradient through the above setting, the clarity evaluation of the local image (i.e., the window image) is realized, and then the window image with the highest clarity can be determined by comparing the image gradient values ​​of each window image, and then the clearest row can be determined, and the optimal focus height can be determined.

[0062] In some embodiments, the step of calculating the image gradient value corresponding to each window image includes: for any window image: calculating the square of the grayscale difference between each pixel point in the window image and the associated pixel point in the image width direction, to obtain the gradient value corresponding to the pixel point; wherein the pixel point and the associated pixel point are spaced K pixels apart along the image width direction, K is an interval number parameter, and K is a positive integer greater than or equal to 2; summing the gradient values ​​corresponding to each pixel point in the window image to obtain the image gradient value corresponding to the window image.

[0063] The Brenner gradient function in the related art is based on the Brenner operator, which only calculates the bisector of the grayscale difference between two pixels that are 2 units apart (i.e., the square of the grayscale difference between two pixels in the x direction (image width direction)), so it is simple, practical, and has low computational complexity. However, in actual applications, it is found that in the process of determining the clearest line, affected by the noise type, morphology, and distribution of the scanned image, if the number of pixel intervals is limited to 2, it is difficult to adapt to the clarity evaluation scenario of linear images with different noise types.

[0064] Therefore, based on the above settings, the embodiment of the present invention provides an improved Brenner gradient function, sets an adjustable interval number parameter K, and adjusts the interval number parameter based on the actual situation (that is, the interval number parameter is adaptively adjusted according to the noise type, morphology, distribution, etc.), so as to obtain a more accurate image gradient value, which helps to improve the accuracy of clarity evaluation, improve calculation efficiency, and thus improve the subsequent image processing effect, and can adapt to different types of images and application scenarios. In addition, the adjustable target interval number can also be applied to different scanning requirements, such as high-resolution scanning or low-resolution scanning.

[0065] According to a specific implementation of the embodiment of the present invention, the image gradient value of the window image The calculation expression is:

[0066]

[0067] in, is the gray value of the pixel, is the gray value of the associated pixel that is K pixels away from the pixel along the width direction of the image. For each row in the window image, the gradient is calculated starting from K+1 pixels because the square of the gray difference between two pixels that are K pixels away is calculated.

[0068] In some of the embodiments, the method further includes a step of calculating an optimal parameter value combination: obtaining a plurality of sample grayscale images of known clearest rows, and determining a plurality of window images corresponding to each sample grayscale image under different window parameter preset values ​​based on a plurality of sliding windows corresponding to different window parameter preset values; calculating image gradient values ​​corresponding to each window image under different interval number parameter preset values ​​based on different interval number parameter preset values, and determining a target window image corresponding to each sample grayscale image under different parameter value combinations and a target row where a center line of the target window image is located according to a maximum gradient value among the image gradient values; calculating a row error according to the known clearest row corresponding to the sample grayscale image and the target row under different parameter value combinations, and calculating an average of the row errors of a plurality of sample grayscale images as a total error, and determining the window parameter preset values ​​and interval number preset values ​​corresponding to the minimum total error as the optimal parameter value combination.

[0069] The above provides a specific implementation method for optimizing the learning of the interval number parameter K and the window parameter (here the optimization of the target window height value parameter d is exemplified) for different noise types, forms, distributions, etc.

[0070] Among them, the sample grayscale images provided in the embodiments of the present invention respectively include different noise types, forms, and distributions, and for any sample grayscale image, its clearest row (that is, the scan line / scan line with the highest clarity in the image) is known, so as to facilitate the subsequent optimization of the interval number parameter K and the target window height value parameter d.

[0071] According to a specific implementation of an embodiment of the present invention, for the above-mentioned multiple sample grayscale images, different interval number parameters K=[2,3,4,5] and different sliding window height value parameters d=[1,3,5,7,9,11,13,15,17] are pre-set. It should be noted that the above-mentioned values ​​are only examples and are not intended to limit the present application. Based on the multiple parameter value combinations consisting of the above-mentioned multiple interval number parameters K and multiple sliding window height value parameters d (it can be understood that if the sliding step value parameter needs to be optimized, the parameter value combination includes a combination of the above-mentioned three types of parameters), the above-mentioned window image determination step and image gradient value determination step are used to calculate the target window image corresponding to each parameter value combination, and the row corresponding to the center line of the target window image is used as the target row (the target row is the clearest row obtained by the above-mentioned calculation method), and then the row error between the target row and the actual row corresponding to different parameter value combinations is determined, and the average value of the row error of the multiple sample grayscale images is calculated as the total error, and the combination of the interval number parameter K and the sliding window step value parameter d corresponding to the minimum total error is determined as the optimal parameter value combination.

[0072] Based on the above settings, the window parameters and interval number parameters are optimized by analyzing multiple sample grayscale images containing different noise types, forms, and distributions, thereby improving the adaptive adjustment mechanism for noise in image clarity evaluation. The optimized window parameters and interval number parameters can be used to find the clearest lines more quickly and accurately, thereby improving the focusing accuracy.

[0073] According to a specific implementation of an embodiment of the present invention, for any parameter value combination consisting of multiple candidate interval number parameters K and multiple candidate window height value parameters d, the calculated row error The expression is:

[0074]

[0075] Among them, abs() is a built-in function used to calculate the absolute value of a number. Indicates the actual row corresponding to the window image (the actual clearest row); Indicates that the window image calculates the target row (the clearest row) based on a certain parameter.

[0076] Furthermore, the row error is calculated for multiple parameter value combinations, and an evaluation function is set to determine the optimal parameter value combination. The evaluation function is as follows:

[0077]

[0078] Among them, [err] represents the set of row errors corresponding to multiple parameter value combinations, avg represents the average value of the row error set, and min represents minimizing the average error, that is, the corresponding parameter value combination (K, d) with the minimum average error is the optimal parameter.

[0079] In some of the embodiments, the step of calculating the total error of multiple sample grayscale images includes: setting the row error corresponding to the defocus as the error threshold, screening the row errors calculated for multiple sample grayscale images under different parameter value combinations according to the error threshold, and calculating the average value of the multiple row errors after the screening.

[0080] The row errors calculated by different parameter value combinations are screened by introducing an error threshold, where the error threshold is the height error corresponding to the depth of focus, and then the row number error. If the row error calculated by a certain parameter value combination exceeds the above error threshold, it will be eliminated and will not participate in the evaluation. Through the above settings, excluding samples with large errors can reduce the impact of noise on subsequent clarity evaluation results, making the screened samples closer to the actual situation, which helps to more accurately determine the optimal parameter value combination corresponding to the window parameter and the number of interval parameters.

[0081] Step S103, determining that the window image corresponding to the maximum gradient value among the image gradient values ​​is the target window image, and determining the target focus height according to the sliding window position corresponding to the target window image.

[0082] The target focus height, i.e., the optimal focus height determined by the embodiment of the present invention, refers to the position of the row where the clearest scanning line in the image is located. Its function is to determine whether the focus of the scanning device is accurate and whether the physical distance between the scanning device and the scanned object (i.e., the target object) needs to be adjusted.

[0083] In some of the embodiments, the step of determining the target focus height according to the sliding window position corresponding to the target window image includes: determining the target position of the window center line of the target window image in the image height direction, and taking the focus height corresponding to the target position as the target focus height.

[0084] By calculating the maximum gradient value of the image gradient in all window images, the target window image corresponding to the maximum gradient value is the clearest window image, and the position of the center line of the target window image in the image height direction is determined. The image row corresponding to this position is the clearest scanning line, corresponding to the best focus height. Through the above settings, the accuracy of image clarity evaluation is guaranteed and the efficiency of determining the clearest image row is improved.

[0085] In some of the embodiments, the method further includes: setting a focus height of the linear scanning device according to the target focus height, so as to scan and photograph the target object based on the set linear scanning device to obtain a target linear scanning image.

[0086] The target focus height determined by the above steps can accurately adjust the focus height of the linear scanning device to ensure that the linear scanning device can work at the optimal focus height, which can significantly improve the overall clarity of the image obtained during scanning and photography. In addition, the determination of the target focus height reduces the number of rescans caused by inaccurate focus, improves the efficiency of obtaining linear images, and improves image quality.

[0087] The image processing method provided by the embodiment of the present invention, by adopting the method of obtaining a grayscale image obtained after linear scanning of the target object, setting a sliding window, sliding the sliding window along the image height direction to obtain multiple window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value; respectively calculating the image gradient values ​​corresponding to each window image; determining the window image corresponding to the maximum gradient value in the image gradient values ​​as the target window image, and determining the target focus height according to the sliding window position corresponding to the target window image. The technical means overcomes the problems of poor stability, low clarity evaluation accuracy, poor image processing effect, and narrow applicable scenes of the clarity evaluation method existing in the related art, realizes dividing the linear image into multiple window images based on the sliding window, and determines the target window image with the highest clarity by comparing the image gradient values ​​corresponding to the multiple window images, and then determines the target focus height, thereby achieving the determination of the clarity of the local image, significantly improving the clarity evaluation accuracy, improving the stability of the clarity evaluation method, and improving the image processing effect, thereby providing support for the focusing operation of the linear scanning in the scanning and photographing process, and expanding the technical effect of the applicable scenes of the image processing method.

[0088] Based on the above-mentioned image processing method provided by the embodiment of the present invention, the embodiment of the present invention also provides an image processing device, which is applied to the clarity evaluation of linear images, the determination of the best focus height and the focusing scene of linear scanning, such as Figure 4 As shown, the image processing device 400 includes:

[0089] The window image determination module 401 is used to obtain a grayscale image of the target object after linear scanning, set a sliding window, and slide the sliding window along the image height direction to obtain multiple window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value.

[0090] Through the above settings, the embodiment of the present invention divides the grayscale image corresponding to the linear image into multiple window images through a preset sliding window (the preset sliding window is determined according to preset window parameters including a target window height value and a target sliding step value), so as to facilitate the subsequent calculation of the image gradient values ​​of each window image, and then determine the clearest window image, which helps to accurately determine the optimal focus height and provide data support for subsequent focusing operations on the linear image.

[0091] In some of the embodiments, the window image determination module 401 is further used to: obtain multiple row images corresponding to the target object, and splice the multiple row images along the image height direction to obtain an RGB color image; wherein the row image is obtained by linearly scanning and photographing the target object based on different preset focusing heights using a linear scanning device; and perform image conversion processing on the RGB color image to obtain a grayscale image.

[0092] Through linear scanning and stitching, it can be ensured that each line in the image is fully evaluated, which can help quickly find the best focus position, achieve automatic focus, and thus improve the focus accuracy. By evaluating the complete stitched image, and in the stitching process, the influence of noise on clarity evaluation can be reduced through preprocessing methods (such as filtering). After conversion to a grayscale image, it is helpful for subsequent calculation of the image gradient value, and then determine the clearest line and the best focus height.

[0093] The gradient value calculation module 402 is used to calculate the image gradient value corresponding to each window image.

[0094] By combining the sliding window and the Brenner gradient through the above setting, the clarity evaluation of the local image (i.e., the window image) is realized, and then the window image with the highest clarity can be determined by comparing the image gradient values ​​of each window image, and then the clearest row can be determined, and the optimal focus height can be determined.

[0095] In some of the embodiments, the gradient value calculation module 402 is further used to: for any window image: calculate the square of the grayscale difference between each pixel point in the window image and the associated pixel point in the image width direction to obtain the gradient value corresponding to the pixel point; wherein the pixel point and the associated pixel point are spaced K pixels apart in the image width direction, K is an interval number parameter, and K is a positive integer greater than or equal to 2; sum the gradient values ​​corresponding to each pixel point in the window image to obtain the image gradient value corresponding to the window image.

[0096] Therefore, based on the above settings, the embodiment of the present invention provides an improved Brenner gradient function, sets an adjustable interval number parameter, and adjusts the interval number parameter based on the actual situation (that is, the interval number parameter is adaptively adjusted according to the noise type, morphology, distribution, etc.), so as to obtain a more accurate image gradient value, which helps to improve the accuracy of clarity evaluation, improve calculation efficiency, and thus improve the subsequent image processing effect, and can adapt to different types of images and application scenarios. In addition, the adjustable target interval number can also be applied to different scanning requirements, such as high-resolution scanning or low-resolution scanning.

[0097] In some of the embodiments, the image processing device 400 further includes a parameter optimization module, which is used to: obtain a plurality of sample grayscale images of known clearest rows, and determine a plurality of window images corresponding to each sample grayscale image under different window parameter preset values ​​based on a plurality of sliding windows corresponding to different window parameter preset values; calculate the image gradient values ​​corresponding to each window image under different interval number parameter preset values ​​based on different interval number parameter preset values, and determine the target window image corresponding to each sample grayscale image under different parameter value combinations and the target row where the center line of the target window image is located according to the maximum gradient value in the image gradient values; calculate the row error according to the known clearest row corresponding to the sample grayscale image and the target row under different parameter value combinations, and calculate the average of the row errors of the plurality of sample grayscale images as the total error, and determine that the window parameter preset values ​​and the interval number preset values ​​corresponding to the total error are the optimal parameter value combination.

[0098] Based on the above settings, the window parameters and interval number parameters are optimized by analyzing multiple sample grayscale images containing different noise types, forms, and distributions, thereby improving the adaptive adjustment mechanism for noise in image clarity evaluation. The optimized window parameters and interval number parameters can be used to find the clearest lines more quickly and accurately, thereby improving the focusing accuracy.

[0099] In some of the embodiments, the parameter optimization module is further used to: set the row error corresponding to defocus as an error threshold, filter the row errors calculated from multiple sample grayscale images under different parameter value combinations according to the error threshold, and calculate the average value of the multiple row errors after the filtering process.

[0100] Through the above settings, excluding samples with large errors can reduce the impact of noise on subsequent clarity evaluation results, making the screened samples closer to the actual situation, and helping to more accurately determine the optimal parameter value combination corresponding to the window parameters and interval number parameters.

[0101] The focus height determination module 403 is used to determine that the window image corresponding to the maximum gradient value among the image gradient values ​​is the target window image, and determine the target focus height according to the sliding window position corresponding to the target window image.

[0102] In some of the embodiments, the focus height determination module 403 is used to determine a target position of a window center line of a target window image in an image height direction, and use a focus height corresponding to the target position as a target focus height.

[0103] By calculating the maximum gradient value of the image gradient in all window images, the target window image corresponding to the maximum gradient value is the clearest window image, and the position of the center line of the target window image in the image height direction, the image row corresponding to this position is the clearest scanning line, corresponding to the best focus height. Through the above settings, the accuracy of image clarity evaluation is guaranteed and the efficiency of determining the clearest image row is improved.

[0104] In some of the embodiments, the image processing device 400 further includes a focus height setting module, which is used to set the focus height of the linear scanning device according to the target focus height, so as to scan and photograph the target object based on the set linear scanning device to obtain a target linear scanning image.

[0105] The target focus height determined by the above steps can accurately adjust the focus height of the linear scanning device to ensure that the linear scanning device can work at the optimal focus height, which can significantly improve the overall clarity of the image obtained during scanning and photography. In addition, the determination of the target focus height reduces the number of rescans caused by inaccurate focus, improves the efficiency of obtaining linear images, and improves image quality.

[0106] The image processing device provided by the embodiment of the present invention has a window image determination module, which is used to obtain a grayscale image of a target object obtained after linear scanning, set a sliding window, and slide the sliding window along the image height direction to obtain a plurality of window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value; a gradient value calculation module, which is used to respectively calculate the image gradient values ​​corresponding to each window image; and a focus height determination module, which is used to determine the window image corresponding to the maximum gradient value in the image gradient value as the target window image, and determine the target focus height according to the sliding window position corresponding to the target window image, thereby overcoming the problems of poor stability, low clarity evaluation accuracy, poor image processing effect, and narrow applicable scenes of the clarity evaluation method in the related art, and realizing the division of the linear image into a plurality of window images, and determining the target window image with the highest clarity by comparing the image gradient values ​​corresponding to the plurality of window images, and then determining the target focus height, thereby achieving the determination of the clarity of the local image, significantly improving the clarity evaluation accuracy, improving the stability of the clarity evaluation method, and improving the image processing effect, thereby providing support for the focusing operation of the linear scanning in the scanning and photographing process, and expanding the technical effect of the applicable scenes of the image processing method.

[0107] An embodiment of the present invention further provides a non-transitory machine-readable medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to execute the method of the embodiment of the present invention.

[0108] The embodiment of the present invention further provides a computer program product, including a computer program, wherein the computer program is used to make the computer perform the method of the embodiment of the present invention when executed by a processor of the computer. The computer program product should be understood as a software product that mainly implements the above method of the present application through a computer program.

[0109] An embodiment of the present invention further provides an electronic device, comprising: at least one processor; and a memory in communication with the at least one processor. The memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the electronic device executes the method of the embodiment of the present invention.

[0110] refer to Figure 5 , a block diagram of an electronic device that can be used as a server or client of an embodiment of the present invention will now be described, which is an example of a hardware device that can be applied to various aspects of the present invention. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0111] like Figure 5 As shown, the electronic device includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 to a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0112] Multiple components in the electronic device are connected to the I / O interface 505, including: an input unit 506, an output unit 507, a storage unit 508, and a communication unit 509. The input unit 506 can be any type of device that can input information to the electronic device, and the input unit 506 can receive input digital or character information, and generate key signal input related to user settings and / or function control of the electronic device. The output unit 507 can be any type of device that can present information, and can include but is not limited to a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 508 can include but is not limited to a disk, an optical disk. The communication unit 509 allows the electronic device to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and can include but is not limited to a modem, a network card, an infrared communication device, and / or a wireless communication transceiver, such as a Bluetooth device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0113] The computing unit 501 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a CPU, a graphics processing unit (GPU), various special artificial intelligence (AI) computing units, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 501 performs the various methods and processes described above. For example, in some embodiments, the method embodiments of the present invention may be implemented as a computer program, which is tangibly contained in a machine-readable medium, such as a storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on an electronic device via a ROM 502 and / or a communication unit 509. In some embodiments, the computing unit 501 may be configured to perform the above-described method in any other appropriate manner (e.g., by means of firmware).

[0114] The computer programs for implementing the methods of the embodiments of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer programs are executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer programs may be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.

[0115] In the context of an embodiment of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or apparatus. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable signal medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, or infrared systems, devices, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0116] It should be noted that the term "including" and its variations used in the embodiments of the present invention are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". The modifications of "one" and "multiple" mentioned in the embodiments of the present invention are illustrative rather than restrictive. Those skilled in the art should understand that unless the context clearly indicates otherwise, it should be understood as "one or more".

[0117] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the images acquired in the embodiments of the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0118] The various steps described in the method implementation methods provided in the embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method implementation methods may include additional steps and / or omit the steps shown. The scope of protection of the present invention is not limited in this respect.

[0119] The term "embodiment" in this specification refers to specific features, structures or characteristics described in conjunction with the embodiment that can be included in at least one embodiment of the present invention. The appearance of this phrase in various places in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. The various embodiments in this specification are described in a related manner, and the same or similar parts between the various embodiments refer to each other. In particular, for the device, equipment, and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts refer to the partial description of the method embodiment.

[0120] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of protection. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the attached claims.

Claims

1. An image processing method, characterized in that: include: Obtain a grayscale image of the target object obtained after linear scanning, set a sliding window, and slide the sliding window along the image height direction to obtain multiple window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value; the grayscale image refers to a grayscale image corresponding to a linear image formed by splicing multiple row images obtained by linear scanning of the target object; Calculating the image gradient values ​​corresponding to each of the window images respectively; Determine a window image corresponding to a maximum gradient value among the image gradient values ​​as a target window image, and determine a target focus height according to a sliding window position corresponding to the target window image; The step of calculating the image gradient value corresponding to each of the window images comprises: for any window image: calculating the square of the grayscale difference between each pixel point in the window image and the associated pixel point in the image width direction, to obtain the gradient value corresponding to the pixel point; wherein the pixel point and the associated pixel point are spaced by K pixels in the image width direction, K is an interval number parameter, and K is a positive integer greater than or equal to 2; summing the gradient values ​​corresponding to each pixel point in the window image, to obtain the image gradient value corresponding to the window image; The method also includes a step of calculating an optimal parameter value combination: obtaining a plurality of sample grayscale images of known clearest rows, and determining a plurality of window images corresponding to each of the sample grayscale images under different window parameter preset values ​​based on a plurality of sliding windows corresponding to different window parameter preset values; calculating image gradient values ​​corresponding to each window image under different interval number parameter preset values ​​based on different interval number parameter preset values, and determining a target window image corresponding to each sample grayscale image under different parameter value combinations and a target row where a center line of the target window image is located based on a maximum gradient value among the image gradient values; calculating a row error based on the known clearest row corresponding to the sample grayscale image and the target row under different parameter value combinations, and calculating an average of the row errors of a plurality of the sample grayscale images as a total error, and determining that the window parameter preset value and the interval number preset value corresponding to the time when the total error is minimized are the optimal parameter value combination.

2. The method according to claim 1, characterized in that: The step of calculating the total error of a plurality of sample grayscale images comprises: The row error corresponding to the defocus is set as the error threshold, and the row errors calculated under different parameter value combinations of the multiple sample grayscale images are screened according to the error threshold, and the average value of the multiple row errors after the screening is calculated as the total error.

3. The method according to claim 1, characterized in that The step of obtaining a grayscale image of the target object after linear scanning comprises: Acquire multiple line images corresponding to the target object, and splice the multiple line images along the image height direction to obtain an RGB color image; wherein the line images are obtained by linearly scanning and photographing the target object based on different preset focus heights using a linear scanning device; The RGB color image is subjected to image conversion processing to obtain the grayscale image.

4. The method according to claim 1, characterized in that: The step of determining the target focus height according to the sliding window position corresponding to the target window image comprises: The target position of the window center line of the target window image in the image height direction is determined, and the focusing height corresponding to the target position is used as the target focusing height.

5. The method according to claim 1, characterized in that: The method further comprises: The focus height of the linear scanning device is set according to the target focus height, so as to scan and photograph the target object based on the set linear scanning device to obtain a target linear scanning image.

6. An image processing device, characterized in that: include: A window image determination module is used to obtain a grayscale image obtained after linear scanning of the target object, set a sliding window, and slide the sliding window along the image height direction to obtain multiple window images corresponding to the grayscale image; wherein the window parameters of the set sliding window include a target window height value and a target sliding step value; the grayscale image refers to a grayscale image corresponding to a linear image formed by splicing multiple row images obtained by linear scanning of the target object; A gradient value calculation module, used to respectively calculate the image gradient values ​​corresponding to each of the window images; A focus height determination module, used to determine the window image corresponding to the maximum gradient value among the image gradient values ​​as the target window image, and determine the target focus height according to the sliding window position corresponding to the target window image; The gradient value calculation module is further used for: for any window image: calculating the square of the grayscale difference between each pixel point in the window image and the associated pixel point in the image width direction, to obtain the gradient value corresponding to the pixel point; wherein the pixel point and the associated pixel point are spaced by K pixels in the image width direction, K is an interval number parameter, and K is a positive integer greater than or equal to 2; summing the gradient values ​​corresponding to each pixel point in the window image, to obtain the image gradient value corresponding to the window image; The device also includes a parameter optimization module, which is used to: obtain a plurality of sample grayscale images of known clearest rows, and determine a plurality of window images corresponding to each of the sample grayscale images under different window parameter preset values ​​based on a plurality of sliding windows corresponding to different window parameter preset values; calculate the image gradient values ​​corresponding to each window image under different interval number parameter preset values ​​based on different interval number parameter preset values, and determine the target window image corresponding to each sample grayscale image under different parameter value combinations and the target row where the center line of the target window image is located according to the maximum gradient value in the image gradient values; calculate the row error according to the known clearest row corresponding to the sample grayscale image and the target row under different parameter value combinations, and calculate the average value of the row errors of the plurality of sample grayscale images as the total error, and determine that the window parameter preset value and the interval number preset value corresponding to the total error are the optimal parameter value combination.

7. An electronic device comprising: A processor, and a memory storing a program, wherein the program comprises instructions, and when the instructions are executed by the processor, the processor executes the method according to any one of claims 1 to 5.

8. A non-transitory machine-readable medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-5.

9. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Non-inductive focusing method and device based on camera

    CN116723395A