Image enhancement method and computer device
By obtaining the grayscale information of the image and determining the compensation curve, calculating the compensated pixel value of the pixel point, and generating an enhanced image, the problem of low image quality in the existing technology is solved, the clarity and contrast of the image are improved, and it is suitable for low Performance equipment.
Patent Information
- Application Number
- CN201910817313.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-08-30
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2039-08-30
AI Technical Summary
Due to the hardware limitations of the image display device, the existing technology cannot achieve high-quality image enhancement, resulting in low-quality, unclear, and insufficient images, which cannot meet users' needs for high-quality images.
By obtaining the grayscale information of the image, determining the compensation curve, and calculating the compensated pixel value of the pixel point based on the compensation curve, an enhanced image is generated. Specific steps include obtaining the grayscale information of the image, determining the control points of the Bessel function, drawing the compensation curve through the Bessel function, and calculating the maximum RGB value and pixel value of the pixel after compensation through interpolation.
The image clarity is improved, the contrast and color vividness are increased, and the method complexity is low. It is suitable for low-performance image display devices and can achieve image enhancement under conditions of low memory and processor requirements.
Smart Images

Figure CN112446831B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to an image enhancement method and computer equipment. Background Art
[0002] With the improvement of people's quality of life and the development of display device technology, people have higher and higher requirements for image quality. In related technologies, due to the hardware limitations of display devices such as memory and processors, complex image enhancement processing cannot be performed, resulting in problems such as low image quality, unclear images, and fewer image details, which cannot meet users' demand for high-quality images. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide an image enhancement method and a computer device to make the image quality higher and more realistic, the image color more vivid, and the image contrast higher, thereby giving users a good visual experience.
[0004] In a first aspect, an embodiment of the present invention provides an image enhancement method, comprising:
[0005] Acquire an image to be processed, and acquire grayscale information of the image to be processed, wherein the grayscale information includes the grayscale of each pixel in the image to be processed;
[0006] Determining a compensation curve corresponding to the image to be processed according to the grayscale information;
[0007] Calculating the compensated pixel value of each pixel in the image to be processed according to the compensation curve;
[0008] An enhanced image is generated according to the compensated pixel values of each pixel point.
[0009] Furthermore, the obtaining of grayscale information of the image to be processed includes:
[0010] Obtaining the grayscale of each pixel in the image to be processed;
[0011] The grayscale information of the image to be processed is obtained according to the grayscale of each pixel.
[0012] Furthermore, the step of obtaining the grayscale of each pixel in the image to be processed includes:
[0013] Obtaining the R value, G value and B value of each pixel in the image to be processed;
[0014] Determine the maximum value among the R value, G value and B value of each pixel respectively, and use the maximum value among the R value, G value and B value of each pixel as the maximum RGB value of each pixel;
[0015] The maximum RGB value of each pixel is used as the grayscale of each pixel.
[0016] Furthermore, the grayscale information also includes the number of occurrences of each grayscale and the percentage of the number of occurrences of each grayscale to the total number of pixels; and obtaining the grayscale information of the image to be processed according to the grayscale of each pixel includes:
[0017] According to the grayscale of each pixel point, a first set including a plurality of first values is obtained, wherein the first value is the number of times each grayscale appears;
[0018] According to the grayscale of each pixel, a second set including a plurality of second values is obtained, wherein the second value is a percentage of the number of occurrences of each grayscale to the total number of pixels;
[0019] Grayscale information is obtained according to the first set and the second set.
[0020] Further, determining a compensation curve corresponding to the image to be processed according to the grayscale information includes:
[0021] Determine a plurality of control points of a Bessel function according to the grayscale information;
[0022] A compensation curve is determined by a Bessel function according to the plurality of control points.
[0023] Further, determining a plurality of control points of the Bessel function according to the grayscale information includes:
[0024] According to the first set and the preset set, a plurality of row pointer values corresponding to the plurality of preset values are obtained, wherein the preset set includes a plurality of preset values, and the preset values are products of the resolutions of the image to be processed and a plurality of preset percentages;
[0025] According to a plurality of row number pointer values corresponding to a plurality of preset values, a plurality of control points of the Bessel function are selected from the second set.
[0026] Furthermore, the obtaining, according to the first set and the preset set, a plurality of row pointer values corresponding to a plurality of preset values respectively comprises:
[0027] For each first value in the first set, calculate a cumulative value corresponding to the first value according to the first value, wherein the cumulative value is a sum of at least one first value, and the at least one first value includes the first value and all first values whose grayscale is less than the grayscale corresponding to the first value;
[0028] For each preset value, obtaining the absolute value of the difference between the preset value and each accumulated value;
[0029] The minimum value is selected from all the absolute values obtained by calculation, and the selected minimum value is used as the row number pointer value corresponding to the preset value.
[0030] Further, the obtaining of the image to be processed and the obtaining of the grayscale information of the image to be processed include:
[0031] Acquire an image to be processed, and acquire a histogram of the image to be processed; wherein the histogram includes the grayscale information.
[0032] Further, determining a compensation curve corresponding to the image to be processed according to the grayscale information includes:
[0033] Determining control points of the Bessel function according to the histogram;
[0034] According to the control points, a compensation curve is determined by a Bessel function.
[0035] Furthermore, obtaining the compensated pixel value of each pixel point according to the compensation curve includes:
[0036] The compensation curve is interpolated according to an interpolation method to obtain the maximum RGB value of each pixel after compensation;
[0037] According to the compensated maximum RGB value of each pixel and the grayscale of each pixel, the compensated pixel value of each pixel is obtained respectively.
[0038] In a second aspect, an embodiment of the present invention further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0039] Acquire an image to be processed, and acquire grayscale information of the image to be processed, wherein the grayscale information includes the grayscale of each pixel in the image to be processed;
[0040] Determining a compensation curve corresponding to the image to be processed according to the grayscale information;
[0041] Calculating the compensated pixel value of each pixel in the image to be processed according to the compensation curve;
[0042] An enhanced image is generated according to the compensated pixel value of each pixel.
[0043] In a third aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0044] Acquire an image to be processed, and acquire grayscale information of the image to be processed, wherein the grayscale information includes the grayscale of each pixel in the image to be processed;
[0045] Determining a compensation curve corresponding to the image to be processed according to the grayscale information;
[0046] Calculating the compensated pixel value of each pixel in the image to be processed according to the compensation curve;
[0047] An enhanced image is generated according to the compensated pixel value of each pixel.
[0048] Compared with the prior art, the embodiments of the present invention have the following advantages:
[0049] According to the method provided by the embodiment of the present invention, an image to be processed is obtained, and grayscale information of the image to be processed is obtained, wherein the grayscale information includes the grayscale of each pixel in the image to be processed; a compensation curve corresponding to the image to be processed is determined according to the grayscale information; the compensated pixel value of each pixel in the image to be processed is calculated according to the compensation curve; and an enhanced image is generated according to the compensated pixel value of each pixel. Compared with the image to be processed, the enhanced image obtained by the method of the present invention is clearer, has increased contrast, and has brighter colors. In addition, the method provided by the present invention has low complexity, is easy to implement, and has low hardware requirements such as memory and processor of the image display device. Therefore, image enhancement can also be achieved on low-performance image display devices by the method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0051] Figure 1 A schematic diagram of a flow chart of an image enhancement method in an embodiment of the present invention;
[0052] Figure 2 is a schematic diagram of grayscale information and accumulated values of an image to be processed in an embodiment of the present invention;
[0053] Figure 3 is a schematic diagram of a scene photograph in which the image to be processed in an embodiment of the present invention is a scene photograph;
[0054] Figure 4 In the embodiment of the present invention Figure 3 Schematic diagram of the corresponding compensation curve;
[0055] Figure 5 In the embodiment of the present invention Figure 3 The corresponding histogram;
[0056] Figure 6 In the embodiment of the present invention Figure 3 The corresponding enhanced image;
[0057] Figure 7 In the embodiment of the present invention Figure 6 Histogram of ;
[0058] Figure 8 The figure is a diagram showing the internal structure of a computer device for image enhancement in an embodiment of the present invention. DETAILED DESCRIPTION
[0059] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0060] After research, the inventor found that due to the limitations of the hardware performance of the image display device, such as the memory and processor, the image enhancement effect is poor. However, with the popularization of various display devices, such as mobile phones, televisions, computers and other devices, users have higher and higher requirements for image clarity. The images in the related technologies can no longer meet the users' demand for high-quality images.
[0061] In order to solve the above problems, in an embodiment of the present invention, an original picture that is blurry or even indistinguishable can be processed into a clear enhanced image that contains a lot of useful information through enhancement processing.
[0062] See also Figure 1 , Figure 1 A method for image enhancement in an embodiment of the present invention is shown. In this embodiment, the method may include the following steps:
[0063] S1: Acquire an image to be processed, and acquire grayscale information of the image to be processed, wherein the grayscale information includes the grayscale of each pixel in the image to be processed.
[0064] In the embodiment of the present invention, the image to be processed may be an image or a frame in a video, and the image to be processed may be displayed on a device with a display screen, such as a television, a computer, or a mobile phone. Figure 2The image to be processed can be a landscape photo. Each pixel in the image to be processed has a corresponding grayscale. By counting the grayscale of each pixel in the image to be processed, the grayscale information of the image to be processed can be obtained.
[0065] Specifically, step S1 includes:
[0066] S11, obtaining the grayscale of each pixel in the image to be processed.
[0067] Grayscale represents the brightness change between the brightest and darkest. In the field of image processing, grayscale can take values of 0-255, with a total of 256 brightness levels. Each pixel on the image to be processed is composed of red, green, and blue at different measurement levels, and finally forms different color points. The change in color is brought about by the grayscale change of the pixel's R value, G value, and B value.
[0068] Specifically, step S11 includes:
[0069] S111, obtaining the R value, G value and B value of each pixel in the image to be processed.
[0070] In the embodiment of the present invention, the R value, G value and B value of each pixel in the image to be processed can be obtained by MATLAB. For example, the size of the image to be processed is M×N, and a data with m rows and n columns can be obtained by MATLAB. The value of the first row and the first column represents the R value, G value and B value of the pixel (1,1). Assume that the value of the first row and the first column is (195,212,228), which means that the R value of the pixel (1,1) is 195, the G value is 212, and the B value is 228.
[0071] S112, respectively determining the maximum value among the R value, G value, and B value of each pixel point, and respectively taking the maximum value among the R value, G value, and B value of each pixel point as the maximum RGB value of each pixel point.
[0072] In the embodiment of the present invention, the R value, G value, and B value of each pixel are compared, and the maximum value obtained by comparison is used as the maximum RGB value. For example, the R value of the pixel (1, 1) is 195, the G value is 212, and the B value is 228. It can be determined that the maximum RGB value of the pixel (1, 1) is 228.
[0073] S113 , taking the maximum RGB value of each pixel as the grayscale of each pixel.
[0074] In the embodiment of the present invention, the grayscale of a pixel is the maximum RGB value of the pixel. In the above example, the grayscale of the pixel (1,1) is 228.
[0075] S12. Obtaining grayscale information of the image to be processed according to the grayscale of each pixel.
[0076] In the embodiment of the present invention, the grayscale information includes the grayscale of each pixel in the image to be processed. For example, the image to be processed has 400 pixels, 80 pixels with a grayscale of 100, 50 pixels with a grayscale of 101, and 270 pixels with a grayscale of 150. The grayscales of the image to be processed are 100, 101, and 150. The grayscales of the image to be processed can be arranged vertically from small to large, i.e., (100, 101, 150). T .
[0077] The grayscale information also includes: the number of occurrences of each grayscale and the percentage of the number of occurrences of each grayscale to the total number of pixels.
[0078] Specifically, step S12 includes:
[0079] S121. Acquire a first set including a plurality of first values according to the grayscale of each pixel, wherein the first value is the number of times each grayscale appears.
[0080] In the embodiment of the present invention, each pixel of the image to be processed has a corresponding grayscale. The total number of grayscales of the image to be processed is the same as the number of pixels of the image to be processed, but the number of grayscale types may be different from the number of pixels. For an image with a resolution greater than 256, some pixels may have the same grayscale. For the same grayscale, if the grayscale appears 3 times, it means that there are 3 pixels with the same grayscale, so the number of grayscale types will be less than the number of pixels. The number of times each grayscale appears is the first value. An image to be processed corresponds to multiple grayscales, and multiple grayscales correspond to multiple first values. The first set is composed of multiple first values. It can be known that the sum of all the first values in the first set is the total number of pixels of the image to be processed.
[0081] For example, the image to be processed has 400 pixels. Assume that there are 80 pixels with a grayscale of 100, that is, the grayscale with a value of 100 appears 80 times, the grayscale with a value of 101 appears 50 times, and the grayscale with a value of 150 appears 270 times. In this example, for the grayscales with values of 100, 101, and 150, the first values are 80, 50, and 270 respectively. The arrangement order of the first values in the first set is the same as the arrangement order of the grayscales. In the above example, the arrangement of the grayscales is: (100, 101, 150) T , accordingly, the first set is: (80,50,270) T .
[0082] S122. Obtain a second set including a plurality of second values according to the grayscale of each pixel, wherein the second value is a percentage of the number of occurrences of each grayscale to the total number of pixels.
[0083] In the embodiment of the present invention, the first value is the number of times each grayscale appears. For a grayscale, the percentage of the number of times the grayscale appears to the total number of pixels is the second value of the grayscale. It can be seen that the first value is the same as the number of the second value. For example, the image to be processed has 400 pixels, and the grayscale with a value of 100 appears 80 times, then the second value of the grayscale with a value of 100 is: 0.2; the grayscale with a value of 101 appears 50 times, then the second value of the grayscale with a value of 101 is: 0.125; the grayscale with a value of 150 appears 270 times, then the second value of the grayscale with a value of 150 is: 0.675. The set composed of the second numbers of multiple grayscales is the set of second values. It can be seen that the sum of all the second values in the set of second values is 1. For example, the second set (0.2, 0.125, 0.675) T .
[0084] S123. Obtain grayscale information according to the first set and the second set.
[0085] In the embodiment of the present invention, the grayscale information includes the grayscale of each pixel in the image to be processed, the number of occurrences of each grayscale, and the percentage of the number of occurrences of each grayscale to the total number of pixels. In the above example, the image to be processed has 400 pixels, and the grayscale information obtained can be in matrix form, as follows: 100 80 0.2 101 50 0.125 150 370 0.765
[0089] The first column is the grayscale that appears in the image to be processed in the above example. The value of a row in the second column represents the number of times the grayscale in the row where the value is located appears. The value of a row in the third column represents the percentage of the grayscale in the row where the value is located to the total number of pixels. Optionally, the tabulate function in MATLAB can be used to directly obtain the grayscale information of the image to be processed in matrix form.
[0090] S2. Determine a compensation curve corresponding to the image to be processed according to the grayscale information.
[0091] In the embodiment of the present invention, a compensation curve is drawn using a Bessel function according to grayscale information. Specifically, step S2 includes:
[0092] S21. Determine a plurality of control points of a Bessel function according to the grayscale information.
[0093] In the embodiment of the present invention, a Bessel curve can be drawn by using the Bessel function, and the Bessel curve can be used as a compensation curve. The representation form of the Bessel function is shown in formula (1):
[0094]
[0095] Wherein, p is a control point, and there are multiple control points. In the embodiment of the present invention, k can be 0 to 8, that is, there are 9 control points: p0, p1, ..., p8, N is equal to 8, t is the subdivision frequency, that is, the inverse of the subdivision degree, 0≤t≤1; Bezier curve description B N As t changes from 0 to 1; the control point p can be calculated according to the grayscale information and the preset set. Specifically, step S21 includes:
[0096] S211. According to the first set and the preset set, a plurality of row pointer values corresponding to the plurality of preset values are obtained, wherein the preset set includes a plurality of preset values, and the preset values are products of the resolutions of the image to be processed and a plurality of preset percentages.
[0097] In an embodiment of the present invention, the multiple preset percentages are 9 fixed percentages, for example, the multiple preset percentages are: (1%, 5%, 10%, 25%, 50%, 75%, 90%, 95%, 99.99%), and the preset values are the products of the resolutions of the images to be processed and the multiple preset percentages, respectively. Then, the preset set H = (1%, 5%, 10%, 25%, 50%, 75%, 90%, 95%, 99.99%) × M × N, where M × N is the resolution.
[0098] Specifically, step S211 includes:
[0099] S211a. For each first value in the first set, calculate a cumulative value corresponding to the first value based on the first value, wherein the cumulative value is the sum of at least one first value, and the at least one first value includes the first value and all first values whose grayscale is less than the grayscale corresponding to the first value.
[0100] In the embodiment of the present invention, the first value is the number of times each grayscale of the image to be processed appears. For example, partial grayscale information of the image to be processed and the first few items of each accumulated value are listed as follows:
[0101]
[0102] The first column is the grayscale arranged from small to large, the second column is the first value corresponding to each grayscale, and the third column is the cumulative value corresponding to each first value; the cumulative value corresponding to grayscale 1 is r1. In the above example, there is no grayscale smaller than grayscale 1, so r1 is equal to its corresponding first value, that is, r1=1; the cumulative value corresponding to grayscale 2 is r2, and the grayscale smaller than 2 is 1, so r2 is equal to the sum of the first value corresponding to grayscale 2 and the first value of grayscale 1, that is, r2=8; The accumulated value corresponding to grayscale 3 is r3. Similarly, r3 should be equal to the sum of the first value corresponding to grayscale 3, the first value corresponding to grayscale 2 and the first value corresponding to grayscale, that is, r3=10; the accumulated value corresponding to grayscale 4 is r4. Similarly, r4 should be equal to the sum of the first value corresponding to grayscale 4, the first value corresponding to grayscale 3, the first value corresponding to grayscale 2 and the first value corresponding to grayscale, that is, r4=13; similarly, the accumulated value corresponding to grayscale 5 is r5=14. In this example, only 5 grayscales are listed, involving a total of 14 pixels. The accumulated value r1=1 corresponding to grayscale 1, and the accumulated value r5=14 corresponding to grayscale 5. It can be known that for the image to be processed, the accumulated value corresponding to the grayscale with the smallest value is equal to the first value corresponding to the grayscale with the smallest value, and the accumulated value corresponding to the grayscale with the largest value is equal to the total number of pixels in the image to be processed.
[0103] S211b. For each preset value, obtain the absolute value of the difference between the preset value and each accumulated value.
[0104] In an embodiment of the present invention, the preset values are the products of the image resolution and a plurality of preset percentages. In the above example, the resolution of the image to be processed is 20×20. According to the preset percentages and the resolution of the image to be processed, the preset set can be calculated as H=(4, 20, 40, 100, 200, 300, 360, 380, 399.96). In this example, the preset values are: h0=4, h1=20, h2=40, h3=100, h4=200, h5=300, h6=360, h7=380, h8=399.96. The image to be processed has a total of 400 pixels. Assuming that the grayscale information of the image to be processed is For the preset value h0=4, find the difference between each accumulated value and h0, and then find the absolute value of the difference. Assuming that the grayscale information of the image to be processed and each accumulated value are as follows Figure 2As shown, the accumulated values corresponding to the gray levels in the fourth column of the figure, for the preset value h0, the differences between each accumulated value and h0 can be obtained, and then the absolute values of the differences are: 6, 30, 48, 83, 107, 123, 153, 179, 201, 233, 251, 269, 291, 323, 343, 368, 383, 396; similarly, the absolute values of the differences between the preset values h1, ..., h8 and each accumulated value can be obtained, which are not listed here one by one.
[0105] S211c. Select a minimum value from all absolute values obtained by calculation, and use the selected minimum value as the row number pointer value corresponding to the preset value.
[0106] In this embodiment, according to the grayscale information, the minimum value of the absolute value obtained in step S211a is selected, that is, the number closest to the preset value in the accumulated values is found, and the difference between the accumulated value closest to the preset value and the preset value is calculated, and the minimum value is used as the row pointer value. In the first few items listed in the above example, for the preset value h0, the difference between the accumulated value closest to h0 and h0 is: 6, that is, the row pointer value corresponding to h0 is 6, and it can also be obtained that the row pointer value corresponding to h1 is 10; the row pointer value corresponding to h2 is 6; the row pointer value corresponding to h3 is 11; the row pointer value corresponding to h4 is 5; the row pointer value corresponding to h5 is 5; the row pointer value corresponding to h6 is 12; the row pointer value corresponding to h7 is 7; and the row pointer value corresponding to h8 is 0.
[0107] S212. Selecting a plurality of control points of the Bessel function from the second set according to a plurality of row pointer values corresponding to a plurality of preset values.
[0108] In the embodiment of the present invention, the control point p = (px, py), py is a preset 9 values, for example, they can be: py0 = 0.01, py1 = 0.05, py2 = 0.1, py3 = 0.25, py4 = 0.5, py5 = 0.75, py6 = 0.9, py7 = 0.95, py8 = 0.999. According to the row number pointer, px is obtained in the second set. The second set includes all the values of the third column of the grayscale information, see Figure 2In the above example, for the preset value h0, its row pointer is 6, then the value corresponding to the 6th row in the second set is used as the px0 corresponding to h0. It can be known that the px0 corresponding to h0 is 0.04, and the control point corresponding to h0 is: p0=(px0,py0)=(0.04,0.01); for the preset value h1, the row pointer of h1 is 10, then the value corresponding to the 10th row in the second set is used as the px1 corresponding to h1, and px1=0.08 can be obtained, then the control point corresponding to h1 is: p1=(px1,py1)=(0.08,0.05), for the preset value h2=6, it can be obtained that px2=0.04, then the control point corresponding to h2 is: p2=(px2,py2)=(0.06,0.1); similarly, According to the above method, the function pointer corresponding to the control point h3 is 11, p3=(px3,py3)=(0.25,0.045); the row pointer value corresponding to h4 is 5, p4=(px4,py4)=(0.06,0.5); the row pointer value corresponding to h5 is 5, p5=(px5,py5)=(0.06,0.75); the row pointer value corresponding to h6 is 12, p6=(px6,py6)=(0.045,0.9); the row pointer value corresponding to h7 is 7, p7=(px7,py7)=(0.075,0.95); the row pointer value corresponding to h8 is 0. When the row pointer is 0, the corresponding control point is p8=(0,0), that is, px8 is 0 and py9 is also 0.
[0109] S22. Determine a compensation curve through a Bessel function according to the multiple control points.
[0110] In the embodiment of the present invention, see Figure 4 , showing a landscape photo Figure 3 Schematic diagram of the corresponding compensation curve. After calculating the 9 control points p0, p1, ..., p8 of the Bessel function, the compensation curve can be drawn using the Bessel function.
[0111] In one implementation, step S1 includes:
[0112] S1a, obtaining an image to be processed, and obtaining a histogram of the image to be processed; wherein the histogram includes the grayscale information.
[0113] In the embodiment of the present invention, the histogram is a visual expression of the grayscale information of the image to be processed. The histogram can intuitively show the grayscale information of the image to be processed. Figure 5 As shown, Figure 5 For landscape photos Figure 3The corresponding histogram, the horizontal axis of the histogram is the grayscale appearing in the landscape image, and the vertical axis is the number of times the grayscale appears, the histogram can reflect the image to be processed. The grayscale information obtained in step S123 can also be counted through the histogram.
[0114] Step S2 also includes:
[0115] S2a, determining the control points of the Bessel function according to the histogram.
[0116] In the embodiment of the present invention, grayscale information can be counted according to the histogram, and the control point of the Bessel function can be determined according to the grayscale information. The specific step of determining the control point of the Bessel function according to the grayscale information is the same as step S21.
[0117] S2b. Determine a compensation curve using a Bessel function according to the control points.
[0118] In the embodiment of the present invention, reference Figure 4 After calculating the 9 control points p0, p1, ..., p8 of the Bessel function, the compensation curve can be drawn through the Bessel function.
[0119] S3. Calculate the compensated pixel value of each pixel in the image to be processed according to the compensation curve.
[0120] In the embodiment of the present invention, each pixel of the image to be processed has a corresponding grayscale compensation value. Specifically, step S3 includes:
[0121] S31 . Interpolate the compensation curve according to an interpolation method to obtain the maximum RGB value of each pixel after compensation.
[0122] In the embodiment of the present invention, interpolation can be performed by the interp1 function in MATLAB, specifically: maxRGB'=interp1(x, y, maxRGB, 'pchip'); wherein x and y are the x and y values of the Bezier curve, respectively. The maximum RGB value of the pixel point, that is, the grayscale of the pixel point, is introduced in the aforementioned step. The grayscale can be recorded as maxRGB. After interpolation processing, the maximum RGB value after compensation is maxRGB', that is, the grayscale after compensation is maxRGB'.
[0123] In the embodiment of the present invention, each maxRGB has its corresponding (x, y). For a maxRGB, the method for determining the (x, y) corresponding to the maxRGB is as follows:
[0124] Normalize the grayscale. The normalization method is to divide the grayscale by 255. For example, for maxRGB1, maxRGB1 is divided by 255 to obtain the normalized value of maxRGB1. Assume that maxRGB1=0, that is, the grayscale is 0, then the normalized value of the pixel with a grayscale of 0 is 0. Assume that maxRGB1=128, that is, the pixel with a grayscale of 128 is 0.502 after normalization.
[0125] The normalized grayscale value is taken as x, and then the y corresponding to x is found on the Bezier curve. For example, the pixel with a grayscale of 128 is normalized to 0.502, that is, the pixel with a grayscale of 128 corresponds to 0.502 in the interpolation function. Assuming that x=0.502 corresponds to y=0.271 through the Bezier curve, for maxRGB1=128, the interpolation formula is: maxRGB1'=interp1(0.502, 0.271, 128, 'pchip'). This function can be used in MATLAB to obtain the supplemented grayscale.
[0126] S32, obtaining the compensated pixel value of each pixel point according to the compensated maximum RGB value of each pixel point and the grayscale of each pixel point.
[0127] In the embodiment of the present invention, the maximum RGB value of each pixel after compensation is obtained after the grayscale of each pixel is interpolated. Specifically, for each pixel, the grayscale compensation value of the pixel can be calculated according to formula (2), and formula (2) is as follows:
[0128]
[0129] Among them, maxRGB' is the grayscale of the pixel after compensation, maxRGB is the grayscale of the pixel, that is, the grayscale of the pixel before compensation, (r, g, b) represents the three color components of the pixel, that is, the pixel value of the pixel, and (r, g, b)' is the pixel value of the pixel after compensation.
[0130] S4. Generate an enhanced image according to the compensated pixel value of each pixel point.
[0131] In an embodiment of the present invention, the compensated pixel value of each pixel is converted into common RGB format data to obtain an enhanced image. This part can be implemented using existing technology, for example, using OpenCV and existing program code to generate an enhanced image based on the compensated pixel value of each pixel.
[0132] See also Figure 6 , Figure 6 for Figure 3 The enhanced image corresponding to the landscape image shown in the figure shows that Figure 3, the contrast and brightness of the enhanced image corresponding to the landscape image are significantly enhanced, and the colors are more vivid. According to the enhanced image corresponding to the landscape image, the histogram of the enhanced image corresponding to the landscape image can be obtained, such as Figure 7 As shown, the histogram of the landscape image is Figure 5 As shown, Figure 7 Compared to Figure 5 , Figure 7 The number of pixels with large grayscale is obviously increased, and the number of pixels with small grayscale is obviously reduced. Such changes enhance the contrast and brightness of the enhanced image and make the colors more vivid.
[0133] The embodiment of the present invention provides a computer device, which may be a terminal, and the internal structure is as follows: Figure 8 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method of image enhancement is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0134] Those skilled in the art will understand that Figure 8 What is shown is only a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0135] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and wherein the processor implements the following steps when executing the computer program:
[0136] Acquire an image to be processed, and acquire grayscale information of the image to be processed, wherein the grayscale information includes the grayscale of each pixel in the image to be processed;
[0137] Determining a compensation curve corresponding to the image to be processed according to the grayscale information;
[0138] Calculating the compensated pixel value of each pixel in the image to be processed according to the compensation curve;
[0139] An enhanced image is generated according to the compensated pixel value of each pixel.
[0140] An embodiment of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0141] Acquire an image to be processed, and acquire grayscale information of the image to be processed, wherein the grayscale information includes the grayscale of each pixel in the image to be processed;
[0142] Determining a compensation curve corresponding to the image to be processed according to the grayscale information;
[0143] Calculating the compensated pixel value of each pixel in the image to be processed according to the compensation curve;
[0144] An enhanced image is generated according to the compensated pixel value of each pixel.
[0145] Those skilled in the art will readily appreciate other embodiments of the invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed in this disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.
[0146] It should be understood that the present invention is not limited to the precise structure described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
[0147] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for image enhancement, characterized in that: include: Acquire an image to be processed, and acquire grayscale information of the image to be processed, wherein the grayscale information includes the grayscale of each pixel in the image to be processed; Determining a compensation curve corresponding to the image to be processed according to the grayscale information; Calculating the compensated pixel value of each pixel in the image to be processed according to the compensation curve; Generate an enhanced image according to the compensated pixel values of each pixel point; The grayscale information also includes the number of occurrences of each grayscale and the percentage of the number of occurrences of each grayscale to the total number of pixels; Obtaining grayscale information of the image to be processed according to the grayscale of each pixel, including: According to the grayscale of each pixel point, a first set including a plurality of first values is obtained, wherein the first value is the number of times each grayscale appears; According to the grayscale of each pixel, a second set including a plurality of second values is obtained, wherein the second value is a percentage of the number of occurrences of each grayscale to the total number of pixels; Obtaining grayscale information according to the first set and the second set; The step of determining a compensation curve corresponding to the image to be processed according to the grayscale information includes: Determine a plurality of control points of a Bessel function according to the grayscale information; Determining a compensation curve by using a Bessel function according to the plurality of control points; The determining of a plurality of control points of the Bessel function according to the grayscale information comprises: According to the first set and the preset set, a plurality of row pointer values corresponding to the plurality of preset values are obtained, wherein the preset set includes a plurality of preset values, and the preset values are products of the resolutions of the image to be processed and a plurality of preset percentages; Selecting a plurality of control points of the Bessel function from the second set according to a plurality of row pointer values corresponding to a plurality of preset values; The obtaining, according to the first set and the preset set, a plurality of row pointer values corresponding to a plurality of preset values respectively comprises: For each first value in the first set, calculate a cumulative value corresponding to the first value according to the first value, wherein the cumulative value is a sum of at least one first value, and the at least one first value includes the first value and all first values whose grayscale is less than the grayscale corresponding to the first value; For each preset value, obtaining the absolute value of the difference between the preset value and each accumulated value; The minimum value is selected from all the absolute values obtained by calculation, and the selected minimum value is used as the row number pointer value corresponding to the preset value.
2. The method according to claim 1, characterized in that The step of obtaining grayscale information of the image to be processed includes: Obtaining the grayscale of each pixel in the image to be processed; The grayscale information of the image to be processed is obtained according to the grayscale of each pixel.
3. The method according to claim 2, characterized in that The step of obtaining the grayscale of each pixel in the image to be processed includes: Obtaining the R value, G value and B value of each pixel in the image to be processed; Determine the maximum value among the R value, G value and B value of each pixel respectively, and use the maximum value among the R value, G value and B value of each pixel as the maximum RGB value of each pixel; The maximum RGB value of each pixel is used as the grayscale of each pixel.
4. The method according to any one of claims 1 to 3, characterized in that: The step of obtaining the image to be processed and obtaining grayscale information of the image to be processed includes: Acquire an image to be processed, and acquire a histogram of the image to be processed; wherein the histogram includes the grayscale information.
5. The method according to claim 4, characterized in that The step of determining a compensation curve corresponding to the image to be processed according to the grayscale information includes: Determining control points of the Bessel function according to the histogram; According to the control points, a compensation curve is determined by a Bessel function.
6. The method according to claim 3, characterized in that The step of obtaining the compensated pixel value of each pixel point according to the compensation curve comprises: The compensation curve is interpolated according to an interpolation method to obtain the maximum RGB value of each pixel after compensation; According to the compensated maximum RGB value of each pixel and the grayscale of each pixel, the compensated pixel value of each pixel is obtained respectively.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
