Image palette generation and image processing method, device, equipment and storage medium
By combining the pixel point indexes of the regions of interest and non-interest in image processing, a palette is generated, which solves the problem of image quality degradation caused by the limited total number of palette indexes, and realizes the effect of maintaining the image display quality while the number of indexes is reduced.
Patent Information
- Application Number
- CN202111069290.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-13
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2041-09-13
AI Technical Summary
During image processing, the total number of palette indexes is limited, which results in discarding the index corresponding to some pixel values when the number of image pixel values exceeds the total number of palette indexes, resulting in a decline in image quality.
By obtaining the indexes corresponding to the pixel points of the area of interest and the non-area of interest of the image to be processed, and when the number of indexes exceeds the preset number, a palette is selected to generate.
On the premise of reducing the number of color palette indexes, ensure the quality of image display and avoid degradation of image quality.
Smart Images

Figure CN113971704B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing, and in particular to an image palette generation and image processing method, device, equipment and storage medium. Background Art
[0002] In the image processing process, a color palette is often used to compress an image to form a code stream, and then the image data is transmitted through the code stream. Furthermore, the code stream receiver can reconstruct the pixel image according to the code stream and the color palette.
[0003] Since the palette compression method can greatly improve the compression rate of image data, the palette compression method is widely used in image data compression. However, in certain scenarios, the total number of palette indexes is limited. When the number of pixel values in an image exceeds the total number of palette indexes, the indexes corresponding to some pixel values need to be discarded, resulting in a decrease in image quality. Therefore, how to improve the quality of an image when the total number of palette indexes is limited is a technical problem that needs to be solved. Summary of the invention
[0004] The present application at least provides an image processing method, device, equipment and storage device to improve image display quality.
[0005] In a first aspect, the present application provides a method for generating a color palette for an image, comprising: obtaining an image to be processed; determining an area of interest and an area of non-interest of the image to be processed; obtaining a first index corresponding to a pixel point in the area of interest, and a second index corresponding to a pixel point in the area of non-interest; merging the second index when the sum of the index numbers of the first index and the second index is greater than a preset number, or merging the first index and the second index separately so that the sum of the index numbers is less than or equal to a preset number; and generating a color palette based on the merged first index and second index.
[0006] The second aspect of the present application provides an image processing method, comprising: acquiring an image to be processed; compressing image data of the image to be processed based on a color palette; wherein the color palette is generated by the method provided by the first aspect above.
[0007] The third aspect of the present application provides an image processing device, including: a palette generation module, used to generate a palette for an image to be processed; a compression module, connected to the palette generation module, used to compress the image to be processed according to the palette; wherein the palette is generated by the method provided in the first aspect above.
[0008] A fourth aspect of the present application provides an electronic device, comprising: a memory and a processor coupled to each other, the processor being used to execute program instructions stored in the memory to implement the method provided in the first aspect or the second aspect above.
[0009] A fifth aspect of the present application provides a computer-readable storage medium having program instructions stored thereon, which implement the method provided in the first aspect or the second aspect when the program instructions are executed by a processor.
[0010] The present application has at least the following beneficial technical effect: compared with the prior art, the palette generation of the present application divides the index into a first index of the area of interest and a second index of the area of no interest, and selectively merges them, which can ensure the quality of image display while reducing the number of palette indexes. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0012] Figure 1 It is a flowchart of a method for generating a color palette of an image of the present application;
[0013] Figure 2 is another flowchart of the method for generating a color palette of an image of the present application;
[0014] Figure 3 It is another flowchart of the method for generating a color palette of an image of the present application;
[0015] Figure 4 It is another flowchart of the method for generating a color palette of an image of the present application;
[0016] Figure 5 It is a flowchart of the image processing method of the present application;
[0017] Figure 6 is a structural schematic diagram of the image processing device of the present application;
[0018] Figure 7 is a structural schematic diagram of an electronic device of the present application;
[0019] Figure 8 It is a structural schematic diagram of the computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0021] The terms "first", "second", and "third" in this application are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first", "second", and "third" can explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products, or devices.
[0022] The first aspect of the present application provides a method for generating a color palette of an image, see Figure 1 , Figure 1 The figure is a flow chart of a method for generating a color palette for an image of the present application, which can be used in an image processing device to generate a color palette for image processing. As shown in the figure, the method includes:
[0023] S11: Obtain the image to be processed.
[0024] The image processing device may acquire the image to be processed according to a preset acquisition rule. The image processing device may be an electronic device with an image acquisition function, such as a camera, a mobile terminal, etc.
[0025] S12: Determine the region of interest and the region of no interest of the image to be processed.
[0026] Specifically, the image to be processed may be processed to achieve the division of the region of interest and the region of no interest. For example, the image to be processed may be subjected to image recognition by using a target recognition technology, and the region division may be performed according to the image recognition result.
[0027] The region of interest is the ROI (region of interest), and the region of non-interest is the region other than the region of interest in the image to be processed.
[0028] In some embodiments, the region of interest and the region of non-interest may be determined according to the value of the region in the image relative to the entire image to be processed. For example, a region in the image with a higher value relative to the entire image to be processed is the region of interest, and a region in the image with a lower value relative to the entire image to be processed is the region of non-interest.
[0029] In some embodiments, the color change value of the region of interest is greater than the color change value of the non-interest region, and / or the motion change value of the region of interest is greater than the motion change value of the non-interest region. A color change value threshold can be set, and the region with a color change value greater than the color change value threshold is the region of interest, and other regions are non-interest regions. Similarly, the region with a motion change value greater than the motion change value threshold is the region of interest, and other regions are non-interest regions.
[0030] When the color change value is used as the basis for dividing the region of interest and the region of no interest, the Euclidean distance processing algorithm can be used to process the image to be processed, and then the region division is achieved according to the processing result. For example, the Euclidean distance processing algorithm is used to calculate the similarity between pixels, and the pixels are judged to be similar pixels according to the preset similarity threshold. Non-similar pixels constitute the region of interest, and their color change value is greater than the color change threshold, and other areas are the region of no interest.
[0031] Among them, the Euclidean distance algorithm formula includes:
[0032]
[0033] Among them, r, g, and b are red, green, and blue pixel values, respectively.
[0034] In some specific embodiments, the Sobel edge detection operator can be used to perform edge detection on the image to be processed. For example, by calculating the horizontal and vertical gradient values of each pixel point, edge points are determined according to a threshold value, and the area formed by the edge points is used as the area of interest, and other areas are used as non-areas of interest.
[0035] Among them, the Sobel convolution factor can include G x and G y ,as follows:
[0036] G x :
[0037] -1 0 +1 -2 0 +2 -1 0 +1
[0038] G y :
[0039] +1 +2 +1 0 0 0 -1 -2 -1
[0040] Among them, G x =Gx *A, G y =G y *A, A represents a component value in a pixel.
[0041] Of course, the present application only shows the division method of some regions of interest and regions of no interest, and is not intended to be limiting.
[0042] S13: Obtain a first index corresponding to a pixel point in the region of interest and a second index corresponding to a pixel point in the non-region of interest.
[0043] One or more pixels in the region of interest may correspond to a first index, and one or more pixels in the region of non-interest may correspond to a second index, thereby obtaining multiple first indexes corresponding to the region of interest and second indexes corresponding to the region of non-interest.
[0044] In some embodiments, the pixels may be indexed according to their pixel values. For example, the indexes with the same pixel values may be mapped to the same index, or the pixels with pixel values within a certain range may be mapped to the same index.
[0045] Based on this, a correspondence between the pixel points in the region of interest and the first index, and a correspondence between the pixel points in the non-region of interest and the second index may be established.
[0046] S14: When the sum of the index numbers of the first index and the second index is greater than a preset number, the second index is merged, or the first index and the second index are merged separately so that the sum of the index numbers is less than or equal to the preset number.
[0047] Specifically, the preset number can be set according to the requirement on the number of indexes of the palette to be generated, so as to ensure that the number of indexes of the generated palette is less than the preset number, and the pixels of the image to be processed are represented by fewer indexes.
[0048] For example, when the index number of the first index and the second index is 1000, and the preset index number is 500, the second index needs to be merged, or the first index and the second index are merged separately, so that the sum of the index numbers of the first index and the second index is less than or equal to 500. At this time, a first index may represent a pixel point corresponding to at least two pixel values, and a second index may also represent a pixel point corresponding to at least two pixel values.
[0049] Therefore, in this way, the pixels of the image to be processed can be represented by a smaller number of indexes. Furthermore, by selectively merging the first index and the second index, the quality of image display can be guaranteed while reducing the number of palette indexes.
[0050] In some specific embodiments, the preset number is the total number of indexes of a specific type of palette, and the specific type of palette may be some existing specific type of palettes whose total number of indexes is fixed.
[0051] It should be understood that when a specific type of palette needs to be generated, when the sum of the index numbers of the first index and the second index is greater than the total number of indexes of the specific type of palette, the index of the palette cannot fully represent the first index and the second index, and it is necessary to reduce the index numbers of the first index and the second index so that the first index and the second index can be fully represented by the index of the palette.
[0052] Of course, when the sum of the index numbers of the first index and the second index is less than or equal to the total number of indexes of the specific type of palette, the palette index can represent all the first indexes and second indexes, and there is no need to merge the first index and the second index.
[0053] Specifically, you can choose to merge the second index, or you can choose to merge the first index and the second index separately, so as to reduce the total number of the first index and the second index.
[0054] It should be understood that when you choose to merge the second index, more first indexes will be retained, so the region of interest can be represented by more first indexes, which can improve the quality of image display. When you choose to merge the first index and the second index, since the first index and the second index correspond to the region of interest and the region of non-interest, respectively, the first indexes of the region of interest are merged, and the second indexes of the region of non-interest are merged, which can improve the pertinence of the index merging. It is understood that because the similarity between the merged first indexes or the second indexes is high, the merged index can better represent the index before the merge, thereby improving the quality of image display.
[0055] In some embodiments, the first index and the second index may be merged in different merging modes, so as to achieve different merging effects and meet different merging requirements. For example, the first index may be merged in a smaller range, and the second index may be merged in a larger range, so as to retain as many first indexes as possible and further improve the image display quality. Of course, the second index may also be retained as much as possible, subject to the actual merging requirements.
[0056] Therefore, by merging the first index and the second index in different ways, different merging requirements can be met to further improve the display quality of the image.
[0057] Furthermore, the step of merging the second index, or merging the first index and the second index respectively, includes: merging the pixel points corresponding to the second index, or merging the pixel points corresponding to the first index and the second index respectively.
[0058] When merging the second index, the pixel points corresponding to the second index are also merged to obtain the corresponding relationship between the merged pixel points and the first index. When merging the first index and the second index respectively, the pixel points corresponding to the first index and the pixel points corresponding to the second index are merged respectively to obtain the relationship between the merged pixel points and the first index and the relationship between the merged pixel points and the second index.
[0059] S15: Generate a color palette based on the merged first index and second index.
[0060] The first index and the second index constitute an index of the palette, and the first index and the second index correspond to pixel values respectively.
[0061] In some embodiments, before the step of generating a color palette based on the first index and the second index, a first pixel value corresponding to the first index and a second pixel value corresponding to the second index are obtained.
[0062] Among them, when the first index corresponds to a pixel value, the pixel value of the first index is the pixel value; when the first index corresponds to multiple pixel values, the pixel value of the first index is one of the multiple pixel values or a new pixel value obtained based on the multiple pixel values.
[0063] In some embodiments, when the first index corresponds to multiple pixel values, the K-means cluster center of the pixel point corresponding to the first index can be used as the first pixel value based on the K-means method. When the first index corresponds to multiple pixel values, the K-means cluster center of the pixel point corresponding to the second index can be used as the second pixel value based on the K-means method. The pixel value obtained in this way can better replace multiple pixel values, thereby obtaining a better display effect.
[0064] Further, a color palette is generated based on the correspondence between the first index and the first pixel value, and the correspondence between the second index and the second pixel value. The color palette also includes the correspondence between the first index and the pixel points of the region of interest, and the correspondence between the second index and the pixel points of the non-region of interest.
[0065] Therefore, after the image processing device compresses the image data of the image to be processed according to the color palette to form compressed data, other devices can reconstruct the image according to the compressed data and the color palette after receiving the compressed data for image display. Specifically, according to the correspondence between the pixel point and the index, and the correspondence between the index and the pixel value, the pixel value of the pixel point can be obtained, thereby realizing the reconstruction of the image.
[0066] See also Figure 2 , Figure 2 It is another flowchart of the method for generating a color palette for an image of the present application.
[0067] In some embodiments, the above step S13 includes the following steps:
[0068] S21: Sort the pixels in the region of interest and the region of no interest respectively according to their weights.
[0069] Specifically, the weight of a pixel can be calculated according to different weights of the components of the pixel. For example, for an image to be processed in RGBA format, the pixel has four components: R, G, B, and A (alpha). Then, the weight of a pixel is P w =(R*w 1 +G*w 2 +B*w 3 +A*w 4 ) / (w 1 +w 2 +w 3 +w 4 ). Among them, w 1 、w 2 、w 3 、w 4 are the weights corresponding to each component, w 1 >=0,w 2 >=0,w 3 >=0,w 4 >=0,w 1 、w 2 、w 3 、w 4 can be the same or different. In some embodiments, w 1 =w 2 =w 3 =w 4 .
[0070] Of course, for an image to be processed in a non-RGBA format, such as an image in an RGB format, the pixel ordering method may also refer to the above method.
[0071] It should be understood that the pixel values of pixels with the same weights may be the same or different.
[0072] More specifically, the pixels can be sorted in order of weight from large to small or from small to large, and the pixels with the same weight can be grouped in the same order, thereby forming a pixel arrangement table of the area of interest and a pixel arrangement table of the area of non-interest.
[0073] S22: setting an index for the pixels with the same weight to obtain a first index corresponding to the pixel in the region of interest and a second index corresponding to the pixel in the non-region of interest.
[0074] The number of pixels with the same weight may be one or more. Therefore, each first index may correspond to one pixel or more pixels, and the same is true for the second index.
[0075] In summary, we can get the sorting table of indexes, and the sorting method of the pixels corresponding to the indexes is also the sorting method of the indexes. Combined with the above content, when the pixels are sorted in descending order according to the weights, the indexes are sorted in descending order according to the weights of the corresponding pixels.
[0076] S23: Merge the indexes of the first index and the second index that have the same color type.
[0077] It should be understood that the first index and the second index have the same color type, that is, the pixel value of the pixel point corresponding to the first index is the same as the pixel value of the pixel point corresponding to the second index.
[0078] The first index is the area corresponding to the pixel point of the region of interest, and the second index is the area corresponding to the pixel point of the non-region of interest. Therefore, there may be a situation in which the pixel value corresponding to a pixel point corresponding to the first index is the same as the pixel value of a pixel point corresponding to the second index in the first index and the second index.
[0079] Based on this, the first index and the second index having the same color type are merged to remove duplicate indexes and avoid unnecessary index occupation.
[0080] See also Figure 3 , Figure 3 It is another flowchart of the method for generating a color palette for an image of the present application.
[0081] Based on the above content, step S14 may include the following steps:
[0082] S31: It is determined that the index numbers of the first index and the second index are less than or equal to a first threshold, and the second index having a color type number less than the first number is merged into an adjacent second index.
[0083] Specifically, it is determined whether the sum of the index numbers of the first index and the second index is less than or equal to a first threshold.
[0084] Wherein, the first threshold is greater than a preset number, and when the sum of the index numbers of the first index and the second index is less than or equal to the first threshold, it is determined that the first index and the second index need to be merged, but only a small merger is required. When the sum of the index numbers of the first index and the second index is greater than the first threshold, it is determined that the first index and the second index need to be merged to a large extent.
[0085] If it is determined that the sum of the index numbers of the first index and the second index is less than or equal to the first threshold, the second index having a color type number less than the first number is merged into an adjacent second index.
[0086] The second index whose number of colors is less than the first number, that is, the types of pixel values of the pixel points corresponding to the second index are less than the first number. The second index whose number of color types is less than the first number can be merged into any one of the two adjacent second indexes, for example, the second index can be merged into a second index with a larger corresponding weight.
[0087] It should be understood that when the second index is merged, the pixel points corresponding to the second index are merged at the same time to obtain a corresponding relationship between the merged pixel points and the second index.
[0088] For example, the first number may be set to 5, and the second indexes with color types less than 5 are merged into adjacent second indexes. Of course, the first number may also be set to other values, which can be set according to actual needs.
[0089] S32: It is determined that the sum of the index numbers of the merged second index and the first index is greater than a preset number, and the first index whose number of color types is less than the second number is merged with the adjacent first index, and the second number is less than the first number.
[0090] Specifically, it is first determined whether the sum of the index numbers of the merged second index and the first index is less than or equal to a preset number.
[0091] If the sum of the index numbers of the merged second index and the first index is less than or equal to the total number of indexes of the palette to be used, then there is no need to continue merging the indexes, and the merging of the indexes is terminated. In this case, only the second index is merged, and more indexes of the region of interest are retained, which can improve the image display quality.
[0092] If it is determined that the sum of the index numbers of the merged second index and the first index is greater than the total number of indexes of the palette to be generated, then the first index whose number of color types is less than the second number is merged with the adjacent first index, and the second number is less than the first number.
[0093] At this time, the first index is further merged. The merging method of the first index is similar to the merging method of the second index. Please refer to the merging method of the second index.
[0094] The second number is smaller than the first number, that is, compared with merging the second indexes, when merging the first indexes, the merging is performed with a smaller amplitude so as to retain more first indexes.
[0095] For example, the second number may be set to 2, that is, the first indexes with a number of color types less than 2 are merged into adjacent first indexes.
[0096] S33: if it is determined that the sum of the index numbers of the merged first index and the merged second index is greater than a preset number, the first number and the second number are increased, and the process returns to step S31.
[0097] If it is determined that the sum of the index numbers of the merged first index and the merged second index is greater than the preset number, it means that further merging is required. At this time, the first number and the second number are increased, and further merging is performed until the sum of the index numbers of the first index and the merged second index is less than or equal to the preset number.
[0098] See also Figure 4 , Figure 4 It is another flowchart of the method for generating a color palette for an image of the present application.
[0099] In some other embodiments, step S14 may include the following steps:
[0100] S41: It is determined that the sum of the index numbers of the first index and the second index is greater than a first threshold, and a second index whose number of color types is less than a third number is merged into an adjacent second index, where the third number is greater than the first number.
[0101] Specifically, when the sum of the index numbers of the first index and the second index is greater than the first threshold, a larger merger is required. In this case, the second index whose number of color types is less than the third number is merged into the adjacent second index, and the third number is greater than the first number.
[0102] For example, the third number may be set to 7, that is, the second indexes with the number of color types less than 7 are merged into adjacent second indexes.
[0103] S42: When it is determined that the sum of the index numbers of the merged second index and the first index is greater than a preset number, the first indexes whose number of color types is less than a fourth number are merged, and the fourth number is greater than the second number and less than the third number.
[0104] It should be understood that if it is determined that the sum of the index numbers of the merged second index and the first index is less than or equal to the total number of indexes of the to-be-generated palette, then there is no need to further merge the indexes.
[0105] If it is determined that the sum of the index numbers of the merged second index and the first index is greater than the total number of indexes of the palette to be generated, the first indexes whose number of color types is less than the fourth number are merged, the fourth number is greater than the second number, and the fourth number is less than the third number.
[0106] At this time, the first indexes are further merged, and the fourth number thereof is smaller than the third number. At this time, the first indexes are merged with a smaller amplitude.
[0107] For example, the fourth number is 4, that is, the first indexes whose number of color types is less than 4 are merged into adjacent first indexes.
[0108] In some embodiments, the difference between the third number and the first number is equal to the difference between the fourth number and the second number. For example, the difference between the third number and the first number is equal to 2, and the difference between the fourth number and the second number is also equal to 2. Of course, the difference between the third number and the first number may not be equal to the difference between the fourth number and the second number.
[0109] Of course, in other embodiments, the difference between the third quantity and the first quantity may not be equal to the difference between the fourth quantity and the second quantity, and no specific limitation is made herein.
[0110] After step S42, the following steps may also be included:
[0111] S43: if it is determined that the sum of the index numbers of the merged first index and the merged second index is greater than a preset number, the third number and the fourth number are increased, and the process returns to step S31.
[0112] If it is determined that the sum of the index numbers of the merged first index and the merged second index is greater than the preset number, it means that further merging is required. At this time, the third number and the fourth number are increased, and further merging is performed until the sum of the index numbers of the merged first index and the merged second index is less than or equal to the preset number.
[0113] The second aspect of the present application also provides an image processing method, see Figure 5 , Figure 5 : is a flow chart of the image processing method of the present application, the method comprising:
[0114] S51: Acquire the image to be processed.
[0115] The image processing device may acquire the image to be processed according to a preset acquisition rule. The image processing device may be an electronic device with an image acquisition function, such as a camera, a mobile terminal, etc.
[0116] S52: Compress the image data of the image to be processed based on the color palette.
[0117] The color palette is generated by the color palette generation method provided in the first aspect. In the image data processing process, the color palette can realize the compression of the image data, and then form a code stream to be transmitted to other devices for display.
[0118] It should be understood that other devices receiving code streams can reconstruct images based on the palette and the code stream. Since more first indexes of the region of interest are retained in the generation of the palette, the image reconstructed based on the palette is closer to the image to be processed in the region of interest and closer to user needs.
[0119] The third aspect of the present application provides an image processing device 60, see Figure 6 , Figure 6 It is a structural schematic diagram of the image processing device 60 of the present application.
[0120] The image processing device 60 includes a palette generation module 61 and a compression module 62, wherein the compression module 62 is connected to the palette generation module 61. The palette generation module 61 is used to generate a palette of the image to be processed, and the compression module 62 is used to compress the image to be processed according to the palette. The palette is generated by the method provided in the first aspect above.
[0121] A fourth aspect of the present application provides an electronic device 70, see Figure 7 , Figure 7 It is a structural schematic diagram of an electronic device 70 of the present application.
[0122] The electronic device 70 includes a memory 71 and a processor 72 coupled to each other, and the processor 72 is used to execute program instructions stored in the memory 71 to implement the method provided by the first aspect or the second aspect above.
[0123] In a specific implementation scenario, the electronic device 70 may include, but is not limited to: a microcomputer, a server, and in addition, the electronic device 70 may also include mobile devices such as a laptop computer and a tablet computer, which are not limited here.
[0124] Specifically, the processor 72 is used to control itself and the memory 71 to implement the steps of the above method embodiment. The processor 72 can also be called a CPU (Central Processing Unit). The processor 72 may be an integrated circuit chip with signal processing capabilities. The processor 72 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 72 can be implemented by an integrated circuit chip.
[0125] The fifth aspect of the present application also provides a computer-readable storage medium 80, see Figure 8 , Figure 7 It is a schematic diagram of the structure of the computer-readable storage medium 80 of the present application.
[0126] The computer-readable storage medium 80 stores program instructions 81 , and when the program instructions 81 are executed by a processor, the method provided by the first aspect or the second aspect is implemented.
[0127] The computer-readable storage medium 80 may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0128] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments without conflict.
[0129] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for generating a color palette of an image, characterized in that: The method comprises: Get the image to be processed; Determining a region of interest and a region of no interest of the image to be processed; Obtaining a first index corresponding to a pixel point in the region of interest and a second index corresponding to a pixel point in the non-region of interest; When the sum of the index numbers of the first index and the second index is greater than a preset number, merging the second index, or merging the first index and the second index separately so that the sum of the index numbers is less than or equal to the preset number; A color palette is generated based on the merged first index and the second index.
2. The method according to claim 1, characterized in that Merging the first index and the second index respectively includes: merging the first index and the second index respectively in different merging modes.
3. The method according to claim 1, characterized in that The step of obtaining a first index corresponding to a pixel point of the region of interest and a second index corresponding to a pixel point of the non-region of interest comprises: Sort the pixels of the region of interest and the region of no interest respectively according to the weights; An index is set for the pixel points with the same weight to obtain a first index corresponding to the pixel points in the region of interest and a second index corresponding to the pixel points in the non-region of interest; The first index and the second index having the same color category are merged.
4. The method according to claim 3, characterized in that When the sum of the index numbers of the first index and the second index is greater than a preset number, the step of merging the second index, or merging the first index and the second index separately so that the sum of the index numbers is less than or equal to the preset number, includes: It is determined that the sum of the index numbers of the first index and the second index is less than or equal to a first threshold, and the second index having a color type number less than the first number is merged into an adjacent second index; It is determined that the sum of the index quantities of the merged second index and the first index is greater than a preset quantity, and the first index whose number of color types is less than a second quantity is merged with the adjacent first index, and the second quantity is less than the first quantity.
5. The method according to claim 4, characterized in that After the step of merging the first indexes whose number of color types is less than the second number and adjacent first indexes, the method further includes: Determining that the sum of the index numbers of the merged first index and the merged second index is greater than the preset number, increasing the first number and the second number; Repeat the steps as claimed in claim 4 until the sum of the index numbers of the merged first index and the merged second index is less than or equal to the preset number.
6. The method according to claim 4, characterized in that When the sum of the index numbers of the first index and the second index is greater than a preset number, the step of merging the second index, or merging the first index and the second index separately so that the sum of the index numbers is less than or equal to the preset number, includes: It is determined that the sum of the index numbers of the first index and the second index is greater than a first threshold, merging the second index whose number of color types is less than a third number into an adjacent second index, and the third number is greater than the first number; It is determined that the sum of the index numbers of the merged second index and the first index is greater than the preset number, and the first indexes whose number of color types is less than a fourth number are merged, the fourth number is greater than the second number, and the fourth number is less than the third number.
7. The method according to claim 1, characterized in that The color change value of the region of interest is greater than the color change value of the non-interest region, and / or the motion change value of the region of interest is greater than the motion change value of the non-interest region.
8. The method according to claim 1, characterized in that The step of merging the second index, or merging the first index and the second index respectively, includes: merging the pixel points corresponding to the second index, or merging the pixel points corresponding to the first index and the second index respectively.
9. The method according to claim 8, characterized in that Before the step of generating a color palette based on the first index and the second index, the method includes: Obtain a first pixel value corresponding to the first index and a second pixel value corresponding to the second index; The step of generating a color palette based on the first index and the second index includes: A color palette is generated based on the correspondence between the first index and the first pixel value, and the correspondence between the second index and the second pixel value.
10. The method according to claim 9, characterized in that The step of obtaining a first pixel value corresponding to the first index and a second pixel value corresponding to the second index includes: Based on the K-means method, the K-means cluster center of the pixel point corresponding to the first index is used as the first pixel value, and the K-means cluster center of the pixel point corresponding to the second index is used as the second pixel value.
11. An image processing method, characterized in that: The method comprises: Get the image to be processed; compressing the image data of the image to be processed based on the color palette; Wherein, the color palette is generated by the method according to any one of claims 1-10.
12. An image processing device, characterized in that: The device comprises: A palette generation module, used to generate a palette for an image to be processed; A compression module, connected to the palette generation module, for compressing the image to be processed according to the palette; Wherein, the color palette is generated by the method according to any one of claims 1-10.
13. An electronic device, characterized in that: It comprises a memory and a processor coupled to each other, wherein the processor is used to execute program instructions stored in the memory to implement the image palette generation method described in any one of claims 1 to 11, or to implement the image processing method described in claim 11.
14. A computer-readable storage medium having program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the color palette generation method for an image described in any one of claims 1 to 10 is implemented, or the image processing method described in claim 11 is implemented.
Citation Information
Patent Citations
Method and apparatus for palette coding with cross block prediction
CN106031171A
Advanced screen content coding with improved palette table and index map coding methods
CN106797457A