Method and device for generating new image based on gradient color

By extracting and processing main and edge colors through clustering and interpolation, the method generates a coherent and natural gradient color, addressing the unnatural transitions in existing methods and enhancing image beauty.

CN119180877APending Publication Date: 2024-12-24BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411042933.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-12-24

AI Technical Summary

Technical Problem

Current gradient color generation methods in image processing focus solely on the main color of an image, resulting in unnatural and abrupt color transitions, failing to fully utilize and harmonize other colors, leading to a lack of coherence and beauty in the generated images.

Method used

A method and device that extract the main color and edge colors of an image using clustering and sliding window techniques, process these colors to generate transition colors through linear interpolation, and fuse them to create a coherent gradient color, enhancing the visual effect by incorporating multiple colors naturally.

Benefits of technology

The method produces a gradient color that is coherent and natural, enriching the image's color palette, resulting in a more aesthetically pleasing and visually appealing image by integrating the gradient color with the original image.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119180877A_ABST
    Figure CN119180877A_ABST
Patent Text Reader

Abstract

The invention provides a method and a device for generating a new image based on gradient colors. The method comprises the following steps: extracting a main color of a target image through a clustering method; a sliding window is adopted to slide on the edge of the target image, and at least one edge color of the target image is extracted; processing the main color and the at least one edge color to generate a gradient color; and generating a fused image according to the target image and the gradient color. The image aesthetic feeling is improved, and the visual effect 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 image processing technology, and in particular to a method and device for generating a new image based on gradient colors. Background Art

[0002] With the development and popularization of image processing technology, people's pursuit of visual effects is getting higher and higher. In the field of digital images, image color processing technology has been widely used and studied. Color can not only enhance the beauty of images, but also convey information, express emotions and intentions. In order to improve the user's visual experience, the technology of extracting and generating gradient colors based on the main color of the image to generate new images has emerged.

[0003] Currently, the gradient color generation process is based on the main color of the image, while ignoring other colors in the image, resulting in an unnatural gradient effect. The color of the new image generated in this way is not coherent enough and cannot fully display the beauty. Summary of the invention

[0004] In order to solve the above technical problem or at least partially solve the above technical problem, the present application provides a method and device for generating a new image based on gradient colors.

[0005] In a first aspect, the present application provides a method for generating a new image based on gradient colors, the method comprising:

[0006] Extract the main color of the target image through clustering method;

[0007] Sliding a sliding window along the edge of the target image to extract at least one edge color of the target image;

[0008] Processing the primary color and the at least one edge color to generate a gradient color;

[0009] A fused image is generated according to the target image and the gradient color.

[0010] Optionally, processing the primary color and the at least one edge color to generate a gradient color includes:

[0011] Traversing the edge colors, calculating the RGB colors and transparent colors corresponding to the primary color and the edge colors, and generating a transition color;

[0012] A plurality of the transition colors are spliced ​​to generate the gradient color.

[0013] Optionally, calculating the RGB color and the transparent color corresponding to the primary color and the edge color to generate a transition color includes:

[0014] Determine the R color, G color, B color and transparent color of the primary color, and determine the R color, G color, B color and transparent color of the edge color;

[0015] The R color, G color and B color corresponding to the primary color and the edge color are processed respectively by using a linear interpolation formula to obtain the RGB color of the transition color;

[0016] Determine the transparent color of the transition color according to the average of the transparent color of the primary color and the transparent color of the edge color;

[0017] The color of the transition color is generated according to the RGB color of the transition color and the transparent color.

[0018] Optionally, the linear interpolation formula is calculated as:

[0019] transition_color=main_color*t+edge_color*(1-t), where transition_color is the transition color, main_color is the main color value, edge_color is the edge color value, and t is the linear interpolation coefficient.

[0020] Optionally, using a sliding window to slide on the edge of the target image to extract at least one edge color of the target image includes:

[0021] Using the Sobel operator to extract the edge image of the target image;

[0022] The edge image is traversed by using a sliding window, and adjacent pixels with the same color in the edge image are merged as an edge color.

[0023] Optionally, before extracting the main color of the target image by a clustering method, the method further includes:

[0024] Convert the file stream of the target image into an RGBA format, wherein the RGBA format is used to represent a color space of red, green, blue, and transparency;

[0025] Convert the RGBA format to HSV or Lab color space.

[0026] Optionally, generating a fused image according to the target image and the gradient color includes:

[0027] Generate a blank image of corresponding size according to the size of the application interface;

[0028] Filling the blank image with the gradient color;

[0029] The target image is inserted into the filled blank image, and the transparency of the target image is set to be reduced.

[0030] In a second aspect, the present application provides a device for generating a new image based on gradient colors, the device comprising:

[0031] A first extraction module, used for extracting the main color of the target image by clustering method;

[0032] A second extraction module, configured to slide a sliding window along an edge of the target image to extract at least one edge color of the target image;

[0033] A processing module, used for processing the main color and the at least one edge color to generate a gradient color;

[0034] A generating module is used to generate a fused image according to the target image and the gradient color.

[0035] In a third aspect, an electronic device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0036] Memory, used to store computer programs;

[0037] The processor is used to implement any of the steps of the method for generating a new image based on gradient colors when executing the program stored in the memory.

[0038] In a fourth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any of the steps of the method for generating a new image based on gradient colors is implemented.

[0039] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:

[0040] The method provided in the embodiment of the present application merges the main color and edge color of the target image into a gradient color. The gradient color generation process takes into account the multiple colors of the target image, the gradient color is coherent and not abrupt, and the generation effect is more natural and smooth. After the target image is subsequently combined with the gradient color to generate a new image, the color of the new image is richer and fits the original color of the target image, thereby enhancing the beauty of the image and increasing the visual effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] 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.

[0042] 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.

[0043] Figure 1 A schematic diagram of the hardware environment of a method for generating a new image based on gradient colors provided in an embodiment of the present application;

[0044] Figure 2 A schematic diagram of primary color extraction provided in an embodiment of the present application;

[0045] Figure 3 A schematic diagram of the system interface provided in the embodiment of the present application;

[0046] Figure 4 A schematic diagram of a process for generating gradient colors provided in an embodiment of the present application;

[0047] Figure 5 A schematic diagram of the overall process of a method for generating a new image based on gradient colors provided in an embodiment of the present application;

[0048] Figure 6 A schematic diagram of the structure of a device for generating a new image based on gradient colors provided in an embodiment of the present application;

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

[0050] 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.

[0051] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present application and have no specific meaning. Therefore, "module" and "component" can be used interchangeably.

[0052] In order to solve the problem mentioned in the background technology, according to one aspect of an embodiment of the present application, a method for generating a new image based on gradient colors is provided, which can be executed by a terminal to improve the aesthetics of the generated new image.

[0053] The following will describe in detail a method for generating a new image based on gradient colors provided in an embodiment of the present application in combination with a specific implementation manner. Figure 1 As shown, the specific steps are as follows:

[0054] Step 101: extracting the main color of the target image by clustering method.

[0055] For any target image in the system, the terminal uses the K-means clustering algorithm to classify the colors in the target image. K-means is a simple and effective clustering method that iteratively assigns data points to the nearest cluster center to minimize the differences within the cluster.

[0056] At the beginning of the clustering process, the terminal randomly selects the colors of k pixels as the initial cluster centers. The value of k selected depends on the complexity of the image and the expected color classification accuracy. For each remaining pixel in the target image, the terminal calculates the distance between its color and the color of the current cluster center. This distance is usually measured using Euclidean distance, but other distance metrics such as color difference can also be used. Based on this distance, each pixel is assigned to the cluster represented by the nearest cluster center. Once all pixels have been assigned to a cluster, the terminal will recalculate the average value of each cluster to determine the new cluster center. This process involves averaging the color values ​​of all pixels in the cluster to obtain a new color, which will be used as the cluster center for the next round of iterations.

[0057] The terminal repeats the above pixel classification and cluster center update steps until the preset number of iterations is reached or the change in the cluster center is less than a certain threshold, indicating that the clustering process has stabilized and the cluster center no longer changes significantly. After the clustering process is completed, the system evaluates the number of pixels in each cluster, that is, the frequency, and the cluster containing the most pixels is considered to represent the dominant color in the target image.

[0058] Figure 2 The schematic diagram of main color extraction, the picture includes at least six colors, after extracting each color in the picture, cluster them according to the number of pixels, and get the color ranking, among which the first one is the main color, and the following colors can be ignored. In addition, the terminal page can also display the image ID, online address, original image address, image width and height, uploading user and other contents of the picture.

[0059] Step 102: Use a sliding window to slide along the edge of the target image to extract at least one edge color of the target image.

[0060] After extracting the image edge of the target image, the terminal uses a sliding window to move on the image edge and regards adjacent pixels with the same color as an edge color, thereby obtaining at least one edge color of the target image.

[0061] Step 103: Process the main color and at least one edge color to generate a gradient color.

[0062] The terminal processes the main color and any edge color to obtain a transition color, then traverses the edge color to obtain multiple transition colors, and finally splices the multiple transition colors to generate a gradient color.

[0063] Step 104: Generate a fused image according to the target image and the gradient color.

[0064] The terminal generates a new image by fusing the target image and the gradient color. There are two fusion methods: one is to insert the target image into the blank image and fill the redundant blank edges with gradient colors; the other is to fill the entire blank image with gradient colors, and then insert the target image into the image filled with gradient colors, and then reduce the transparency of the target image so that the target image and the gradient background can be integrated as much as possible.

[0065] In the present application, the main color and edge color of the target image are merged into a gradient color. The generation process of the gradient color takes into account the multiple colors of the target image. The gradient color is coherent and not abrupt, and the generation effect is more natural and smooth. When the target image is subsequently combined with the gradient color to generate a new image, the color of the new image is richer and fits the original color of the target image, thereby enhancing the beauty of the image and increasing the visual effect.

[0066] The present application provides a system applied in a terminal, in which a user uploads one or more images. The system can extract the main color and edge color of a selected image and generate a gradient color, and then fuse the image and the gradient color to generate a new image, and display the new image to the user.

[0067] The system interface can display multiple images, and display specific data for main color extraction or edge color extraction of the target image on one side of the interface. The specific data includes but is not limited to the image ID, online address, original image address, image width and height, uploading user, etc. of the target image. Figure 3 As shown, multiple images can be displayed on the left side of the system interface, and the extracted main color can be displayed on the right side of the system interface.

[0068] The taskbar of the system interface can also filter images, so that the filtered images are used as target images for color extraction. The image filtering labels of the taskbar include but are not limited to: business party, file type, site type, upload mode, width, height, file size, compression percentage, etc.

[0069] As an optional implementation, the process of processing the primary color and at least one edge color to generate a gradient color is as follows: Figure 4 As shown, the method comprises the following steps:

[0070] Step 401: traverse the edge colors, calculate the RGB colors and transparent colors corresponding to the primary color and the edge color, and generate a transition color.

[0071] Step 402: splicing multiple transition colors to generate gradient colors.

[0072] The terminal traverses the edge colors and performs the following operations on each edge color: determines the R color, G color, B color and transparent color corresponding to the main color and the edge color, and processes the R color of the main color and the R color of the edge color to obtain the R color of the transition color; processes the G color of the main color and the G color of the edge color to obtain the G color of the transition color; processes the B color of the main color and the B color of the edge color to obtain the B color of the transition color, performs mean processing on the transparent color of the main color and the transparent color of the edge color to obtain the transparent color of the transition color, thus obtaining the RGB color (green-red-blue, red-green-blue) color and transparent color of the transition color, and the color of the transition color can be determined based on the RGB color and the transparent color.

[0073] Among them, transparent color is represented by alpha (alpha channel). In the color channel mode, alpha represents the alpha channel, which refers to the different brightness parameters of the color.

[0074] The terminal obtains the transition colors generated by each edge color and the main color. The number of transition colors is the same as the number of edge colors. For multiple transition colors, they can be spliced ​​to form a gradient color.

[0075] There are many ways of splicing, which can be to splice the transition colors randomly or to splice the transition colors according to the connection order of the edge colors. In this way, the color sorting effect of the gradient color obtained is more consistent with the color sorting effect of the target image, thereby increasing the visual effect.

[0076] In the present application, the main color and each edge color are merged into a transition color, and then multiple transition colors are spliced ​​into a gradient color, so that the gradient color obtained fully reflects each color in the target image. As an optional implementation, the main color and multiple edge colors can also be mixed into a gradient color, but the gradient color obtained in this way is not clearly divided. The gradient color formed by splicing multiple transition colors has a clearer color division and a more obvious gradient effect.

[0077] In addition, the present application adopts an intelligent gradient color generation algorithm, which can automatically generate natural and smooth gradient colors according to the main color and edge color of the image, thereby enhancing the visual beauty of the image. Compared with the existing technologies, most of which require users to manually adjust color parameters and lack intelligent and automated processing methods, the present application meets the needs of users to quickly process images.

[0078] As an optional implementation, the RGB color and transparent color corresponding to the primary color and the edge color are calculated to generate a transition color, including: determining the R color, G color, B color and transparent color of the primary color, and determining the R color, G color, B color and transparent color of the edge color; using a linear interpolation formula to process the R color, G color and B color corresponding to the primary color and the edge color respectively to obtain the RGB color of the transition color; determining the transparent color of the transition color according to the mean of the transparent color of the primary color and the transparent color of the edge color; generating the color of the transition color according to the RGB color and transparent color of the transition color.

[0079] The terminal determines the R color, G color, B color and transparent color of the primary color, and determines the R color, G color, B color and transparent color of the edge color. The terminal uses a linear difference formula to process the corresponding R color, G color and B color between the primary color and the edge color respectively, and obtains the R color, G color and B color of the transition color, and then calculates the mean of the transparent color of the primary color and the transparent color of the edge color, and uses the mean as the transparent color of the transition color. In this way, the RGB color and transparent color of the transition color are obtained, and the color of the transition color can be determined.

[0080] Specifically, determining the transition color between the main color and the edge color is a key step in creating a smooth color gradient. The calculation of this transition color involves precise adjustment of each dimension in the color space (usually red, green, blue, and transparency). The following is a detailed process description:

[0081] 1. Extraction of color information: First, the terminal needs to extract the color information of the main color and edge color from the image. This means that for each color, it is necessary to determine the values ​​of its three RGB (red, green, and blue) channels, as well as the value of the transparent color (usually expressed as the alpha channel), which can be obtained by analyzing and calculating the pixel values ​​of the corresponding area in the image.

[0082] 2. Calculation of color difference: The terminal will use linear interpolation to calculate the transition values ​​of each color channel between the main color and the edge color. Linear interpolation is a simple mathematical method that assumes that the color changes evenly between two known values. For each color channel (R, G, B), the following formula is used to calculate the transition color:

[0083] transition_color=main_color*t+edge_color*(1-t)

[0084] Among them, transition_color is the transition color, main_color is the main color value, edge_color is the edge color value, and t is the linear interpolation coefficient. t is an interpolation factor between 0 and 1, which determines whether the transition color is closer to the main color or the edge color.

[0085] 3. Calculation of transparency: For the transparency of transition colors, it is necessary to calculate the average transparency of the main color and the edge color. This method assumes that the transparency changes linearly between the two colors. The calculation formula is as follows:

[0086] transition_alpha=(main_alpha+edge_alpha) / 2

[0087] Among them, transition_alpha is the transparency of the transition color, main_alpha and edge_alpha are the transparency of the main color and edge color respectively.

[0088] 4. Synthesis of transition colors: The R color, G color, B color and transparent color of the transition color are obtained through the above steps. These values ​​together define the complete RGBA color information of the transition color. In this way, the terminal can use these values ​​to render or display image areas with smooth color transitions.

[0089] In the present application, by accurately calculating and defining transition colors, rich visual effects can be achieved in digital images while maintaining color harmony and consistency.

[0090] For each edge color, the linear interpolation formula needs to be calculated three times, that is, the RGB value of the transition color corresponding to the edge color is calculated.

[0091] For any edge color, the following three formulas are needed to calculate the RGB value of the corresponding transition color:

[0092] transition_colorR=main_colorR*t+edge_colorR*(1-t), wherein transition_colorR is the R color of the transition color, main_colorR is the R color of the main color value, edge_colorR is the R color of the edge color value, and t is the linear interpolation coefficient.

[0093] transition_colorG=main_colorG*t+edge_colorG*(1-t), where transition_colorG is the G color of the transition color, main_colorG is the G color of the main color value, edge_colorG is the G color of the edge color value, and t is the linear interpolation coefficient.

[0094] transition_colorB=main_colorB*t+edge_colorB*(1-t), where tBansition_colorB is the B color of the transition color, main_colorB is the B color of the main color value, edge_colorB is the B color of the edge color value, and t is the linear interpolation coefficient.

[0095] As an optional implementation, a sliding window is used to slide on the edge of a target image to extract at least one edge color of the target image, including: using a Sobel operator to extract an edge image of the target image; using a sliding window to traverse the edge image, and merging adjacent pixels of the same color in the edge image as a kind of edge color.

[0096] The terminal uses the Sobel operator to extract the edge image of the target image. The specific process of extracting the edge image is: convert the color target image into a grayscale image, use the Sobel operator to calculate the gradient of the grayscale image in the horizontal direction (Gx) and the vertical direction (Gy), and then calculate the gradient amplitude G and direction θ. According to the calculated gradient amplitude G, a threshold can be set to extract the edge. If the gradient amplitude of a pixel position is higher than the threshold, the pixel is considered to be part of the edge; if it is lower than the threshold, it is not an edge. This process is called thresholding.

[0097] Among them, the calculation formula of amplitude G and direction θ is:

[0098] Amplitude:

[0099] direction:

[0100] The sliding window in the embodiment of the present application is of variable length, and the window range is represented by two left and right pointers. Starting from the upper left corner of the edge image, the left pointer does not move. If the colors of the adjacent pixels on the right are consistent, the right pointer moves one window to the right until pixels of different colors are detected. The color in the entire window is recorded as an edge color. The left pointer moves to the first pixel of the different color, and the right pointer continues to move one window to the right to detect whether the color of the next pixel is consistent with the color of the pixel just slid. If they are consistent, continue to slide to the right. If they are inconsistent, the color in the entire window is recorded as an edge color. Continue the above process until the entire edge image is traversed.

[0101] In an embodiment of the present application, a sliding window of variable length can be used to detect and record color edges in edge images. The key to this method is to use two pointers to define the scope of the window and dynamically adjust the size of the window through specific rules. The following is a detailed description of the process.

[0102] 1. Initialize the sliding window: First, place the sliding window in the upper left corner of the edge image. This window is defined by two pointers: the left pointer and the right pointer. Initially, both pointers are located at the far left of the image and the size of the window is zero.

[0103] 2. Window sliding and color detection: The left pointer is fixed at first, and the right pointer starts to move to the right. Check whether the color of the pixel pointed by the right pointer is consistent with the color of the pixel pointed by the left pointer. If so, the right pointer continues to move one pixel to the right to expand the range of the window.

[0104] 3. Edge color recording: When the right pointer encounters a pixel with a different color from the pixel pointed by the left pointer, it indicates that a color edge has been reached. At this time, the color in the entire window is recorded as an edge color.

[0105] 4. Window reset and continued detection: Next, the left pointer moves to the first pixel position of the detected different color, and the right pointer moves one pixel to the right again, starting a new round of window expansion and color detection. This process is repeated: if the color of the pixel pointed by the right pointer is consistent with the color of the pixel pointed by the left pointer, the right pointer continues to move to the right; if not, the color in the current window is recorded as the new edge color.

[0106] 5. Traverse the entire image: By continuing the above process, the entire edge image can be traversed. Each time a color change is detected, the color in the current window is recorded as the edge color, and the left pointer is moved to the new color boundary to start a new window. In this way, all significant color edges in the image can be gradually and continuously identified.

[0107] 6. Complete traversal: When the left pointer returns to the upper left corner of the image again, the entire traversal process is completed. At this time, all color edges in the image have been recorded and detection can be stopped.

[0108] Through this variable-length sliding window technique, color edges in edge images can be effectively identified and recorded without presetting the window size. This method is suitable for images with color gradients and uneven distributions because it allows the window to dynamically adapt to changes in local color features.

[0109] As an optional implementation, before extracting the main color of the target image by a clustering method, the method also includes: converting the file stream of the target image into an RGBA format, wherein the RGBA format is used to represent a color space of red, green, blue, and transparency; and converting the RGBA format into an HSV or Lab color space.

[0110] Digital images can be stored in a variety of formats, including but not limited to JPEG, PNG, GIF, BMP, etc. These formats may differ in how they store color information. For example, some images may be in RGB (red-green-blue) format, while others may be in CMYK (cyan-magenta-yellow-black) format, which is used for printing. The RGB format is commonly used for screen display, and each channel has a value ranging from 0 to 255. Some images may only have grayscale information, or may contain an alpha channel (transparency information, i.e. RGBA).

[0111] In order to process them uniformly, you first need to convert all images to a common format. RGBA is a common choice because it contains not only color information but also transparency information. This can be done with image processing software or programming libraries. For example, if the original image is in JPEG format, you need to convert it to RGBA format to ensure that each pixel has four channels of information.

[0112] Although the RGB color space is widely used in electronic display devices, it is not the most convenient choice for some color analysis tasks. HSV and Lab color spaces are more suitable for color recognition and processing.

[0113] In the HSV color space, hue indicates the type of color, such as red, green, etc.; saturation indicates the purity of the color, and high saturation means a brighter color; value indicates the brightness of the color. One advantage of the HSV color space is that it separates color information (hue and saturation) from brightness information (brightness), which makes it easier to identify colors when lighting conditions change.

[0114] In the Lab color space, the L component represents the brightness of the color, the a component represents the color in the range from magenta to green, and the b component represents the color in the range from yellow to blue. The Lab color space is a color model based on human eye perception. It covers all colors visible to the human eye and is distributed in a uniform manner, which means that the visual difference between colors is proportional to their distance in the Lab space.

[0115] In HSV or Lab color space, it is more convenient to perform color processing tasks such as main color extraction and edge color extraction. These operations are more intuitive and accurate in HSV or Lab color space because the structure of these spaces is closer to human perception of color.

[0116] As an optional implementation manner, generating a fused image according to the target image and the gradient color includes two embodiments.

[0117] In one embodiment, a canvas is generated according to the length and width of the application interface, and the target image is drawn onto the canvas. If the target image does not fill the entire canvas, a gradient color is used to fill the blank area outside the target image.

[0118] Specifically, considering that the pictures selected by users may have various sizes and resolutions, which may not be suitable for the application interface, if the pictures are simply cropped or scaled to fit the size of the application interface, part of the picture content may be lost or the image may be deformed. Therefore, the blank area is filled with gradient colors so that the generated new picture can just fit the size of the application interface, and then the new picture is used as the background image of the application interface. The gradient color filling area is determined according to the length and width of the application interface and the picture. Specifically, if the length and width of the target picture are both smaller than the length and width of the application interface, the gradient color is used to fill the surroundings of the target picture, that is, the blank area is filled with gradient colors so that the length and width of the new picture just fit the length and width of the application interface, that is, the filled picture can just fit into the application interface.

[0119] In two embodiments, a blank image of a corresponding size is generated according to the size of the application interface; the blank image is filled with gradient colors; the target image is inserted into the filled blank image, and the transparency of the target image is set to be reduced.

[0120] First, according to the size of the application interface, i.e., width and height, these sizes will be used to determine the size of the blank image generated. Use image editing software (such as Photoshop, GIMP, etc.) or programming libraries (such as Python's PIL or Pillow library) to create a new image file whose size is consistent with the size of the application interface. At this point, the image is a completely blank canvas without any content. Use gradient colors to fill the blank image, thereby creating a visual effect of a smooth transition from one color to another. Import the pre-prepared target image into the image filled with gradient colors. The size of the target image should be smaller than the size of the blank image so that it can be placed on the background without covering the entire background. The effect produced at this time is consistent with the effect in the first embodiment. On this basis, in order to make the target image more integrated with the background, its transparency can be reduced. This can be achieved by adjusting the alpha channel of the image to make it partially transparent, so that the gradient color of the background can be displayed through the target image. The specific value of transparency depends on the design intent and the needs of visual effects. After completing the above steps, the final image will be a blank image with a gradient background, containing a smaller target image with reduced transparency. This effect makes the target image appear more prominent while blending into the background, creating a modern and visually appealing design.

[0121] The size of the blank image in this application is set according to the size of the application interface, so that the blank image can be directly used as the background image of the application interface after filling. The size of the application interface and the size of its newly generated background image are highly adapted, without the need for image stretching, to avoid reduced image clarity.

[0122] Based on the same technical concept, the embodiment of the present application also provides a schematic diagram of the overall process of a method for generating a new image based on gradient colors, such as Figure 5 As shown, the following steps are included:

[0123] Step 501: The target image is uploaded to the system.

[0124] Step 502: extracting the main color of the target image by clustering method.

[0125] Step 503: Use the Sobel operator to extract the edge image of the target image; use a sliding window to traverse the edge image, and merge adjacent pixels with the same color in the edge image into one edge color.

[0126] Step 504: Calculate the RGB colors corresponding to the primary color and an edge color using a linear interpolation formula to generate an RGB color of a transition color.

[0127] Step 505: performing mean processing on the transparent color of the main color and the transparent color of the edge color to obtain the transparent color of the transition color;

[0128] Step 506: Determine the transition color according to the RGB color and the transparent color of the transition color.

[0129] Step 507: Combine multiple transition colors to generate gradient colors.

[0130] Step 508: Draw the target image onto the cancas canvas, and fill the blank area except the target image with a gradient color.

[0131] Step 509: A blank image is filled with gradient colors as the background, and the transparency of the target image is set to be lowered after the target image is inserted.

[0132] Among them, step 508 and step 509 are parallel steps, and one of the steps can be selected to be executed.

[0133] Generate a fused image based on the target image and gradient color.

[0134] Based on the same technical concept, the embodiment of the present application also provides a device for generating a new image based on gradient colors, such as Figure 6 As shown, the device comprises:

[0135] A first extraction module 601 is used to extract the main color of the target image by clustering method;

[0136] A second extraction module 602 is used to slide a sliding window on the edge of the target image to extract at least one edge color of the target image;

[0137] A processing module 603 is used to process the main color and at least one edge color to generate a gradient color;

[0138] The generating module 604 is used to generate a fused image according to the target image and the gradient color.

[0139] Optionally, the processing module 603 is used to:

[0140] Traverse the edge colors, calculate the corresponding RGB colors and transparent colors between the main color and the edge color, and generate a transition color;

[0141] Combine multiple transition colors to generate gradient colors.

[0142] Optionally, the processing module 603 is used to:

[0143] Determine the R color, G color, B color and transparent color of the main color, and determine the R color, G color, B color and transparent color of the edge color;

[0144] The linear interpolation formula is used to process the R color, G color and B color corresponding to the main color and the edge color respectively to obtain the RGB color of the transition color;

[0145] Determine the transparent color of the transition color according to the average of the transparent color of the main color and the transparent color of the edge color;

[0146] Generates the color of the transition color based on the RGB color of the transition color and the transparent color.

[0147] Optionally, the linear interpolation formula is calculated as:

[0148] transition_color=main_color*t+edge_color*(1-t), where transition_color is the transition color, main_color is the main color value, edge_color is the edge color value, and t is the linear interpolation coefficient.

[0149] Optionally, the second extraction module 602 is used to:

[0150] Use Sobel operator to extract the edge image of the target image;

[0151] A sliding window is used to traverse the edge image, and adjacent pixels with the same color in the edge image are merged as one edge color.

[0152] Optionally, the device is also used for:

[0153] Convert the file stream of the target image into RGBA format, where the RGBA format is used to represent the color space of red, green, blue and transparency;

[0154] Convert RGBA format to HSV or Lab color space.

[0155] Optionally, the generating module 604 is used to:

[0156] Generate a blank image of corresponding size according to the size of the application interface;

[0157] Fill the blank image with gradient colors;

[0158] Insert the target image into the filled blank image and set the transparency of the target image to be lowered.

[0159] Based on the same technical concept, an embodiment of the present invention further provides an electronic device, such as Figure 7 As shown, it includes a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702, and the memory 703 communicate with each other through the communication bus 704.

[0160] Memory 703, used for storing computer programs;

[0161] The processor 701 is used to implement the above steps when executing the program stored in the memory 703.

[0162] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0163] The communication interface is used for communication between the above electronic device and other devices.

[0164] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0165] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0166] In another embodiment of the present invention, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium. When the computer program is executed by a processor, the steps of implementing any of the above methods include the following contents:

[0167] Extract the main color of the target image through clustering method;

[0168] A sliding window is used to slide on the edge of the target image to extract at least one edge color of the target image;

[0169] Processing the main color and at least one edge color to generate a gradient color;

[0170] Generate a fused image based on the target image and gradient color.

[0171] Optionally, processing the primary color and at least one edge color to generate a gradient color includes:

[0172] Traverse the edge colors, calculate the corresponding RGB colors and transparent colors between the main color and the edge color, and generate a transition color;

[0173] Combine multiple transition colors to generate gradient colors.

[0174] Optionally, the corresponding RGB colors and transparent colors between the primary color and the edge color are calculated to generate a transition color including:

[0175] Determine the R color, G color, B color and transparent color of the main color, and determine the R color, G color, B color and transparent color of the edge color;

[0176] The linear interpolation formula is used to process the R color, G color and B color corresponding to the main color and the edge color respectively to obtain the RGB color of the transition color;

[0177] Determine the transparent color of the transition color according to the average of the transparent color of the main color and the transparent color of the edge color;

[0178] Generates the color of the transition color based on the RGB color of the transition color and the transparent color.

[0179] Optionally, the linear interpolation formula is calculated as:

[0180] transition_color=main_color*t+edge_color*(1-t), where transition_color is the transition color, main_color is the main color value, edge_color is the edge color value, and t is the linear interpolation coefficient.

[0181] Optionally, using a sliding window to slide on an edge of the target image to extract at least one edge color of the target image includes:

[0182] Use Sobel operator to extract the edge image of the target image;

[0183] A sliding window is used to traverse the edge image, and adjacent pixels with the same color in the edge image are merged as one edge color.

[0184] Optionally, before extracting the main color of the target image by a clustering method, the method further includes:

[0185] Convert the file stream of the target image into RGBA format, where the RGBA format is used to represent the color space of red, green, blue and transparency;

[0186] Convert RGBA format to HSV or Lab color space.

[0187] Optionally, generating a fused image according to the target image and the gradient color includes:

[0188] Generate a blank image of corresponding size according to the size of the application interface;

[0189] Fill the blank image with gradient colors;

[0190] Insert the target image into the filled blank image and set the transparency of the target image to be lowered.

[0191] In another embodiment of the present invention, a computer program product including instructions is provided, which enables the computer to execute any one of the methods in the above embodiments when the computer program product is executed on the computer.

[0192] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0193] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0194] 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 generating a new image based on gradient color, characterized in that: The method comprises: Extract the main color of the target image through clustering method; Sliding a sliding window along the edge of the target image to extract at least one edge color of the target image; Processing the primary color and the at least one edge color to generate a gradient color; A fused image is generated according to the target image and the gradient color.

2. The method according to claim 1, characterized in that Processing the primary color and the at least one edge color to generate a gradient color includes: Traversing the edge colors, calculating the RGB colors and transparent colors corresponding to the primary color and the edge colors, and generating a transition color; A plurality of the transition colors are spliced ​​to generate the gradient color.

3. The method according to claim 2, characterized in that Calculating the RGB color and transparent color corresponding to the primary color and the edge color to generate a transition color includes: Determine the R color, G color, B color and transparent color of the primary color, and determine the R color, G color, B color and transparent color of the edge color; The R color, G color and B color corresponding to the primary color and the edge color are processed respectively by using a linear interpolation formula to obtain the RGB color of the transition color; Determine the transparent color of the transition color according to the average of the transparent color of the primary color and the transparent color of the edge color; The color of the transition color is generated according to the RGB color of the transition color and the transparent color.

4. The method according to claim 3, characterized in that The linear interpolation formula is calculated as: transition_color=main_color*t+edge_color*(1-t), where transition_color is the transition color, main_color is the main color value, edge_color is the edge color value, and t is the linear interpolation coefficient.

5. The method according to claim 1, characterized in that Sliding a sliding window along an edge of the target image to extract at least one edge color of the target image comprises: Using the Sobel operator to extract the edge image of the target image; The edge image is traversed by using a sliding window, and adjacent pixels with the same color in the edge image are merged as an edge color.

6. The method according to claim 1, characterized in that Before extracting the main color of the target image by a clustering method, the method further includes: Convert the file stream of the target image into an RGBA format, wherein the RGBA format is used to represent a color space of red, green, blue, and transparency; Convert the RGBA format to HSV or Lab color space.

7. The method according to claim 1, characterized in that Generating a fused image according to the target image and the gradient color includes: Generate a blank image of corresponding size according to the size of the application interface; Filling the blank image with the gradient color; The target image is inserted into the filled blank image, and the transparency of the target image is set to be reduced.

8. A device for generating a new image based on gradient colors, characterized in that: The device comprises: A first extraction module, used for extracting the main color of the target image by clustering method; A second extraction module, configured to slide a sliding window along an edge of the target image to extract at least one edge color of the target image; A processing module, used for processing the main color and the at least one edge color to generate a gradient color; A generating module is used to generate a fused image according to the target image and the gradient color.

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 the method steps described in any one of claims 1 to 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 steps described in any one of claims 1 to 7 are implemented.