Detailed Description
In order to make the objects, features and advantages of the present invention more obvious and understandable, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The first embodiment:
in order to solve the technical problem in the related art that color cast correction cannot be performed on an unknown source image that cannot obtain camera calibration data, the present embodiment provides an image color cast correction method, as shown in fig. 1, which is a basic flow diagram of the image color cast correction method provided by the present embodiment, and the image color cast correction method provided by the present embodiment includes the following steps:
step 101, acquiring a correction seed region in a target image.
Specifically, the Color shading blind removal has the difficulty that the Color cast of the pixel is gradually changed, so that it is difficult to accurately estimate the Color cast of each pixel. Based on this, in the embodiment, first, it is determined that, in an input picture, a region of color rendering is relatively well calculated, that is, a region with a significant color cast is used as a correction seed region, generally, under the irradiation of natural light or indoor white light, a highlight but not overexposed region in the picture should be white, but due to the existence of color rendering, these regions may be relatively light red or blue, these colors may be basically assumed to be the colors of real color rendering, and then the corresponding region is the correction seed region. It should be noted that the image to be corrected input by the present embodiment may be an image of unknown source, for example, an image obtained from a cloud.
As shown in fig. 2, which is a schematic flow chart of a method for acquiring a seed correction region according to this embodiment, in an optional implementation manner of this embodiment, acquiring a seed correction region in a target image specifically includes the following steps:
step 201, converting a target image from an RGB color space to an HSV color space;
step 202, calculating a mask of each pixel point in the target image by adopting a mask value formula;
and step 203, determining a region formed by the pixel points with the mask value of 1 as a correction seed region in the target image.
Specifically, the mask value formula of this embodiment is as follows:
wherein, M represents a mask, (x, y) represents coordinates of a pixel point, R, G, B represents three color channels of red, green and blue respectively, V represents gray scale, and S represents saturation.
It should be noted that, in the above formula, the luminance value, that is, the gray level, of a pixel point is checked first, and when the luminance of the pixel point is too low (for example, less than 0.8) or saturated (equal to 1), the pixel point is excluded. Secondly, according to the observation, the colorrendering colors are basically red and green, and the blue color is very little, so if the value of the blue channel of the pixel point is larger than that of the other two channels, the color rendering is also excluded. If the color saturation of the pixel point is too high (for example, greater than 0.1), it indicates that the color of the pixel point is likely to be the color of the object itself and is also excluded. The remaining pixel points are all pixels which are brighter and have a small amount of red and green colors, and the color of the pixel points can be considered to have a high probability caused by color shading.
In the actual use process, some input images often do not have the correction seed regions meeting the conditions, and the algorithm jumps out in the case. Usually, these images are either vivid in the color of the scene itself or the light source itself has a strong color (such as yellow light), in which case the color rendering of the image itself is also hard to see by the naked eye, so it is reasonable that the algorithm does not process these images.
And 102, calculating a regional color cast correction coefficient of the correction seed region.
Specifically, the basic idea of this embodiment is to determine regions with relatively good estimation of color shift amount, estimate local color shift amount of the image in these regions, and then diffuse these local color shift amounts to the whole image to perform color shift correction of the whole image.
In an optional implementation manner of this embodiment, the calculating the regional color cast correction coefficient of the correction seed region includes: calculating the color offset of each pixel point in the correction seed region by adopting a color offset calculation formula; and determining the calculated color offset as a regional color cast correction coefficient of the correction seed region.
Specifically, the color shift amount calculation formula of the present embodiment is expressed as follows:
where (i, j) represents the coordinates of all the pixel points in a field centered on (x, y).
In this embodiment, each pixel point in the seed region is a pixel point with M (x, y) > 0, and since (i, j) is all pixel points in a field with (x, y) as the center, M (i, j) > 0. It should also be understood that the size of this field is a parameter that can be flexibly set according to the actual usage scenario, and is usually in the width of 3 to 10 pixels. Both offsets should be 1 if there is no color rendering, the RB component would be greater than 1 if it is red, and the GB component would be less than 1 if it is green.
It should be noted that the present embodiment takes the blue channel as the reference channel, and then calculates the ratio of red/blue, and green/blue, of course, in other embodiments, one of the other two channels may be used as the reference channel.
And 103, calculating a global color cast correction coefficient of the target image based on the regional color cast correction coefficient.
Specifically, the present embodiment requires that the calculated color shift amount be diffused from the correction seed area to the full map. Considering that color rendering is irrelevant to the shot scene and is very smooth, the embodiment may implement diffusion in a filtering manner, and diffuse the color correction coefficient from the local part to the whole image.
In practical applications, color shading has an important characteristic that the color is uniformly changed from the optical center of the camera lens to the outside. Assuming that the positions of the lens optical center and the image center are identical, that is, the color shading presents different annular bands outward from the image center. In consideration of this characteristic, the embodiment does not perform filtering in the (x, y) space coordinates of the image during filtering, but converts the image to polar coordinates first, then performs filtering in the polar coordinate space, and then converts the image to space coordinates.
As shown in fig. 3, which is a flowchart of a method for calculating a global color cast correction coefficient according to this embodiment, in an optional implementation manner of this embodiment, calculating a global color cast correction coefficient of a target image based on a regional color cast correction coefficient specifically includes the following steps:
step 301, converting all pixel points in a target image from a space coordinate to a polar coordinate;
step 302, performing Gaussian filtering on masks of all pixel points in a polar coordinate, and performing Gaussian filtering on the regional color cast correction coefficient;
and step 303, calculating the global color cast correction coefficient of the target image by adopting a global color cast correction coefficient calculation formula based on the Gaussian filtering result.
Specifically, the calculation formula of the global color cast correction coefficient of the present embodiment is as follows:
wherein, M ' is a mask after filtering, RB ' is an RB component of the region color cast correction coefficient after filtering, and GB ' is a GB component of the region color cast correction coefficient after filtering.
Fig. 4 is a schematic diagram of the filtering for converting an image into polar coordinates according to the present embodiment, where a represents in spatial coordinates and B represents in polar coordinates. In this embodiment, for one pixel (x, y) in the image, first the distance r and the angle θ from the center point of the image are calculated, and then its position in polar coordinates is located, with the horizontal axis being the angle and the vertical axis being the distance. In polar coordinates, the mask M is first subjected to an anisotropic Gaussian filter, the Gaussian function g (σ)
r,σ
θ) Standard deviation of (a)
θ>>σ
rThat is to say, this embodiment encourages the pixel points under the same radius to have more consistent color correction amount by performing filtering of a larger scale in the horizontal direction. The image is then transformed from polar to spatial coordinates after filtering. Ignoring two spatial transformations, filtered masks
In addition, RB 'and GB' can be obtained by filtering RB and GB separately in the same manner. It should also be noted that, in practical applications, the gaussian filter function may be replaced by other low-pass filter functions, such as box filters with different lengths and widths, which is not limited herein.
And 104, performing global correction on the color cast of the pixel points in the target image according to the global color cast correction coefficient.
Specifically, color shading in the picture is removed without depending on a pre-calibrated blind algorithm, the color correction coefficient is diffused to the whole picture from the local part, and the color shading removal can be performed to a certain degree on the whole picture under the condition that a camera is not calibrated in advance, so that the quality of the picture is improved.
In an optional implementation manner of this embodiment, performing global correction on color cast of a pixel point in a target image according to a global color cast correction coefficient includes: and based on the global color cast correction coefficient, carrying out global correction on the color cast of the pixel points in the target image in R, G, B three color channels by adopting a color cast correction calculation formula.
In this embodiment, after obtaining the full image correction coefficient, the three channels R, G, and B of the final image are respectively corrected in a manner corresponding to the following color cast correction calculation formula:
according to the image color cast correction method provided by the embodiment of the invention, a correction seed region in a target image is obtained; calculating a regional color cast correction coefficient of the correction seed region; calculating a global color cast correction coefficient of the target image based on the regional color cast correction coefficient; and performing global correction on the color cast of the pixel points in the target image according to the global color cast correction coefficient. By implementing the method, the global color cast correction coefficient of the image is determined based on the color cast correction coefficient of the local area with obvious color cast in the image, so that the color cast correction is carried out on the whole image without depending on calibration data of a camera for shooting the image, the blind removal of the color shading of the image with unknown source can be effectively carried out, and the method has wider applicability.
Second embodiment:
in order to solve the technical problem in the related art that the color cast correction cannot be performed on an unknown source image that cannot obtain camera calibration data, the present embodiment shows an image color cast correction device, and specifically, referring to fig. 5, the image color cast correction device of the present embodiment includes:
an obtaining module 501, configured to obtain a correction seed region in a target image;
a first calculating module 502, configured to calculate a regional color cast correction coefficient of the correction seed region;
a second calculating module 503, configured to calculate a global color cast correction coefficient of the target image based on the regional color cast correction coefficient;
and the correction module 504 is configured to perform global correction on color cast of a pixel point in the target image according to the global color cast correction coefficient.
In an optional implementation manner of this embodiment, the obtaining module 501 is specifically configured to: converting the target image from an RGB color space to an HSV color space; calculating the mask of each pixel point in the target image by adopting a mask value taking formula; and determining a region formed by the pixel points with the mask value of 1 as a correction seed region in the target image. Moreover, the mask value formula of the present embodiment is expressed as follows:
wherein, M represents a mask, (x, y) represents coordinates of a pixel point, R, G, B represents three color channels of red, green and blue respectively, V represents gray scale, and S represents saturation.
Further, in an optional implementation manner of this embodiment, the first calculating module 502 is specifically configured to: calculating the color offset of each pixel point in the correction seed region by adopting a color offset calculation formula; and determining the calculated color offset as a regional color cast correction coefficient of the correction seed region. Further, the color shift amount calculation formula of the present embodiment is expressed as follows:
where (i, j) represents the coordinates of all the pixel points in a field centered on (x, y).
Further, in an optional implementation manner of this embodiment, the second calculating module 503 is specifically configured to: converting all pixel points in the target image from the space coordinate to the polar coordinate; performing Gaussian filtering on masks of all pixel points in the polar coordinates, and performing Gaussian filtering on the regional color cast correction coefficient; and calculating the global color cast correction coefficient of the target image by adopting a global color cast correction coefficient calculation formula based on the Gaussian filtering result. The global color cast correction coefficient calculation formula of the present embodiment is expressed as follows:
wherein, M ' is a mask after filtering, RB ' is an RB component of the region color cast correction coefficient after filtering, and GB ' is a GB component of the region color cast correction coefficient after filtering.
Further, in an optional implementation manner of this embodiment, the correcting module 504 is specifically configured to: and based on the global color cast correction coefficient, carrying out global correction on the color cast of the pixel points in the target image in R, G, B three color channels by adopting a color cast correction calculation formula. The formula for calculating the color cast correction in this embodiment is:
it should be noted that, the image color cast correcting method in the foregoing embodiment can be implemented based on the image color cast correcting device provided in this embodiment, and it can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working process of the image color cast correcting device described in this embodiment may refer to the corresponding process in the foregoing method embodiment, and details are not repeated here.
The image color cast correction device provided by the embodiment is adopted to obtain a correction seed area in a target image; calculating a regional color cast correction coefficient of the correction seed region; calculating a global color cast correction coefficient of the target image based on the regional color cast correction coefficient; and performing global correction on the color cast of the pixel points in the target image according to the global color cast correction coefficient. By implementing the method, the global color cast correction coefficient of the image is determined based on the color cast correction coefficient of the local area with obvious color cast in the image, so that the color cast correction is carried out on the whole image without depending on calibration data of a camera for shooting the image, the blind removal of the color shading of the image with unknown source can be effectively carried out, and the method has wider applicability.
The third embodiment:
the present embodiment provides an electronic device, as shown in fig. 6, which includes a processor 601, a memory 602, and a communication bus 603, wherein: the communication bus 603 is used for realizing connection communication between the processor 601 and the memory 602; the processor 601 is configured to execute one or more computer programs stored in the memory 602 to implement at least one step of the image color cast correcting method in the first embodiment.
The present embodiments also provide a computer-readable storage medium including volatile or non-volatile, removable or non-removable media implemented in any method or technology for storage of information such as computer-readable instructions, data structures, computer program modules or other data. Computer-readable storage media include, but are not limited to, RAM (Random Access Memory), ROM (Read-Only Memory), EEPROM (Electrically Erasable Programmable Read-Only Memory), flash Memory or other Memory technology, CD-ROM (Compact disk Read-Only Memory), Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by a computer.
The computer-readable storage medium in this embodiment may be used for storing one or more computer programs, and the stored one or more computer programs may be executed by a processor to implement at least one step of the method in the first embodiment.
The present embodiment also provides a computer program, which can be distributed on a computer readable medium and executed by a computing device to implement at least one step of the method in the first embodiment; and in some cases at least one of the steps shown or described may be performed in an order different than that described in the embodiments above.
The present embodiments also provide a computer program product comprising a computer readable means on which a computer program as shown above is stored. The computer readable means in this embodiment may include a computer readable storage medium as shown above.
It will be apparent to those skilled in the art that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software (which may be implemented in computer program code executable by a computing device), firmware, hardware, and suitable combinations thereof. In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be performed by several physical components in cooperation. Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit.
In addition, communication media typically embodies computer readable instructions, data structures, computer program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as known to one of ordinary skill in the art. Thus, the present invention is not limited to any specific combination of hardware and software.
The foregoing is a more detailed description of embodiments of the present invention, and the present invention is not to be considered limited to such descriptions. For those skilled in the art to which the invention pertains, several simple deductions or substitutions can be made without departing from the spirit of the invention, and all shall be considered as belonging to the protection scope of the invention.