WO2019006965A1 - 图像处理方法、装置、电子设备及计算机可读存储介质 - Google Patents

图像处理方法、装置、电子设备及计算机可读存储介质 Download PDF

Info

Publication number
WO2019006965A1
WO2019006965A1 PCT/CN2017/112951 CN2017112951W WO2019006965A1 WO 2019006965 A1 WO2019006965 A1 WO 2019006965A1 CN 2017112951 W CN2017112951 W CN 2017112951W WO 2019006965 A1 WO2019006965 A1 WO 2019006965A1
Authority
WO
WIPO (PCT)
Prior art keywords
result
plane
row
mask
value
Prior art date
Application number
PCT/CN2017/112951
Other languages
English (en)
French (fr)
Inventor
杨亮
张文明
陈少杰
Original Assignee
武汉斗鱼网络科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 武汉斗鱼网络科技有限公司 filed Critical 武汉斗鱼网络科技有限公司
Publication of WO2019006965A1 publication Critical patent/WO2019006965A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/90Determination of colour characteristics
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10024Color image

Definitions

  • the present invention belongs to the field of image processing technologies, and in particular, to an image processing method, apparatus, electronic device, and computer readable storage medium.
  • an embodiment of the present invention provides an image processing method, including: obtaining an ARGB image to be converted; acquiring a Y-plane mask and a UV plane mask respectively from the ARGB image; respectively acquiring from the ARGB image M pixel values of the i-th row and M pixel values of the i+1th row, wherein M is an integer greater than 1; according to the obtained Y-plane mask value, the M pixel values of the ith row And the M pixel values of the i+1th row, obtaining pixel values of the Y plane; according to the obtained UV plane mask value, the ith row M pixel values, and the i+1th row M The pixel value is obtained, and the pixel value of the UV plane is obtained.
  • an embodiment of the present invention provides an image processing method, including: obtaining an ARGB image to be converted; acquiring a Y plane mask and a UV plane mask; and acquiring M rows of the ith row from the ARGB image respectively a pixel value and M pixel values of the i+1th row, wherein M is an integer greater than 1; according to the obtained Y-plane mask, the M pixel values of the i-th row, and the (i+1)th M pixel values of the row to obtain pixel values of the Y plane; A pixel value of the UV plane is obtained according to the obtained UV plane mask, M pixel values of the i-th row, and M pixel values of the (i+1)-th row.
  • an embodiment of the present invention provides an image processing apparatus, including: an ARGB image acquiring unit configured to obtain an ARGB image to be converted.
  • a mask acquisition unit configured to acquire a Y-plane mask and a UV plane mask, respectively, from the ARGB image.
  • the pixel acquiring unit is configured to respectively acquire M pixel values of the i-th row and M pixel values of the i+1th row from the ARGB image, wherein M is an integer greater than 1.
  • a Y-plane pixel value acquiring unit configured to obtain a pixel value of the Y plane according to the obtained Y-plane mask value, the M pixel values of the i-th row, and the M pixel values of the (i+1-th row) .
  • the UV plane pixel value acquiring unit is configured to obtain a pixel value of the UV plane according to the obtained UV plane mask value, the ith row M pixel value, and the i+1th row M pixel value.
  • an embodiment of the present invention provides an image processing apparatus, including: an ARGB image acquiring unit configured to obtain an ARGB image to be converted; and a mask acquiring unit configured to obtain a Y plane mask and a UV plane mask; a pixel acquiring unit configured to respectively acquire M pixel values of the i-th row and M pixel values of the i+1th row from the ARGB image, where M is an integer greater than 1; Y pixel value acquiring unit, configured Obtaining a pixel value of the Y plane according to the obtained Y plane mask, the M pixel values of the ith row, and the M pixel values of the i+1th row; the UV pixel value acquiring unit is configured to A pixel value of the UV plane is obtained according to the obtained UV plane mask, M pixel values of the i-th row, and M pixel values of the (i+1)-th row.
  • an embodiment of the present invention provides an electronic device, including: a processor and a memory, the processor being coupled to the memory; and the memory configured to store a program.
  • the processor is configured to invoke a program stored in the memory to perform the image processing method described above.
  • an embodiment of the present invention provides an electronic device, including: a memory configured to store a computer program, and a processor configured to invoke the computer program to perform image processing according to any one of claims 7-11 method.
  • an embodiment of the present invention provides a computer readable storage medium.
  • the readable storage medium stores program code executable by the processor in the computer.
  • the readable storage medium includes a plurality of instructions, the program code being arranged to cause the processor to perform the above method.
  • an embodiment of the present invention provides a computer readable storage medium, where a computer program is stored, and when the computer program is executed, the image processing method provided by the embodiment of the present invention is implemented.
  • the image processing method, device, electronic device and computer readable storage medium provided by the embodiments of the present invention can process multiple pixels at a time when converting the RGB format into the YUV format, for example, 2, compared with the prior art. 3, 4, thus optimizing the efficiency of converting RGB format into YUV format, improving the conversion efficiency, and solving the problem that the conversion efficiency of the existing conversion method is relatively low under a large resolution image.
  • FIG. 1 is a structural block diagram of an electronic device according to an embodiment of the present invention.
  • FIG. 2 is a flowchart of a method for an image processing method according to an embodiment of the present invention.
  • FIG. 3 is a flowchart of a method for obtaining step S204 in FIG. 2 according to an embodiment of the present invention.
  • FIG. 4 is a flow chart showing a method for obtaining step S205 in FIG. 2 according to an embodiment of the present invention.
  • FIG. 5 is a flowchart of a method for obtaining step S403 in FIG. 4 according to an embodiment of the present invention.
  • FIG. 6 is a functional block diagram of an image processing apparatus according to an embodiment of the present invention.
  • FIG. 7 is a functional block diagram of a Y-plane pixel value acquiring unit in FIG. 6 according to an embodiment of the present invention.
  • FIG. 8 is a functional block diagram of a UV plane pixel value acquiring unit in FIG. 6 according to an embodiment of the present invention.
  • FIG. 1 is a structural block diagram of an electronic device 100 according to an embodiment of the present invention.
  • the electronic device 100 includes an image processing device 110, a memory 120, a storage controller 130, and a processor 140.
  • the components of the memory 120, the storage controller 130, and the processor 140 are electrically connected directly or indirectly to each other to implement data transmission or interaction.
  • the components can be electrically connected to one another via one or more communication buses or signal lines.
  • the image processing device 110 includes at least one software function module that can be stored in the memory 120 or in an operating system (OS) of the electronic device 100 in the form of software or firmware.
  • the processor 140 is configured to execute executable modules stored in the memory 120, such as software functional modules or computer programs included with the image processing device 110.
  • the memory 120 can be, but not limited to, a random access memory (RAM), a read only memory (ROM), and a programmable read-only memory (PROM). Erasable Programmable Read-Only Memory (EPROM), Electric Erasable Programmable Read-Only Memory (EEPROM), and the like.
  • RAM random access memory
  • ROM read only memory
  • PROM programmable read-only memory
  • EPROM Erasable Programmable Read-Only Memory
  • EEPROM Electric Erasable Programmable Read-Only Memory
  • the memory 120 is configured to store a program, and the processor 140 executes the program after receiving the execution instruction, and the method executed by the electronic device 100 defined by the process disclosed in any embodiment of the present invention may be applied. In processor 140, or implemented by processor 140.
  • Processor 140 may be an integrated circuit chip with signal processing capabilities.
  • the above processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; or may be a digital signal processor (DSP) or an application specific integrated circuit (ASIC). , off-the-shelf programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
  • the methods, steps, and logical block diagrams disclosed in the embodiments of the present invention may be implemented or carried out.
  • the general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
  • RGB color mode (Red, Green, Blue, red, green, blue color mode) is a color of industry The standard is to obtain different colors by changing the three color channels of red (R), green (G), and blue (B), and RGB is the three channels representing red, green, and blue.
  • R red
  • G green
  • B blue
  • RGB the three channels representing red, green, and blue.
  • the ARGB pixel format is one of the RGB color formats, using 32 bits to represent one pixel, RGB components each using 8 bits, and the remaining 8 bits are used as transparency Alpha.
  • the order of the components of ARGB in the memory is: B0, G0, R0, A0, B1, G1, R1, A1, B2, G2, R2, A2.
  • the YUV (color coding method) format is divided into three components, "Y" for brightness (Luminance or Luma), that is, gray value; and "U” and “V” for color (Chrominance or Chroma)
  • the role is to describe the color and saturation of the image, which is used to specify the color of the pixel.
  • YUV format is mainly used in the field of television systems and analog video. It separates luminance information (Y) from color information (UV). It can display complete images without UV information, but it is only black and white. This design is well solved. The compatibility of color TVs with black and white TVs.
  • YUV does not require three independent video signals to be transmitted at the same time as RGB, so the bandwidth used to transmit data in the YUV format is extremely small.
  • the storage format of the YUV stream is closely related to the way it is sampled. There are three main sampling methods: YUV4:4:4, YUV4:2:2, and YUV4:2:0. There are two main categories of YUV formats: the planar format and the packed format. For the planar YUV format, the Y of all pixels is stored consecutively, followed by the U of all the pixels, followed by the V of all the pixels. For the packed YUV format, Y, U, and V of each pixel are continuously interleaved.
  • the NV12 pixel format belongs to one of the YUV420 formats, and is a two-plane mode, that is, Y and UV are divided into two planes, but UV (CbCr) is interleaved.
  • the width of a NV12 image is width and height is height
  • the width of its Y plane is width
  • the number of bytes in a line of Y plane is width
  • the height of the Y plane is height
  • its UV plane The width is width/2
  • the number of bytes in one line of the UV plane is width
  • the height of the UV plane is height/2.
  • FIG. 2 is a flowchart of an image processing method according to a first embodiment of the present invention, including steps S201-S205.
  • Step S201 Obtain an ARGB image to be converted.
  • the image to be converted is an ARGB image, that is, an image conversion is required.
  • ARGB image is an ARGB image, that is, an image conversion is required.
  • Step S202 Acquire a Y plane mask and a UV plane mask respectively from the ARGB image.
  • the SSE instruction is a single instruction and multiple data instruction, that is, one machine instruction of the SSE can process multiple pieces of data, and the conventional CPU instruction can only process a single piece of data.
  • one pixel contains Alpha transparency component, red component, green component, blue component, one component per component, that is, one pixel occupies 4 bytes of memory space, ordinary CPU
  • an AMR pixel is processed by an instruction, only 4 bytes of data can be processed at a time, that is, one pixel.
  • the SSE instruction 16 bytes of data, that is, 4 pixels, can be processed at a time. That is to say, one conversion operation of the SSE instruction is equivalent to four conversions of the ordinary CPU instruction, so the efficiency of conversion using the SSE instruction is at least four times that of the ordinary CPU instruction.
  • the ARGB pixel format uses 32 bits to represent one pixel, and the SSE instruction processes ARGB pixels, 16 bytes of data can be processed at a time, that is, 4 pixels. Therefore, in this embodiment, when using the SSE instruction conversion, the 128-bit __m128i data type is used to maximize the conversion efficiency. It should be noted that, in this embodiment, the case where only four pixels are processed at a time by the SSE instruction is taken as an example, and the case of processing 2 or 3 pixels at a time is similar, in order to avoid cumbersome, no longer one by one. Shown for example.
  • the Y-plane mask is obtained from the ARGB image, for example, _mm_set1_epi32 of the SSE instruction is called to expand 0x0000FF00 to 128, the Y-plane mask in the NV12 format is obtained, and the value is stored to lumMask.
  • Obtaining a UV plane mask from the ARGB image when converting using the SSE instruction for example, calling _mm_set1_epi16 of the SSE instruction to expand 0x00ff to 128 bits, obtaining a UV plane mask of the NV12 format, and storing the value to In uvMask.
  • Step S203 Obtain M pixel values of the i-th row and M pixel values of the i+1th row from the ARGB image, where M is an integer greater than 1.
  • the M pixel values of the i-th row are obtained from the ARGB image, for example, the _mm_load_si128 instruction of the SSE instruction is called to store the 4 pixel values of the i-th row into the __m128i line1 variable.
  • the M pixel values of the i+1th row are obtained from the ARGB image.
  • the call of the SSE instruction _mm_load_si128 command is used to store the 4 pixel values of the i+1th row into the __m128i line2 variable.
  • Step S204 Obtain a pixel value of the Y plane according to the obtained Y-plane mask value, the M pixel values of the i-th row, and the M pixel values of the (i+1-th row).
  • the pixel value of the Y plane can be obtained by the obtained Y-plane mask value, the M pixel values of the i-th row, and the M pixel values of the i+1-th row.
  • the obtained Y-plane mask value, the M-th pixel value of the ith row, and the M-th row of the M-th row may be obtained by the method step shown in FIG.
  • the pixel value is obtained, and the pixel value of the Y plane is obtained.
  • the method steps shown in FIG. 3 specifically include: steps S301-S305.
  • Step S301 Perform the AND operation on the obtained Y-plane mask value and the M pixel values in the ith row to obtain a first result.
  • the first result is obtained.
  • the mm_and_si128 instruction of the SSE instruction is called to change the line1 variable value (the 4 pixel values of the i-th row) with The lumMask value (Y-plane mask value) is ANDed to obtain the first result, and the first result is stored in andResult1.
  • Step S302 Perform the AND operation on the obtained Y-plane mask value and the M-th pixel values in the (i+1)th row to obtain a second result.
  • a second result is obtained, for example, the _mm_and_s128i instruction of the SSE instruction is called to the line2 variable (four of the i+1th row)
  • the pixel value is ANDed with the lumMask value (Y plane mask value) to obtain a second result, and the second result is stored in andResult2.
  • Step S303 Perform arithmetic right shift on the obtained first result to obtain a third result.
  • a first result is obtained, and then the obtained first result is arithmetically shifted right to obtain a third result, for example, calling _mm_srli_si128
  • the andResult1 (first result) in the previous step is arithmetically shifted one bit to the left to obtain a third result, and the third result is stored in srlResult1.
  • Step S304 Perform arithmetic right shift on the obtained second result to obtain a fourth result.
  • a second result is obtained, and then the obtained second result is arithmetically shifted to the right to obtain a fourth result, for example, calling _ Mm_srli_si128 arithmetically shifts andResult2 (second result) in the previous step by one bit to obtain a fourth result, and stores the fourth result in srlResult2.
  • Step S305 Obtain a pixel value of the Y plane according to the obtained third result and the fourth result.
  • the pixel value of the Y plane can be obtained. That is, the lower eight bytes in the third result are the Y pixel values of the i-th row, and the lower eight bytes in the fourth result are the Y pixel values of the i+1th row.
  • the pixel value of the Y plane includes: a Y pixel value of the i-th row and a Y pixel value of the i+1th row.
  • the lower 8 bytes of data in the third result are stored in the lower 8 bytes of the pointer array A, and the lower 8 bytes of the fourth result are data.
  • the first integer value in the pointer array A is taken as the Y pixel value of the i-th row, and the second integer value is taken as the Y pixel value of the i+1th row.
  • the __mm_packs_epi32 instruction that calls the SEE instruction stores the lower 8 bytes of srlResult1 (third result) and the lower 8 bytes of srlResult2 (fourth result) in the previous step into the variable packVal.
  • the first integer value in the m128i_u32 array in the packVal structure obtained in the previous step is the first The Y pixel value of the i line
  • the second integer value in the m128i_u32 array is the Y pixel value of the i+1th line.
  • the first integer value in the pointer array A is the lower 8 bytes in the third result
  • the second integer value in the pointer array A is the lower 8 bytes in the fourth result.
  • the pointer array A can be the above packVal.
  • Step S205 Obtain a pixel value of the UV plane according to the obtained UV plane mask value, the ith row M pixel value, and the i+1th row M pixel value.
  • the pixel value of the UV plane can be obtained by the obtained UV plane mask value, M pixel values of the i-th row, and M pixel values of the i+1th row.
  • the obtained UV plane mask value, the ith row M pixel value, and the i+1th row M pixels may be obtained by using the method step shown in FIG. 4 Value, the pixel value of the UV plane is obtained.
  • the method steps shown in FIG. 4 include steps S401-S403.
  • Step S401 Perform the AND operation on the obtained UV plane mask value and the M pixel values in the ith row to obtain a fifth result.
  • UV plane mask value After the obtained UV plane mask value is compared with the M pixel values of the ith row, a fifth result is obtained.
  • the _mm_and_si128 instruction is called to change the line1 variable value (the 4 pixel values of the i-th row) and the uvMask value.
  • (UV plane mask value) performs an AND operation to obtain a fifth result, and stores the fifth result in uvandResult1.
  • Step S402 Perform the AND operation on the obtained UV plane mask value and the M pixels in the i+1th row to obtain a sixth result.
  • the obtained UV plane mask value is compared with the M pixel values of the i+1th row, a sixth result is obtained.
  • the _mm_and_s128i instruction is called to change the line2 variable value (the 4 pixel values of the i-th row) with
  • the uvMask value (UV plane mask value) is ANDed to obtain a sixth result, and the sixth result is stored in uvandResult2.
  • Step S403 Obtain pixel values of the UV plane according to the obtained fifth result and the sixth result.
  • the pixel value of the UV plane can be obtained.
  • the pixel value of the UV plane can be obtained according to the obtained fifth result and the sixth result by the method step shown in FIG. 5.
  • the method steps shown in FIG. 5 include steps S501-S504.
  • Step S501 Adding the fifth result and the sixth result to obtain a seventh result.
  • the fifth result and the sixth result are added to obtain a seventh result.
  • the _mm_add_epi64 instruction that invokes the SSE instruction will uvandResult1 (fifth result) and uvandResult2 (sixth result) Add, get the seventh result, and store the seventh result in the addVal variable.
  • Step S502 The second 32-bit integer in the seventh result is exchanged with the first 32-bit integer, and the third 32-bit integer is exchanged with the fourth 32-bit integer to obtain an eighth result.
  • the integer in the seventh result is exchanged, and optionally, the second 32-bit integer in the seventh result is exchanged with the first 32-bit integer, and the third 32-bit integer is The fourth 32-bit integer is exchanged to obtain an eighth result.
  • the _mm_shuffle_epi32 instruction that calls the SSE instruction swaps the third 32-bit integer of addVal (the seventh result) with the fourth 32-bit integer, and the second 32-bit integer of addVal (the seventh result) is the same.
  • a 32-bit integer is exchanged to obtain an eighth result, and the eighth result is stored in the addValShuffle variable.
  • Step S503 Adding the eighth result and the seventh result and averaging to obtain a ninth result.
  • the eighth result is added to the seventh result, and then the added result is averaged to obtain a ninth result.
  • the SSE instruction _mm_add_epi64 instruction adds addVal (seventh result) to addValShuffle (eighth result)
  • Step S504 Exchanging the second 32-bit integer in the ninth result with the fourth 32-bit integer, and exchanging the first 32-bit integer with the third 32-bit integer to obtain a pixel of the UV plane. value.
  • the integer in the seventh result is exchanged, and optionally, the second 32-bit integer in the ninth result is exchanged with the fourth 32-bit integer, and the first 32 is The bit integer is exchanged with the third 32-bit integer to obtain the pixel value of the UV plane.
  • the _mm_shuffle_epi32 instruction that invokes the SSE instruction exchanges the second 32-bit integer of avgVal (ninth result) with the fourth 32-bit integer, and exchanges the first 32-bit integer with the third 32-bit integer.
  • the result is stored in the avgValShuffle variable.
  • the first 32-bit integer value in the m128i_u32 array stored in the avgValShuffle variable is the UV pixel value of the i-th row, which is the pixel value of the UV plane.
  • the pixel value of the UV plane includes: the UV pixel value of the i-th row.
  • the process of converting ARGB pixels into NV12 pixels by using the SSE instruction is realized. Since the SSE instruction can process the characteristics of multiple data, the method is at least 4 times faster than the existing conversion algorithm. So it greatly provides conversion efficiency.
  • An embodiment of the present invention further provides an image processing apparatus 110, as shown in FIG.
  • the image processing device 110 package The ARGB image acquisition unit 111, the mask acquisition unit 112, the pixel acquisition unit 113, the Y-plane pixel value acquisition unit 114, and the UV plane pixel value acquisition unit 115 are included.
  • the ARGB image acquisition unit 111 is configured to obtain an ARGB image to be converted.
  • the mask acquisition unit 112 is configured to acquire a Y-plane mask and a UV plane mask, respectively, from the ARGB image.
  • the pixel acquiring unit 113 is configured to respectively acquire M pixel values of the i-th row and M pixel values of the i+1th row from the ARGB image, where M is an integer greater than 1.
  • the Y-plane pixel value obtaining unit 114 is configured to obtain a Y-plane according to the obtained Y-plane mask value, the M pixel values of the i-th row, and the M pixel values of the (i+1-th row) The pixel value.
  • the UV plane pixel value obtaining unit 115 is configured to obtain a pixel of a UV plane according to the obtained UV plane mask value, the ith row M pixel value, and the i+1th row M pixel value. value.
  • the Y-plane pixel value obtaining unit 114 includes: a first result obtaining sub-unit 1141 , a second result obtaining sub-unit 1142 , a third result obtaining sub-unit 1143 , and a fourth result obtaining sub-unit 1144 . And the Y-plane pixel value acquisition sub-unit 1145.
  • the first result obtaining subunit 1141 is configured to perform an AND operation on the obtained Y plane mask value and the M pixel values of the ith row to obtain a first result.
  • the second result obtaining subunit 1142 is configured to perform an AND operation on the obtained Y plane mask value and the M pixel values of the i+1th row to obtain a second result.
  • the third result obtaining subunit 1143 is configured to perform an arithmetic right shift on the obtained first result to obtain a third result.
  • the fourth result obtaining subunit 1144 is configured to perform an arithmetic right shift on the obtained second result to obtain a fourth result.
  • the Y-plane pixel value acquisition sub-unit 1145 obtains a pixel value of the Y-plane according to the obtained third result and the fourth result.
  • the UV plane pixel value obtaining unit 115 may include: a fifth result obtaining subunit 1151, a sixth result obtaining subunit 1152, a seventh result obtaining subunit 1153, and an eighth result obtaining subunit. 1154.
  • the fifth result acquisition subunit 1151 is configured to perform an AND operation on the obtained UV plane mask value and the M pixel values in the ith row to obtain a fifth result.
  • the sixth result acquisition subunit 1152 is configured to obtain the obtained UV plane mask value and the (i+1)th The M pixels of the row are ANDed to obtain a sixth result.
  • the seventh result acquisition subunit 1153 is configured to add the fifth result and the sixth result to obtain a seventh result.
  • the eighth result acquisition subunit 1154 is configured to exchange the second 32-bit integer in the seventh result with the first 32-bit integer, and the third 32-bit integer and the fourth 32-bit integer After the exchange, the eighth result is obtained.
  • the ninth result acquisition subunit 1155 is configured to add the eighth result to the seventh result and then average the value to obtain a ninth result.
  • the UV plane pixel value obtaining subunit 1156 is configured to exchange the second 32-bit integer in the ninth result with the fourth 32-bit integer, and the first 32-bit integer is the same as the third 32-bit integer. After the integers are exchanged, the pixel values of the UV plane are obtained.
  • the embodiment provides an image processing method, which is substantially the same as the image processing method in the first embodiment, except that in this embodiment, the Y plane mask and the UV plane mask are not from ARGB. Obtained in the image.
  • the Y-plane mask can be obtained by the following steps:
  • the first SSE instruction is invoked, and the M first mask values are connected together to obtain a Y-plane mask.
  • the first SSE instruction may be an _mm_set1_epi32() instruction.
  • the UV plane mask can be obtained by the following steps:
  • the second SSE instruction is invoked to connect 2M of the second mask values together to obtain a UV plane mask.
  • the second SSE instruction may be an _mm_set1_epi16() instruction.
  • the Y-plane mask and the UV plane mask may also be preset mask values.
  • the embodiment further provides an image processing apparatus which is substantially the same as the image processing apparatus in the first embodiment, except that the mask acquisition unit obtains a Y-plane mask by:
  • the first SSE instruction is invoked, and the M first mask values are connected together to obtain a Y-plane mask.
  • the mask acquisition unit obtains a UV plane mask by:
  • the second SSE instruction is invoked to connect 2M of the second mask values together to obtain a UV plane mask.
  • An embodiment of the present invention further provides an electronic device, where the electronic device includes a memory and a processor.
  • a computer program is stored in the memory, and the processor is configured to invoke the computer program to implement an image processing method provided by an embodiment of the present invention.
  • the embodiment of the invention further provides a computer readable storage medium, on which a computer program is stored, and when the computer program is executed, the image processing algorithm provided by the embodiment of the invention is implemented.
  • each block of the flowchart or block diagram can represent a module, a program segment, or a portion of code that includes one or more of the Executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may also occur in a different order than those illustrated in the drawings.
  • each block of the block diagrams and/or flowcharts, and combinations of blocks in the block diagrams and/or flowcharts can be implemented in a dedicated hardware-based system that performs the specified function or action. Or it can be implemented by a combination of dedicated hardware and computer instructions.
  • each functional module in each embodiment of the present invention may be integrated to form a separate part, or each module may exist separately, or two or more modules may be integrated to form a separate part.
  • the functions, if implemented in the form of software functional modules and sold or used as separate products, may be stored in a computer readable storage medium.
  • the technical solution of the present invention which is essential or contributes to the prior art, or a part of the technical solution, may be embodied in the form of a software product, which is stored in a storage medium, including Several instructions to make a computer device (can It is a personal computer, server, or network device, etc.) that performs all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. .
  • the image processing method, the device, the electronic device and the computer readable storage medium provided by the embodiments of the present invention optimize the existing image conversion method, and can convert the image in the ARGB format into the image in the NV12 format at one time. Multiple pixels for improved conversion efficiency.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Image Processing (AREA)

Abstract

本发明涉及图像处理方法、装置、电子设备及计算机可读存储介质,属于图像处理技术领域。该方法包括:获得待转换的ARGB图像;从所述ARGB图像中分别获取Y平面掩码和UV平面掩码;从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数;根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值;根据获得的所述UV平面掩码值、所述第i行M个像素值和所述第i+1行M个像素值,获得UV平面的像素值。该方法与现有技术相比,优化了RGB格式转换成YUV格式的效率,提高了转换效率,解决了现有转换方法在较大分辨率图像下,转换效率比较低下的问题。

Description

图像处理方法、装置、电子设备及计算机可读存储介质
相关申请的交叉引用
本申请要求于2017年07月07日提交中国专利局的申请号为201710548915X、名称为“图像处理方法、装置、电子设备及计算机可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明属于图像处理技术领域,具体涉及图像处理方法、装置、电子设备及计算机可读存储介质。
背景技术
在进行H264编码时,需要将RGB格式的像素转换为YUV格式的像素,这样才能进行H264编码。通常的做法是利用YUV与RGB间的相关转换算法,在CPU(Central Process Unit)上执行RGB格式转换成YUV格式。然而,但图像分辨率很大的情况下,现有的转换算法非常消耗CPU资源,转换效率比较低下。如何解决现有转换方法在较大分辨率图像下,转换效率比较低下的问题,成为了行业内关注的焦点。
发明内容
鉴于此,本发明的目的在于提供一种图像处理方法、装置、电子设备及计算机可读存储介质,以有效地改善上述问题。
本发明的实施例是这样实现的:
一方面,本发明实施例提供了一种图像处理方法,包括:获得待转换的ARGB图像;从所述ARGB图像中分别获取Y平面掩码和UV平面掩码;从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数;根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值;根据获得的所述UV平面掩码值、所述第i行M个像素值和所述第i+1行M个像素值,获得UV平面的像素值。
第二方面,本发明实施例提供了一种图像处理方法,包括:获得待转换的ARGB图像;获取Y平面掩码及UV平面掩码;从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数;根据获得的所述Y平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值; 根据获得的所述UV平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获得UV平面的像素值。
第三方面,本发明实施例提供了一种图像处理装置,包括:ARGB图像获取单元,配置成获得待转换的ARGB图像。掩码获取单元,配置成从所述ARGB图像中分别获取Y平面掩码和UV平面掩码。像素获取单元,配置成从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数。Y平面像素值获取单元,配置成根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值。UV平面像素值获取单元,配置成根据获得的所述UV平面掩码值、所述第i行M个像素值和所述第i+1行M个像素值,获得UV平面的像素值。
第四方面,本发明实施例提供了一种图像处理装置,包括:ARGB图像获取单元,配置成获得待转换的ARGB图像;掩码获取单元,配置成获得Y平面掩码及UV平面掩码;像素获取单元,配置成从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数;Y像素值获取单元,配置成根据获得的所述Y平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值;UV像素值获取单元,配置成根据获得的所述UV平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获得UV平面的像素值。
第五方面,本发明实施例提供了一种电子设备,包括:处理器和存储器,所述处理器与所述存储器耦合;所述存储器配置成存储程序。所述处理器配置成调用存储在所述存储器中的程序,执行上述图像处理方法。
第六方面,本发明实施例提供了一种电子设备,包括:存储器,配置成存储计算机程序;处理器,配置成调用所述计算机程序,执行权利要求7-11任一项所述的图像处理方法。
第七方面,本发明实施例提供了一种计算机可读存储介质。所述可读取存储介质存储有处理器可执行的程序代码于计算机内。所述可读取存储介质包括多条指令,所述程序代码多条指令被配置成使所述处理器执行上述方法。
第八方面,本发明实施例提供了一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被执行时实现本发明实施例提供的图像处理方法。
本发明实施例提供的图像处理方法、装置、电子设备及计算机可读存储介质,与现有技术相比,在将RGB格式转换成YUV格式时,一次性可以处理多个像素,例如,2、 3、4,因而优化了RGB格式转换成YUV格式的效率,提高了转换效率,解决了现有转换方法在较大分辨率图像下,转换效率比较低下的问题。
本发明的其他特征和优点将在随后的说明书阐述,并且,部分地从说明书中变得显而易见,或者通过实施本发明实施例而了解。本发明的目的和其他优点可通过在所写的说明书、权利要求书以及附图中所特别指出的结构来实现和获得。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。通过附图所示,本发明的上述及其它目的、特征和优势将更加清晰。在全部附图中相同的附图标记指示相同的部分。并未刻意按实际尺寸等比例缩放绘制附图,重点在于示出本发明的主旨。
图1示出了本发明实施例提供的一种电子设备的结构框图。
图2示出了本发明实施例提供的一种图像处理方法的方法流程图。
图3示出了本发明实施例提供的一种获得图2中的步骤S204的方法流程图。
图4示出了本发明实施例提供的一种获得图2中的步骤S205的方法流程图。
图5示出了本发明实施例提供的一种获得图4中的步骤S403的方法流程图。
图6示出了本发明实施例提供的一种图像处理装置的功能模块框图。
图7示出了本发明实施例提供的一种图6中的Y平面像素值获取单元的功能模块框图。
图8示出了本发明实施例提供的一种图6中的UV平面像素值获取单元的功能模块框图。
具体实施方式
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。通常在此处附图中描述和示出的本发明实施例的组件可以以各种不同的配置来布置和设计。
因此,以下对在附图中提供的本发明的实施例的详细描述并非旨在限制要求保护的本发明的范围,而是仅仅表示本发明的选定实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护 的范围。
应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。
在本发明的描述中,需要说明的是,术语“第一”、“第二”、“第三”等仅用于区分描述,而不能理解为指示或暗示相对重要性。
第一实施例
如图1所示,图1示出了本发明实施例提供的一种电子设备100的结构框图。所述电子设备100包括:图像处理装置110、存储器120、存储控制器130和处理器140。
所述存储器120、存储控制器130、处理器140各元件相互之间直接或间接地电性连接,以实现数据的传输或交互。例如,这些元件相互之间可通过一条或多条通讯总线或信号线实现电性连接。所述图像处理装置110包括至少一个可以软件或固件(firmware)的形式存储于所述存储器120中或固化在所述电子设备100的操作系统(operating system,OS)中的软件功能模块。所述处理器140配置成执行存储器120中存储的可执行模块,例如所述图像处理装置110包括的软件功能模块或计算机程序。
其中,存储器120可以是,但不限于,随机存取存储器(Random Access Memory,RAM),只读存储器(Read Only Memory,ROM),可编程只读存储器(Programmable Read-Only Memory,PROM),可擦除只读存储器(Erasable Programmable Read-Only Memory,EPROM),电可擦除只读存储器(Electric Erasable Programmable Read-Only Memory,EEPROM)等。其中,存储器120配置成存储程序,所述处理器140在接收到执行指令后,执行所述程序,后述本发明实施例任一实施例揭示的流程定义的电子设备100所执行的方法可以应用于处理器140中,或者由处理器140实现。
处理器140可能是一种集成电路芯片,具有信号的处理能力。上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(DSP)、专用集成电路(ASIC)、现成可编程门阵列(FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本发明实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
在进行H264编码时,需要将RGB格式的像素转换为YUV格式的像素,这样才能进行H264编码。首先对RGB和YUV分别作出解释:
RGB色彩模式(Red、Green、Blue,红、绿、蓝三色色彩模式)是工业界的一种颜色 标准,是通过对红(R)、绿(G)、蓝(B)三个颜色通道的变化以及它们相互之间的叠加来得到不同的颜色,RGB即是代表红、绿、蓝三个通道的颜色,这个标准几乎包括了人类视力所能感知的所有颜色,是目前运用最广的颜色系统之一。
其中,ARGB像素格式是RGB颜色格式中的一种,使用32位来表示一个像素,RGB分量各用去8位,剩下的8位用作透明度Alpha。在内存中ARGB各分量的排列顺序为:B0、G0、R0、A0、B1、G1、R1、A1、B2、G2、R2、A2。
YUV(颜色编码方法)格式分为三个分量,“Y”表示明亮度(Luminance或Luma),也就是灰度值;而“U”和“V”表示的则是色度(Chrominance或Chroma),作用是描述影像色彩及饱和度,用于指定像素的颜色。YUV格式主要用于电视系统以及模拟视频领域,它将亮度信息(Y)与色彩信息(UV)分离,没有UV信息一样可以显示完整的图像,只不过是黑白的,这样的设计很好地解决了彩色电视机与黑白电视的兼容问题。并且,YUV不像RGB那样要求三个独立的视频信号同时传输,所以用YUV格式传输数据占用的频宽极少。YUV码流的存储格式与其采样的方式密切相关,主流的采样方式有三种,YUV4:4:4,YUV4:2:2,YUV4:2:0。YUV格式有两大类:planar平面格式和packed打包格式。对于planar的YUV格式,先连续存储所有像素点的Y,紧接着存储所有像素点的U,随后是所有像素点的V。对于packed的YUV格式,每个像素点的Y,U,V是连续交错存储的。
其中,NV12像素格式属于YUV420格式中的一种,是一种two-plane模式,即Y和UV分为两个平面,但是UV(CbCr)为交错存储的。其中我们假设一幅NV12图像的宽是width、高是height,那么它的Y平面的宽是width,Y平面一行像素的字节数是width,Y平面的高度是height;而它的UV平面的宽是width/2,UV平面一行像素的字节数是width,UV平面的高度是height/2。
基于以上分析,本发明第一实施例提供了一种图像处理方法。如图2所示,其中,图2示出了本发明第一实施例提供的一种图像处理方法的流程图,包括:步骤S201-S205。
步骤S201:获得待转换的ARGB图像。
在将一种格式的图像转化为另一种格式的图像时,需要先获得待转换的图像,本实施例中,可选地,该待转换的图像为ARGB图像,即,获得需要进行图像转换的ARGB图像。
步骤S202:从所述ARGB图像中分别获取Y平面掩码和UV平面掩码。
由于SSE指令是一种单指令多数据的指令,也就是说SSE的一条机器指令能够处理多条数据,而传统的CPU指令只能够处理单条数据。对于ARGB格式的像素来说,其一个像素包含Alpha透明度分量,红色分量,绿色分量,蓝色分量,每个分量一个字节,也就是说一个像素占用4个字节的内存空间,普通的CPU指令处理ARGB像素时,一次只能够处理4个字节的数据,也就是一个像素;而利用SSE指令时,一次可以处理16个字节的数据,也就是4个像素。也就是说SSE指令的一次转换操作相当于普通CPU指令的4次转换,所以利用SSE指令转换的效率至少是普通CPU指令的4倍。
由于ARGB像素格式使用32位来表示一个像素,而采用SSE指令处理ARGB像素时,一次可以处理16个字节的数据,也就是4个像素。故本实施例中,在利用SSE指令转换时,使用的是128位的__m128i数据类型,以最大化提高其转换效率。其中,需要说明的是,本实施例中,仅以SSE指令一次处理4个像素的情形为例进行说明,其一次处理2或3个像素的情形与之类似,为了避免累赘,不再一一举例示出。
在利用SSE指令进行转换时,从所述ARGB图像中获取Y平面掩码,例如,调用SSE指令的_mm_set1_epi32将0x0000FF00扩展到128,获取NV12格式中的Y平面掩码,并且将该值存储到lumMask中。
在利用SSE指令进行转换时,从所述ARGB图像中获取UV平面掩码,例如,调用SSE指令的_mm_set1_epi16将0x00ff扩展到128位,获取NV12格式的UV平面掩码,并将该值存储到uvMask中。
步骤S203:从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数。
从所述ARGB图像中获取第i行的M个像素值,例如,调用SSE指令的_mm_load_si128指令将第i行的4个像素值存储到__m128i line1变量中。
从所述ARGB图像中获取第i+1行的M个像素值,例如,调用SSE指令的调用_mm_load_si128指令将第i+1行的4个像素值存储到__m128i line2变量中。
步骤S204:根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值。
通过获得的Y平面掩码值、第i行的M个像素值以及第i+1行的M个像素值,便可获得Y平面的像素值。作为一种实施方式,可选地,可以通过如图3所示方法步骤根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值。其中,图3所示的方法步骤具体包括:步骤S301-S305。
步骤S301:将获得的所述Y平面掩码值与所述第i行的M个像素值进行与运算,得到第一结果。
将获得的Y平面掩码值与第i行的M个像素值进行与运算后,得到第一结果,例如,调用SSE指令的mm_and_si128指令将line1变量值(第i行的4个像素值)与lumMask值(Y平面掩码值)进行与运算,得到第一结果,并将第一结果存储到andResult1中。
步骤S302:将获得的所述Y平面掩码值与所述第i+1行的M个像素值进行与运算,得到第二结果。
将获得的Y平面掩码值与第i+1行的M个像素值进行与运算后,得到第二结果,例如,调用SSE指令的_mm_and_s128i指令将line2变量(第i+1行的4个像素值)与lumMask值(Y平面掩码值)进行与运算,得到第二结果,并将第二结果存储到andResult2中。
步骤S303:对得到的所述第一结果进行算术右移,得到第三结果。
将获得的Y平面掩码值与第i行的M个像素值进行与运算后,得到第一结果,然后对得到的第一结果进行算术右移,得到第三结果,例如,调用_mm_srli_si128将上步中的andResult1(第一结果)算术右移一位,得到第三结果,并将第三结果存储到srlResult1中。
步骤S304:对得到的所述第二结果进行算术右移,得到第四结果。
将获得的Y平面掩码值与第i+1行的M个像素值进行与运算后,得到第二结果,然后对得到的第二结果进行算术右移,得到第四结果,例如,调用_mm_srli_si128将上步中的andResult2(第二结果)算术右移一位,得到第四结果,并将第四结果存储到srlResult2中。
步骤S305:根据得到的所述第三结果和所述第四结果,获得Y平面的像素值。
根据获得的第三结果和第四结果,便可以获得Y平面的像素值。即,第三结果中的低八字节便为第i行的Y像素值,第四结果中的低八字节便为第i+1行的Y像素值。其中,Y平面的像素值包括:第i行的Y像素值和第i+1行的Y像素值。为了便于运算及存储,优选地,将所述第三结果中的低8字节的数据存储到指针数组A中的低8字节中,将所述第四结果中的低8字节的数据存储到指针数组A中的高8字节中,将所述指针数组A中的第一个整数值作为第i行的Y像素值,第二个整数值作为第i+1行的Y像素值。例如,调用SEE指令的__mm_packs_epi32指令将上步中的srlResult1(第三结果)的低8字节和srlResult2(第四结果)的低8字节存储到变量packVal中。其中srlResult1的 低8字节在packVal的低8字节中,srlResult2的低8字节在packVal的高8字节中,将上步中获取到的packVal结构中的m128i_u32数组中的第一个整数值就是第i行的Y像素值,m128i_u32数组中的第二个整数值就是第i+1行的Y像素值。
其中,指针数组A中的第一个整数值即为第三结果中的低8字节,指针数组A中的第二个整数值即为第四结果中的低8字节。其中,指针数组A可以为上述的packVal。
步骤S205:根据获得的所述UV平面掩码值、所述第i行M个像素值和所述第i+1行M个像素值,获得UV平面的像素值。
通过获得的UV平面掩码值、第i行的M个像素值以及第i+1行的M个像素值,便可获得UV平面的像素值。
作为一种实施方式,可选地,可以通过如图4所示方法步骤根据获得的所述UV平面掩码值、所述第i行M个像素值和所述第i+1行M个像素值,获得UV平面的像素值。其中,图4所示的方法步骤包括:步骤S401-S403。
步骤S401:将获得的所述UV平面掩码值与所述第i行的M个像素值进行与运算,得到第五结果。
将获得的UV平面掩码值与第i行的M个像素值进行与运算后,得到第五结果,例如,调用_mm_and_si128指令将line1变量值(第i行的4个像素值)与uvMask值(UV平面掩码值)进行与运算,得到第五结果,并将第五结果存储到uvandResult1中。
步骤S402:将获得的所述UV平面掩码值与所述第i+1行的M个像素进行与运算,得到第六结果。
将获得的UV平面掩码值与第i+1行的M个像素值进行与运算后,得到第六结果,例如,调用_mm_and_s128i指令将line2变量值(第i行的4个像素值)与uvMask值(UV平面掩码值)进行与运算,得到第六结果,并将第六结果存储到uvandResult2中。
步骤S403:根据获得的所述第五结果和所述第六结果获得UV平面的像素值。
通过获得的第五结果和第六结果,便可获得UV平面的像素值。作为一种实施方式,可选地,可以通过如图5所示方法步骤根据获得的所述第五结果和所述第六结果获得UV平面的像素值。其中,图5所示的方法步骤包括:步骤S501-S504。
步骤S501:将所述第五结果和所述第六结果进行加法运算,得到第七结果。
获得第五结果和第六结果后,将第五结果和第六结果进行加法运算,得到第七结果,例如,调用SSE指令的_mm_add_epi64指令将uvandResult1(第五结果)和uvandResult2(第六结果)相加,得到第七结果,并将第七结果存储到addVal变量中。
步骤S502:将所述第七结果中的第二个32位整数同第一个32位整数进行交换,第三个32位整数与第4个32位整数进行交换后得到第八结果。
获得第七结果后,对第七结果中的整数进行交换运算,可选地,将第七结果中的第二个32位整数同第一个32位整数进行交换,第三个32位整数与第4个32位整数进行交换后得到第八结果。例如,调用SSE指令的_mm_shuffle_epi32指令将addVal(第七结果)的第三个32位整数与第4个32位整数进行交换,并且将addVal(第七结果)的第二个32位整数同第一个32位整数进行交换后得到第八结果,并将第八结果存储到addValShuffle变量中。
步骤S503:将所述第八结果与所述第七结果相加后取平均值得到第九结果。
得到第八结果后,将第八结果与第七结果相加,然后对相加的结果取平均值得到第九结果。例如,调用SSE指令_mm_add_epi64指令将addVal(第七结果)与addValShuffle(第八结果)相加,然后调用_mm_srai_epi16指令对相加后的结果取平均值得到第九结果,并将第九结果存储到avgVal变量中。
步骤S504:将所述第九结果中的第二个32位整数同第四个32位整数进行交换,将第一个32位整数同第三个32位整数进行交换后,得到UV平面的像素值。
得到第九结果后,对第七结果中的整数进行交换运算,可选地,将所述第九结果中的第二个32位整数同第四个32位整数进行交换,将第一个32位整数同第三个32位整数进行交换后得到UV平面的像素值。例如,调用SSE指令的_mm_shuffle_epi32指令对avgVal(第九结果)的第二个32位整数同第四个32位整数进行交换,并且对第一个32位整数同第三个32位整数进行交换,将得到的结果存储到avgValShuffle变量中。其中,存储于avgValShuffle变量中的m128i_u32数组中的第一个32位整数值就是第i行的UV像素值,即为UV平面的像素值。其中UV平面的像素值包括:第i行的UV像素值。
其中,需要再次强调的是,本实施例中,仅以SSE指令一次处理4个像素的情形为例进行说明,其一次处理2或3个像素的情形与之类似,为了避免累赘,不再一一举例示出。因此,并不能将其理解成是对本发明的限制
通过上面这些步骤,实现了利用SSE指令将ARGB像素转换为NV12像素的过程,由于SSE指令一个指令可以处理多条数据的特性,使得该方法比现有的转换算法在效率上至少快4倍,所以极大提供了转换效率。
本发明实施例还提供一种图像处理装置110,如图6所示。该图像处理装置110包 括:ARGB图像获取单元111、掩码获取单元112、像素获取单元113、Y平面像素值获取单元114和UV平面像素值获取单元115。
所述ARGB图像获取单元111,配置成获得待转换的ARGB图像。
所述掩码获取单元112,配置成从所述ARGB图像中分别获取Y平面掩码和UV平面掩码。
所述像素获取单元113,配置成从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数。
所述Y平面像素值获取单元114,配置成根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值。
所述UV平面像素值获取单元115,配置成根据获得的所述UV平面掩码值、所述第i行M个像素值和所述第i+1行M个像素值,获得UV平面的像素值。
其中,如图7所示,所述Y平面像素值获取单元114包括:第一结果获取子单元1141、第二结果获取子单元1142、第三结果获取子单元1143、第四结果获取子单元1144和Y平面像素值获取子单元1145。
所述第一结果获取子单元1141,配置成将获得的所述Y平面掩码值与所述第i行的M个像素值进行与运算,得到第一结果。
所述第二结果获取子单元1142,配置成将获得的所述Y平面掩码值与所述第i+1行的M个像素值进行与运算,得到第二结果。
所述第三结果获取子单元1143,配置成对得到的所述第一结果进行算术右移,得到第三结果。
所述第四结果获取子单元1144,配置成对得到的所述第二结果进行算术右移,得到第四结果。
所述Y平面像素值获取子单元1145,根据得到的所述第三结果和所述第四结果,获得Y平面的像素值。
其中,如图8所示,所述UV平面像素值获取单元115可以包括:第五结果获取子单元1151、第六结果获取子单元1152、第七结果获取子单元1153、第八结果获取子单元1154、第九结果获取子单元1155和UV平面像素值获取子单元1156。
所述第五结果获取子单元1151,配置成将获得的所述UV平面掩码值与所述第i行的M个像素值进行与运算,得到第五结果。
所述第六结果获取子单元1152,配置成将获得的所述UV平面掩码值与所述第i+1 行的M个像素进行与运算,得到第六结果。
所述第七结果获取子单元1153,配置成将所述第五结果和所述第六结果进行加法运算,得到第七结果。
所述第八结果获取子单元1154,配置成将所述第七结果中的第二个32位整数同第一个32位整数进行交换,第三个32位整数与第4个32位整数进行交换后得到第八结果。
所述第九结果获取子单元1155,配置成将所述第八结果与所述第七结果相加后取平均值得到第九结果。
所述UV平面像素值获取子单元1156,配置成将所述第九结果中的第二个32位整数同第四个32位整数进行交换,将第一个32位整数同第三个32位整数进行交换后,得到UV平面的像素值。
需要说明的是,本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。
本发明实施例所提供的图像处理装置110,其实现原理及产生的技术效果和前述方法实施例相同,为简要描述,装置实施例部分未提及之处,可参考前述方法实施例中相应内容。
第二实施例
本实施例提供一种图像处理方法,所述图像处理方法与第一实施例中的图像处理方法大致相同,不同之处在于,本实施例中,Y平面掩码及UV平面掩码不是从ARGB图像中获得。
在本实施例中,Y平面掩码可以通过如下步骤获得:
获得32位的第一掩码值;
调用第一SSE指令,将M个所述第一掩码值连接在一起,得到Y平面掩码。
其中,所述第一SSE指令可以是_mm_set1_epi32()指令。
UV平面掩码可以通过如下步骤获得:
获得16位的第二掩码值;
调用第二SSE指令,将2M个所述第二掩码值连接在一起,得到UV平面掩码。
其中,所述第二SSE指令可以是_mm_set1_epi16()指令。
此外,所述Y平面掩码和所述UV平面掩码还可以是预设的掩码值。
本实施例还提供一种图像处理装置,所述图像处理装置与第一实施例中的图像处理装置大致相同,其不同之处在于,所述掩码获取单元通过如下方式获得Y平面掩码:
获得32位的第一掩码值;
调用第一SSE指令,将M个所述第一掩码值连接在一起,得到Y平面掩码。
所述掩码获取单元通过如下方式获得UV平面掩码:
获得16位的第二掩码值;
调用第二SSE指令,将2M个所述第二掩码值连接在一起,得到UV平面掩码。
本发明实施例还提供一种电子设备,所述电子设备包括存储器及处理器。所述存储器中存储有计算机程序,所述处理器配置成调用所述计算机程序,实现本发明实施例提供的图像处理方法。
本发明实施例还提供一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被执行时实现本发明实施例提供的图像处理算法。
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,也可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,附图中的流程图和框图显示了根据本发明的多个实施例的装置、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,所述模块、程序段或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现方式中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。
另外,在本发明各个实施例中的各功能模块可以集成在一起形成一个独立的部分,也可以是各个模块单独存在,也可以两个或两个以上模块集成形成一个独立的部分。
所述功能如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以 是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
工业实用性
本发明实施例提供的图像处理方法、装置、电子设备及计算机可读存储介质,对现有的图像转换方法进行了优化,在将ARGB格式的图像转换为NV12格式的图像时,可以一次性转换多个像素,提高了转换效率。

Claims (22)

  1. 一种图像处理方法,其特征在于,包括:
    获得待转换的ARGB图像;
    从所述ARGB图像中分别获取Y平面掩码和UV平面掩码;
    从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数;
    根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值;
    根据获得的所述UV平面掩码值、所述第i行M个像素值和所述第i+1行M个像素值,获得UV平面的像素值。
  2. 根据权利要求1所述的图像处理方法,其特征在于,所述的根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值的步骤包括:
    将获得的所述Y平面掩码值与所述第i行的M个像素值进行与运算,得到第一结果;
    将获得的所述Y平面掩码值与所述第i+1行的M个像素值进行与运算,得到第二结果;
    对得到的所述第一结果进行算术右移,得到第三结果;
    对得到的所述第二结果进行算术右移,得到第四结果;
    根据得到的所述第三结果和所述第四结果,获得Y平面的像素值。
  3. 根据权利要求2所述的图像处理方法,其特征在于,所述的根据得到的所述第三结果和所述第四结果,获得Y平面的像素值的步骤包括:
    将所述第三结果中的低8字节的数据存储到指针数组A中的低8字节中;
    将所述第四结果中的低8字节的数据存储到指针数组A中的高8字节中;
    将所述指针数组A中的第一个整数值作为第i行的Y像素值,第二个整数值作为第i+1行的Y像素值。
  4. 根据权利要求1-3任一项所述的图像处理方法,其特征在于,所述的根据获得的所述UV平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素获得UV平面的像素值的步骤包括:
    将获得的所述UV平面掩码值与所述第i行的M个像素值进行与运算,得到第 五结果;
    将获得的所述UV平面掩码值与所述第i+1行的M个像素进行与运算,得到第六结果;
    根据获得的所述第五结果和所述第六结果获得UV平面的像素值。
  5. 根据权利要求4所述的图像处理方法,其特征在于,所述的根据获得的所述第五结果和所述第六结果获得UV平面的像素值的步骤包括:
    将所述第五结果和所述第六结果进行加法运算,得到第七结果;
    将所述第七结果中的第二个32位整数同第一个32位整数进行交换,第三个32位整数与第4个32位整数进行交换后得到第八结果;
    将所述第八结果与所述第七结果相加后取平均值得到第九结果;
    将所述第九结果中的第二个32位整数同第四个32位整数进行交换,将第一个32位整数同第三个32位整数进行交换后,得到UV平面的像素值。
  6. 根据权利要求1-5任一项所述的图像处理方法,其特征在于,所述M的数值为4。
  7. 一种图像处理方法,其特征在于,包括:
    获得待转换的ARGB图像;
    获取Y平面掩码及UV平面掩码;从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数;
    根据获得的所述Y平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值;
    根据获得的所述UV平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获Y平面的像素值。
  8. 根据权利要求7所述的图像处理方法,其特征在于,获得Y平面掩码的步骤,包括:
    获得32位的第一掩码值;
    调用第一SSE指令,将M个所述第一掩码值连接在一起,得到Y平面掩码。
  9. 根据权利要求7或8所述的图像处理方法,其特征在于,获得UV平面掩码的步骤,包括:
    获得16位的第二掩码值;
    调用第二SSE指令,将2M个所述第二掩码值连接在一起,得到UV平面掩码。
  10. 根据权利要求7-9任一项所述的图像处理方法,其特征在于,根据获得的所 述Y平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值的步骤,包括:
    将获得的所述Y平面掩码与所述第i行的M个像素值进行与运算,得到第一结果;
    将获得的所述Y平面掩码与所述第i+1行的M个像素进行与运算,得到第二结果;
    对得到的所述第一结果进行算术右移,得到第三结果;
    对得到的所述第二结果进行算术右移,得到第四结果;
    根据得到的所述第三结果和所述第四结果,获得Y平面的像素值。
  11. 根据权利要求10所述的图像处理方法,其特征在于,根据得到的所述第三结果和第四结果,获得Y平面的像素值的步骤,包括:
    将所述第三结果中的低8字节的数据存储到指针数组A中的低8字节中;
    将所述第四结果中的低8字节的数据存储到指针数组A中的高8字节中;
    将所述指针数组A中的第一个整数值作为第i行的Y像素值,将所述指针数组A中的第二个整数值作为第i+1行的Y像素值。
  12. 根据权利要求7-11任一项所述的图像处理方法,其特征在于,根据获得的所述UV平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获Y平面的像素值的步骤,包括:
    将获得的所述UV平面掩码与所述第i行的M个像素值进行与运算,得到第五结果;
    将获得的所述UV平面掩码与所述第i+1行的M个像素进行与运算,得到第六结果;
    根据获得的所述第五结果和所述第六结果获得UV平面的像素值。
  13. 根据权利要求12所述的图像处理方法,其特征在于,根据获得的所述第五结果和所述第六结果获得UV平面的像素值的步骤,包括:
    将所述第五结果和所述第六结果进行加法运算,得到第七结果;
    将所述第七结果中的第二个32位整数同第一个32位整数进行交换,第三个32位整数与第4个32位整数进行交换后得到第八结果;
    将所述第八结果与所述第七结果相加后取平均值得到第九结果;
    将所述第九结果中的第二个32位整数同第四个32位整数进行交换,将第一个32位整数同第三个32位整数进行交换后,得到UV平面的像素值。
  14. 一种图像处理装置,其特征在于,包括:
    ARGB图像获取单元,配置成获得待转换的ARGB图像;
    掩码获取单元,配置成从所述ARGB图像中分别获取Y平面掩码和UV平面掩码;
    像素获取单元,配置成从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数;
    Y平面像素值获取单元,配置成根据获得的所述Y平面掩码值、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值;
    UV平面像素值获取单元,配置成根据获得的所述UV平面掩码值、所述第i行M个像素值和所述第i+1行M个像素值,获得UV平面的像素值。
  15. 根据权利要求14所述的图像处理装置,其特征在于,所述M的数值为4。
  16. 一种图像处理装置,其特征在于,包括:
    ARGB图像获取单元,配置成获得待转换的ARGB图像;
    掩码获取单元,配置成获得Y平面掩码及UV平面掩码;
    像素获取单元,配置成从所述ARGB图像中分别获取第i行的M个像素值和第i+1行的M个像素值,其中,M为大于1的整数;
    Y平面像素值获取单元,配置成根据获得的所述Y平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获得Y平面的像素值;
    UV平面像素值获取单元,配置成根据获得的所述UV平面掩码、所述第i行的M个像素值和所述第i+1行的M个像素值,获得UV平面的像素值。
  17. 根据权利要求16所述的图像处理装置,其特征在于,所述掩码获取单元获得Y平面掩码的方式,包括:
    获得32位的第一掩码值;
    调用第一SSE指令,将M个所述第一掩码值连接在一起,得到Y平面掩码。
  18. 根据权利要求16或17所述的图像处理装置,其特征在于,所述掩码获取单元获得UV平面掩码的方式,包括:
    获得16位的第二掩码值;
    调用第二SSE指令,将2M个所述第二掩码值连接在一起,得到UV平面掩码。
  19. 一种电子设备,其特征在于,包括:处理器和存储器,所述处理器与所述存储器耦合;
    所述存储器配置成存储程序;
    所述处理器配置成调用存储在所述存储器中的程序,执行权利要求1-6任一项所述的图像处理方法。
  20. 一种电子设备,其特征在于,包括:存储器,配置成存储计算机程序;
    处理器,配置成调用所述计算机程序,执行权利要求7-13任一项所述的图像处理方法。
  21. 一种计算机可读存储介质,其特征在于,所述计算机可读取存储介质存储有处理器可执行的程序代码于计算机内,所述可读取存储介质包括多条指令,所述程序代码多条指令被配置成使所述处理器执行权利要求1-6任一项所述的图像处理方法。
  22. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被执行时实现权利要求7-13任一项所述的图像处理方法。
PCT/CN2017/112951 2017-07-07 2017-11-24 图像处理方法、装置、电子设备及计算机可读存储介质 WO2019006965A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710548915.X 2017-07-07
CN201710548915.XA CN107341835B (zh) 2017-07-07 2017-07-07 图像处理方法、装置、电子设备及计算机可读存储介质

Publications (1)

Publication Number Publication Date
WO2019006965A1 true WO2019006965A1 (zh) 2019-01-10

Family

ID=60219196

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/112951 WO2019006965A1 (zh) 2017-07-07 2017-11-24 图像处理方法、装置、电子设备及计算机可读存储介质

Country Status (2)

Country Link
CN (1) CN107341835B (zh)
WO (1) WO2019006965A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107341835B (zh) * 2017-07-07 2018-08-03 武汉斗鱼网络科技有限公司 图像处理方法、装置、电子设备及计算机可读存储介质
CN110324598A (zh) * 2018-03-30 2019-10-11 武汉斗鱼网络科技有限公司 一种图像处理方法、装置及计算机设备
CN113596581B (zh) * 2021-07-30 2023-10-27 上海商汤临港智能科技有限公司 一种图像格式转换方法、装置、计算机设备和存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5798753A (en) * 1995-03-03 1998-08-25 Sun Microsystems, Inc. Color format conversion in a parallel processor
CN101452578A (zh) * 2007-12-06 2009-06-10 精工爱普生株式会社 用于在图形环境中进行颜色格式转换的系统和方法
US20160246720A1 (en) * 2015-02-23 2016-08-25 Intel Corporation Instructions and logic to fork processes of secure enclaves and establish child enclaves in a secure enclave page cache
CN107341835A (zh) * 2017-07-07 2017-11-10 武汉斗鱼网络科技有限公司 图像处理方法、装置、电子设备及计算机可读存储介质

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003271947A (ja) * 2002-03-18 2003-09-26 Ricoh Co Ltd 自動画像合成装置、自動画像合成方法、およびそのプログラム
CN101489144B (zh) * 2008-01-17 2010-09-29 华晶科技股份有限公司 相机的自动色彩空间与情境转换方法
CN102231206B (zh) * 2011-07-14 2012-11-28 浙江理工大学 适用于汽车辅助驾驶系统的彩色夜视图像亮度增强方法
CN106228581B (zh) * 2016-08-01 2019-06-21 武汉斗鱼网络科技有限公司 通过gpu将像素格式由argb转换为nv12的方法及系统

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5798753A (en) * 1995-03-03 1998-08-25 Sun Microsystems, Inc. Color format conversion in a parallel processor
CN101452578A (zh) * 2007-12-06 2009-06-10 精工爱普生株式会社 用于在图形环境中进行颜色格式转换的系统和方法
US20160246720A1 (en) * 2015-02-23 2016-08-25 Intel Corporation Instructions and logic to fork processes of secure enclaves and establish child enclaves in a secure enclave page cache
CN107341835A (zh) * 2017-07-07 2017-11-10 武汉斗鱼网络科技有限公司 图像处理方法、装置、电子设备及计算机可读存储介质

Also Published As

Publication number Publication date
CN107341835B (zh) 2018-08-03
CN107341835A (zh) 2017-11-10

Similar Documents

Publication Publication Date Title
US8947449B1 (en) Color space conversion between semi-planar YUV and planar YUV formats
US8760461B2 (en) Device, system, and method for wide gamut color space support
US8508624B1 (en) Camera with color correction after luminance and chrominance separation
CN106228581B (zh) 通过gpu将像素格式由argb转换为nv12的方法及系统
CA2975172A1 (en) A method and apparatus of encoding and decoding a color picture
WO2019006965A1 (zh) 图像处理方法、装置、电子设备及计算机可读存储介质
US20180352263A1 (en) Method and device for processing color image data representing colors of a color gamut
US20080012953A1 (en) Image Sensors
JP2018507620A (ja) カラー・ピクチャを復号する方法および装置
US10554862B2 (en) System and method for retaining color gamut
US20120218292A1 (en) System and method for multistage optimized jpeg output
CN114040246A (zh) 图形处理器的图像格式转换方法、装置、设备及存储介质
US20180139360A1 (en) Method and device for processing color image data representing colors of a color gamut
CN111861964A (zh) 图像处理方法、装置和存储介质
CN1267813C (zh) 处理色差信号4∶2∶0平面图像数据格式存储器的系统与方法
BR102014009378A2 (pt) compressão de buffer de cor
CN113554721B (zh) 图像数据格式转换方法和装置
CN107948652B (zh) 一种进行图像转换的方法和设备
JP2006510292A5 (zh)
US20110280315A1 (en) Hardware pixel processing pipeline and video processing instructions
JP2006262062A (ja) 画像処理装置および画像処理プログラム
CN114155137A (zh) 格式转换方法、控制器及计算机可读存储介质
US20220245862A1 (en) Image processing method and device, camera apparatus and storage medium
EP3096510A1 (en) Method and device for processing color image data representing colors of a color gamut
US8630488B2 (en) Creating a duotone color effect using an ICC profile

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17917057

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17917057

Country of ref document: EP

Kind code of ref document: A1