Image enhancement method for identifying peak value transformation nonlinear curve
Technical Field
The invention belongs to the technical field of image processing, and particularly relates to an image enhancement method for identifying a peak value transformation nonlinear curve.
background
The untreated dark field picture is too dark and the details in the dark area are not well visible to the human eye. The brightness information directly related to the image brightness is used for finding a way to adjust the brightness distribution, so that the overall visual condition of the picture can be improved, and details and characteristics can be embodied.
At present, when image processing is used for processing brightness image contrast, technologies such as histogram equalization and CLAHE are mostly used, but the technologies still have great defects, such as too much "general" processing, white (when processing dark field images), false white of images, and some black objects become very unnatural for stretching details. In the common histogram equalization process, because the brightness level is reduced, brightness blocks appear in many modules, and mosaic blocks appear in an image.
the image enhancement method for identifying the peak value transformation nonlinear curve is provided, meanwhile, a dark field image, a bright image and a common image are processed, the dark field image, the bright image and the common image cannot be whitened when dark part details are processed, meanwhile, a bright area is well reserved when the dark part details are well processed, the details are also well reserved, and mosaic blocks rarely occur.
Disclosure of Invention
the invention aims to provide an image enhancement method for identifying a peak value transformation nonlinear curve, which carries out preprocessing on an image through an image preprocessing module, a peak identification module, a transformation nonlinear curve module and a guide filtering and output image module, judges whether the image has a peak and the position of the peak, selects a nonlinear curve transformation mode and a transformation curve according to the judgment result, carries out guide filtering on the image, retains the details of the image, and avoids the situations of excessive processing, mosaic blocks and the like.
In order to solve the technical problems, the invention is realized by the following technical scheme:
the invention relates to an image enhancement method for identifying a peak value transformation nonlinear curve, which comprises the following steps:
SS 00: inputting an image;
SS 01: preprocessing the image through an image preprocessing module:
s011: acquiring the bit width N (bit), the resolution width m and the height n of an image;
S012: processing the image on the Y component;
If the image is a gray image, directly outputting the image;
if the image is a true color image, converting the image according to a formula for converting color RGB into YUV and outputting the converted image, wherein the formula for converting color RGB into YUV is as follows:
Y=0.299R+0.582G+0.114B
U=-0.1687R-0.3313G+0.5B+128;
V=0.5R-0.4187G-0.813B+128
S013: extracting brightness information of the image after obtaining the Y component to obtain brightness distribution information h of the imageii denotes the respective brightness level of the image;
S014: according to the formulaCalculating a probability density p (i) of the luminance level;
Wherein n isiThe number of pixels included in the corresponding luminance level;
nathe total number of pixels contained in the brightness level is obtained by accumulation;
SS 02: judging whether the image has a peak, a peak type and a position where the peak exists through a peak identification module, and selecting a nonlinear curve transformation mode according to a judgment result;
If it isDefining that a 'fine peak' condition occurs in the brightness distribution, and defining the condition as a condition one; if it isDefining that the brightness distribution has a 'rough peak' condition, and defining the condition as a second condition; where round is rounded to the nearest integer;
SS 03: transforming the curve through a non-linear curve transformation module; the mode of converting the curve by the nonlinear curve conversion module is a mode I, a mode II and a mode III respectively;
the first mode and the second mode divide the brightness distribution map into two regions to be processed respectively, different dark threshold values are set, and the purpose of setting the dark threshold values is to divide the image processing regions so that the processing of the image can not be too white to cause unreality of the image;
The third way is the ordinary linear transformation after recognizing the brightness distribution as a normal image;
SS 04: the image guiding filtering is carried out through the guiding filtering output image module, certain linear processing weighting is carried out on the brightness distribution obtained by the processing and the original brightness distribution condition, the details of the image are reserved, and the conditions of excessive processing and the like can not occur:
s041: newly obtained luminance distribution information h1Performing primary guiding filtering with the original brightness distribution condition, and performing guiding filtering in order to keep the original details; obtaining the final brightness distribution statistical information hout:
Wherein h is0=h1+ahi+ b, a and b may be modified according to the user's requirement, with a being 0.2 and b being 0 as default;
S042: finding the value of the corresponding pixel point and the original brightness distribution information to obtain a new Y component of the image, restoring the Y component to the RGB color model, and completing image enhancement; the conversion formula for the Y component reverts back to RGB is:
R=Y+1.42(V-128)
G=Y-0.33414(U-128)-0.71414(V-128);
B=Y+1.772(U-128)
Wherein the grayscale image is directly output.
Further, the specific method for selecting the nonlinear curve transformation mode according to the determination result in step SS02 is as follows: when i is more than 0 and less than round (0.12X 2)N) And if the first condition is met, the situation of 'fine sharp peak' appears in the region of the brightness distribution close to the origin, and the first nonlinear curve transformation mode is selected to be implemented.
Further, the specific method for selecting the nonlinear curve transformation mode according to the determination result in step SS02 is as follows: when round (0.12X 2)N)<i<round(0.3×2N) If the condition one is satisfied, the value is found to be round (0.12 multiplied by 2)N)<i<round(0.3×2N) When the 'fine peak' condition occurs, the non-linear curve transformation is selected to be carried outAnd a second transformation mode.
further, the specific method for selecting the nonlinear curve transformation mode according to the determination result in step SS02 is as follows: when i is more than 0 and less than round (0.3X 2)N) If the condition two is satisfied, i is greater than 0 and less than round (0.3 multiplied by 2)N) And when the situation of 'coarse peak' occurs, selecting to implement a second nonlinear curve transformation mode, and transforming the value of gamma according to the situation.
Further, the specific method for selecting the nonlinear curve transformation mode according to the determination result in step SS02 is as follows: when round (0.3X 2)N)<i<round(0.5×2N) In the process, because the human eyes are more sensitive to the dark field condition and not very sensitive to the reaction under the normal bright condition, in order to reduce the complexity of the algorithm and accelerate the algorithm speed, whether the condition two is met is judged, if the condition two is met, a first nonlinear curve transformation mode is selected, and when round (0.3 multiplied by 2) is adoptedN)≦i<2NWhen gamma is more than 0.3 and less than 1, the default gamma is 0.5, and the aim is to stretch the middle area.
further, the specific method for selecting the nonlinear curve transformation mode according to the determination result in step SS02 is as follows: when round (0.5X 2)N)<i<round(0.85×2N) If the condition one is satisfied, a peak appears in the bright area, the bright area is stretched in the middle of the compression, the first nonlinear curve transformation mode is selected to be implemented, and when round (0.3 multiplied by 2) is performedN)≦i<2NWhen gamma is more than 1 and less than 3, the default gamma is 2.2.
further, the specific method for selecting the nonlinear curve transformation mode according to the determination result in step SS02 is as follows: if the image does not satisfy the first condition and the second condition on the whole brightness level, the image is defined as a 'normal transformation image', a third nonlinear curve transformation mode is selected to be implemented, and the average brightness of the image is calculated.
Further, the first way of transforming the curve by the nonlinear curve module in step SS03 is: separating out 'dark' region adjustment, when i is more than 0 and less than round (0.3X 2)N) When h is presenta=hi γGamma is more than 0.3 and less than 1, gamma is determined according to the adjustment intensity, and the default gamma is 0.5, thenWhen round (0.3X 2)N)≦i<2NWhen h is presentc=(hi-round(0.3×2N))γThe gamma value is judged according to the bright area condition,Last h11And h12integration to get a new h1Wherein h is1To output luminance distribution information.
Further, the second way of transforming the curve by the nonlinear curve module in step SS03 is: separating out 'dark' region adjustment, when i is more than 0 and less than round (0.6 multiplied by 2)N) When h is presenta=hi γgamma is more than 0.3 and less than 1, gamma is determined according to the adjustment intensity, and the default gamma is 0.5, thenWhen round (0.6X 2)N)≦i<2Nwhen h is presentc=(hi-round(0.6×2N))γthe gamma value is judged according to the bright area condition, thenlast h11And h12Integration to get a new h1wherein h is1To output luminance distribution information.
further, the third way of transforming the curve by the nonlinear curve module in step SS03 is:
Calculating I according to the formulaave:
If Iave<round(0.55×2N) Gamma is more than 0.3 and less than 1, and the default gamma is 0.7;
If Iave≧round(0.55×2N) 1 < gamma < 3, default gammais 1.5;
hb=hi γthen, then
Wherein h is1To output luminance distribution information.
the invention has the following beneficial effects:
1. The invention carries out the guide filtering of the image through the guide filtering output image module, carries out certain linear processing weighting on the processed brightness information and the original brightness distribution condition, keeps the details of the image, does not have the conditions of excessive processing and the like, has obvious processing effect aiming at the image with poor definition and darker brightness, is simultaneously suitable for common images, has good processing effect, simple and understandable algorithm and high implementation efficiency, and can realize the code by using if nested sentences in the code.
2. According to the invention, the curve is transformed by the nonlinear curve transformation module, different dark thresholds are set, so that the image processing is partitioned, the unreal image caused by excessive whitening of the image processing can be avoided, the details are reserved during brightness adjustment, and compared with histogram equalization, the histogram equalization is easy to have the phenomena of whitening and mosaic blocks, and the phenomena are all inhibited in the invention.
Of course, it is not necessary for any product in which the invention is practiced to achieve all of the above-described advantages at the same time.
drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a schematic diagram of an image enhancement method for identifying a peak transform nonlinear curve according to the present invention;
FIG. 2 is a flow chart of spike identification in the present invention;
FIG. 3 is a diagram illustrating a first method for transforming a curve by the nonlinear curve module according to the present invention;
FIG. 4 is a diagram illustrating a second method for transforming a curve by the nonlinear curve transformation module according to the present invention;
fig. 5 is a schematic diagram of a third method for transforming a curve by the nonlinear curve module according to the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious 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.
Referring to fig. 1 to 5, the present invention is an image enhancement method for identifying a peak transformation nonlinear curve, which has an obvious effect on processing a dark field image and is also suitable for processing a general image, and mainly includes an image preprocessing module, a peak identification module, a transformation nonlinear curve module, and a guided filtering and image output module. The image preprocessing module obtains image output through RGB to YVU conversion or gray level image direct output, and obtains image brightness distribution information. The peak identification module has 6 cases to judge which type to belong to in order to select the scheme of processing next. The nonlinear curve transformation module has 3 processing curves, and 3 processing curve selections are carried out through the selection of the peak identification module, and then curve attributes are selected. And the final guiding filtering output image module is used for preserving details and avoiding distortion. After image guide filtering, the Y component is converted back to RGB mode, and the gray scale is directly output. The method specifically comprises the following steps:
SS 00: inputting an image;
SS 01: preprocessing the image through an image preprocessing module, preparing for subsequent image processing by acquiring parameters such as bit width N bit, resolution width m, height N and the like of the image, acquiring a Y component in the next step, converting the image into a true color image by adopting an RGB-YUV formula, and directly outputting a gray image; after the Y component is obtained, extracting brightness information of the image, and preprocessing the image specifically comprises the following steps:
s011: acquiring bit width N (bit), image resolution width m and height n, i of an image to represent each brightness level of the image;
S012: processing the image on the Y component;
If the image is a gray image, directly outputting the image;
if the image is a true color image, converting the image according to a formula for converting color RGB into YUV and outputting the converted image, wherein the formula for converting color RGB into YUV is as follows:
Y=0.299R+0.582G+0.114B
U=-0.1687R-0.3313G+0.5B+128;
V=0.5R-0.4187G-0.813B+128
S013: extracting brightness information of the image after obtaining the Y component to obtain brightness distribution information h of the imagei;
S014: according to the formulaCalculating a probability density p (i) of the luminance level;
Wherein n isithe number of pixels included in the corresponding luminance level;
naThe total number of pixels contained in the brightness level is obtained by accumulation;
SS 02: whether the image has a peak, a peak type and a position where the peak exists is judged through a peak identification module, a nonlinear curve transformation mode is selected according to a judgment result, whether the minimum brightness has a fine peak is identified, and if the minimum brightness has the fine peak, the situation is set as a condition and the next step is left for processing. It is then identified whether fine spikes are present in the general low luminance, and neither is there any more to identify whether coarse spikes are present in the entire region of low luminance. And then identifying whether the peak exists in the middle bright area or not and whether the peak exists in the high bright area or not, preparing for stretching the middle bright area or the high bright area, and defining the image as a normal image under the condition that all the peaks are not satisfied:
if it isDefining that a 'fine peak' condition occurs in the brightness distribution, and defining the condition as a condition one; if it isdefining that the brightness distribution has a 'rough peak' condition, and defining the condition as a second condition; where round is rounded to the nearest integer;
As shown in fig. 2, the specific method for selecting the nonlinear curve transformation manner according to the determination result in step SS02 is as follows: when i is more than 0 and less than round (0.12X 2)N) Judging whether a first condition is met, if so, selecting a first nonlinear curve transformation mode when a 'fine sharp peak' condition appears in a region of the brightness distribution close to the origin; when round (0.12X 2)N)<i<round(0.3×2N) If the condition one is satisfied, the value is found to be round (0.12 multiplied by 2)N)<i<round(0.3×2N) When the situation of 'fine peak' occurs, selecting a second nonlinear curve transformation mode; when i is more than 0 and less than round (0.3X 2)N) If the condition two is satisfied, i is greater than 0 and less than round (0.3 multiplied by 2)N) If the 'rough peak' occurs, selecting a second nonlinear curve transformation mode, and transforming the value of gamma according to the situation; when round (0.3X 2)N)<i<round(0.5×2N) In the process, because the human eyes are more sensitive to the dark field condition and not very sensitive to the reaction under the normal bright condition, in order to reduce the complexity of the algorithm and accelerate the algorithm speed, whether the condition two is met is judged, if the condition two is met, a first nonlinear curve transformation mode is selected, and when round (0.3 multiplied by 2) is adoptedN)≦i<2Nwhen the gamma is more than 0.3 and less than 1, the default gamma is 0.5, and the middle area is stretched; when round (0.5X 2)N)<i<round(0.85×2N) Judging whether the condition two is met or not, if the condition one is met, a peak appears in a bright area, and selecting to implement nonlinear curve transformation for compressing the middle stretching bright areaChange the transformation method one, and when round (0.3X 2)N)≦i<2NWhen the gamma is more than 1 and less than 3, the default gamma is 2.2; if the image does not meet the first condition and the second condition on the whole brightness level, defining the image as a 'normal transformation image', selecting a third nonlinear curve transformation mode, and calculating the average brightness of the image;
SS 03: transforming the curve through a non-linear curve transformation module; the mode of transforming the nonlinear curve module is a mode one, a mode two and a mode three, and the curves corresponding to the mode one, the mode two and the mode three are shown in fig. 3-5; the first mode and the second mode divide the brightness statistical chart into two regions to be processed respectively, different dark threshold values are set, the purpose of setting the dark threshold values is to divide the image processing into regions, the processing of the image cannot be too white to cause unreal image, and the two dark threshold values can be modified to a certain extent according to the requirements of users; the third mode is common linear transformation after the brightness distribution is identified as a normal image, 2 curves are set in the invention, and more curves can be generated between two excessive curves in practical application;
The first method is as follows: separating out 'dark' region adjustment, when i is more than 0 and less than round (0.3X 2)N) When h is presenta=hi γGamma is more than 0.3 and less than 1, gamma is determined according to the adjustment intensity, and the default gamma is 0.5, thenWhen round (0.3X 2)N)≦i<2NWhen h is presentc=(hi-round(0.3×2N))γthe gamma value is judged according to the bright area condition,Last h11And h12Integration to get a new h1wherein h is1to output luminance distribution information.
The second method is as follows: separating out 'dark' region adjustment, when i is more than 0 and less than round (0.6 multiplied by 2)N) When h is presenta=hi γ0.3 < gamma < 1, gamma being determined by the strength of the adjustmentWhen the default gamma is 0.5, thenWhen round (0.6X 2)N)≦i<2NWhen h is presentc=(hi-round(0.6×2N))γthe gamma value is judged according to the bright area condition, thenLast h11And h12integration to get a new h1Wherein h is1To output luminance distribution information.
The third method is as follows:
Calculating I according to the formulaave:
If Iave<round(0.55×2N) Gamma is more than 0.3 and less than 1, and the default gamma is 0.7;
if Iave≧round(0.55×2N) Gamma is more than 1 and less than 3, and the default gamma is 1.5;
hb=hi γThen, then
Wherein h is1to output luminance distribution information.
SS 04: the image guiding filtering is carried out through the guiding filtering output image module, certain linear processing weighting is carried out on the brightness distribution information obtained by the processing and the original brightness information, the details of the image are reserved, and the situations of excessive processing and the like can not occur:
S041: newly obtained luminance distribution information h1Performing primary guiding filtering with original brightness information, and performing guiding filtering in order to retain original details; obtaining the final brightness distribution statistical information hout:
Wherein h is0=h1+ahithe values of a and b are transformed according to the requirements of users, and the default value of a is 0.2, and the default value of b is 0;
S042: finding the value of the corresponding pixel point and the original brightness statistical information to obtain a new Y component of the image, restoring the Y component to the RGB color model, and completing image enhancement; the conversion formula for the Y component reverts back to RGB is:
R=Y+1.42(V-128)
G=Y-0.33414(U-128)-0.71414(V-128);
B=Y+1.772(U-128)
Wherein the grayscale image is directly output.
An image enhancement method for identifying a peak value transformation nonlinear curve carries out guiding filtering on an image through a guiding filtering output image module, certain linear processing weighting is carried out on processed brightness distribution information and brightness statistical information, the details of the image are reserved, the situations of excessive processing and the like are avoided, an obvious processing effect is achieved for the image with poor definition and darker brightness, the method is suitable for common images, the processing effect is good, the algorithm is simple and easy to understand, the implementation efficiency is high, and the code can be achieved by using if nested statements in the code; the method has the advantages that the curve is transformed through the nonlinear curve transformation module, different dark thresholds are set, the image is processed in a partition mode, the unreal image caused by excessive whitening of the image cannot be processed, details are reserved during brightness adjustment, and compared with histogram equalization, the histogram equalization is prone to have the phenomena of whitening and mosaic blocks and is restrained in the method.
in the description herein, references to the description of "one embodiment," "an example," "a specific example" or the like are intended to mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
the preferred embodiments of the invention disclosed above are intended to be illustrative only. The preferred embodiments are not intended to be exhaustive or to limit the invention to the precise embodiments disclosed. Obviously, many modifications and variations are possible in light of the above teaching. The embodiments were chosen and described in order to best explain the principles of the invention and the practical application, to thereby enable others skilled in the art to best utilize the invention. The invention is limited only by the claims and their full scope and equivalents.