Method and device for extracting theme color of picture, electronic equipment and storage medium

The image data is obtained through canvas and the octree color quantization algorithm is used to solve the problem of large deviation in the color extraction of pictures in the prior art, achieving more accurate color extraction and background coordination, and improving user experience.

CN118967925AInactive Publication Date: 2024-11-15BEIJING QINGSONG YIKANG INFORMATION TECHNOLOGY CO LTD
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411014444.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-26
Publication Date
2024-11-15
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The prior art has large deviations in extracting the theme colors of the picture, especially the inaccuracy caused by the Gaussian blur method and the influence on the color of the viewport area, so the true color value of the picture cannot be accurately obtained.

Method used

The canvas method is used to obtain the RGB color of each pixel of the image data, and through the octree color quantization algorithm, a large number of pixels RGB colors are quantized into simple leaf node count values, and the color with the most frequent occurrence frequency is selected as the theme color.

Benefits of technology

It improves the accuracy of the extraction of the theme color of the picture, avoids the inaccuracy of high-magnification enlargement, ensures the coordination and consistency between the background color and the picture, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118967925A_ABST
    Figure CN118967925A_ABST
Patent Text Reader

Abstract

The invention relates to a method and a device for extracting a theme color of a picture, electronic equipment and a storage medium. The method comprises the following steps: acquiring image data of a target image in an interface of a website or application software; obtaining the RGB color of each pixel in the image data through a canvas method; an octree is adopted to quantify the RGB color of each pixel, the count value of each leaf node in the octree is obtained, and the count value of each leaf node is used for indicating the occurrence frequency of one color in the target image; and selecting the first n colors with the highest count value as theme colors in the interface, wherein n is a positive integer. The subject color extraction accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for extracting theme colors of images. Background Art

[0002] Extracting the theme color of an image is mainly used in the interface design of websites and applications. The adaptive color scheme can be dynamically adjusted as the content changes (such as carousels, article pictures, etc.) to ensure color coordination and make the website look beautiful in any background. User experience is the core of modern web design, and adaptive colors can help create a consistent and attractive visual experience. Extracting the theme color of an image can ensure that the background color is consistent with the displayed image, improving the user's sense of immersion.

[0003] Among the current methods of extracting the theme color of an image, the intelligent multimedia service of the object storage provides image processing functions, but it is a paid service and needs to be purchased before it can be used. Alternatively, the image can be enlarged many times using Gaussian blur, and then blurred as the background color. However, it is equivalent to just blurring the image as the background image, and the real color value cannot be obtained. Moreover, the result is not accurate and is greatly affected by the color in the viewport area (DOM element area) after the image is enlarged. If the image is colored as a whole, but the viewport area is white after enlargement, then its theme color will be displayed as white, which is basically wrong, so there is a large deviation. Summary of the invention

[0004] The present application provides a method, device, electronic device and storage medium for extracting theme colors of pictures, so as to solve the problem of large deviation in the extracted theme colors of pictures.

[0005] In a first aspect, the present application provides a method for extracting a theme color of an image, the method comprising:

[0006] Acquire image data of a target image in an interface of a website or application software;

[0007] Obtain the RGB color of each pixel in the image data through the canvas method;

[0008] quantizing the RGB color of each pixel using an octree to obtain a count value of each leaf node in the octree, wherein the count value of each leaf node is used to indicate the frequency of occurrence of a color in the target image;

[0009] The first n colors with the highest count values ​​are selected as the theme colors in the interface, where n is a positive integer.

[0010] Optionally, an octree is used to quantize the RGB color of each pixel, and the count value of each leaf node in the octree is obtained, including:

[0011] Traverse each pixel in the image data and perform the target operation on each pixel:

[0012] An octree color quantization algorithm is used to determine whether the RGB color of the pixel hits any leaf node, wherein each leaf node is used to indicate a color region in a color space;

[0013] If it hits, the count value of the hit leaf node is increased by one;

[0014] If there is no hit, then find the leaf node closest to the RGB color of the pixel and add one to the count value of the closest leaf node.

[0015] Optionally, using an octree color quantization algorithm to determine whether the RGB color of the pixel hits any leaf node includes:

[0016] Marking the RGB color of the pixel in a three-dimensional coordinate format;

[0017] According to the index of the root node, determine the target child node corresponding to the coordinate range where the three-dimensional coordinates of the pixel are located, wherein the color area of ​​each node in the octree has a corresponding coordinate range;

[0018] According to the index of the target child node, a leaf node corresponding to the coordinate range where the three-dimensional coordinates of the pixel are located is determined.

[0019] Optionally, finding a leaf node that is closest to the RGB color of the pixel includes:

[0020] Determine the coordinate range of each leaf node of the target subnode;

[0021] Determine the approximation between the three-dimensional coordinates of the pixel and the coordinate range of each leaf node;

[0022] The leaf node with the largest similarity is selected as the closest leaf node.

[0023] Optionally, obtaining the RGB color of each pixel in the image data by a canvas method includes:

[0024] Draw the target image onto the canvas element through the onload callback function;

[0025] Get the context object of the canvas element through canvas.getContext('2d');

[0026] Call the drawImage() method to draw the target image onto the canvas;

[0027] The ImageData object is obtained from the context environment object through the getImageData() method, wherein the ImageData object contains the RGB color of each pixel in the image data.

[0028] Optionally, after selecting the first n colors with the highest count values ​​as the theme colors in the interface, the method further includes:

[0029] The background color of the website or the application software is set to be consistent with the target image through a cascading style sheet.

[0030] Optionally, obtaining image data of a target image in an interface of a website or application software includes:

[0031] Create an invisible img element on the HTML page;

[0032] Setting the src attribute of the img element to the uniform resource locator of the target image in the interface of the website or application software;

[0033] According to the uniform resource locator, the target image is loaded using the img element.

[0034] In a second aspect, the present application provides a device for extracting a theme color of a picture, the device comprising:

[0035] A first acquisition module is used to acquire image data of a target image in an interface of a website or application software;

[0036] A second acquisition module is used to acquire the RGB color of each pixel in the image data by using a canvas method;

[0037] A quantization module, used to quantize the RGB color of each pixel using an octree to obtain a count value of each leaf node in the octree, wherein the count value of each leaf node is used to indicate the frequency of occurrence of a color in the target image;

[0038] The selection module is used to select the first n colors with the highest count values ​​as the theme colors in the interface, where n is a positive integer.

[0039] In a third aspect, the present application provides an electronic device comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus.

[0040] In a fourth aspect, the present application further provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute the method for extracting the theme color of an image as described in any one of the above items of the present application.

[0041] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art: after the RGB color of each pixel in the image data is obtained by the canvas method, the octree color quantization calculation is used to quantize a large number of pixel RGB colors into simple leaf node count values, and then the most frequently occurring colors are extracted as representative colors to obtain the theme color. Compared with the inaccurate theme color extraction caused by Gaussian blur in the prior art, the present application does not have a high-magnification magnified image, but extracts the colors that appear more frequently as the theme color, thereby improving the accuracy of theme color extraction. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0044] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0045] Figure 1 A flow chart of a method for extracting the theme color of an image provided in an embodiment of the present application;

[0046] Figure 2 A schematic diagram of the overall process of a method for extracting the theme color of an image provided in an embodiment of the present application;

[0047] Figure 3 A schematic diagram of the structure of a device for extracting the theme color of a picture provided in an embodiment of the present application;

[0048] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are 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 making creative work are within the scope of protection of this application.

[0050] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.

[0051] This application provides a method for extracting the theme color of an image, which is applied to a terminal and is used to improve the accuracy of the theme color of the image. Figure 1 As shown, the method comprises the following steps:

[0052] Step 101: Acquire image data of a target image in an interface of a website or application software.

[0053] Step 102: Obtain the RGB color of each pixel in the image data through the canvas method.

[0054] Step 103: quantize the RGB color of each pixel using an octree to obtain a count value of each leaf node in the octree, wherein the count value of each leaf node is used to indicate the frequency of occurrence of a color in the target image.

[0055] Step 104: Select the first n colors with the highest count values ​​as the theme colors in the interface, where n is a positive integer.

[0056] The interface design of a website or APP application should ensure that the colors are coordinated and consistent, which is conducive to improving the user's sense of immersion. This application is applicable to many scenarios, including but not limited to the following scenarios:

[0057] 1. Content-driven interfaces: such as news websites, blogs, or social media platforms, which often display different content, including carousels, article illustrations, etc. Adaptive color schemes can adjust the interface color according to the tone of the image to maintain a consistent visual style and improve aesthetics.

[0058] 2. Media players or video services: The interface of a video player or music player can be adjusted according to the color tone of the media content being played, creating a more immersive viewing experience.

[0059] 3. Game interface: UI elements in the game may need to change color according to the in-game environment to enhance the immersion and interactivity of the game.

[0060] The current interface is the interface of a website or application software. The terminal loads the target image in the current interface and obtains the image data of the target image. Which image is loaded in the current interface depends on the adaptive color scheme. For example, if the website homepage design generally has a carousel image, the adaptive color scheme is to use the carousel image as the target image, then the images in other positions on the homepage are no longer needed. The adaptive color scheme can also be that wherever there are images in the interface, an outer frame is added to the image according to its theme color, and then a glowing theme color shadow effect is added, and then all these multiple images are loaded as the target image.

[0061] The terminal draws the image on the canvas, and then obtains an ImageData object from the canvas context object. The ImageData object contains the RGB (red-green-blue) color of each pixel of the target image. The RGB color space is the most commonly used in digital images. Based on the three basic colors of red, green, and blue, different proportions are superimposed to produce rich and wide colors.

[0062] Octree is a structure that is convenient for representing RGB color space. Each node of the octree represents a volume element of a cube. Each node has eight child nodes. The volume elements represented by the eight child nodes added together equal the volume of the parent node. The only node at the 0th layer represents the entire color space. The 8 child nodes at the next layer represent a color space respectively. The 8 child nodes below a child node represent a more specific color space of its parent node, and the division continues until the leaf node.

[0063] Octree is used to represent the color space for easy searching. The path from the root node to the leaf node can be obtained through the RGB color of the pixel. The count value of the leaf node corresponding to the pixel is increased by one. After traversing all pixels, the count value of each leaf node is obtained, and the RGB color of each pixel is quantized into the count value of the leaf node. The count value of each leaf node is used to indicate the frequency of a color appearing in the target image. These colors are subsequently sorted according to the count value of the leaf node, and the top n most frequent colors are returned as the result, usually including several of the most representative colors as the theme colors in the interface, and n is a positive integer.

[0064] In this application, after the canvas method is used to obtain the RGB color of each pixel in the image data, the octree color quantization calculation is used to quantize a large number of pixel RGB colors into simple leaf node count values, and then the most frequently occurring colors are extracted as representative colors to obtain the theme color. Compared with the inaccurate theme color extraction caused by Gaussian blur in the prior art, this application does not have a high-magnification magnified image, but extracts the colors that appear more frequently as the theme color, thereby improving the accuracy of theme color extraction.

[0065] After the terminal obtains the theme color, it sets the background color of the website or application software through the cascading style sheet CSS to make it consistent with the target image, thereby improving the visual quality of the interface and user experience. Alternatively, the UI elements in the interface are set to be consistent with the color of the target image. The UI color includes but is not limited to: icons, scroll bars, text, buttons, status bars, etc. For example, the text in the game is set to be consistent with the color of the image in the game to enhance the immersion and interactivity of the game.

[0066] As an optional implementation, an octree is used to quantize the RGB color of each pixel, and obtaining the count value of each leaf node in the octree includes: traversing each pixel in the image data, and performing a target operation on each pixel: using an octree color quantization algorithm to determine whether the RGB color of the pixel hits any leaf node, wherein each leaf node is used to indicate a color area in the color space; if it hits, the count value of the hit leaf node is increased by one; if it does not hit, finding the leaf node closest to the RGB color of the pixel, and increasing the count value of the closest leaf node by one.

[0067] First, the octree data structure is initialized. The specific process is as follows: the terminal creates an empty Octree data structure. The Octree data structure is a layered cube, which is particularly suitable for storing data in three-dimensional space. Each minimum cube corresponds to a leaf node, representing a color area in the color space. The colors represented by adjacent leaf nodes are similar. The parent node of the leaf node includes all the colors of its leaf nodes, that is, the entire color space is divided into different child nodes according to color, and the child nodes then divide their colors into different leaf nodes. The number of layers of child nodes in the embodiment of the present application is not limited.

[0068] The terminal traverses each pixel in the image data and performs the target operation on each pixel: if the RGB color of the pixel is exactly the same as the color of a leaf node in the octree, it means that the RGB color of the pixel hits the leaf node, then the count value of the leaf node is increased by one, and the count value indicates the number of pixels with the same color, and also indicates the frequency of the occurrence of the color. If the RGB color of the pixel is different from the color of any leaf node in the octree, it means that the RGB color of the pixel does not hit the leaf node, then the leaf node corresponding to the color closest to the RGB color of the pixel is searched in the octree, and then the count value of the closest leaf node is increased by one. This process continues until all pixels are processed, and finally the leaf nodes will accumulate all the colors in the target image, and the count value of each leaf node reflects the frequency of the corresponding color in the image.

[0069] The embodiment of the present application uses an octree color quantization algorithm to implement color quantization, discretizing a continuous color space into a finite number of colors, which can reduce the color depth of the image while maintaining the overall visual effect of the image as much as possible.

[0070] As an optional implementation, using an octree color quantization algorithm to determine whether the RGB color of a pixel hits any leaf node includes: marking the RGB color of the pixel in the form of three-dimensional coordinates; determining, according to the index of the root node, a target child node corresponding to the coordinate range of the three-dimensional coordinates of the pixel, wherein the color area of ​​each node in the octree has a corresponding coordinate range; and determining, according to the index of the target child node, a leaf node corresponding to the coordinate range of the three-dimensional coordinates of the pixel.

[0071] Each node in the octree also has a corresponding coordinate range. Specifically, the terminal divides the entire color space into multiple color areas. Each color area has a corresponding coordinate range, which belongs to the coordinate range of the leaf node. Then the coordinate range of the parent node is the union of the coordinate ranges of the child nodes. In this way, each node in the octree has a corresponding coordinate range. The coordinate range represents at least one color area of ​​the node in the color space. If it is a leaf node, then its coordinate range represents a color area. If it is a parent node, then its coordinate range includes multiple color areas. The coordinate range of the root node represents the entire color space.

[0072] The octree has its own index, similar to a dictionary. The parent node has the index of the child node, and so on, layer by layer, until the second-to-last child node has the index of the leaf node. Every time a pixel reaches a node, it can know the coordinate range of its child nodes based on the index of the current node, and then reach the child node based on the pointer of the child node, and continue to perform the above operations until it reaches a leaf node.

[0073] For example, the terminal marks the RGB color of the pixel in the form of three-dimensional coordinates, inputs the three-dimensional coordinates into the root node of the octree, first determines the coordinate range of each child node in the lower layer according to the index of the root node, determines which coordinate range the three-dimensional coordinate of the pixel belongs to, and jumps to the child node according to the pointer of the child node, takes the child node as the parent node, and continues to determine the coordinate range of its lower-level child nodes according to the index of the parent node, and then the three-dimensional coordinates of the pixel continue to jump to the lower-level child nodes, and repeats the above steps until jumping to the leaf node.

[0074] This application finds the leaf node corresponding to the pixel from the root node to the leaf node based on the index, thereby improving the search efficiency of the leaf node.

[0075] Among them, the embodiment of the present application can also increase transparency on the basis of RGB color, and accordingly, the coordinate range of the node in the octree also needs to add transparency.

[0076] As an optional implementation, finding the leaf node closest to the RGB color of a pixel includes: determining the coordinate range of each leaf node of the target child node; determining the approximation between the three-dimensional coordinates of the pixel and the coordinate range of each leaf node; and selecting the leaf node with the greatest approximation as the closest leaf node.

[0077] If the pixel does not find a leaf node with exactly the same color as its color, then the leaf node closest to its color can be determined and then jumped to that leaf node. Specifically, after the pixel reaches the last parent node, the coordinate range of each leaf node of the parent node is determined, and then the coordinate range of the pixel's three-dimensional coordinates is determined, and then the coordinate range of which leaf node is closest. Specifically, the sum or average of the coordinate differences in each dimension can be calculated, and the smallest result can be selected as the closest leaf node.

[0078] When a leaf node with exactly the same color cannot be found, the application selects the one with the closest color as the leaf node to ensure the accuracy of pixel color calculation.

[0079] As an optional implementation, obtaining the RGB color of each pixel in the image data through the canvas method includes: drawing the target image onto the canvas element through the onload callback function; obtaining the context environment object of the canvas element through canvas.getContext('2d'); calling the drawImage() method to draw the target image onto the canvas; obtaining the ImageData object from the context environment object through the getImageData() method, wherein the ImageData object contains the RGB color of each pixel in the image data.

[0080] Canvas is a drawing board element in front-end HTML. In HTML5, the canvas element is used to render graphics on a web page. It does not draw anything by itself, but is a blank canvas. This element can be used by JavaScript to draw paths, boxes, circles, characters, and add images on it. Drawing the target image on the Canvas element refers to the process of using JavaScript and the Canvas API to display an image on the canvas element.

[0081] The context object obtained by canvas.getContext('2d') is the CanvasRenderingContext2D object, which is the core part of the HTML5 Canvas API. The context object provides a series of methods and properties for drawing and manipulating graphics on the canvas element. In simple terms, the drawing context is a set of instructions that allow you to perform various drawing operations on the canvas, such as drawing shapes, drawing paths, filling and stroking, translation, rotation, scaling and tilting, image processing, text rendering, composite operations, saving and restoring states, etc. When calling canvas.getContext('2d'), you are actually telling the browser or application software that you want to use 2D rendering mode. The canvas element itself is just a container and has no drawing capabilities, while the CanvasRenderingContext2D object contains all the methods and properties that actually perform drawing operations.

[0082] The terminal calls the drawImage() method to draw the target image on the canvas, and then obtains the ImageData object from the context object through the getImageData() method, where the ImageData object contains the RGB color of each pixel in the image data.

[0083] As an optional implementation, the process of obtaining image data of a target image in the interface of a website or application software includes: the terminal creates an invisible img element on the HTML page, then sets the src attribute of the img element to the uniform resource locator url of the target image in the interface of the website or application software, and finally, based on the uniform resource locator, uses the img element to load the target image, and when the target image is loaded, the onload callback function of the img element is triggered.

[0084] Based on the same technical concept, this application provides a schematic diagram of the overall process of extracting the theme color of an image, such as Figure 2 As shown, the method includes the following steps.

[0085] Step 201: Acquire image data of a target image in an interface of a website or application software.

[0086] Step 202: Obtain the RGB color of each pixel in the image data through the canvas method.

[0087] Step 203: using an octree color quantization algorithm to discretize the continuous color space into a finite number of colors, specifically including the following steps.

[0088] Step 2031: Initialize the Octree data structure: create an empty Octree data structure, each node represents a color region in the entire color space, and each node corresponds to a coordinate range.

[0089] Step 2032: traverse the pixel: convert the RGB color of the pixel into a three-dimensional coordinate, determine the leaf node corresponding to the pixel according to the index, and increase the count value of the corresponding leaf node by one.

[0090] Step 2033: For the leaf node that cannot be found, determine the leaf node that is closest to the RGB color of the pixel, and increase the count value of the closest leaf node by one.

[0091] Step 2034: After all pixels are traversed, the count value of each leaf node is obtained.

[0092] Step 204: Select the first n colors with the highest count values ​​as the theme colors in the interface.

[0093] Step 205: Use CSS to set the theme color as the background color of the website or application software.

[0094] Based on the same technical concept, this application provides a method for extracting the theme color of an image, such as Figure 3 As shown, the method includes:

[0095] The first acquisition module 301 is used to acquire image data of a target image in the interface of a website or application software;

[0096] The second acquisition module 302 is used to acquire the RGB color of each pixel in the image data by using a canvas method;

[0097] A quantization module 303 is used to quantize the RGB color of each pixel using an octree to obtain a count value of each leaf node in the octree, wherein the count value of each leaf node is used to indicate the frequency of a color appearing in the target image;

[0098] The selection module 304 is used to select the first n colors with the highest count values ​​as the theme colors in the interface, where n is a positive integer.

[0099] Optionally, the quantization module 303 is used to:

[0100] Iterate over each pixel in the image data and perform the target operation on each pixel:

[0101] The octree color quantization algorithm is used to determine whether the RGB color of the pixel hits any leaf node, where each leaf node is used to indicate a color area in the color space;

[0102] If it hits, the count value of the hit leaf node is increased by one;

[0103] If there is no hit, find the leaf node closest to the RGB color of the pixel and increase the count value of the closest leaf node by one.

[0104] Optionally, the quantization module 303 is used to:

[0105] Mark the RGB color of the pixel in the form of three-dimensional coordinates;

[0106] According to the index of the root node, determine the target child node corresponding to the coordinate range where the three-dimensional coordinates of the pixel are located, wherein the color area of ​​each node in the octree has a corresponding coordinate range;

[0107] According to the index of the target child node, the leaf node corresponding to the coordinate range where the three-dimensional coordinates of the pixel are located is determined.

[0108] Optionally, the quantization module 303 is used to:

[0109] Determine the coordinate range of each leaf node of the target child node;

[0110] Determine the approximation between the three-dimensional coordinates of the pixel and the coordinate range of each leaf node;

[0111] Select the leaf node with the largest similarity as the closest leaf node.

[0112] Optionally, the second acquisition module 302 is used to:

[0113] Draw the target image onto the canvas element through the onload callback function;

[0114] Get the context object of the canvas element through canvas.getContext('2d');

[0115] Call the drawImage() method to draw the target image onto the canvas;

[0116] The ImageData object is obtained from the context object through the getImageData() method, where the ImageData object contains the RGB color of each pixel in the image data.

[0117] Optionally, the device is also used to select the first n colors with the highest count values ​​as the theme colors in the interface, and then set the background color in the website or application software to be consistent with the target image through a cascading style sheet.

[0118] Optionally, the first acquisition module 301 is used to:

[0119] Create an invisible img element on the HTML page;

[0120] Set the src attribute of the img element to the uniform resource locator of the target image in the interface of the website or application software;

[0121] According to the uniform resource locator, use the img element to load the target image.

[0122] like Figure 4 As shown, an embodiment of the present application provides an electronic device, including a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other through the communication bus 404.

[0123] The memory 403 is used to store computer programs.

[0124] In one embodiment of the present application, the processor 401 is used to execute the program stored in the memory 403 to implement the method for extracting the theme color of the picture provided by any of the above method embodiments, including:

[0125] Acquire image data of a target image in an interface of a website or application software;

[0126] Obtain the RGB color of each pixel in the image data through the canvas method;

[0127] quantizing the RGB color of each pixel using an octree to obtain a count value of each leaf node in the octree, wherein the count value of each leaf node is used to indicate the frequency of occurrence of a color in the target image;

[0128] The first n colors with the highest count values ​​are selected as the theme colors in the interface, where n is a positive integer.

[0129] Optionally, an octree is used to quantize the RGB color of each pixel, and the count value of each leaf node in the octree is obtained, including:

[0130] Traverse each pixel in the image data and perform the target operation on each pixel:

[0131] An octree color quantization algorithm is used to determine whether the RGB color of the pixel hits any leaf node, wherein each leaf node is used to indicate a color region in a color space;

[0132] If it hits, the count value of the hit leaf node is increased by one;

[0133] If there is no hit, then find the leaf node closest to the RGB color of the pixel and add one to the count value of the closest leaf node.

[0134] Optionally, using an octree color quantization algorithm to determine whether the RGB color of the pixel hits any leaf node includes:

[0135] Marking the RGB color of the pixel in a three-dimensional coordinate format;

[0136] According to the index of the root node, determine the target child node corresponding to the coordinate range where the three-dimensional coordinates of the pixel are located, wherein the color area of ​​each node in the octree has a corresponding coordinate range;

[0137] According to the index of the target child node, a leaf node corresponding to the coordinate range where the three-dimensional coordinates of the pixel are located is determined.

[0138] Optionally, finding a leaf node that is closest to the RGB color of the pixel includes:

[0139] Determine the coordinate range of each leaf node of the target subnode;

[0140] Determine the approximation between the three-dimensional coordinates of the pixel and the coordinate range of each leaf node;

[0141] The leaf node with the largest similarity is selected as the closest leaf node.

[0142] Optionally, obtaining the RGB color of each pixel in the image data by a canvas method includes:

[0143] Draw the target image onto the canvas element through the onload callback function;

[0144] Get the context object of the canvas element through canvas.getContext('2d');

[0145] Call the drawImage() method to draw the target image onto the canvas;

[0146] The ImageData object is obtained from the context environment object through the getImageData() method, wherein the ImageData object contains the RGB color of each pixel in the image data.

[0147] Optionally, after selecting the first n colors with the highest count values ​​as the theme colors in the interface, the method further includes:

[0148] The background color of the website or the application software is set to be consistent with the target image through a cascading style sheet.

[0149] Optionally, obtaining image data of a target image in an interface of a website or application software includes:

[0150] Create an invisible img element on the HTML page;

[0151] Setting the src attribute of the img element to the uniform resource locator of the target image in the interface of the website or application software;

[0152] According to the uniform resource locator, the target image is loaded using the img element.

[0153] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for extracting the theme color of an image provided in any of the aforementioned method embodiments are implemented.

[0154] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0155] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0156] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.

[0157] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for extracting the theme color of an image, characterized in that: The method comprises: Acquire image data of a target image in an interface of a website or application software; Obtain the RGB color of each pixel in the image data through the canvas method; quantizing the RGB color of each pixel using an octree to obtain a count value of each leaf node in the octree, wherein the count value of each leaf node is used to indicate the frequency of occurrence of a color in the target image; The first n colors with the highest count values ​​are selected as the theme colors in the interface, where n is a positive integer.

2. The method according to claim 1, characterized in that: The RGB color of each pixel is quantized using an octree, and the count value of each leaf node in the octree is obtained including: Traverse each pixel in the image data and perform the target operation on each pixel: An octree color quantization algorithm is used to determine whether the RGB color of the pixel hits any leaf node, wherein each leaf node is used to indicate a color region in a color space; If it hits, the count value of the hit leaf node is increased by one; If there is no hit, then find the leaf node closest to the RGB color of the pixel and add one to the count value of the closest leaf node.

3. The method according to claim 1, characterized in that Using the octree color quantization algorithm to determine whether the RGB color of the pixel hits any leaf node includes: Marking the RGB color of the pixel in a three-dimensional coordinate format; According to the index of the root node, determine the target child node corresponding to the coordinate range where the three-dimensional coordinates of the pixel are located, wherein the color area of ​​each node in the octree has a corresponding coordinate range; According to the index of the target child node, a leaf node corresponding to the coordinate range where the three-dimensional coordinates of the pixel are located is determined.

4. The method according to claim 3, characterized in that Finding the leaf node closest to the RGB color of the pixel includes: Determine the coordinate range of each leaf node of the target subnode; Determine the approximation between the three-dimensional coordinates of the pixel and the coordinate range of each leaf node; The leaf node with the largest similarity is selected as the closest leaf node.

5. The method according to claim 1, characterized in that The method of obtaining the RGB color of each pixel in the image data by canvas includes: Draw the target image onto the canvas element through the onload callback function; Get the context object of the canvas element through canvas.getContext('2d'); Call the drawImage() method to draw the target image onto the canvas; The ImageData object is obtained from the context environment object through the getImageData() method, wherein the ImageData object contains the RGB color of each pixel in the image data.

6. The method according to claim 1, characterized in that After selecting the first n colors with the highest count values ​​as the theme colors in the interface, the method further includes: The background color of the website or the application software is set to be consistent with the target image through a cascading style sheet.

7. The method according to claim 1, characterized in that Acquiring image data of a target image in the interface of a website or application software includes: Create an invisible img element on the HTML page; Setting the src attribute of the img element to the uniform resource locator of the target image in the interface of the website or application software; According to the uniform resource locator, the target image is loaded using the img element.

8. A device for extracting the theme color of a picture, characterized in that: The device comprises: A first acquisition module is used to acquire image data of a target image in an interface of a website or application software; A second acquisition module is used to acquire the RGB color of each pixel in the image data by using a canvas method; A quantization module, used to quantize the RGB color of each pixel using an octree to obtain a count value of each leaf node in the octree, wherein the count value of each leaf node is used to indicate the frequency of occurrence of a color in the target image; The selection module is used to select the first n colors with the highest count values ​​as the theme colors in the interface, where n is a positive integer.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-7 when executing a program stored in a memory.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Method and device for determining theme color, electronic equipment and readable storage medium

    CN112328345A

  • Website language-based PDF file generation method and device, equipment and storage medium

    CN113627126A

  • Page color pickup method and device, computer equipment, storage medium and product

    CN115601567A

  • Image theme color extraction method, and method and device for creating map based on image

    CN116012476A

  • Laser marking sample color block main color extraction method and system

    CN117351099A