Image quality optimization method and device
By filtering, downsampling, upsampling and gradient difference calculation methods on the image, the image processing process is optimized, the problem of incomplete image recovery and unclear details is solved, and a more natural and clear image effect is achieved.
Patent Information
- Application Number
- CN202410591991.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-14
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-05-14
AI Technical Summary
Existing image quality restoration methods fail to effectively consider image characteristics, resulting in incomplete image restoration, abnormal broken edge pixels and black and white pixels. In addition, there are many pixel errors during the processing, resulting in incorrect judgment of image boundaries.
An image quality optimization method is adopted, including obtaining YUV format images, performing image filtering, downsampling and upsampling, filtering by calculating the overall gradient difference, performing transparency enhancement and sharpening, and finally image enhancement to ensure that the image Boundary completeness and detail clarity.
It effectively solves the problem of unclear details in image enhancement. By first filtering noise reduction, transparency enhancement and sharpening processing, it ensures that the image becomes more natural, image boundary filtering and enhancement are more effective, and the local area distribution of the image is more clear. clear.
Smart Images

Figure CN118172285B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a method and device for optimizing image quality. Background Art
[0002] Images captured by cameras are mostly in RAW format, and are output as RGB after a series of image quality restoration operations. Existing image quality restoration methods do not consider the characteristics of the image itself for enhancement, resulting in the loss of the image that should be restored, such as abnormal broken edge and line pixels, black and white block pixels, such as Sobel and Robert operators, which will cause abnormal pixel enhancement. Due to too many image pixel errors in the existing processing process, such as directly restoring an object without actually judging the size of an object, errors in image boundary judgment are caused, incomplete image boundary restoration, and broken edges often occur. Summary of the invention
[0003] The present invention aims at at least one of the shortcomings of the above-mentioned prior art and provides a method for improving image quality. To achieve the above-mentioned purpose, the present invention adopts the following technical solutions:
[0004] In the first aspect, a method for optimizing image quality is proposed, including obtaining a YUV format image, extracting the Y component and performing the following processing steps:
[0005] Perform image filtering to obtain a first output image after filtering;
[0006] Perform downsampling processing on the first output image, and perform upsampling on the downsampling result to restore the width and height of the original image; calculate the gain by comparing the size of the upsampled image and the first output image, and adjust the first output image by the gain to obtain the second output image;
[0007] Perform image enhancement processing on the second output image to obtain a third output image.
[0008] Preferably, the method of performing image filtering to obtain a filtered first output image comprises the following steps:
[0009] Perform multiple filtering of different scales on the original image to obtain multiple first filtered images, and calculate the first gradient difference between each first filtered image and the original image respectively;
[0010] Calculate the overall gradient difference based on the width and height of the image and all first gradient differences;
[0011] The original image is overall filtered according to the overall gradient difference to obtain a first output image after filtering.
[0012] Preferably, the method for performing overall filtering on the original image according to the overall gradient difference comprises the following steps:
[0013] Using an N*N window, calculate the variance and mean of the pixels in the window matrix.
[0014] Use the window to traverse the image and calculate the first output image according to the following formula yout1 Values:
[0015] ,
[0016] in, R is the variance of pixels within the window matrix, Y(i, j) is the pixel value of the original image in the N*N window, diff_f is the overall gradient difference, and mean is the mean of the pixels in the window matrix.
[0017] Preferably, after downsampling the first output image, the method further comprises the step of filtering the downsampling image to eliminate upsampling abnormal points, thereby obtaining a downsampling result.
[0018] Preferably, the steps of image enhancement processing are as follows:
[0019] Perform image filtering on the second output image to obtain a second filtered image; calculate a second gradient difference between the second filtered image and the original image; calculate a sum of the second output image and the second gradient difference to obtain a third output image.
[0020] Preferably, the method for calculating the second gradient difference comprises the following steps: performing multiple filtering of different scales on the second output image to obtain multiple second filtered images, and calculating the second gradient difference based on the original image and all the second filtered data.
[0021] Preferably, the gain is calculated by comparing the size of the upsampled image and the first output image. yk The formula is as follows:
[0022] ,
[0023] in, yout1 is the first output image, meanup is the upsampling result, d is the intensity parameter, df It is the overall gain plus or minus parameter.
[0024] In a second aspect, a device for optimizing image quality is provided, comprising:
[0025] A receiving unit, used to obtain the Y component of the YUV format image;
[0026] A first filtering unit, used to perform image filtering to obtain a first output image after filtering;
[0027] The first enhancement unit is used to perform downsampling processing on the first output image, and perform upsampling on the downsampling result to restore the width and height of the original image; calculate the gain by comparing the size of the upsampled image and the first output image, and adjust the first output image by the gain to obtain the second output image.
[0028] The second enhancement unit is used to perform image enhancement processing on the second output image.
[0029] Preferably, the first filtering unit includes a gradient difference calculation unit and an overall filtering unit.
[0030] A gradient difference calculation unit is used to perform multiple filtering of different scales on the original image to obtain multiple first filtered images, and respectively calculate the first gradient difference between each first filtered image and the original image; and calculate the overall gradient difference according to the width and height of the image and all the first gradient differences;
[0031] The overall filtering unit is used to perform overall filtering on the original image according to the overall gradient difference to obtain a first output image after filtering.
[0032] Preferably, the step of the second enhancement unit performing image enhancement processing on the second output image includes: performing image filtering on the second output image to obtain a second filtered image; calculating the second gradient difference between the second filtered image and the original image; and calculating the sum of the second output image and the second gradient difference to obtain a third output image.
[0033] The present invention has the following beneficial effects: This solution adopts a method of first performing filtering and noise reduction processing, then performing transparency enhancement processing, and finally performing sharpening enhancement processing, which effectively solves the problem of unclear details in existing image enhancement technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the embodiments of the present application 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 of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0035] Figure 1 It is an overall flow chart of an image quality optimization method. DETAILED DESCRIPTION
[0036] The following will be combined with the accompanying drawings to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0037] The terms "first", "second", etc. in the claims and specification of the present application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way are interchangeable under appropriate circumstances. This is merely a way of distinguishing objects with the same properties in the embodiments of the present application. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, so that a process, method, system, product or apparatus that includes a series of units is not necessarily limited to those units, but may include other units not expressly listed or inherent to these processes, methods, products or apparatus.
[0038] Example 1: Figure 1 As shown, the first idea of this solution is to perform image filtering, transparency enhancement and image quality enhancement in sequence. This method can effectively solve the problem of image enhancement and make the image more natural. Specifically, a method for image quality optimization is disclosed, including obtaining a YUV format image, extracting the Y component and performing the following processing steps:
[0039] Perform image filtering to obtain a first output image after filtering;
[0040] Perform downsampling processing on the first output image, and perform upsampling on the downsampling result to restore the width and height of the original image; calculate the gain by comparing the size of the upsampled image and the first output image, and adjust the first output image by the gain to obtain the second output image;
[0041] Perform image enhancement processing on the second output image to obtain a third output image.
[0042] This method first performs filtering and noise reduction processing because it takes into account the difficulty of noise reduction processing due to linear amplification in the subsequent steps. Furthermore, this method first performs transparency enhancement processing because if sharpening is performed and then transparency processing is performed, the transparency enhancement processing will make the sharpened details blurred. Based on this method, the problem of image enhancement can be effectively solved, and it is more effective for filtering and enhancing image boundaries, making the image more natural. At the same time, by downsampling and upsampling the filtered image, the distribution of the local area of the image is clearer, which is more conducive to the judgment of subsequent transparency processing.
[0043] The first stage: image filtering
[0044] The method of performing image filtering to obtain a filtered first output image comprises the following steps:
[0045] Perform multiple filtering of different scales on the original image to obtain multiple first filtered images, and calculate the first gradient difference between each first filtered image and the original image respectively;
[0046] Calculate the overall gradient difference based on the width and height of the image and all first gradient differences;
[0047] The original image is overall filtered according to the overall gradient difference to obtain a first output image after filtering.
[0048] Here, taking two scales of filtering as an example, the original image is processed M Filtering of various scales to obtain multiple first filtered images fi1 and the first filtered image fi2 In this scheme M =2, calculate the first filtered image respectively fi1 and the first filtered image fi2 The first gradient difference diff1 and the first gradient difference diff2 with the original image; according to the width and height of the image and all the first gradient differences diff1 , diff2 Calculate the overall gradient difference; perform overall filtering on the original image according to the overall gradient difference to obtain the first output image after filtering, as shown in the following matrix a and matrix b :
[0049]
[0050]
[0051] pass a and b Filter the original image at different scales to obtain fi1 and fi2:
[0052] ,
[0053] Calculate the gradient difference according to the filters of different sizes diff1 and diff2,
[0054] diff1 = abs ( Y - fi1 ), diff2 = abs(Y - fi2)
[0055] where diff1 and diff2 It is only a reference for the two dimensions disclosed in this embodiment. Those skilled in the art can obtain gradient differences in several other dimensions through the above method, such as selecting filters with different parameters, or selecting 3, 4 or more filters to perform multi-dimensional gradient difference calculations, or selecting matrix a as a 5*5 Gaussian filter, b as a 3*3 Gaussian filter, or setting a 7*7 Gaussian filter, etc.
[0056] Get the width of the image matrix Y m , Gao Wei n, calculate the overall gradient difference of the image diff_f
[0057] diff_f = fix (( sum ( diff1 + diff2 + x ) / ( m * n ))
[0058] in, x is the preset value, the default value is 10, x Value and diffM Adding checks and balances between different dimensions, x The larger the value, the greater the overall intensity of the overall gradient difference.
[0059] The method of filtering the original image as a whole according to the overall gradient difference includes the following steps: using an N*N window to calculate the variance and mean of the pixels in the window matrix; using the window to traverse the image (or understand it as using a sliding window method) to calculate the first output image according to the following formula yout1 Values:
[0060] yout1(i, j) = R * ( Y ( i , j ) -mean ) / ( R + diff_f ) +mean
[0061] in, R is the variance of pixels within the window matrix, Y(i, j) is the center pixel of the window, diff_f is the overall gradient difference, and mean is the mean of the pixels in the window matrix.
[0062] As a reference, a window of 5*5 is used, and the center pixel of the window is Y(i, j) , i is the i-th row of image Y, j is the j-th column of image Y, and window q is q = y ( i - 2:i + 2, j - 2:j + 2 ), which represents a 5*5 window.
[0063] Find the variance of the 5*5 matrix in the q matrix, denoted as R, find the mean in the q matrix, denoted as mean, and calculate the yout1 value of each point based on the center pixel of the window, the overall gradient difference, the mean and the variance.
[0064] Specifically, the formula yout1(i, j) It is equal to the variance multiplied by the difference between the original image and the 5*5 mean, divided by the variance plus the overall gradient difference, plus the mean. The first output image yout1 is the result after filtering and is also the output of the first stage.
[0065] The second stage: image transparency enhancement processing
[0066] Perform downsampling processing on the first output image, and perform upsampling on the downsampling result to restore the width and height of the original image; calculate the gain by comparing the size of the upsampled image and the first output image, and adjust the first output image by the gain to obtain the second output image;
[0067] Preferably, after downsampling the first output image, the method further includes the steps of: filtering the downsampled image to eliminate upsampling outliers to obtain a downsampling result, and then upsampling the sampling result to restore it to the width and height of the original image.
[0068] Specifically, for the first output image yout1 Perform downsampling with a length of 64 and a width of 32, and set the downsampling result to meandown , where the length 64 and the width 32 are reference values disclosed in this application, where the downsampling algorithm is a well-known algorithm, and the image is filtered and the result is set to meandown1 .
[0069]
[0070] meandown1 = filter ( b, meandown )
[0071] The downsampled image is filtered by filter b, and the downsampled result is restored to an image with a width of m and a height of n by upsampling. The upsampling is also a well-known algorithm. The downsampled result is set to meanup .
[0072] The gain is calculated by comparing the size of the upsampled image with the first output image. yk The formula is as follows:
[0073]
[0074] By identifying the difference between yout1 and the upsampled image, the gain is obtained yk ,in, yout1 is the first output image, meanup is the upsampling result, d is the intensity parameter, df It is the overall gain plus or minus parameter. The larger the parameter value, the stronger the permeability. In this application, the default value of d is 0.2. The larger the intensity parameter, the stronger the permeability.
[0075] Then the first output image is adjusted by gain to obtain the second output image yout2 , the formula is as follows: yout2 = yk * yout1 ; yout2 It is the output result of the first stage image transparency enhancement.
[0076] Phase 3: Image quality improvement (enhancement)
[0077] The steps of image enhancement processing are as follows: performing image filtering on the second output image to obtain a second filtered image; calculating a second gradient difference between the second filtered image and the original image; calculating a sum of the second output image and the second gradient difference to obtain a third output image. In this solution, there can be one or more filters.
[0078] Preferably, the method of calculating the second gradient difference using multiple filters includes the following steps: performing multiple filtering of different scales on the second output image to obtain multiple second filtered images, and calculating the second gradient difference based on the original image and all second filtered data.
[0079] It is preferred to use the same filter as the first stage to filter yout2, and obtain two filtering results, fil1 and fil2.
[0080] fil1=filter(a,yout2),fil2=filter(b,yout2)
[0081]
[0082]
[0083] Subtract the image Y from fil1 and fil2 , and get the second gradient difference diffs , the formula is as follows:
[0084] diffs = 2 * Y - fil1 - fil2
[0085] With the second output image yout2 Add the second gradient difference to get the third output image of the last step yout3 , the third output image yout3 The calculation formula is as follows:
[0086] yout3 =yout2+dt*diffs ,in, dt is the strength parameter, the default value is 0.5.
[0087] It should be noted that the original image referred to in this article is also called image Y, the Y component of the image, etc.
[0088] Embodiment 2: A device for optimizing image quality is disclosed, comprising:
[0089] A receiving unit, used to obtain the Y component of the YUV format image;
[0090] A first filtering unit, used to perform image filtering to obtain a first output image after filtering;
[0091] A first enhancement unit is used to perform downsampling processing on the first output image, and perform upsampling on the downsampling result to restore the width and height of the original image; calculate the gain by comparing the size of the upsampled image and the first output image, and adjust the first output image by the gain to obtain the second output image;
[0092] The second enhancement unit is used to perform image enhancement processing on the second output image.
[0093] Among them, the first filtering unit includes a gradient difference calculation unit and an overall filtering unit. The gradient difference calculation unit is used to perform multiple filtering of different scales on the original image to obtain multiple first filtered images, and calculate the first gradient difference between each first filtered image and the original image respectively; and calculate the overall gradient difference according to the width and height of the image and all the first gradient differences.
[0094] The overall filtering unit is used to perform overall filtering on the original image according to the overall gradient difference to obtain a first output image after filtering.
[0095] Among them, the step of the second enhancement unit performing image enhancement processing on the second output image includes: performing image filtering on the second output image to obtain a second filtered image; calculating the second gradient difference between the second filtered image and the original image; calculating the sum of the second output image and the second gradient difference to obtain a third output image.
[0096] For the implementation of other functions of the first filtering unit, the first enhancing unit and the second enhancing unit, please refer to the relevant contents disclosed in Example 1.
[0097] Further disclosed is a computer storage medium storing a computer program, which is called to implement a method for optimizing image quality as disclosed in Example 1.
[0098] Further disclosed is a computer device, including a memory and a processor, wherein the memory is used to store one or more computer programs, wherein the one or more computer programs are executed by the processor to implement a method for optimizing image quality as disclosed in Example 1.
[0099] Exemplarily, the computer program can be divided into one or more modules / units, one or more modules / units are stored in a memory and executed by a processor, and the I / O interface transmission of data is completed by an input interface and an output interface to complete the present invention. One or more modules / units can be a series of computer program instruction segments that can complete specific functions, and the instruction segments are used to describe the execution process of the computer program in a computer device.
[0100] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may include, but is not limited to, a memory and a processor. Those skilled in the art may understand that this embodiment is only an example of a computer device and does not constitute a limitation on the computer device. The computer device may include more or fewer components, or a combination of certain components, or different components. For example, the computer device may also include an input device, a network access device, a bus, etc.
[0101] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0102] The memory can be an internal storage unit of a computer device, such as a hard disk or memory of a computer device. The memory can also be an external storage device of a computer device, such as a plug-in hard disk equipped on a computer device, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. Furthermore, the memory can also include both the internal storage unit of a computer device and an external storage device. The memory is used to store computer programs and other programs and data required by the computer device. The memory can also be used to temporarily store data in an output device. The aforementioned storage media include various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories ROM, random access memories RAM, disks or optical disks.
[0103] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. The units may or may not be physically separated, and the components displayed as units may be one physical unit or multiple physical units, that is, they may be located in one place, or they may be distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this embodiment.
[0104] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A method for optimizing image quality, characterized in that: It includes obtaining a YUV format image, extracting the Y component and performing the following processing steps: Perform multiple filtering of different scales on the original image to obtain multiple first filtered images, and calculate the first gradient difference between each first filtered image and the original image respectively; Calculate the overall gradient difference based on the width and height of the image and all first gradient differences; Performing overall filtering on the original image according to the overall gradient difference to obtain a first output image after filtering; Perform downsampling processing on the first output image, and perform upsampling on the downsampling result to restore the width and height of the original image; calculate the gain by comparing the size of the upsampled image and the first output image, and adjust the first output image by the gain to obtain the second output image; Perform image enhancement processing on the second output image to obtain a third output image.
2. The image quality optimization method according to claim 1, characterized in that: The method of performing overall filtering on the original image according to the overall gradient difference includes the following steps: Using an N*N window, calculate the variance and mean of the pixels in the window matrix. Use the window to traverse the image and calculate the first output image according to the following formula yout1 Values: , in, R is the variance of pixels within the window matrix, Y(i,j) is the pixel value of the original image in the N*N window, diff_f is the overall gradient difference, and mean is the mean of the pixels in the window matrix.
3. The image quality optimization method according to claim 1, characterized in that: After downsampling the first output image, the method further includes the step of filtering the downsampling image to eliminate upsampling abnormal points, thereby obtaining a downsampling result.
4. The image quality optimization method according to claim 1, characterized in that: The steps of image enhancement processing are as follows: Perform image filtering on the second output image to obtain a second filtered image; calculate a second gradient difference between the second filtered image and the original image; calculate a sum of the second output image and the second gradient difference to obtain a third output image.
5. The image quality optimization method according to claim 4, characterized in that: The method for calculating the second gradient difference comprises the following steps: performing multiple filtering of different scales on the second output image to obtain multiple second filtered images, and calculating the second gradient difference according to the original image and all the second filtered data.
6. The image quality optimization method according to claim 1, characterized in that: The gain is calculated by comparing the size of the upsampled image with the first output image. yk The formula is as follows: , in, yout1 is the first output image, meanup is the upsampling result, d is the intensity parameter, df It is the overall gain plus or minus parameter.
7. A device for optimizing image quality, characterized in that: include: A receiving unit, used to obtain the Y component of the YUV format image; A first filtering unit, configured to perform multiple filtering operations of different scales on the original image to obtain multiple first filtered images, and respectively calculate a first gradient difference between each first filtered image and the original image; Calculate the overall gradient difference based on the width and height of the image and all first gradient differences; Performing overall filtering on the original image according to the overall gradient difference to obtain a first output image after filtering; A first enhancement unit, configured to perform downsampling processing on the first output image, and perform upsampling on the downsampling result to restore the width and height of the original image; The gain is calculated by comparing the size of the upsampled image and the first output image, and the first output image is adjusted by the gain to obtain the second output image; The second enhancement unit is used to perform image enhancement processing on the second output image.
8. The image quality optimization device according to claim 7, characterized in that: The first filtering unit includes a gradient difference calculation unit and an overall filtering unit, A gradient difference calculation unit, used to perform multiple filtering of different scales on the original image to obtain multiple first filtered images, and respectively calculate a first gradient difference between each first filtered image and the original image; Calculate the overall gradient difference based on the width and height of the image and all first gradient differences; The overall filtering unit is used to perform overall filtering on the original image according to the overall gradient difference to obtain a first output image after filtering.
9. The image quality optimization device according to claim 7, characterized in that: The step of performing image enhancement processing on the second output image by the second enhancement unit includes: performing image filtering on the second output image to obtain a second filtered image; calculating a second gradient difference between the second filtered image and the original image; and calculating a sum of the second output image and the second gradient difference to obtain a third output image.
