Disclosure of Invention
In view of the above, an object of the present invention is to provide an image processing method, an image processing apparatus and an electronic device, so as to solve the problem of large calculation amount in the process of performing image processing in the prior art.
In order to achieve the above purpose, the embodiment of the invention adopts the following technical scheme:
an image processing method comprising:
performing color quantity reduction processing on an image to be processed, wherein the image to be processed is in a YUV format;
performing first format conversion processing on the image to be processed after the subtraction processing to obtain an image in an RGB format;
and performing second format conversion processing on the RGB format image to obtain and display the bitmap file format image.
In a preferred option of the embodiment of the present invention, in the image processing method, the step of performing color quantity reduction processing on the image to be processed includes:
acquiring a brightness value of an image to be processed, wherein the image to be processed is in a YUV422 format;
and replacing the brightness value with a brightness unit value to finish the color quantity reduction processing.
In a preferred option of the embodiment of the present invention, in the image processing method, the step of performing a first format conversion process on the to-be-processed image subjected to the subtraction process to obtain an image in an RGB format includes:
acquiring a brightness value, a color value and a saturation value of the image to be processed after the subtraction processing;
and searching corresponding red channel values, green channel values and blue channel values in a preset database according to the acquired brightness values, color values and saturation values to obtain the image in the RGB format, wherein the database has corresponding relations between the brightness values, the color values and the saturation values of the same image and the red channel values, the green channel values and the blue channel values.
In a preferred option of the embodiment of the present invention, in the image processing method, before the step of searching the corresponding red channel value, green channel value, and blue channel value in the preset database according to the obtained brightness value, color value, and saturation value is executed, the method may further include:
acquiring a plurality of images with different brightness values, color values and saturation values;
respectively calculating a red channel value, a green channel value and a blue channel value of each image according to a floating-point matrix multiplication formula;
for each image, the corresponding relationship is established between the brightness value, the color value and the saturation value of the image and the red channel value, the green channel value and the blue channel value so as to construct a database.
In a preferred choice of the embodiment of the present invention, in the image processing method, the floating-point matrix multiplication formula is:
R=0.299*Y+0.587*U+0.114*V;
G=(U-V)*0.565;
B=(U-V)*0.713;
wherein, R is a red channel value, G is a green channel value, B is a blue channel value, Y is a brightness value, U is a color value, and V is a saturation value.
In a preferred choice of the embodiment of the present invention, in the image processing method, the floating-point matrix multiplication formula is:
R=1.16*(Y-16)+1.59*(V-128);
G=1.16*(Y-16)-0.39*(U-128)-0.81*(V-128);
B=1.16*(Y-16)+2.01*(U-128);
wherein, R is a red channel value, G is a green channel value, B is a blue channel value, Y is a brightness value, U is a color value, and V is a saturation value.
An embodiment of the present invention further provides an image processing apparatus, including:
the color quantity reduction module is used for reducing the color quantity of an image to be processed, wherein the image to be processed is in a YUV format;
the first format conversion module is used for carrying out first format conversion processing on the image to be processed after the subtraction processing so as to obtain an image in an RGB format;
and the second format conversion module is used for performing second format conversion processing on the RGB format image to obtain and display the bitmap file format image.
In a preferred option of the embodiment of the present invention, in the image processing apparatus, the color number reducing module includes:
the brightness value obtaining submodule is used for obtaining the brightness value of an image to be processed, wherein the image to be processed is in a YUV422 format;
and the brightness value replacing submodule is used for replacing the brightness value with a brightness unit value so as to finish the color quantity reduction processing.
In a preferable selection of the embodiment of the present invention, in the image processing apparatus, the first format conversion module includes:
the gray data acquisition submodule is used for acquiring the brightness value, the color value and the saturation value of the image to be processed after the reduction processing;
and the color data searching submodule is used for searching corresponding red channel values, green channel values and blue channel values in a preset database according to the acquired brightness values, color values and saturation values so as to obtain an image in an RGB format, wherein the database has corresponding relations between the brightness values, the color values and the saturation values of the same image and the red channel values, the green channel values and the blue channel values.
An embodiment of the present invention further provides an electronic device, including a memory, a processor, and an image processing apparatus, where the image processing apparatus includes one or more software functional modules stored in the memory and executed by the processor, where the software functional modules include:
the color quantity reduction module is used for reducing the color quantity of an image to be processed, wherein the image to be processed is in a YUV format;
the first format conversion module is used for carrying out first format conversion processing on the image to be processed after the subtraction processing so as to obtain an image in an RGB format;
and the second format conversion module is used for performing second format conversion processing on the RGB format image to obtain and display the bitmap file format image.
According to the image processing method, the image processing device and the electronic equipment, the calculated amount of conversion between the YUV format and the RGB format can be reduced by reducing the color number of the image to be processed, so that the problem of large calculated amount in the image processing process in the prior art is solved, the problem of long time consumption caused by large calculated amount in the previewing process is solved, and the user experience is greatly improved.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, 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. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. 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.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. In the description of the present invention, the terms "first", "second", and the like are used only for distinguishing the description, and are not intended to be construed as only or implying relative importance.
As shown in fig. 1, an embodiment of the invention provides an electronic device 10 including a memory 12, a processor 14, and an image processing apparatus 100.
The memory 12 and the processor 14 are electrically connected, directly or indirectly, to enable the transfer or interaction of data. For example, the components may be electrically connected to each other via one or more communication buses or signal lines. The image processing apparatus 100 includes at least one software functional module that can be stored in the memory 12 in the form of software or firmware (firmware). The processor 14 is used for executing executable computer programs stored in the memory 12, such as software functional modules and computer programs included in the image processing apparatus 100, so as to implement the image processing method.
The Memory 12 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like. Wherein the memory 12 is used for storing a program, and the processor 14 executes the program after receiving the execution instruction.
The processor 14 may be an integrated circuit chip having signal processing capabilities. The Processor 14 may be a general-purpose Processor including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will be appreciated that the configuration shown in FIG. 1 is merely illustrative and that the electronic device 10 may include more or fewer components than shown in FIG. 1 or may have a different configuration than shown in FIG. 1. The components shown in fig. 1 may be implemented in hardware, software, or a combination thereof.
Alternatively, the specific type of the electronic device 10 is not limited, and may be, for example, but not limited to, a smart phone, a Personal Computer (PC), a tablet PC, a Personal Digital Assistant (PDA), a Mobile Internet Device (MID), and other devices having a data processing function.
With reference to fig. 2, an embodiment of the present invention further provides an image processing method applicable to the electronic device 10. Wherein the method steps defined by the method related flow may be implemented by the processor 14. The specific process shown in fig. 2 will be described in detail below.
Step S110, performing color quantity reduction processing on the image to be processed.
Step S120, performing a first format conversion process on the to-be-processed image subjected to the subtraction process to obtain an image in an RGB format.
Step S130, performing a second format conversion process on the RGB format image to obtain and display a bitmap image.
In this embodiment, the image to be processed may be an image generated by calling a camera by application software to acquire data. And the image to be processed is in a YUV format and correspondingly has a brightness value, a color value and a saturation value.
The image in YUV format is gray color data, and the amount of color data is large, if the image is directly converted into RGB format, there is a large calculation amount, and the amount of data to be stored is also large (greater than 2)24). Therefore, the reduction processing may be performed on the number of colors in order to perform the first format conversion processing when step S110 is performed.
After the RGB format image is obtained, the RGB format image may be converted into a bitmap file format to facilitate display of the RGB format image. The bitmap file format is a Windows standard format graphic file, an image is defined to be composed of pixel points, and each pixel point can be represented by multiple colors, for example, 2, 4, 8, 16, 24 and 32 bit colors.
Further, in executing step S110, the reduction processing may be performed on the luminance value in consideration of the luminance value having a small influence on the first format conversion processing. In the present embodiment, in conjunction with fig. 3, step S110 may include step S111 and step S113.
And step S111, acquiring the brightness value of the image to be processed.
In this embodiment, the image to be processed may be in YUV422 format, that is, a luminance value: color value: the saturation value was 4: 2: 2. in order to ensure the effectiveness of the first format conversion process, the two excess high luminance values may be subtracted.
In step S113, the luminance value is replaced with a luminance unit value to complete the color number reduction process.
In this embodiment, the brightness unit value may be assigned to 1, that is, the brightness value is assigned to 1 by executing step S113, so as to complete the reduction of the number of colors. For example, Y2 representing high luminance among the luminance values Y [ Y0, Y1, Y2] may be assigned to 1 to obtain gray-scale color data [ Y0U0V0, Y1U1V1, 1U2V2] in which the color quantity reduction processing is completed.
Alternatively, the manner of performing the first format conversion process in step S120 is not limited, and for example, the calculation may be performed by a corresponding matrix algorithm, and the lookup may be performed by a table lookup method. In this embodiment, in conjunction with fig. 4, step S120 may include step S121 and step S123.
Step S121, obtaining a brightness value, a color value, and a saturation value of the subtracted image to be processed.
Step S123, finding the corresponding red channel value, green channel value, and blue channel value in a preset database according to the obtained brightness value, color value, and saturation value, so as to obtain an image in RGB format.
In this embodiment, the database has a corresponding relationship between the brightness value, the color value, and the saturation value of the same image and the red channel value, the green channel value, and the blue channel value, so as to convert the image in the YUV format into the image in the RGB format according to the corresponding relationship.
The database may be constructed by performing calculation in advance for a plurality of commonly used images, and calculating and storing a new image in the database in actual application, so as to be directly searched next time. With reference to fig. 5, in this embodiment, the image processing method may further include step S140, step S150, and step S160 to construct a database.
In step S140, a plurality of images with different brightness values, color values and saturation values are obtained.
Step S150, red channel values, green channel values and blue channel values of the images are respectively calculated according to a floating-point matrix multiplication formula.
Step S160, for each image, the luminance value, the color value, and the saturation value of the image are associated with the red channel value, the green channel value, and the blue channel value to construct a database.
The content of the floating-point matrix algorithm is not limited, and may be an algorithm commonly used in the prior art, as follows:
Y 0.299 0.587 0.114 R
U=-0.147-0.289 0.436*G;
V 0.615-0.515-0.100 B
wherein, R is a red channel value, G is a green channel value, B is a blue channel value, Y is a brightness value, U is a color value, and V is a saturation value.
In this embodiment, considering that the resolution of the human eye is low, the above algorithm can be simplified to obtain the following formula:
R=0.299*Y+0.587*U+0.114*V;
G=(U-V)*0.565;
B=(U-V)*0.713;
wherein, R is a red channel value, G is a green channel value, B is a blue channel value, Y is a brightness value, U is a color value, and V is a saturation value.
Further, to further simplify the calculation and avoid reducing the user experience due to errors, in this embodiment, the maximum error value and the minimum error value may be compensated to perform the correction, where the maximum error value is 128 and the minimum error value is 16, and the formula obtained by the correction is as follows:
R=1.16*(Y-16)+1.59*(V-128);
G=1.16*(Y-16)-0.39*(U-128)-0.81*(V-128);
B=1.16*(Y-16)+2.01*(U-128);
wherein, R is a red channel value, G is a green channel value, B is a blue channel value, Y is a brightness value, U is a color value, and V is a saturation value.
With reference to fig. 6, an embodiment of the present invention further provides an image processing apparatus 100 applicable to the electronic device 10. The image processing apparatus 100 may include a color quantity reduction module 110, a first format conversion module 120, and a second format conversion module 130.
The color quantity reduction module 110 is configured to perform color quantity reduction processing on an image to be processed, where the image to be processed is in a YUV format. In the present embodiment, the color number reducing module 110 may be configured to execute step S110 shown in fig. 2, and the detailed description of the color number reducing module 110 may refer to the foregoing description of step S110.
The first format conversion module 120 is configured to perform a first format conversion process on the to-be-processed image subjected to the subtraction process to obtain an image in an RGB format. In this embodiment, the first format conversion module 120 may be configured to perform step S120 shown in fig. 2, and the detailed description about the first format conversion module 120 may refer to the foregoing description about step S120.
The second format conversion module 130 is configured to perform a second format conversion process on the RGB-format image to obtain and display an image in a bitmap file format. In this embodiment, the second format conversion module 130 may be configured to perform step S130 shown in fig. 2, and the detailed description about the second format conversion module 130 may refer to the foregoing description about step S130.
Referring to fig. 7, in this embodiment, the color quantity reduction module 110 may include a luminance value obtaining sub-module 111 and a luminance value replacing sub-module 113.
The brightness value obtaining submodule 111 is configured to obtain a brightness value of an image to be processed, where the image to be processed is in a YUV422 format. In this embodiment, the brightness value obtaining sub-module 111 may be configured to perform step S111 shown in fig. 3, and for the detailed description of the brightness value obtaining sub-module 111, reference may be made to the description of step S111.
The luminance value replacing sub-module 113 is configured to replace the luminance value with a luminance unit value to complete the color number reduction processing. In this embodiment, the luminance value replacement sub-module 113 may be configured to perform step S113 shown in fig. 3, and the detailed description about the luminance value replacement sub-module 113 may refer to the foregoing description about step S113.
With reference to fig. 8, in this embodiment, the first format conversion module 120 may include a gray scale data obtaining sub-module 121 and a color data searching sub-module 123.
The gray data obtaining submodule 121 is configured to obtain a brightness value, a color value, and a saturation value of the to-be-processed image after the subtraction processing. In this embodiment, the gray scale data obtaining sub-module 121 may be configured to perform step S121 shown in fig. 4, and the detailed description of the gray scale data obtaining sub-module 121 may refer to the description of step S121.
The color data searching submodule 123 is configured to search, according to the obtained brightness value, color value, and saturation value, a preset database for a corresponding red channel value, green channel value, and blue channel value to obtain an image in an RGB format, where the database has a correspondence relationship between the brightness value, color value, and saturation value of the same image and the red channel value, green channel value, and blue channel value. In this embodiment, the color data lookup sub-module 123 may be configured to perform step S123 shown in fig. 4, and the detailed description of the color data lookup sub-module 123 may refer to the description of step S123.
With reference to fig. 9, in this embodiment, the image processing apparatus 100 may further include an image acquisition module 140, a color data calculation module 150, and a database construction module 160.
The image obtaining module 140 is configured to obtain a plurality of images with different brightness values, color values, and saturation values. In this embodiment, the image obtaining module 140 may be configured to perform step S140 shown in fig. 5, and the foregoing description of step S140 may be referred to for specific description of the image obtaining module 140.
The color data calculation module 150 is configured to calculate a red channel value, a green channel value, and a blue channel value of each image according to a floating-point matrix multiplication formula. In the present embodiment, the color data calculating module 150 can be used to execute step S150 shown in fig. 5, and the detailed description of the color data calculating module 150 can refer to the foregoing description of step S150.
The database construction module 160 is configured to, for each image, establish a corresponding relationship between the brightness value, the color value, and the saturation value of the image and the red channel value, the green channel value, and the blue channel value, so as to construct a database. In this embodiment, the database building module 160 may be configured to execute step S160 shown in fig. 5, and the detailed description about the database building module 160 may refer to the foregoing description about step S160.
In summary, according to the image processing method, the image processing apparatus 100 and the electronic device 10 provided by the present invention, the amount of computation for converting between the YUV format and the RGB format can be reduced by performing the color quantity reduction processing on the image to be processed, so as to improve the problem of large computation amount in the image processing process in the prior art, thereby solving the problem of long time consumption due to large computation amount in the preview process, and greatly improving the user experience.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus and method embodiments described above are illustrative only, as the flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, an electronic device, or a network device) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes. It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.