CN115760653B - Image correction method, device, equipment and readable storage medium - Google Patents
Image correction method, device, equipment and readable storage medium Download PDFInfo
- Publication number
- CN115760653B CN115760653B CN202310028630.9A CN202310028630A CN115760653B CN 115760653 B CN115760653 B CN 115760653B CN 202310028630 A CN202310028630 A CN 202310028630A CN 115760653 B CN115760653 B CN 115760653B
- Authority
- CN
- China
- Prior art keywords
- image
- gray value
- calibration
- detected
- pixel point
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Landscapes
- Image Processing (AREA)
Abstract
The invention provides an image correction method, an image correction device and a readable storage medium. The method comprises the following steps: obtaining a black image and a plurality of calibration images; calculating the scaling coefficient of the gray value of each pixel point in each calibration image; selecting a target first average gray value closest to a calculation result obtained by calculating a second average gray value and variance based on pixel points in a bright area of an image to be detected from a plurality of first average gray values corresponding to a plurality of calibration images; and correcting the image to be detected based on the scaling coefficient of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image and the gray value of each pixel point in the image to be detected by taking the calibration image corresponding to the target first average gray value as the standard calibration image, so as to obtain the corrected image to be detected. The invention solves the problem that the prior art cannot obtain accurate correction results when the absorption and reflection of the light of the product to be detected are greatly different from those of the calibration object.
Description
Technical Field
The present invention relates to the field of image processing technologies, and in particular, to an image correction method, apparatus, device, and readable storage medium.
Background
Ideally, when the camera images a target with uniform brightness, the gray values of all pixels in the resulting image should be theoretically the same, however, in practice, there tends to be a large difference in gray values of the individual pixels in the image.
The gray value of each pixel in the image is usually corrected by adopting a flat field correction method at present, wherein the most common flat field correction method is a two-point correction method, namely, the gray value of each pixel in the image is corrected by a scaling factor based on a calibration object with uniform gray level, and the method can quickly correct the gray value of each pixel in the image, but under the condition that the absorption and reflection of light by a product to be detected and the absorption and reflection of light by the calibration object are greatly different, if the gray value of each pixel in the image is still corrected by the scaling factor based on the calibration object with uniform gray level, the correction result is necessarily inaccurate.
Disclosure of Invention
The invention mainly aims to provide an image correction method, an image correction device and a readable storage medium, and aims to solve the problem that an accurate correction result cannot be obtained in the prior art when the absorption and reflection of light of a product to be detected and the absorption and reflection of light of a calibration object are greatly different.
In a first aspect, the present invention provides an image correction method, the image correction method comprising:
obtaining a black image and a plurality of calibration images, wherein the black image is an image acquired when a camera lens is completely shielded, the plurality of calibration images are images of calibration objects with uniform gray scales acquired when the camera lens is not shielded under different preset illumination, and the preset illumination corresponds to the calibration images one by one;
calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image and the first average gray value of the pixel points in each calibration image;
determining a bright area of an image to be detected, and calculating a second average gray value of pixel points in the bright area and a variance of gray values of the pixel points in the bright area;
calculating to obtain a calculation result based on the second average gray value and the variance;
selecting a target first average gray value closest to a calculation result from a plurality of first average gray values corresponding to a plurality of calibration images, wherein the calibration images correspond to the first average gray values one by one;
and correcting the image to be detected based on the scaling coefficient of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image and the gray value of each pixel point in the image to be detected by taking the calibration image corresponding to the target first average gray value as the standard calibration image, so as to obtain the corrected image to be detected.
Optionally, the step of calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image, and the first average gray value of the pixel points in each calibration image includes:
respectively calculating the difference value of the gray value of each pixel point in each calibration image minus the gray value of each corresponding pixel point in the black image to obtain a plurality of difference values;
and calculating the quotient of dividing each difference value by the first average gray value of the pixel points in each calibration image, and taking each quotient as the scaling factor of the gray value of each corresponding pixel point in each calibration image.
Optionally, the step of determining the bright area of the image to be detected includes:
counting the gray values of all pixel points in the image to be detected to obtain a gray histogram;
determining the maximum gray values, corresponding to the gray values, of which the number is greater than a threshold value from the gray histogram as target gray values;
and determining the area where the pixel point with the gray value larger than the target gray value in the image to be detected is a bright area.
Optionally, the step of calculating a calculation result based on the second average gray value and the variance includes:
Calculating the sum of the quotient of the variance divided by the second average gray value and the second average gray value, wherein the sum is 3 times, and obtaining a calculation result.
Optionally, the step of correcting the image to be detected based on the scaling factor of the gray value of each pixel in the standard calibration image, the gray value of each pixel in the black image, and the gray value of each pixel in the image to be detected to obtain the corrected image to be detected includes:
calculating the product of the gray value of each pixel point of the image to be detected multiplied by the scaling coefficient of the gray value of each corresponding pixel point in the standard calibration image;
and adding the gray value of each corresponding pixel point in the black image by using the product to obtain the gray value of each pixel point in the corrected image to be detected.
Optionally, after the step of acquiring the black image and the plurality of calibration images, the method includes:
and determining abnormal pixel points in each calibration image, and recording coordinates of the abnormal pixel points, wherein the pixel points with gray values outside a preset gray value range are the abnormal pixel points.
Optionally, after the step of correcting the image to be detected with the calibration image corresponding to the target first average gray value as the standard calibration image based on the scaling factor of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image, and the gray value of each pixel point in the image to be detected, the step of obtaining the corrected image to be detected includes:
Determining abnormal pixel points in the corrected image to be detected based on the coordinates of the abnormal pixel points in the standard calibration image, wherein the coordinates of the abnormal pixel points in the corrected image to be detected are the same as the coordinates of the abnormal pixel points in the standard calibration image;
filtering gray values of abnormal pixel points in the corrected image to be detected based on N filters respectively to obtain N new gray values corresponding to each abnormal pixel point in the corrected image to be detected, wherein N is a positive integer, and the window sizes of the filters are different;
and replacing the gray value of the abnormal pixel point in the corrected image to be detected by the average value of N new gray values corresponding to each abnormal pixel point in the corrected image to be detected.
In a second aspect, the present invention also provides an image correction apparatus including:
the acquisition module is used for acquiring a black image and a plurality of calibration images, wherein the black image is an image acquired when the camera lens is completely shielded, the plurality of calibration images are images of calibration objects with uniform gray scales acquired when the camera lens is not shielded under different preset illumination, and the preset illumination corresponds to the calibration images one by one;
The first calculation module is used for calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image and the first average gray value of the pixel points in each calibration image;
the determining module is used for determining a bright area of the image to be detected and calculating a second average gray value of the pixel points in the bright area and a variance of the gray values of the pixel points in the bright area;
the second calculation module is used for calculating and obtaining a calculation result based on the second average gray value and the variance;
the selecting module is used for selecting a target first average gray value closest to the calculation result from a plurality of first average gray values corresponding to a plurality of calibration images, wherein the calibration images correspond to the first average gray values one by one;
the correction module is used for correcting the image to be detected based on the scaling coefficient of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image and the gray value of each pixel point in the image to be detected by taking the calibration image corresponding to the target first average gray value as the standard calibration image, so as to obtain the corrected image to be detected.
In a third aspect, the present invention also provides an image correction apparatus comprising a processor, a memory, and an image correction program stored on the memory and executable by the processor, wherein the image correction program, when executed by the processor, implements the steps of the image correction method as described above.
In a fourth aspect, the present invention also provides a readable storage medium having stored thereon an image correction program, wherein the image correction program, when executed by a processor, implements the steps of the image correction method as described above.
In the invention, a black image and a plurality of calibration images are acquired, wherein the black image is an image acquired when a camera lens is completely shielded, the plurality of calibration images are images of calibration objects with uniform gray scales acquired when the camera lens is not shielded under different preset illumination, and the preset illumination corresponds to the calibration images one by one; calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image and the first average gray value of the pixel points in each calibration image; determining a bright area of an image to be detected, and calculating a second average gray value of pixel points in the bright area and a variance of gray values of the pixel points in the bright area; calculating to obtain a calculation result based on the second average gray value and the variance; selecting a target first average gray value closest to a calculation result from a plurality of first average gray values corresponding to a plurality of calibration images, wherein the calibration images correspond to the first average gray values one by one; and correcting the image to be detected based on the scaling coefficient of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image and the gray value of each pixel point in the image to be detected by taking the calibration image corresponding to the target first average gray value as the standard calibration image, so as to obtain the corrected image to be detected. According to the invention, images of a plurality of uniform gray scale calibration objects with different absorption and reflection of light are simulated by using images of a plurality of calibration objects with different preset light, then a standard calibration image corresponding to a target first average gray scale value with the closest calculation result obtained based on the second average gray scale value of pixel points in a light area of the image to be detected and the variance calculation is selected, the standard calibration image is the image of the uniform gray scale calibration object with the closest absorption and reflection of light by the image to be detected, and finally the scaling factor of the gray scale value of each pixel point in the image of the uniform gray scale calibration object with the closest absorption and reflection of light by the image to be detected, namely the scaling factor of the gray scale value of each pixel point in the standard calibration image, the gray scale value of each pixel point in the black image and the gray scale value of each pixel point in the image to be detected are corrected, so that the problem that the gray scale value of each pixel point in the image can not be corrected accurately by using the uniform gray scale calibration object based on the large difference between the absorption and reflection of light by the detection product and the absorption and reflection of the calibration object in the prior art can be solved.
Drawings
Fig. 1 is a schematic diagram of a hardware configuration of an image correction apparatus according to an embodiment of the present invention;
FIG. 2 is a flowchart of a first embodiment of an image correction method according to the present invention;
FIG. 3 is a flowchart of a second embodiment of an image correction method according to the present invention;
FIG. 4 is a flowchart of a third embodiment of an image correction method according to the present invention;
fig. 5 is a schematic functional block diagram of an embodiment of an image correction apparatus according to the present invention.
The achievement of the objects, functional features and advantages of the present invention will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
In a first aspect, an embodiment of the present invention provides an image correction apparatus, which may be an apparatus having a data processing function such as a personal computer (personal computer, PC), a notebook computer, a server, or the like.
Referring to fig. 1, fig. 1 is a schematic diagram of a hardware configuration of an image correction apparatus according to an embodiment of the present invention. In an embodiment of the present invention, the image correction apparatus may include a processor 1001 (e.g., a central processing unit Central Processing Unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein the communication bus 1002 is used to enable connected communications between these components; the user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard); the network interface 1004 may optionally include a standard wired interface, a WIreless interface (e.g., WIreless-FIdelity, WI-FI interface); the memory 1005 may be a high-speed random access memory (random access memory, RAM) or a stable memory (non-volatile memory), such as a disk memory, and the memory 1005 may alternatively be a storage device independent of the processor 1001. Those skilled in the art will appreciate that the hardware configuration shown in fig. 1 is not limiting of the invention and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
With continued reference to fig. 1, an operating system, a network communication module, a user interface module, and an image correction program may be included in the memory 1005, which is one type of computer storage medium in fig. 1. The processor 1001 may call an image correction program stored in the memory 1005 and execute the image correction method provided by the embodiment of the present invention.
In a second aspect, an embodiment of the present invention provides an image correction method.
In an embodiment, referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of an image correction method according to the present invention. As shown in fig. 2, the image correction method includes:
step S10, obtaining a black image and a plurality of calibration images, wherein the black image is an image acquired when a camera lens is completely shielded, the plurality of calibration images are images of calibration objects with uniform gray scales acquired when the camera lens is not shielded under different preset illumination, and the preset illumination corresponds to the calibration images one by one;
in this embodiment, a black image captured by a camera lens when the camera lens is completely blocked and a calibration image of a calibration object with uniform gray level acquired when the camera lens is not blocked under different preset illuminations are obtained.
Step S20, calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image and the first average gray value of the pixel points in each calibration image;
in this embodiment, the gray Value value_offset of each pixel in the black image is obtained, the gray Value value_current of each pixel in each calibration image is calculated based on the gray Value of each pixel in each calibration image to obtain the Average gray Value of each pixel in each calibration image, the Average gray Value of each pixel in the calibration image is recorded as the first Average gray Value, and the scaling factor of the gray Value of each pixel in each calibration image is calculated based on the gray Value value_offset of each pixel in the black image, the gray Value value_current of each pixel in each calibration image, and the first Average gray Value value_average of each pixel in each calibration image. It is easily conceivable that there are several calibration images with several first average gray values, i.e. the number of calibration images corresponds one-to-one to the number of first average gray values.
Further, in an embodiment, step S20 includes:
Respectively calculating the difference value of the gray value of each pixel point in each calibration image minus the gray value of each corresponding pixel point in the black image to obtain a plurality of difference values;
and calculating the quotient of dividing each difference value by the first average gray value of the pixel points in each calibration image, and taking each quotient as the scaling factor of the gray value of each corresponding pixel point in each calibration image.
In this embodiment, taking 5 calibration images as an example, namely, calibration image a, calibration image B, calibration image C, calibration image D and calibration image E, respectively, dividing a plurality of differences of gray values of each pixel point at corresponding positions in the black image by a first average gray value of each pixel point in the calibration image a based on gray values of each pixel point in the calibration image a, respectively, where the obtained quotient is a scaling factor of gray values of each corresponding pixel point in the calibration image a, namely, dividing a pixel point q of a first row and a first column in the black image 1 The gray value of (a), the pixel point a of the first row and the first column in the calibration image A 1 Is substituted into the formula for the first average gray value of the pixel points in the calibration image ACalculating to obtain a pixel point a in the calibration image A 1 And so on, the gray value of each pixel point in the black image and the calibration chart The gray value of each pixel point in the image A and the first average gray value of the pixel points in the calibration image A are respectively substituted into the formula
The scaling factor of the gray value of each pixel corresponding to the calibration image A can be calculated, and then the scaling factor of the gray value of each pixel in the black image, the gray value of each pixel in each calibration image and the first average gray value of each pixel in each calibration image can be calculated by the above formulas. The gray Value of each pixel point in the black image is represented by value_offset, the gray Value of each pixel point in each calibration image is represented by value_current, the first Average gray Value of each pixel point in each calibration image is represented by value_average, and the scaling factor of the gray Value of each corresponding pixel point in each calibration image is represented by scale.
Step S30, determining a bright area of an image to be detected, and calculating a second average gray value of pixel points in the bright area and a variance of gray values of the pixel points in the bright area;
in this embodiment, an image to be detected of an object to be detected is obtained, and a bright area of the image to be detected is determined. Calculating the average gray value of the pixel points in the bright area of the image to be detected based on the gray values of the pixel points in the bright area of the image to be detected, and marking the average gray value of the pixel points in the bright area of the image to be detected as a second average gray value And the variance of the gray value of the pixel point in the bright area of the image to be detected +.>。
Further, in an embodiment, referring to fig. 3, fig. 3 is a flowchart illustrating a second embodiment of an image correction method according to the present invention. As shown in fig. 3, the step of determining the bright area of the image to be detected includes:
step S301, counting gray values of all pixel points in an image to be detected to obtain a gray histogram;
step S302, determining the maximum gray value, the number of which is greater than a threshold value, corresponding to the gray value from the gray histogram as a target gray value;
step S303, determining the area where the pixel point with the gray value larger than the target gray value in the image to be detected is a bright area.
In this embodiment, gray values of all pixel points in an image to be detected are counted to obtain a gray histogram, wherein a horizontal axis of the gray histogram represents the gray values, and a vertical axis of the gray histogram represents the number corresponding to each gray value.
And determining the maximum gray value of the gray values with the number larger than the threshold value from the gray histogram of the image to be detected as a target gray value. Taking the threshold value of 5 as an example, if several peaks in the broken line gray level histogram are respectively: the maximum gray value 220 of the gray values with the number greater than the threshold value is determined to be the target gray value, wherein the gray value is 50, the number of the pixel points is 3, the gray value is 100, the number of the pixel points is 50, the gray value is 150, the number of the pixel points is 60, the gray value is 220, the number of the pixel points is 40, and the gray value is 245, and the number of the pixel points is 245 and 2.
Step S40, calculating to obtain a calculation result based on the second average gray value and the variance;
in this embodiment, a second average gray value of the pixel points in the bright region of the image to be detected is obtainedAnd the variance of the gray value of the pixel point in the bright area of the image to be detected +.>Thereafter, a second average gray value +.based on the pixel points in the bright area of the image to be detected>And the variance of the gray value of the pixel point in the bright area of the image to be detected +.>And (5) calculating to obtain a calculation result.
Further, in an embodiment, step S40 includes:
calculating the sum of the quotient of the variance divided by the second average gray value and the second average gray value, wherein the sum is 3 times, and obtaining a calculation result.
In this embodiment, based on the 3 sigma principle, the calculated result is obtained by dividing the variance of the gray value of the pixel point in the bright area of the image to be detected by the quotient of the second average gray value of the pixel point in the bright area of the image to be detected and the sum of the second average gray value of the pixel point in the bright area of the image to be detected. That is, the second average gray value of the pixel point in the bright area of the image to be detectedAnd the variance of the gray value of the pixel point in the bright area of the image to be detected +. >Substitution formulaObtaining the calculation result->。
Step S50, selecting a target first average gray value closest to a calculation result from a plurality of first average gray values corresponding to a plurality of calibration images, wherein the calibration images correspond to the first average gray values one by one;
in this embodiment, since the number of the calibration images corresponds to the number of the first Average gray values one by one, if there are 5 calibration images, the calculation result is selected from the 5 first Average gray values value_average corresponding to the 5 imagesThe closest target is the first average gray value. It is readily appreciated that the number of calibration images is provided herein for reference only and is not limiting.
And step S60, using a calibration image corresponding to the target first average gray value as a standard calibration image, and correcting the image to be detected based on the scaling coefficient of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image and the gray value of each pixel point in the image to be detected to obtain a corrected image to be detected.
In this embodiment, since each first average gray value has its corresponding calibration image, after selecting the target first average gray value, the calibration image corresponding to the target first average gray value is used as the standard calibration image, and then each pixel point in the corresponding position in the image to be detected is corrected based on the scaling factor of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image, and the gray value of each pixel point in the image to be detected, so as to obtain the corrected image to be detected.
Further, in an embodiment, the step of correcting the image to be detected based on the scaling factor of the gray value of each pixel in the standard calibration image, the gray value of each pixel in the black image, and the gray value of each pixel in the image to be detected to obtain a corrected image to be detected includes:
calculating the product of the gray value of each pixel point of the image to be detected multiplied by the scaling coefficient of the gray value of each corresponding pixel point in the standard calibration image;
and adding the gray value of each corresponding pixel point in the black image by using the product to obtain the gray value of each pixel point in the corrected image to be detected.
In this embodiment, the gray value of the pixel point a of the first row and the second column in the image to be detected is calculated to multiply the gray value of the pixel point a of the first row and the second column in the standard calibration imageIs based on the product of the scaling coefficients of +.>Plus pixel points of the first row and the second column in the black image +.>The gray value of the pixel point a of the first row and the second column in the image to be detected after correction is obtained, namely the gray value of the pixel point a of the first row and the second column in the image to be detected, and the pixel point of the first row and the second column in the standard calibration image are->Is set in the first row and the second row of pixels in the black image +. >Is substituted into the formula
And calculating to obtain the gray value of the pixel point a of the first row and the second column in the corrected image to be detected. Wherein (1)>Gray value of pixel point a representing the first row and the second column in the corrected image to be detected, < >>Representing the gray value of the pixel point a of the first row and the second column in the image to be detected,pixels representing the first row and the second column of the standard calibration image>Is used for the scaling factor of the gray value of (c),pixel points representing the first row and the second column in a black image +.>Is a gray value of (a). And so on, respectively substituting the gray value of each pixel point of the image to be detected, the scaling coefficient of the gray value of each corresponding pixel point in the standard calibration image and the gray value of each corresponding pixel point in the black image into the formula->And obtaining the gray value of each pixel point in the corrected image to be detected.
In the embodiment, a black image and a plurality of calibration images are acquired, wherein the black image is an image acquired when a camera lens is completely shielded, the plurality of calibration images are images of calibration objects with uniform gray scales acquired when the camera lens is not shielded under different preset illumination, and the preset illumination corresponds to the calibration images one by one; calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image and the first average gray value of the pixel points in each calibration image; determining a bright area of an image to be detected, and calculating a second average gray value of pixel points in the bright area and a variance of gray values of the pixel points in the bright area; calculating to obtain a calculation result based on the second average gray value and the variance; selecting a target first average gray value closest to a calculation result from a plurality of first average gray values corresponding to a plurality of calibration images, wherein the calibration images correspond to the first average gray values one by one; and correcting the image to be detected based on the scaling coefficient of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image and the gray value of each pixel point in the image to be detected by taking the calibration image corresponding to the target first average gray value as the standard calibration image, so as to obtain the corrected image to be detected. According to the embodiment, images of a plurality of uniform gray scale calibration objects with different absorption and reflection of light are simulated by using images of a plurality of calibration objects with different preset lights, then a standard calibration image corresponding to a target first average gray scale value which is obtained by calculating based on a second average gray scale value of pixel points in a bright area of the image to be detected and variance, wherein the standard calibration image is an image of the uniform gray scale calibration object which is closest to the absorption and reflection of the light by the image to be detected, and finally the scaling factor of the gray scale value of each pixel point in the image of the uniform gray scale calibration object which is closest to the absorption and reflection of the light by the image to be detected, namely the scaling factor of the gray scale value of each pixel point in the standard calibration image, the gray scale value of each pixel point in the black image and the gray scale value of each pixel point in the image to be detected are selected, so that the problem that the gray scale value of each pixel point in the image to be detected cannot be corrected by using the uniform gray scale calibration coefficient obtained by the image can still be solved under the condition that the difference of absorption and reflection of the light by the detection product is very large.
Further, in an embodiment, referring to fig. 4, fig. 4 is a flowchart of a third embodiment of the image correction method according to the present invention. As shown in fig. 4, after the step of acquiring the black image and the plurality of calibration images, the method includes:
step S70, determining abnormal pixel points in each calibration image, and recording coordinates of the abnormal pixel points, wherein the pixel points with gray values outside a preset gray value range are the abnormal pixel points.
In this embodiment, the gray values of the pixels in each calibration image are detected respectively, and if there are pixels whose gray values are outside the preset gray value range, the pixels whose gray values are outside the preset gray value range are abnormal pixels. After determining the abnormal pixel points in each calibration image, the coordinates of the abnormal pixel points in the calibration image are recorded. It should be noted that, the step S70 may be performed after the step S10, and may also be performed after the step S60, and the step S70 needs to be performed before the step S80.
Further, in an embodiment, with continued reference to fig. 4, after step S60, the method includes:
step S80, determining abnormal pixel points in the corrected image to be detected based on the coordinates of the abnormal pixel points in the standard calibration image, wherein the coordinates of the abnormal pixel points in the corrected image to be detected are the same as the coordinates of the abnormal pixel points in the standard calibration image;
Step S90, respectively filtering gray values of abnormal pixel points in the corrected image to be detected based on N filters to obtain N new gray values corresponding to each abnormal pixel point in the corrected image to be detected, wherein N is a positive integer, and the window sizes of the filters are different;
step S110, replacing the gray value of the abnormal pixel point in the corrected image to be detected with the average value of N new gray values corresponding to each abnormal pixel point in the corrected image to be detected.
In this embodiment, taking the window sizes of the N filters of 3,3 filters of 3×3,5×5,7×7, respectively, the coordinates of the abnormal pixels in the standard calibration image are (0, 1), (10, 3), and (15, 20) respectively as examples, after the coordinates of the abnormal pixels in each calibration image are recorded, the abnormal pixels of the pixels in the corresponding position in the corrected image to be detected are determined according to the positions of the abnormal pixels in the standard calibration image, that is, if the coordinates of the abnormal pixels in the standard calibration image are (0, 1), (10, 3), and (15, 20), the coordinates of the 3 pixels in the corrected image to be detected are also the abnormal pixels, that is, the coordinates of the abnormal pixels in the corrected image to be detected are the same as the coordinates of the abnormal pixels in the standard calibration image.
And (3) carrying out Gaussian filtering on gray values of 3 abnormal pixel points with coordinates of (0, 1), (10, 3) and (15, 20) in the corrected image to be detected based on the 3 filters, and after filtering, carrying out 3 new gray values corresponding to the abnormal pixel points with coordinates of (0, 1), (10, 3) and (15, 20) in the corrected image to be detected. It is easy to think that other filtering methods can be used to filter the gray value of the abnormal pixel point in the corrected image to be detected. Replacing the gray value of the (0, 1) abnormal pixel point in the corrected image with the average value of the 3 new gray values corresponding to the (0, 1) abnormal pixel point in the corrected image, replacing the gray value of the (10, 3) abnormal pixel point in the corrected image with the average value of the 3 new gray values corresponding to the (10, 3) abnormal pixel point in the corrected image, and replacing the gray value of the (15, 20) abnormal pixel point in the corrected image with the average value of the 3 new gray values corresponding to the (15, 20) abnormal pixel point in the corrected image. The gray values of the abnormal pixels in the corrected image to be detected are filtered through N filters respectively, the average value of N new gray values corresponding to each abnormal pixel in the corrected image to be detected obtained after filtering is used for replacing the gray value of the abnormal pixel in the corrected image to be detected, the correction of the gray value of the abnormal pixel in the corrected image to be detected is completed, and the probability that the gray value of the pixel in the corresponding position in the corrected image to be detected is inaccurate due to the abnormal pixel existing in the standard calibration image when the image to be detected is corrected is reduced.
In a third aspect, an embodiment of the present invention further provides an image correction apparatus.
In an embodiment, referring to fig. 5, fig. 5 is a schematic functional block diagram of an image correction device according to an embodiment of the invention. As shown in fig. 5, the image correction apparatus includes:
the acquisition module 10 is configured to acquire a black image and a plurality of calibration images, where the black image is an image acquired when the camera lens is completely blocked, the plurality of calibration images are images of calibration objects with uniform gray scales acquired when the camera lens is not blocked under different preset illuminations, and the preset illuminations correspond to the calibration images one by one;
the first calculating module 20 is configured to calculate a scaling factor of the gray value of each pixel in each calibration image based on the gray value of each pixel in the black image, the gray value of each pixel in each calibration image, and the first average gray value of the pixels in each calibration image;
a determining module 30, configured to determine a bright area of an image to be detected, and calculate a second average gray value of the pixel points in the bright area and a variance of the gray values of the pixel points in the bright area;
a second calculation module 40, configured to calculate a calculation result based on the second average gray value and the variance;
The selecting module 50 is configured to select a target first average gray value closest to the calculation result from a plurality of first average gray values corresponding to a plurality of calibration images, where the calibration images correspond to the first average gray values one to one;
the correction module 60 is configured to correct the image to be detected based on the scaling factor of the gray value of each pixel in the standard calibration image, the gray value of each pixel in the black image, and the gray value of each pixel in the image to be detected, with the calibration image corresponding to the target first average gray value as the standard calibration image, so as to obtain a corrected image to be detected.
Further, in an embodiment, the first computing module 20 is configured to:
respectively calculating the difference value of the gray value of each pixel point in each calibration image minus the gray value of each corresponding pixel point in the black image to obtain a plurality of difference values;
and calculating the quotient of dividing each difference value by the first average gray value of the pixel points in each calibration image, and taking each quotient as the scaling factor of the gray value of each corresponding pixel point in each calibration image.
Further, in an embodiment, the determining module 30 is configured to:
counting the gray values of all pixel points in the image to be detected to obtain a gray histogram;
Determining the maximum gray values, corresponding to the gray values, of which the number is greater than a threshold value from the gray histogram as target gray values;
and determining the area where the pixel point with the gray value larger than the target gray value in the image to be detected is a bright area.
Further, in an embodiment, the second calculating module 40 is configured to:
calculating the sum of the quotient of the variance divided by the second average gray value and the second average gray value, wherein the sum is 3 times, and obtaining a calculation result.
Further, in an embodiment, the correction module 60 is configured to:
calculating the product of the gray value of each pixel point of the image to be detected multiplied by the scaling coefficient of the gray value of each corresponding pixel point in the standard calibration image;
and adding the gray value of each corresponding pixel point in the black image by using the product to obtain the gray value of each pixel point in the corrected image to be detected.
Further, in an embodiment, the determining module 30 is further configured to:
and determining abnormal pixel points in each calibration image, and recording coordinates of the abnormal pixel points, wherein the pixel points with gray values outside a preset gray value range are the abnormal pixel points.
Further, in an embodiment, the correction module 60 is further configured to:
Determining abnormal pixel points in the corrected image to be detected based on the coordinates of the abnormal pixel points in the standard calibration image, wherein the coordinates of the abnormal pixel points in the corrected image to be detected are the same as the coordinates of the abnormal pixel points in the standard calibration image;
filtering gray values of abnormal pixel points in the corrected image to be detected based on N filters respectively to obtain N new gray values corresponding to each abnormal pixel point in the corrected image to be detected, wherein N is a positive integer, and the window sizes of the filters are different;
and replacing the gray value of the abnormal pixel point in the corrected image to be detected by the average value of N new gray values corresponding to each abnormal pixel point in the corrected image to be detected.
The functional implementation of each module in the image correction device corresponds to each step in the embodiment of the image correction method, and the functions and implementation processes thereof are not described in detail herein.
In a fourth aspect, embodiments of the present invention also provide a readable storage medium.
The readable storage medium of the present invention stores thereon an image correction program which, when executed by a processor, implements the steps of the image correction method as described above.
The method implemented when the image correction program is executed may refer to various embodiments of the image correction method of the present invention, and will not be described herein.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above, comprising several instructions for causing a terminal device to perform the method according to the embodiments of the present invention.
The foregoing description is only of the preferred embodiments of the present invention, and is not intended to limit the scope of the invention, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.
Claims (9)
1. An image correction method, characterized in that the image correction method comprises:
obtaining a black image and a plurality of calibration images, wherein the black image is an image acquired when a camera lens is completely shielded, the plurality of calibration images are images of calibration objects with uniform gray scales acquired when the camera lens is not shielded under different preset illumination, and the preset illumination corresponds to the calibration images one by one;
calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image and the first average gray value of the pixel points in each calibration image;
determining a bright area of an image to be detected, and calculating a second average gray value of pixel points in the bright area and a variance of gray values of the pixel points in the bright area;
Calculating to obtain a calculation result based on the second average gray value and the variance;
selecting a target first average gray value closest to a calculation result from a plurality of first average gray values corresponding to a plurality of calibration images, wherein the calibration images correspond to the first average gray values one by one;
the calibration image corresponding to the target first average gray value is used as a standard calibration image, and the image to be detected is corrected based on the scaling coefficient of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image and the gray value of each pixel point in the image to be detected, so that a corrected image to be detected is obtained;
the step of calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image and the first average gray value of the pixel points in each calibration image, includes:
respectively calculating the difference value of the gray value of each pixel point in each calibration image minus the gray value of each corresponding pixel point in the black image to obtain a plurality of difference values;
and calculating the quotient of dividing each difference value by the first average gray value of the pixel points in each calibration image, and taking each quotient as the scaling factor of the gray value of each corresponding pixel point in each calibration image.
2. The image correction method as claimed in claim 1, wherein the step of determining a bright area of the image to be detected comprises:
counting the gray values of all pixel points in the image to be detected to obtain a gray histogram;
determining the maximum gray values, corresponding to the gray values, of which the number is greater than a threshold value from the gray histogram as target gray values;
and determining the area where the pixel point with the gray value larger than the target gray value in the image to be detected is a bright area.
3. The image correction method according to claim 1, wherein the step of calculating a calculation result based on the second average gray value and the variance comprises:
calculating the sum of the quotient of the variance divided by the second average gray value and the second average gray value, wherein the sum is 3 times, and obtaining a calculation result.
4. The image correction method according to claim 1, wherein the step of correcting the image to be detected based on the scaling factor of the gray value of each pixel in the standard calibration image, the gray value of each pixel in the black image, and the gray value of each pixel in the image to be detected, to obtain the corrected image to be detected, comprises:
Calculating the product of the gray value of each pixel point of the image to be detected multiplied by the scaling coefficient of the gray value of each corresponding pixel point in the standard calibration image;
and adding the gray value of each corresponding pixel point in the black image by using the product to obtain the gray value of each pixel point in the corrected image to be detected.
5. The image correction method according to claim 1, characterized by comprising, after the step of acquiring the black image and the plurality of calibration images:
and determining abnormal pixel points in each calibration image, and recording coordinates of the abnormal pixel points, wherein the pixel points with gray values outside a preset gray value range are the abnormal pixel points.
6. The image correction method according to claim 5, wherein after the step of correcting the image to be detected based on the scaling factor of the gray value of each pixel in the standard calibration image, the gray value of each pixel in the black image, and the gray value of each pixel in the image to be detected, which is the calibration image corresponding to the target first average gray value, to obtain the corrected image to be detected, the step of correcting the image to be detected comprises:
determining abnormal pixel points in the corrected image to be detected based on the coordinates of the abnormal pixel points in the standard calibration image, wherein the coordinates of the abnormal pixel points in the corrected image to be detected are the same as the coordinates of the abnormal pixel points in the standard calibration image;
Filtering gray values of abnormal pixel points in the corrected image to be detected based on N filters respectively to obtain N new gray values corresponding to each abnormal pixel point in the corrected image to be detected, wherein N is a positive integer, and the window sizes of the filters are different;
and replacing the gray value of the abnormal pixel point in the corrected image to be detected by the average value of N new gray values corresponding to each abnormal pixel point in the corrected image to be detected.
7. An image correction apparatus, characterized in that the image correction apparatus comprises:
the acquisition module is used for acquiring a black image and a plurality of calibration images, wherein the black image is an image acquired when the camera lens is completely shielded, the plurality of calibration images are images of calibration objects with uniform gray scales acquired when the camera lens is not shielded under different preset illumination, and the preset illumination corresponds to the calibration images one by one;
the first calculation module is used for calculating a scaling factor of the gray value of each pixel point in each calibration image based on the gray value of each pixel point in the black image, the gray value of each pixel point in each calibration image and the first average gray value of the pixel points in each calibration image;
The determining module is used for determining a bright area of the image to be detected and calculating a second average gray value of the pixel points in the bright area and a variance of the gray values of the pixel points in the bright area;
the second calculation module is used for calculating and obtaining a calculation result based on the second average gray value and the variance;
the selecting module is used for selecting a target first average gray value closest to the calculation result from a plurality of first average gray values corresponding to a plurality of calibration images, wherein the calibration images correspond to the first average gray values one by one;
the correction module is used for correcting the image to be detected based on the scaling coefficient of the gray value of each pixel point in the standard calibration image, the gray value of each pixel point in the black image and the gray value of each pixel point in the image to be detected by taking the calibration image corresponding to the target first average gray value as the standard calibration image, so as to obtain a corrected image to be detected;
the first calculation module is specifically configured to calculate difference values of gray values of each pixel point in each calibration image minus gray values of each corresponding pixel point in the black image, so as to obtain a plurality of difference values;
and calculating the quotient of dividing each difference value by the first average gray value of the pixel points in each calibration image, and taking each quotient as the scaling factor of the gray value of each corresponding pixel point in each calibration image.
8. An image correction apparatus comprising a processor, a memory, and an image correction program stored on the memory and executable by the processor, wherein the image correction program, when executed by the processor, implements the steps of the image correction method according to any one of claims 1 to 6.
9. A readable storage medium, wherein an image correction program is stored on the readable storage medium, wherein the image correction program, when executed by a processor, implements the steps of the image correction method according to any one of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310028630.9A CN115760653B (en) | 2023-01-09 | 2023-01-09 | Image correction method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310028630.9A CN115760653B (en) | 2023-01-09 | 2023-01-09 | Image correction method, device, equipment and readable storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN115760653A CN115760653A (en) | 2023-03-07 |
CN115760653B true CN115760653B (en) | 2023-05-09 |
Family
ID=85348735
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310028630.9A Active CN115760653B (en) | 2023-01-09 | 2023-01-09 | Image correction method, device, equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115760653B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116630433B (en) * | 2023-04-24 | 2024-01-26 | 理工特智科技(重庆)有限公司 | Full-scale blackness film image digitizing method, system, equipment and medium |
Family Cites Families (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP4208396B2 (en) * | 2000-08-31 | 2009-01-14 | キヤノン株式会社 | Image processing method, apparatus, and recording medium |
US8659685B2 (en) * | 2008-06-25 | 2014-02-25 | Aptina Imaging Corporation | Method and apparatus for calibrating and correcting shading non-uniformity of camera systems |
JP5218767B2 (en) * | 2009-01-13 | 2013-06-26 | 株式会社リコー | Image processing apparatus, image processing method, program, and recording medium |
CN104680489B (en) * | 2015-02-11 | 2018-09-11 | 深圳怡化电脑股份有限公司 | A kind of method for correcting image and system |
CN105631819A (en) * | 2015-12-25 | 2016-06-01 | 深圳市安健科技股份有限公司 | Flat-field correction method and system of CCD DR detector |
CN106840387B (en) * | 2016-12-09 | 2019-03-05 | 中国科学院国家天文台 | A kind of Objective extraction and flat field correction method of the biggish imaging system of gain difference |
CN107197122A (en) * | 2017-06-12 | 2017-09-22 | 武汉中导光电设备有限公司 | A kind of method for correcting flat field being imaged for area array cameras |
CN107255521B (en) * | 2017-06-28 | 2019-03-26 | 华中科技大学鄂州工业技术研究院 | A kind of Infrared Image Non-uniformity Correction method and system |
CN108088845B (en) * | 2017-12-07 | 2020-09-11 | 武汉精测电子集团股份有限公司 | Imaging correction method and device based on weak information retention |
CN109934875A (en) * | 2017-12-18 | 2019-06-25 | 长光华大基因测序设备(长春)有限公司 | Camera calibration peace field correction apparatus, camera calibration method and method for correcting flat field |
CN111383280A (en) * | 2018-12-29 | 2020-07-07 | 中国科学院长春光学精密机械与物理研究所 | Spatial remote sensing TDICCD camera non-uniformity correction method and device |
CN113808046B (en) * | 2021-09-18 | 2024-04-02 | 凌云光技术股份有限公司 | Flat field correction parameter acquisition method and device |
CN114757853B (en) * | 2022-06-13 | 2022-09-09 | 武汉精立电子技术有限公司 | Method and system for acquiring flat field correction function and flat field correction method and system |
CN115170676A (en) * | 2022-07-25 | 2022-10-11 | Oppo广东移动通信有限公司 | Sensor calibration and image correction method and device, electronic equipment and storage medium |
-
2023
- 2023-01-09 CN CN202310028630.9A patent/CN115760653B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN115760653A (en) | 2023-03-07 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107403421B (en) | Image defogging method, storage medium and terminal equipment | |
CN107507558B (en) | Correction method of LED display screen | |
US8503734B2 (en) | Detecting image detail level | |
CN111368587B (en) | Scene detection method, device, terminal equipment and computer readable storage medium | |
CN105049734A (en) | License camera capable of giving shooting environment shooting prompt and shooting environment detection method | |
CN112070682B (en) | Method and device for compensating image brightness | |
CN113240630A (en) | Speckle image quality evaluation method and device, terminal equipment and readable storage medium | |
CN111896233B (en) | Contrast testing method, contrast testing device and storage medium | |
CN115760653B (en) | Image correction method, device, equipment and readable storage medium | |
CN112689100B (en) | Image detection method, device, equipment and storage medium | |
CN109886864B (en) | Privacy mask processing method and device | |
CN112153371A (en) | Image quality detection method, device, storage medium and product detection method | |
US20150187051A1 (en) | Method and apparatus for estimating image noise | |
JP2014197243A (en) | Pattern processor, pattern processing method and pattern processing program | |
CN113962876B (en) | Pixel distortion correction method, correction device and terminal | |
CN116337412A (en) | Screen detection method, device and storage medium | |
CN114007013A (en) | Fuzzy region determination and anti-shake performance detection method and system, and anti-shake performance detection equipment | |
CN107256540B (en) | Image restoration method and device and three-dimensional reconstruction system | |
CN112017163B (en) | Image ambiguity detection method, device, electronic equipment and storage medium | |
CN113256635A (en) | Defect detection method, device, equipment and readable storage medium | |
CN111369513A (en) | Abnormity detection method, abnormity detection device, terminal equipment and storage medium | |
US20190149757A1 (en) | Image processing device, image processing method, and image processing program | |
CN114820376A (en) | Fusion correction method and device for stripe noise, electronic equipment and storage medium | |
CN111435080B (en) | Water level measuring method, device and system | |
CN115484447B (en) | Projection method, projection system and projector based on high color gamut adjustment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |