Image Processing Method and Apparatus

By generating and processing palettes in parallel with multi-threaded parallel processing, and using the palette to process multi-frame images in parallel, solving the problem of low efficiency of GIF animation generation in the prior art, and achieving more efficient image processing and GIF animation generation.

CN114037785BActive Publication Date: 2025-07-25GAODING XIAMEN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111204017.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-15
Publication Date
2025-07-25
Estimated Expiration
2041-10-15

AI Technical Summary

Technical Problem

The prior art is inefficient when generating GIF animations, especially when there are many frames or high image resolution, the palette generation and pixel traversal efficiency are low.

Method used

By generating a palette in parallel through multi-threading, processing multi-frame images in parallel, sharing palettes, encoding images frame by frame, and optimizing image processing flow.

Benefits of technology

The palette generation efficiency and image processing efficiency of each frame of images are improved, and the GIF animation generation efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114037785B_ABST
    Figure CN114037785B_ABST
Patent Text Reader

Abstract

The present disclosure relates to an image processing method and apparatus. The method includes: obtaining a preset number of images to be processed; generating a color palette based on the images to be processed; processing the images to be processed using the color palette; and encoding the processed images frame by frame. The image processing method and apparatus of the present disclosure generate a color palette based on multiple frames of images to be processed and share the color palette, effectively improving the generation efficiency of the color palette for each frame of images to be processed on average. In addition, by generating the color palette in parallel with multiple threads and processing the images to be processed in parallel, the image processing efficiency is further improved, and the generation efficiency of GIF animated images is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure generally relates to the field of computer technology. More specifically, the present disclosure relates to an image processing method and apparatus. Background Art

[0002] A dynamic image refers to a picture that produces a certain dynamic effect when a set of specific static images are switched at a specified frequency. The common format of dynamic images is GIF (Graphics Interchange Format). GIF animated images are characterized by a "small size" and are easy to place and call at any time, and are often used for web decoration.

[0003] In the prior art, in order to generate a GIF animated image, it is usually necessary to generate a 256-color palette based on each frame image in the GIF, and then use this palette to sequentially traverse each pixel point in the frame image to find the color in the palette that is closest to it, and replace the original color of the pixel with the color in the palette until this frame image is processed and then encoded into a frame in the GIF and written to a file. Repeat this operation until all frames are encoded, that is, the GIF export is completed.

[0004] The above method has the following technical problems: 1. Each frame image needs to call the palette generation algorithm once, and it is serial. If the number of exported frames is relatively large, the efficiency is relatively low; 2. When using the palette to process the original image, it is necessary to sequentially traverse each pixel point. If the image resolution is relatively high, the efficiency is relatively low.

[0005] Therefore, how to obtain an image processing method with higher efficiency is a problem to be solved in the prior art. Summary of the Invention

[0006] In order to at least partially solve the technical problems mentioned in the background art, the solution of the present disclosure provides an image processing method and apparatus.

[0007] According to a first aspect of the present disclosure, the present disclosure provides an image processing method, wherein the method includes: obtaining a preset number of images to be processed; generating a palette based on the images to be processed; processing the images to be processed using the palette; and encoding the processed images frame by frame.

[0008] Optionally, the generating a palette based on the images to be processed includes: determining whether there is an idle thread; if so, generating a palette for the images to be processed through the idle thread.

[0009] Optionally, generating a color palette for the image to be processed by the idle thread includes: if there are multiple idle threads, selecting at least one of the idle threads according to a preset rule to generate the color palette for the image to be processed.

[0010] Optionally, processing the image to be processed using the color palette includes: processing the image to be processed frame by frame using the color palette.

[0011] Optionally, processing the image to be processed frame by frame using the color palette includes: dividing a single frame of the image to be processed into multiple regions according to a preset region division rule; processing at least two of the regions simultaneously using the color palette.

[0012] Optionally, the image processing method further includes: while encoding the processed image frame by frame, determining whether the encoded file meets a preset export condition; if so, exporting the file.

[0013] According to a second aspect of the present disclosure, the present disclosure provides an image processing apparatus, wherein the apparatus includes: an acquisition module configured to acquire a preset number of images to be processed; a color palette generation module configured to generate a color palette based on the images to be processed; a processing module configured to process the images to be processed using the color palette; and an encoding module configured to encode the processed images frame by frame.

[0014] Optionally, the color palette generation module is configured to generate a color palette based on the images to be processed in the following manner: determining whether there are idle threads; if so, generating a color palette for the images to be processed by the idle threads.

[0015] Optionally, the color palette generation module is configured to generate a color palette for the images to be processed by the idle threads in the following manner: if there are multiple idle threads, selecting at least one of the idle threads according to a preset rule to generate the color palette for the images to be processed.

[0016] Optionally, the processing module is configured to process the images to be processed in the following manner: processing the images to be processed frame by frame using the color palette.

[0017] Optionally, the processing module is configured to process the images to be processed frame by frame in the following manner: dividing a single frame of the image to be processed into multiple regions according to a preset region division rule; processing at least two of the regions simultaneously using the color palette.

[0018] Optionally, the image processing apparatus further includes an export module configured to determine whether a file obtained by encoding satisfies a preset export condition while encoding the processed images frame by frame; if so, export the file.

[0019] According to a third aspect of the present disclosure, there is provided an electronic device, where the electronic device includes a memory and a processor, and a computer program is stored in the memory. When the processor executes the computer program, the method according to the first aspect of the present disclosure above is implemented.

[0020] According to a fourth aspect of the present disclosure, there is provided a computer-readable storage medium, where the storage medium stores a computer program, and when the computer program is executed, the method according to the first aspect of the present disclosure above is implemented.

[0021] The image processing method and apparatus of the present disclosure generate a color palette based on multiple frames of images to be processed and share the color palette, effectively improving the generation efficiency of the color palette for each frame of the image to be processed on average. In addition, by generating the color palette in parallel with multiple threads and processing the images to be processed in parallel, the image processing efficiency is further improved, and the generation efficiency of GIF animated images is improved. Description of the Drawings

[0022] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, features, and advantages of the exemplary embodiments of the present disclosure will become readily understood. In the drawings, several embodiments of the present disclosure are shown in an exemplary rather than restrictive manner, and the same or corresponding reference numerals represent the same or corresponding parts, where:

[0023] Figure 1 is a flowchart showing an image processing method according to an embodiment of the present disclosure;

[0024] Figure 2 is a schematic block diagram showing an image processing apparatus according to an embodiment of the present disclosure. Detailed Embodiments

[0025] The technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are some, but not all, of the embodiments of the present disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of the present disclosure without creative efforts shall fall within the protection scope of the present disclosure.

[0026] The following will describe in detail the specific embodiments of the present disclosure with reference to the accompanying drawings.

[0027] The present disclosure provides an image processing method. Refer to Figure 1 , Figure 1is a flowchart showing an image processing method according to an embodiment of the present disclosure. As Figure 1 shown, the method includes the following steps S101 - S104. Step S101: Obtain a preset number of images to be processed. Step S102: Generate a color palette based on the images to be processed. Step S103: Process the images to be processed using the color palette. Step S104: Encode the processed images frame by frame.

[0028] The image processing method of the present disclosure generates a color palette based on multiple frames of images to be processed and shares this color palette, effectively improving the efficiency of generating the color palette for each frame of the images to be processed on average.

[0029] In step S101, a preset number of images to be processed can be obtained.

[0030] According to an embodiment of the present disclosure, in order to process an image, the image to be processed should first be obtained. The image to be processed can be obtained through any appropriate means, for example, it can be from a gallery, specially designed by a designer, or obtained by video decoding, etc.

[0031] The number of images to be processed can be set or determined according to actual needs. For example, the number of frames of images sharing the color palette can be determined according to the memory size, and then the number of images to be processed can be determined; or, the number of images to be processed can be determined according to the number of frames of the GIF animation finally obtained, etc. In this embodiment, it is preferred to obtain 1 - 4 frames of images to be processed.

[0032] In step S102, a color palette can be generated based on the images to be processed.

[0033] According to an embodiment of the present disclosure, generating a color palette based on the images to be processed can be generating a color palette based on multiple frames of images to be processed, so as to share this color palette to process these multiple frames of images to be processed later. The specific number of these multiple frames of images to be processed can be determined according to actual situations. For example, it can be determined according to the memory size, or according to the number of images required for the GIF animation, or it can be determined by combining the above two influencing factors.

[0034] Preferably, generating the color palette based on the images to be processed includes: determining whether there is an idle thread; if so, generating a color palette for the images to be processed through the idle thread.

[0035] Embodiments of the present disclosure make full use of the multi-core performance of the CPU (Central Processing Unit). Through the multi-thread parallel method, multiple color palettes can be generated simultaneously. Specifically, after obtaining a preset number of images to be processed, first determine whether there are idle threads. If so, use the idle thread to generate a color palette for the preset number of images to be processed; if not, wait until the previous color palette generation task ends, and then add the task of generating a color palette based on the preset number of images to be processed to the thread that has just become idle for processing.

[0036] It should be noted that generating a color palette based on multiple frames of images occupies more memory in the calculation process compared to generating a color palette based on a single frame of image, and the larger the number of image frames (i.e., the number of frames sharing a color palette), the more memory is occupied. Therefore, the number of frames sharing a color palette needs to be determined according to the memory size of the device.

[0037] Preferably, generating a color palette for the image to be processed by the idle thread includes: if there are multiple idle threads, select at least one of the idle threads according to a preset rule to generate the color palette for the image to be processed.

[0038] Specifically, if, according to the memory size, the preset number of images to be processed can share a color palette, select one of the idle threads to generate a color palette for the preset number of images to be processed; if the memory is not sufficient to support the preset number of images to be processed sharing a color palette, divide the preset number of images to be processed into two or more groups in sequence, and process them respectively by two or more idle threads. The specific number of groups can be determined in combination with the memory size and the number of idle threads. The rule for selecting idle threads is not limited to the above two, and can be set according to the actual situation or needs. By multi-thread parallel, multiple color palettes are generated simultaneously, thus maximizing the use of CPU resources and effectively improving the color palette generation efficiency.

[0039] It should be noted that the method for generating a color palette can be any color palette generation method in the prior art, which will not be elaborated here.

[0040] In step S103, the color palette can be used to process the image to be processed.

[0041] According to the embodiments of the present disclosure, using a color palette to process an image to be processed can be to process multiple frames of images to be processed sharing the color palette frame by frame with a color palette generated in step S102, or to process multiple frames of images to be processed sharing the color palette in parallel with the color palette.

[0042] The palette is actually an RGB color table with 256 entries, and each entry in the color table is a 24-bit RGB color value. When using the palette, instead of storing the 24-bit color value in memory, a 4-bit or 8-bit index of the palette is stored. When processing the image to be processed using the palette, that is, replacing the color of each pixel in the image to be processed with the color in the palette that is closest to it. Among them, methods such as traversing each pixel and establishing the palette index all adopt existing technologies and will not be elaborated here.

[0043] Preferably, the processing of the image to be processed using the palette includes: processing the image to be processed frame by frame using the palette. That is, using this palette to process multiple frames of images to be processed sharing this palette frame by frame in sequence, and this sequence can be the sequence of images in the finally pre-generated GIF animated image.

[0044] Preferably, the processing of the image to be processed frame by frame using the palette includes: dividing a single frame of the image to be processed into multiple regions according to a preset region division rule; processing at least two of the regions simultaneously using the palette.

[0045] Specifically, the region division rule can be set according to actual needs. For example, it can be to divide the single frame of the image to be processed into corresponding numbers of regions according to the number of parallel processing threads; it can also be to divide the single frame of the image to be processed according to its resolution so that the number of pixel points in each region is controlled within a certain range; it can also be to divide the single frame of the image to be processed according to the color blocks in it; and so on. By using the palette to traverse and process multiple regions in parallel, the processing time of each frame of the image is effectively reduced.

[0046] In step S104, the processed images can be encoded frame by frame.

[0047] According to an embodiment of the present disclosure, the images processed using the palette are encoded frame by frame into the required data format and written into a file. For example, in order to obtain a GIF animated image, the images processed using the palette can be encoded frame by frame into the data format required by GIF and written into a file.

[0048] As a preferred embodiment, the image processing method of the present disclosure further includes: while encoding the processed images frame by frame, determining whether the file obtained by encoding meets a preset export condition; if so, exporting the file.

[0049] Specifically, for each encoded frame of an image, it is determined whether the obtained encoded file meets a preset export condition. If so, the file is exported; if not, continue to wait until the obtained encoded file meets the preset export condition. Among them, the export condition can be set according to actual needs. For example, it can be the number of images included in the file, the size of the file, the effect of the file, and so on. This preferred embodiment can be used to generate multiple GIF animations.

[0050] It can be understood that the image processing method of the present disclosure can be used to continuously process images, that is, the foregoing steps S101 - S104 can be executed cyclically to process multiple frames of images and obtain multiple GIF animations or files in other different data formats.

[0051] The present disclosure also provides an image processing apparatus. The apparatus is used to execute the steps in the image processing method embodiments described above in combination with Figure 1 the description.

[0052] Referring to Figure 2 , Figure 2 FIG. is a schematic block diagram showing an image processing apparatus 100 according to an embodiment of the present disclosure. The apparatus 100 includes an acquisition module 101, a palette generation module 102, a processing module 103, and an encoding module 104. The acquisition module 101 is configured to acquire a preset number of images to be processed. The palette generation module 102 is configured to generate a palette based on the images to be processed. The processing module 103 is configured to process the images to be processed using the palette. The encoding module 104 is configured to encode the processed images frame by frame.

[0053] According to an embodiment of the present disclosure, the palette generation module 102 is used to generate a palette based on the images to be processed in the following manner: determine whether there are idle threads; if so, generate a palette for the images to be processed through the idle threads.

[0054] According to an embodiment of the present disclosure, the palette generation module 102 is used to generate a palette for the images to be processed through the idle threads in the following manner: if there are multiple idle threads, select at least one of the idle threads according to a preset rule to generate the palette for the images to be processed.

[0055] According to an embodiment of the present disclosure, the processing module 103 is used to process the images to be processed in the following manner: process the images to be processed frame by frame using the palette.

[0056] According to an embodiment of the present disclosure, the processing module 103 is configured to process the image to be processed frame by frame in the following manner: divide a single frame of the image to be processed into multiple regions according to a preset region division rule; and process at least two of the regions simultaneously using the color palette.

[0057] According to an embodiment of the present disclosure, the encoding module 104 is configured to encode the image processed using the color palette frame by frame into a required data format and write it into a file. It can be understood that for the case where the file is a GIF animated image, the encoding module 104 can be a GIF encoder.

[0058] As a preferred embodiment, the image processing device further includes an export module configured to, while encoding the processed image frame by frame, determine whether the encoded file meets a preset export condition; if so, export the file.

[0059] It can be understood that Figure 2 for the image processing device in the embodiments described above with reference to Figure 1 the specific manners in which each module performs operations have been described in detail in the embodiments of the image processing method described in combination with

[0060] Embodiments of the present disclosure further provide an electronic device, where the electronic device includes a memory and a processor, and a computer program is stored in the memory. When the processor executes the computer program, the following steps are implemented: obtaining a preset number of images to be processed; generating a color palette based on the images to be processed; processing the images to be processed using the color palette; and encoding the processed images frame by frame.

[0061] It can be understood that the steps implemented when the processor executes the computer program are basically the same as the implementation manners of the respective steps in the above method, and the specific manners have been described in detail in the embodiments of the image processing method, and will not be elaborated herein.

[0062] In another aspect, the present disclosure provides a computer-readable storage medium, where a computer program is stored in the storage medium. When the computer program is executed, the following steps are implemented: obtaining a preset number of images to be processed; generating a color palette based on the images to be processed; processing the images to be processed using the color palette; and encoding the processed images frame by frame.

[0063] It can be understood that the steps implemented when the processor executes the computer program are basically the same as the implementation manners of the respective steps in the above method, and the specific manners have been described in detail in the embodiments of the image processing method, and will not be elaborated herein.

[0064] The above has introduced the embodiments of the present disclosure in detail. Specific examples are used herein to elaborate on the principles and implementation manners of the present disclosure. The description of the above embodiments is only used to help understand the method and its core idea of the present disclosure; at the same time, for those of ordinary skill in the art, according to the idea of the present disclosure, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to the present disclosure.

[0065] It should be understood that the terms "first" and "second" etc. in the claims, the specification and the drawings of the present disclosure are used to distinguish different objects, rather than to describe a specific order. The terms "including" and "comprising" used in the specification and claims of the present disclosure indicate the presence of the described features, wholes, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their combinations.

[0066] It should also be understood that the terms used in the specification of the present disclosure herein are only for the purpose of describing specific embodiments and are not intended to limit the present disclosure. As used in the specification and claims of the present disclosure, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include the plural forms. It should be further understood that the term "and / or" used in the specification and claims of the present disclosure refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0067] The above has introduced the embodiments of the present disclosure in detail. Specific examples are used herein to elaborate on the principles and implementation manners of the present disclosure. The description of the above embodiments is only used to help understand the method and its core idea of the present disclosure. At the same time, any changes or deformations made by those skilled in the art based on the idea of the present disclosure in the specific implementation manners and application scopes of the present disclosure fall within the protection scope of the present disclosure. In summary, the content of this specification should not be construed as a limitation to the present disclosure.

Claims

1. An image processing method, wherein, The method includes: Obtaining a preset number of images to be processed, including: determining the number of frames of images sharing a common color palette according to the device memory; determining the preset number according to the number of frames; and / or determining the preset number according to the number of image frames required by a file, where the file is a file obtained by encoding the processed images frame by frame; Based on the images to be processed, generating multiple color palettes in parallel using multiple threads, where each color palette corresponds to multiple frames of the images to be processed among the preset number of images to be processed; Using the multiple color palettes to process frame by frame the multiple frames of images to be processed corresponding to each color palette among the images to be processed, including: a target color palette dividing any single frame of the images to be processed corresponding to it into multiple regions according to a preset region division rule, and using the target color palette to process at least two of the regions simultaneously, where the target color palette is any one of the multiple color palettes; Encoding the processed images frame by frame to obtain the file corresponding to the preset number of images to be processed.

2. The image processing method according to claim 1, wherein, The generating multiple color palettes in parallel using multiple threads based on the images to be processed includes: Judging whether there are idle threads; if so, generating a color palette for the images to be processed through the idle threads.

3. The image processing method according to claim 2, wherein, The generating a color palette for the images to be processed through the idle threads includes: If there are multiple idle threads, selecting at least one of them according to a preset rule to generate the color palette for the images to be processed.

4. The image processing method according to any one of claims 1 to 3, wherein, The processing the images to be processed using the color palette includes: Processing the images to be processed frame by frame using the color palette.

5. The image processing method according to any one of claims 1 to 4, wherein, The method further includes: While encoding the processed images frame by frame, judging whether the obtained file meets a preset export condition; if so, exporting the file.

6. An image processing apparatus, wherein, The device includes: An obtaining module configured to obtain a preset number of images to be processed, including: determining the number of frames of images sharing a common color palette according to the device memory; determining the preset number according to the number of frames; and / or determining the preset number according to the number of image frames required by a file, where the file is a file obtained by encoding the processed images frame by frame; A color palette generating module configured to generate multiple color palettes in parallel using multiple threads based on the images to be processed, where each color palette corresponds to multiple frames of the images to be processed among the preset number of images to be processed; A processing module configured to use the multiple color palettes to process frame by frame the multiple frames of images to be processed corresponding to each color palette among the images to be processed, including: a target color palette dividing any single frame of the images to be processed corresponding to it into multiple regions according to a preset region division rule, and using the target color palette to process at least two of the regions simultaneously, where the target color palette is any one of the multiple color palettes; An encoding module configured to encode the processed images frame by frame to obtain the file corresponding to the preset number of images to be processed.

7. The image processing apparatus according to claim 6, wherein, The color palette generating module is used to generate multiple color palettes in parallel using multiple threads based on the images to be processed in the following manner: Determine whether there is an idle thread; if so, generate a color palette for the image to be processed through the idle thread.

8. The image processing apparatus according to claim 7, wherein, The color palette generation module is configured to generate a color palette for the image to be processed through the idle thread in the following manner: If there are multiple idle threads, select at least one of them according to a preset rule to generate the color palette for the image to be processed.

9. The image processing apparatus according to any one of claims 6 to 8, wherein, The processing module is configured to process the image to be processed in the following manner: Process the image to be processed frame by frame using the color palette.

10. The image processing apparatus according to any one of claims 6 to 9, wherein, The device further includes an export module, which is configured to, while encoding the processed image frame by frame, determine whether the file obtained by encoding meets a preset export condition; if so, export the file.

11. An electronic device, wherein, The electronic device includes a memory and a processor. A computer program is stored in the memory. When the processor executes the computer program, the method according to any one of claims 1 to 5 is implemented.

12. A computer-readable storage medium, wherein, The storage medium stores a computer program. When the computer program is executed, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Method, device and system for generating dynamic picture

    CN111435995A

  • Image decoding method and device based on parallel thread, equipment and storage medium

    CN113395523A