Image enhancement method, image enhancement device, computer device and readable storage medium
Technical Field
The invention relates to the technical field of machine vision, in particular to an image enhancement method, an image enhancement device, a computer device and a computer readable storage medium for eliminating illumination influence based on image overall situation.
Background
In the field of image processing, a necessary and critical step of vision-based target detection and tracking is to extract information of a target, such as an outline, a position and the like of the target, from an image, but because a visible light camera which takes the image is influenced by illumination when imaging, the illumination is too strong and too weak, which causes missing or failure of target information extraction. Thus, eliminating the illumination effect is a very critical and essential issue for vision-based target detection and tracking.
Disclosure of Invention
In view of the foregoing, there is a need for an image enhancement method, apparatus, computer apparatus and computer readable storage medium capable of eliminating the influence of illumination on target detection and tracking in an image.
A first aspect of the present application provides an image enhancement method, the method comprising:
acquiring an original image, and converting the original image into an HSV color space;
acquiring a V-channel image from the converted image of the HSV color space, and averaging the V-channel image;
carrying out histogram equalization on the V channel image subjected to the averaging removal;
carrying out black and white binarization on the V channel image subjected to histogram equalization;
and outputting the image subjected to black-white binarization to detect the target in the image.
Preferably, the method of de-averaging the V-channel image includes:
calculating the pixel average value of all pixel points in the V-channel image;
comparing the pixel value of each pixel point with the pixel average value, and judging whether the pixel value of each pixel point is less than or equal to the pixel average value;
if the pixel value of the pixel point is less than or equal to the pixel average value, setting the pixel value of the pixel point to be zero; and
and if the pixel value of the pixel point is larger than the average pixel value, keeping the pixel value of the pixel point unchanged.
Preferably, the method for histogram equalization of the de-averaged V-channel image includes:
counting the occurrence times of each pixel value in the de-averaged V-channel image, and calculating a normalized probability statistic PiWherein P isiCalculated by the following formula:
wherein n isiRepresenting the number of times a pixel value i appears in the V-channel image, and N representing the sum of all the pixel numbers in the V-channel image;
calculating a cumulative distribution S of pixel values in the de-averaged V-channel imagekWherein the cumulative distribution SkCalculated by the following formula:
wherein the value range of k is [0,255 ];
resetting the pixel value of each pixel point according to the cumulative distribution of the pixel values, wherein adjusting the pixel values is performed according to the following formula:
Vnew=Si×gray_max
wherein, gray _ max is the maximum value of gray, i is the pixel value between 0 and the maximum value of gray _ max, Si represents the cumulative distribution corresponding to the pixel value, VnewIs the new pixel value after adjustment.
Preferably, the method for performing black and white binarization on the histogram equalized V-channel image includes:
judging whether the pixel value of each pixel point is greater than a preset threshold value or not;
if the pixel value is larger than the preset threshold value, setting the pixel value to be 255;
and if the pixel value is smaller than the preset value, setting the pixel value to be 0.
Preferably, the preset threshold is a pixel average value after averaging.
Preferably, the preset threshold is a pixel average value after histogram equalization.
A second aspect of the present application provides an image enhancement apparatus, the apparatus comprising: the image conversion module is used for acquiring an original image and converting the original image into an HSV color space;
the averaging removal module is used for obtaining a V-channel image from the converted image of the HSV color space and averaging the V-channel image;
the histogram equalization module is used for performing histogram equalization on the de-averaged V channel image;
the black-and-white binarization module is used for performing black-and-white binarization on the V channel image subjected to histogram equalization;
and the image output module is used for outputting the image subjected to black-white binarization to detect the target in the image.
A third aspect of the application provides a computer apparatus comprising a processor for implementing the image enhancement method when executing a computer program stored in a memory.
A fourth aspect of the present application provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the image enhancement method.
The invention enhances the image edge information by preprocessing the image such as conversion, averaging removal, histogram equalization and the like, highlights the target main body, eliminates the influence of illumination on the image and is beneficial to the detection and tracking of the target information.
Drawings
Fig. 1 is a flowchart of an image enhancement method according to an embodiment of the present invention.
Fig. 2 is an original image provided by one embodiment of the present invention.
Fig. 3 is a V-channel image after converting the original image shown in fig. 2 into an HSV color space.
Fig. 4 is a V-channel image obtained by averaging the V-channel images in fig. 3.
Fig. 5 is a V-channel image obtained by histogram equalizing the V-channel image subjected to the averaging in fig. 4.
Fig. 6 is an image obtained by subjecting the histogram-equalized V-channel image of fig. 5 to black-and-white binarization.
Fig. 7 is a block diagram of an image enhancement apparatus according to an embodiment of the present invention.
FIG. 8 is a schematic diagram of a computer device according to an embodiment of the invention.
Detailed Description
In order that the above objects, features and advantages of the present invention can be more clearly understood, a detailed description of the present invention will be given below with reference to the accompanying drawings and specific embodiments. It should be noted that the embodiments and features of the embodiments of the present application may be combined with each other without conflict.
In the following description, numerous specific details are set forth to provide a thorough understanding of the present invention, and the described embodiments are merely a subset of the embodiments of the present invention, rather than a complete embodiment. 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.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
Preferably, the image enhancement method of the present invention is applied in one or more computer devices. The computer device is a device capable of automatically performing numerical calculation and/or information processing according to a preset or stored instruction, and the hardware thereof includes, but is not limited to, a processor, an external storage medium, a memory, and the like.
The computer device may be, but is not limited to, a desktop computer, a notebook computer, a cloud server, a smart phone, and the like. The computer device can be in man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch panel, gesture recognition equipment, voice control equipment and the like.
Example one
Fig. 1 is a flowchart of image enhancement according to an embodiment of the present invention. The order of the steps in the flow chart may be changed and some steps may be omitted according to different needs. For convenience of explanation, only portions related to the embodiments of the present invention are shown.
As shown in fig. 1, the image enhancement method specifically includes the following steps:
and step S1, acquiring an original image to be processed, and converting the original image into an HSV color space.
The HSV color space is an intuitive color model and is widely applied to image editing. The HSV color space includes three components, Hue (Hue), Saturation (Saturation), and brightness (Value). The color calling angle measurement is in a value range of 0-360 degrees, the value is calculated from red in a counterclockwise direction, the red is 0 degree, the green is 120 degrees, the blue is 240 degrees, and the complementary colors are as follows: yellow is 60 °, cyan is 180 °, and magenta is 300 °. The saturation S indicates how close the color is to the spectral color, the higher the saturation, the darker and more brilliant the color. The brightness indicates the degree to which the color is bright.
In this embodiment, the color space of the original image may be, but is not limited to, RGB, YUV, and the like.
In one embodiment, when the color space of the original image is RGB, the original image is converted from RGB color space to HSV color space by: setting the corresponding RGB value of each pixel point in the original image of the RGB color space as (r, g, b), and the corresponding HSV value after conversion to the HSV color space as (h, s, v), and performing conversion from the RGB color space to the HSV color space by using the following formula:
wherein max is the maximum value of r, g and b, min is the minimum value of r, g and b:
v=max。
in another embodiment, when the color space of the original image is RGB, the original image may be further converted from RGB color space to HSV color space by a multiple regression equation or a neural network conversion model. Converting an original image from an RGB color space to an HSV color space by a multivariate multiple regression equation or a neural network conversion model is prior art and will not be described herein again.
In other embodiments, when the color space of the original image is YUV, the original image is first converted from YUV color space to RGB color space, and then from RGB color space to HSV color space, wherein the YUV color space is converted to RGB color space by the following method:
R=Y+1.402*(V-128);
G=Y–0.344*(U-128)–0.714*(V-128);
B=Y+1.772*(U-128);
after the RGB values are obtained, the RGB color space of the image is then converted into HSV color space by the RGB to HSV conversion method as described above.
For example, if fig. 2 shows an original image of RGB color space to be processed, the original image includes a black and white checkerboard O as a detection target. Converting the original image in fig. 2 from RGB color space to HSV color space, and as shown in fig. 3, converting the original image into a V-channel image.
And step S2, acquiring a V-channel image from the converted image of the HSV color space, and averaging the V-channel image.
Specifically, the method for de-averaging the V-channel image includes:
1) calculating the pixel average value in the V channel image;
calculating the pixel average value of the V-channel image is realized by the following method: acquiring pixel values of all pixel points of the V-channel image, adding all the pixel values, and dividing the sum by the total number of the pixels to obtain an average value image _ mean of all the pixels in the V-channel image;
2) comparing the pixel value v of each pixel point with the pixel average value image _ mean, and judging whether the pixel value v of each pixel point is less than or equal to the pixel average value image _ mean;
3) if the pixel value v of the pixel point is less than or equal to the pixel average value image _ mean, setting the pixel value v of the pixel point to be zero; and
4) if the pixel value v of the pixel point is larger than the pixel average value image _ mean, the pixel value of the pixel point is kept unchanged;
that is, the pixel value V1 of the pixel point in the V-channel image obtained by averaging the V-channel image may be represented as:
for example, continuing with the description of the image as described above, in this example, the detection target in the original image is a checkerboard with black and white grids, which is composed of two extreme colors, white portions in the checkerboard become gray under dark illumination, and black portions in the checkerboard become white when light is bright, so that the image needs to be enhanced to highlight the target. By obtaining the V-channel image after the averaging in fig. 4 by the averaging in the V-channel image in fig. 3, the detection target can be highlighted by changing the black portion to pure black in both the light-up and dark conditions.
And step S3, performing histogram equalization on the de-averaged V-channel image.
Specifically, the method for performing histogram equalization on the de-averaged V-channel image includes:
1) statistics ofCalculating the occurrence frequency of each pixel value in the de-averaged V-channel image and the normalized probability statistics PiWherein P isiCalculated by the following formula:
wherein n isiRepresenting the number of times a pixel value i appears in the V-channel image, and N representing the sum of all the pixel numbers in the V-channel image;
2) calculating a cumulative distribution S of pixel values in the de-averaged V-channel imagekWherein the cumulative distribution SkCalculated by the following formula:
wherein the value range of k is [0,255 ];
3) resetting the pixel value of each pixel point according to the cumulative distribution of the pixel values, wherein adjusting the pixel values is performed according to the following formula:
Vnew=Si×gray_max
wherein, gray _ max is the maximum value of gray, i is the pixel value between 0 and the maximum value of gray _ max, Si represents the cumulative distribution corresponding to the pixel value, VnewIs the new pixel value after adjustment.
In this embodiment, the maximum value of the gradation is 255. In other embodiments, the maximum gray level value may be set to other values within the interval of 0 to 255 as needed.
For example, continuing with the image illustration as described above, after the V-channel image is de-averaged, the black portion of the V-channel image in fig. 4 becomes pure black, and the white portion is still the original color. The histogram equalized image shown in fig. 5 is obtained after the histogram equalization, and the global contrast of the image is increased, especially when the contrast of useful data in the image is quite close. In this way, the luminance can be better distributed over the histogram.
And step S4, performing black and white binarization on the V channel image subjected to histogram equalization.
Specifically, the method for performing black-and-white binarization on the histogram equalized V-channel image includes:
judging whether the pixel value of each pixel point is greater than a preset threshold value or not;
if the pixel value is larger than the preset threshold value, setting the pixel value to be 255;
and if the pixel value is smaller than the preset value, setting the pixel value to be 0.
In an embodiment of the present invention, the preset threshold is a pixel average value after averaging.
In another embodiment of the present invention, the preset threshold is a pixel average value after histogram equalization.
In other embodiments of the present invention, the preset threshold may be manually set according to a scene and pre-stored in a preset storage location.
For example, continuing with the description of the image, after performing black-and-white binarization on the V-channel image after histogram equalization shown in fig. 5, the image after black-and-white binarization shown in fig. 6 is obtained, interference is reduced in the image after black-and-white binarization, and a black-and-white checkerboard as a target to be detected is more prominent, thereby facilitating target detection.
And step S5, outputting the V-channel image subjected to black-white binarization, wherein the output V-channel image subjected to black-white binarization is used for target detection.
The image enhancement method provided by the invention enhances the image through preprocessing such as conversion, averaging removal, histogram equalization and the like, so that the target is more prominent, and the influence of illumination on target detection is eliminated.
Example two
Fig. 7 is a structural diagram of an image enhancement apparatus according to a second embodiment of the present invention, which only shows portions related to the second embodiment of the present invention for convenience of description, and is described in detail below.
Referring to fig. 7, the image enhancement apparatus 100 may be divided into a plurality of functional modules according to the functions performed by the apparatus, and the functional modules are used for performing the steps in the corresponding embodiment of fig. 1 to realize the function of enhancing the image. In an embodiment of the present invention, the functional modules of the image enhancement apparatus 100 may include an image conversion module 101, a de-averaging module 102, a histogram equalization module 103, a black-and-white binarization module 104, and an image output module 105. The functions of the respective functional blocks will be described in detail in the following embodiments.
The image conversion module 101 obtains an original image to be processed, and converts the original image into an HSV color space.
In this embodiment, the color space of the original image may be, but is not limited to, RGB, YUV, and the like.
In one embodiment, when the color space of the original image is RGB, the image conversion module 101 converts the original image from RGB color space to HSV color space by: setting the corresponding RGB value of each pixel point in the original image of the RGB color space as (r, g, b), and the corresponding HSV value after conversion to the HSV color space as (h, s, v), and performing conversion from the RGB color space to the HSV color space by using the following formula:
wherein max is the maximum value of r, g and b, min is the minimum value of r, g and b:
v=max。
in another embodiment, when the color space of the original image is RGB, the image conversion module 101 may further convert the original image from RGB color space to HSV color space by using a multiple regression equation or a neural network conversion model. Converting an original image from an RGB color space to an HSV color space by a multivariate multiple regression equation or a neural network conversion model is prior art and will not be described herein again.
In other embodiments, when the color space of the original image is YUV, the image conversion module 101 converts the original image from YUV color space to RGB color space, and then converts the original image from RGB color space to HSV color space, wherein the YUV color space is converted to RGB color space by the following method:
R=Y+1.402*(V-128);
G=Y–0.344*(U-128)–0.714*(V-128);
B=Y+1.772*(U-128);
after the image conversion module 101 obtains the RGB values, the RGB color space of the image is then converted into the HSV color space by the RGB to HSV conversion method.
The averaging module 102 is configured to obtain a V-channel image from the converted image in the HSV color space, and perform averaging on the V-channel image.
Specifically, the method for the de-averaging module 102 to de-average the V-channel image includes:
1) calculating the pixel average value in the V channel image;
calculating the pixel average value of the V-channel image is realized by the following method: acquiring pixel values of all pixel points of the V-channel image, adding all the pixel values, and dividing the sum by the total number of the pixels to obtain an average value image _ mean of all the pixels in the V-channel image;
2) comparing the pixel value v of each pixel point with the pixel average value image _ mean, and judging whether the pixel value v of each pixel point is less than or equal to the pixel average value image _ mean;
3) if the pixel value v of the pixel point is less than or equal to the pixel average value image _ mean, setting the pixel value v of the pixel point to be zero;
4) if the pixel value v of the pixel point is larger than the pixel average value image _ mean, the pixel value of the pixel point is kept unchanged;
that is, the pixel value V1 of the pixel point in the V-channel image obtained by averaging the V-channel image may be represented as:
the histogram equalization module 103 is configured to perform histogram equalization on the de-averaged V-channel image.
Specifically, the method for histogram equalization of the de-averaged V-channel image by the histogram equalization module 103 includes:
1) counting the occurrence times of each pixel value in the de-averaged V-channel image, and calculating a normalized probability statistic PiWherein P isiCalculated by the following formula:
wherein n isiRepresenting the number of times a pixel value i appears in the V-channel image, and N representing the sum of all the pixel numbers in the V-channel image;
2) calculating a cumulative distribution S of pixel values in the de-averaged V-channel imagekWherein the cumulative distribution SkCalculated by the following formula:
wherein the value range of k is [0,255 ];
3) resetting the pixel value of each pixel point according to the cumulative distribution of the pixel values, wherein adjusting the pixel values is performed according to the following formula:
Vnew=Si×gray_max;
wherein, gray _ max is the maximum value of gray, i is the pixel value between 0 and the maximum value of gray _ max, Si represents the cumulative distribution corresponding to the pixel value, VnewIs the new pixel value after adjustment.
In this embodiment, the maximum value of the gradation is 255. In other embodiments, the maximum gray level value may be set to other values within the interval of 0 to 255 as needed.
The black-and-white binarization module 104 is configured to perform black-and-white binarization on the V-channel image subjected to histogram equalization.
Specifically, the method for performing black-and-white binarization on the histogram equalized V-channel image by the black-and-white binarization module 104 includes:
judging whether the pixel value of each pixel point is greater than a preset threshold value or not;
if the pixel value is larger than the preset threshold value, setting the pixel value to be 255;
and if the pixel value is smaller than the preset value, setting the pixel value to be 0.
In an embodiment of the present invention, the preset threshold is a pixel average value after averaging.
In another embodiment of the present invention, the preset threshold is a pixel average value after histogram equalization.
In other embodiments of the present invention, the preset threshold may be manually set according to a scene and pre-stored in a preset storage location.
The image output module 105 is configured to output the black-and-white binarized V-channel image, and the output black-and-white binarized V-channel image is used for target detection.
EXAMPLE III
Fig. 8 is a schematic diagram of a computer device according to a third embodiment of the present invention. The computer device 1 comprises a memory 20, a processor 30 and a computer program 40, such as an image enhancement program, stored in the memory 20 and executable on the processor 30. The processor 30, when executing the computer program 40, implements the steps in the above-described embodiment of the image enhancement method, such as the steps S1-S5 shown in fig. 1. Alternatively, the processor 30, when executing the computer program 40, implements the functions of each module/unit in the above-mentioned device embodiments, such as the modules 101 to 105 in fig. 7.
Illustratively, the computer program 40 may be partitioned into one or more modules/units that are stored in the memory 20 and executed by the processor 30 to implement the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution process of the computer program 40 in the computer apparatus 1. For example, the computer program 40 can be divided into an image conversion module 101, a de-averaging module 102, a histogram equalization module 103, a black-and-white binarization module 104 and an image output module 105 in fig. 7, and the specific functions of each module are described in embodiment two.
The computer device 1 may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. It will be understood by those skilled in the art that the schematic diagram 8 is only an example of the computer apparatus 1, and does not constitute a limitation to the computer apparatus 1, and may include more or less components than those shown, or combine some components, or different components, for example, the computer apparatus 1 may further include an input and output device, a network access device, a bus, and the like.
The Processor 30 may be a Central Processing Unit (CPU), and may include other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, and the like. The general purpose processor may be a microprocessor or the processor may be any conventional processor or the like, and the processor 30 is the control center of the computer device 1 and connects the various parts of the whole computer device 1 by various interfaces and lines.
The memory 20 may be used for storing the computer program 40 and/or the module/unit, and the processor 30 implements various functions of the computer device 1 by running or executing the computer program and/or the module/unit stored in the memory 20 and calling data stored in the memory 20. The memory 20 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, a phonebook, etc.) created according to the use of the computer apparatus 1, and the like. The storage 20 may include an external storage medium, and may also include a memory. In addition, the memory 20 may include high speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), at least one magnetic disk storage device, a Flash memory device, or other volatile solid state storage device.
The modules/units integrated with the computer device 1 may be stored in a computer-readable storage medium if they are implemented in the form of software functional units and sold or used as separate products. Based on such understanding, all or part of the flow of the method of implementing the above embodiments may also be implemented by a computer program, which may be stored in a computer readable storage medium and used by a processor to implement the steps of the above embodiments of the method. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
In the embodiments provided in the present invention, it should be understood that the disclosed computer apparatus and method can be implemented in other ways. For example, the above-described embodiments of the computer apparatus are merely illustrative, and for example, the division of the units is only one logical function division, and there may be other divisions when the actual implementation is performed.
In addition, functional units in the embodiments of the present invention may be integrated into the same processing unit, or each unit may exist alone physically, or two or more units are integrated into the same unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof. The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference sign in a claim should not be construed as limiting the claim concerned. Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. The units or computer means recited in the computer means claims may also be implemented by the same unit or computer means, either in software or in hardware. The terms first, second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.