[go: up one dir, main page]

CN120107409A - Image color replacement method, device, equipment and storage medium - Google Patents

Image color replacement method, device, equipment and storage medium Download PDF

Info

Publication number
CN120107409A
CN120107409A CN202510113962.6A CN202510113962A CN120107409A CN 120107409 A CN120107409 A CN 120107409A CN 202510113962 A CN202510113962 A CN 202510113962A CN 120107409 A CN120107409 A CN 120107409A
Authority
CN
China
Prior art keywords
color
image
current
target
region
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202510113962.6A
Other languages
Chinese (zh)
Inventor
王静
马坤
童小敏
苏嘉鹏
赵培源
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xi'an Clover Cyber Technology Co ltd
Original Assignee
Xi'an Clover Cyber Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xi'an Clover Cyber Technology Co ltd filed Critical Xi'an Clover Cyber Technology Co ltd
Priority to CN202510113962.6A priority Critical patent/CN120107409A/en
Publication of CN120107409A publication Critical patent/CN120107409A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T11/002D [Two Dimensional] image generation
    • G06T11/40Filling a planar surface by adding surface attributes, e.g. colour or texture

Landscapes

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

Abstract

The application discloses an image color replacement method, device, equipment and storage medium, wherein the scheme automatically performs color replacement according to target theme colors selected by users, so that pictures with uniform styles and good visual effects are generated, and the efficiency of performing image color replacement is improved; in addition, by further adjusting the colors of the color areas, the color of each color area can be accurately replaced, and the accuracy of image color replacement is improved.

Description

Image color replacement method, device, equipment and storage medium
Technical Field
The present application relates to the field of image processing technologies, and in particular, to an image color replacement method, apparatus, device, and storage medium.
Background
Image processing plays an important role in modern design and development work. Especially in the fields of website development, application development, advertisement production, user interface design (UI design for short), etc., quick adjustment and replacement of image colors are common demands in daily work. Many developers also need to adjust the picture color to different scene, theme or branding requirements when processing images.
Currently, with the popularization of front-end development, UI component libraries and design systems, developers often need to quickly achieve the uniformity of images and UI topics. Whether adjusting the color of a picture or automatically changing the hue of a picture according to different topics, these tasks often require frequent collaboration between designers and developers. Without automation tools, developers have to rely on UI designers to provide modified images, both wasting time and increasing development cycles.
Therefore, the existing image color replacement method has a problem of low efficiency.
Disclosure of Invention
The present application aims to solve at least the technical problems existing in the prior art, and therefore, a first aspect of the present application provides an image color replacement method, which includes:
acquiring the current image color corresponding to the image to be processed and the target theme color determined by the user;
adjusting the color of the current image based on the target theme color to obtain a new image;
Under the condition that the new image does not meet the first preset condition, carrying out color region identification on the new image to obtain a plurality of color regions, the current region colors corresponding to the color regions and the current region sizes;
and aiming at each color region, acquiring a target region color determined by a user from a preset color selector corresponding to the color region, and replacing the current region color based on the target region color and the current region size of the color region to obtain a target image.
In one possible implementation, adjusting the color of the current image based on the target theme color results in a new image, including:
Performing color space conversion processing on the current image color to generate a converted image color, wherein the color space of the converted image color is consistent with the color space of the target theme color;
calculating the current similarity between the converted image color and the target theme color;
And adjusting the color of the current image based on the current similarity and the target theme color to obtain a new image.
In one possible implementation, performing a color space conversion process on a current image color to generate a converted image color includes:
carrying out normalization processing on RGB values of the current image color to obtain a normalization result;
Calculating to obtain the current brightness, the current tone and the current saturation based on the maximum value and the minimum value in the normalization result;
based on the current brightness, the current hue and the current saturation, a converted image color is obtained.
In one possible implementation, the current similarity includes a first similarity, and the adjusting the color of the current image based on the current similarity and the target theme color to obtain a new image includes:
acquiring a first tone corresponding to the current image color and a second tone corresponding to the target theme color, and acquiring a first similarity between the first tone and the second tone;
Under the condition that the first similarity meets a second preset condition, replacing the first tone with a second tone;
Adjusting the first saturation and the first brightness corresponding to the current image color to obtain the second saturation and the second brightness;
And adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain a new image.
In one possible implementation, adjusting the color of the current image based on the second hue, the second saturation, the second brightness, and the target theme color results in a new image, including:
for each target pixel in the image to be processed, replacing the current image color corresponding to each target pixel with a target theme color to obtain a new pixel;
based on the second hue, the second saturation, the second brightness and each new pixel, a new image is obtained.
In one possible implementation, the adjusting the color of the current image based on the second hue, the second saturation, the second brightness, and the target theme color to obtain the new image further includes:
For each color region in the image to be processed, replacing the current image color corresponding to each color region with a target theme color to obtain a new color region;
based on the second hue, the second saturation, the second brightness and the respective new color areas, a new image is obtained.
In one possible implementation, the adjusting the color of the current image based on the second hue, the second saturation, the second brightness, and the target theme color to obtain the new image further includes:
adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain an intermediate image;
and acquiring an edge area of the intermediate image, and processing the edge area by adopting a preset gradual change algorithm to obtain a new image.
A second aspect of the present application proposes an image color replacement apparatus, the apparatus comprising:
the acquisition module is used for acquiring the current image color corresponding to the image to be processed and the target theme color determined by the user;
the adjusting module is used for adjusting the color of the current image based on the target theme color to obtain a new image;
The identification module is used for carrying out color region identification on the new image under the condition that the new image does not meet the first preset condition to obtain a plurality of color regions, the current region colors corresponding to the color regions and the current region sizes;
The replacing module is used for acquiring the color of the target area determined by the user from the preset color selector corresponding to the color area aiming at each color area, and replacing the color of the current area based on the color of the target area and the current area size of the color area to obtain a target image.
In one possible implementation manner, the adjusting module is specifically configured to:
Performing color space conversion processing on the current image color to generate a converted image color, wherein the color space of the converted image color is consistent with the color space of the target theme color;
calculating the current similarity between the converted image color and the target theme color;
And adjusting the color of the current image based on the current similarity and the target theme color to obtain a new image.
In one possible implementation manner, the adjusting module is further configured to:
carrying out normalization processing on RGB values of the current image color to obtain a normalization result;
Calculating to obtain the current brightness, the current tone and the current saturation based on the maximum value and the minimum value in the normalization result;
based on the current brightness, the current hue and the current saturation, a converted image color is obtained.
In one possible implementation manner, the current similarity includes a first similarity, and in one possible implementation manner, the adjustment module is further configured to:
acquiring a first tone corresponding to the current image color and a second tone corresponding to the target theme color, and acquiring a first similarity between the first tone and the second tone;
Under the condition that the first similarity meets a second preset condition, replacing the first tone with a second tone;
Adjusting the first saturation and the first brightness corresponding to the current image color to obtain the second saturation and the second brightness;
And adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain a new image.
In one possible implementation manner, the adjusting module is further configured to:
for each target pixel in the image to be processed, replacing the current image color corresponding to each target pixel with a target theme color to obtain a new pixel;
based on the second hue, the second saturation, the second brightness and each new pixel, a new image is obtained.
In one possible implementation manner, the adjusting module is further configured to:
For each color region in the image to be processed, replacing the current image color corresponding to each color region with a target theme color to obtain a new color region;
based on the second hue, the second saturation, the second brightness and the respective new color areas, a new image is obtained.
In one possible implementation manner, the adjusting module is further configured to:
adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain an intermediate image;
and acquiring an edge area of the intermediate image, and processing the edge area by adopting a preset gradual change algorithm to obtain a new image.
A third aspect of the present application proposes an electronic device comprising a processor and a memory, the memory storing at least one instruction, at least one program, a set of codes or a set of instructions, the at least one instruction, the at least one program, the set of codes or the set of instructions being loaded and executed by the processor to implement the image color replacement method according to the first aspect.
A fourth aspect of the present application proposes a computer readable storage medium having stored therein at least one instruction, at least one program, a set of codes or a set of instructions, the at least one instruction, the at least one program, the set of codes or the set of instructions being loaded and executed by a processor to implement the image color replacement method according to the first aspect.
The embodiment of the application has the following beneficial effects:
The image color replacement method comprises the steps of obtaining a current image color corresponding to an image to be processed and a target theme color determined by a user, adjusting the current image color based on the target theme color to obtain a new image, carrying out color region identification on the new image under the condition that the new image does not meet a first preset condition to obtain a plurality of color regions, current region colors corresponding to the color regions and current region sizes, obtaining the target region color determined by the user from a preset color selector corresponding to the color regions for each color region, and replacing the current region color based on the target region color and the current region sizes of the color regions to obtain the target image. According to the scheme, the color replacement is automatically carried out according to the target theme color selected by the user, so that the picture with uniform style and good visual effect is generated, and the efficiency of carrying out the image color replacement is improved; in addition, by further adjusting the colors of the color areas, the color of each color area can be accurately replaced, and the accuracy of image color replacement is improved.
Drawings
FIG. 1 is a block diagram of a computer device according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating steps of an image color replacement method according to an embodiment of the present application;
FIG. 3 is a flowchart illustrating steps for obtaining a new image according to an embodiment of the present application;
FIG. 4 is a flowchart illustrating steps for generating converted image colors according to an embodiment of the present application;
FIG. 5 is a flowchart illustrating steps for adjusting the color of a current image according to an embodiment of the present application;
FIG. 6 is a flowchart illustrating another step of adjusting the color of a current image according to an embodiment of the present application;
FIG. 7 is a flowchart illustrating steps for adjusting the color of a current image according to an embodiment of the present application;
FIG. 8 is a flowchart illustrating steps for adjusting the color of a current image according to an embodiment of the present application;
fig. 9 is a block diagram of an image color replacement apparatus according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
With the popularity of front-end development, UI component libraries and design systems, developers often need to quickly achieve the uniformity of images and UI topics. Whether adjusting the color of a picture or automatically changing the hue of a picture according to different topics, these tasks often require frequent collaboration between designers and developers. Without automation tools, developers have to rely on UI designers to provide modified images, both wasting time and increasing development cycles. Therefore, it is important to be able to automatically perform image color replacement, whether according to a specified color replacement or intelligently adjusting according to a theme color.
Existing image processing tools often fail to meet these requirements, especially when multiple picture formats (e.g., JPG, PNG, SVG, etc.) need to be supported and seamless integration is achieved in different development environments. Therefore, most of image processing tools in the prior art need to manually select color areas, are difficult to process complex images efficiently, have low automatic color recognition and replacement accuracy, are difficult to accurately position the color areas in multicolor images, cannot realize intelligent adjustment of the color tone of the whole image aiming at the theme colors input by the user, can only realize simple color filling and has poor visual effect, and in addition, some tools have poor support on vector images in common formats and influence application scenes in cross formats.
Based on the above, the application provides an image color replacement method, which comprises the steps of obtaining a current image color corresponding to an image to be processed and a target theme color determined by a user, adjusting the current image color based on the target theme color to obtain a new image, carrying out color region identification on the new image under the condition that the new image does not meet a first preset condition to obtain a plurality of color regions, current region colors corresponding to the color regions and current region sizes, obtaining the target region color determined by the user from a preset color selector corresponding to the color regions for each color region, and replacing the current region color based on the target region color and the current region sizes of the color regions to obtain the target image. According to the scheme, the color replacement is automatically carried out according to the target theme color selected by the user, so that the picture with uniform style and good visual effect is generated, and the efficiency of carrying out the image color replacement is improved; in addition, by further adjusting the colors of the color areas, the color of each color area can be accurately replaced, and the accuracy of image color replacement is improved.
The terms "first" and "second" are used below for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include one or more such feature. In the description of the embodiments of the present disclosure, unless otherwise indicated, the meaning of "a plurality" is two or more. In addition, the use of "based on" or "according to" is intended to be open and inclusive in that a process, step, calculation, or other action "based on" or "according to" one or more of the stated conditions or values may in practice be based on additional conditions or beyond the stated values.
The image color replacement method provided by the application can be applied to computer equipment (electronic equipment), wherein the computer equipment can be a server or a terminal, the server can be one server or a server cluster consisting of a plurality of servers, the embodiment of the application is not particularly limited to the embodiment, and the terminal can be but not limited to various personal computers, notebook computers, smart phones, tablet computers and portable wearable equipment.
Taking the example of a computer device being a server, FIG. 1 illustrates a block diagram of a server, as shown in FIG. 1, which may include a processor and memory connected by a system bus. Wherein the processor of the server is configured to provide computing and control capabilities. The memory of the server includes nonvolatile storage medium and internal memory. The nonvolatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The computer program is executed by a processor to implement an image color replacement method.
It will be appreciated by those skilled in the art that the structure shown in fig. 1 is merely a block diagram of a portion of the structure associated with the present inventive arrangements and does not constitute a limitation of the servers to which the present inventive arrangements are applied, alternatively the servers may include more or less components than those shown, or may combine certain components, or have different arrangements of components.
The execution subject of the embodiment of the present application may be a computer device or an image color replacement device, and in the following method embodiment, the execution subject is described with reference to the computer device.
Fig. 2 is a flowchart of steps of an image color replacement method according to an embodiment of the present application. As shown in fig. 2, the method comprises the steps of:
step 202, obtaining the current image color corresponding to the image to be processed and the target theme color determined by the user.
The format of the image to be processed may be various, and the embodiment of the application is not limited in particular, and the mode improves the universality and flexibility of image color replacement, and may be, for example, JPG, PNG, JPEG, SVG or other various image formats.
The user can upload the image to be processed in advance, and after the image to be processed is uploaded, the file format can be read through FILERENDER and beforeUpload events of the JavaScript uploading file, and whether the image format limit is met or not is identified. In addition, for the Raster image, i.e., for the JPG, PNG, JPEG format image, the File Render.readAsDataURL can be used to read the file as a Data URL, and the SVG format image can be parsed using DOMParser.
The FILERENDER is mainly used for writing file data into an output stream, so as to return file contents to a client. The beforeUpload event is used to perform some operations prior to file upload, and the operations required by the user, such as verifying file type, size, etc., can be performed in the callback function of this event. The master image is a grid-like image formed by arranging a plurality of pixels, each representing a point in the image. readAsDataURL is a FileReader object method for reading a specified file as DataURL, i.e., a string in the data URL format.
SVG files are an XML-based vector graphics file format that uses mathematical formulas to describe the shape, color, and position of graphics so that it can be parsed using DOMParser, DOMParser is an API for parsing HTML or XML documents that allows developers to convert HTML or XML documents in the form of strings into an operable document object model Document Object Model, DOM for short.
The current image color corresponding to the image to be processed is the current color of each pixel, and the color of each pixel in the image is stored in an RGB (red, green and blue) form.
The target theme colors determined by the user can be directly input by the user or can be selected by the user in a color selector. The target theme color can be expressed by a Hue-Saturation-luminance (HSL) color model, because the HSL model can more intuitively express Hue and can conveniently adjust the Saturation and luminance of color.
And 204, adjusting the color of the current image based on the target theme color to obtain a new image.
After the current image color and the target theme color determined by the user are obtained, the current image color can be adjusted based on the target theme color, so that a new image is obtained. In some alternative embodiments, the current image color may be replaced directly with the target theme color, resulting in a new image.
In other alternative embodiments, as shown in fig. 3, fig. 3 is a flowchart of a step of obtaining a new image according to an embodiment of the present application, including:
Step 302, performing color space conversion processing on the current image color to generate a converted image color.
Step 304, calculating the current similarity between the converted image color and the target theme color.
And 306, adjusting the color of the current image based on the current similarity and the target theme color to obtain a new image.
Wherein, since the current image color is stored in RGB form and the target subject color is stored in HSL form, for comparison and replacement of colors, a color space conversion process is required for the current image color, so that the current image color is converted from RGB to HSL, that is, the color space of the converted image color is consistent with the color space of the target subject color.
Optionally, in performing color space conversion processing, as shown in fig. 4, fig. 4 is a flowchart of steps for generating converted image colors according to an embodiment of the present application, including:
Step 402, performing normalization processing on the RGB values of the current image color to obtain a normalization result.
Step 404, calculating to obtain the current brightness, the current hue and the current saturation based on the maximum value and the minimum value in the normalization result.
Step 406, obtaining the converted image color based on the current brightness, the current hue and the current saturation.
The normalization processing may be performed on the RGB values of the current image color, that is, the color value of each pixel is divided by 255, so as to obtain a normalization result, where the normalized RGB values are in the range of [0,1 ].
Next, the maximum value max and the minimum value min in the normalization result can be determined, so that the current brightness l can be calculated based on the maximum value max and the minimum value min, namely
The current hue h and the current saturation s may be calculated based on a maximum value max, where if the maximum value max is equal to the minimum value min, it is indicated that the color is not hue, in which case h=0, s=0. If the maximum value max is not equal to the minimum value min, thenThe value of h can be calculated according to the position of the maximum value max, and the calculation mode of the current hue h depends on which color channel the maximum value comes from, and the specific calculation process can refer to the prior art, which is not described herein.
Finally, the converted image color can be derived based on the current brightness, the current hue, and the current saturation.
Then, the current similarity between the converted image color and the target theme color can be calculated, and the current image color is adjusted based on the current similarity and the target theme color, so that a new image is obtained. In some alternative embodiments, the current similarity may include a first similarity, as shown in fig. 5, where fig. 5 is a flowchart of a step for adjusting a current image color according to an embodiment of the present application, including:
Step 502, a first hue corresponding to the current image color and a second hue corresponding to the target theme color are obtained, and a first similarity between the first hue and the second hue is obtained.
Step 504, replacing the first tone with the second tone if the first similarity satisfies a second preset condition.
Step 506, adjusting the first saturation and the first brightness corresponding to the current image color to obtain the second saturation and the second brightness.
And step 508, adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain a new image.
When calculating the first similarity between the first hue and the second hue, the first similarity may be calculated by a euclidean distance algorithm, that is, the first similarity may be determined by a euclidean distance between the first hue and the second hue, or may be calculated by other algorithms, which is not limited in detail in the embodiment of the present application.
Therefore, the first tone may be replaced with the second tone when the first similarity meets a second preset condition, where the second preset condition may be a preset similarity threshold, and when the first similarity meets the preset similarity threshold, it is indicated that the first tone and the second tone are similar, that is, it is indicated that the difference between the current image color and the target theme color is small, and the first tone may be directly replaced with the second tone.
And then, according to the requirements of a user or the visual effect of the image, the first saturation and the first brightness corresponding to the color of the current image can be adjusted to obtain the second saturation and the second brightness, so that the visual effect of the target theme color can be more attached to the visual effect of the target theme color.
Finally, the current image color may be adjusted based on the second hue, the second saturation, the second brightness, and the target theme color to obtain a new image.
In some alternative embodiments, as shown in fig. 6, fig. 6 is a flowchart of another step for adjusting the color of a current image according to an embodiment of the present application, including:
step 602, replacing the current image color corresponding to each target pixel with the target theme color for each target pixel in the image to be processed, thereby obtaining a new pixel.
Step 604, obtaining a new image based on the second hue, the second saturation, the second brightness and each new pixel.
Each target pixel in the image to be processed is a pixel which is determined to need to be subjected to color replacement, so that the current image color corresponding to each target pixel can be replaced by the target theme color to obtain a new pixel, and finally, a new image is obtained based on a second tone, a second saturation, a second brightness and each new pixel, and the color replacement process is completed.
In other alternative embodiments, as shown in fig. 7, fig. 7 is a flowchart of a further step of adjusting a color of a current image according to an embodiment of the present application, including:
Step 702, replacing the current image color corresponding to each color area with the target theme color to obtain a new color area for each color area in the image to be processed.
Step 704, obtaining a new image based on the second hue, the second saturation, the second brightness and each new color region.
Besides performing color replacement on each pixel, each color area in the image to be processed can be adjusted, and the colors in the same color area are similar or identical, so that the current image color corresponding to each color area can be replaced by the target theme color to obtain a new color area, and finally, a new image can be obtained based on a second tone, a second saturation, a second brightness and each new color area, thereby completing the color replacement process.
In yet other alternative embodiments, as shown in fig. 8, fig. 8 is a flowchart of a further step of adjusting a color of a current image according to an embodiment of the present application, including:
Step 802, adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain an intermediate image.
Step 804, obtaining an edge area of the intermediate image, and processing the edge area by adopting a preset gradual change algorithm to obtain a new image.
After the color of the current image is adjusted based on the second hue, the second saturation, the second brightness and the target theme color, an intermediate image is obtained, the intermediate image can be further adjusted and optimized, namely, the edge area of the intermediate image can be obtained through related algorithms such as edge extraction, and the like, and then the edge area is processed through a preset gradual change algorithm, so that a new image is finally obtained. The specific process of processing the edge area may refer to the prior art, and will not be described herein.
In the embodiment of the application, through adopting a gradual change algorithm for some edge transition areas, the replaced color is smoothly transited so as to avoid obvious color difference contrast.
And 206, performing color region identification on the new image to obtain a plurality of color regions, the current region colors corresponding to the color regions and the current region sizes under the condition that the new image does not meet the first preset condition.
The first preset condition may be a preset overall image effect, where the overall image effect may be that the overall image color is coordinated and unified, and the local image color has no deviation from the true color, that is, when the new image does not meet the preset overall image effect, the new image may be subjected to color region identification, so as to obtain multiple color regions, and the current region color and the current region size corresponding to each color region.
Alternatively, the canvas context may be acquired first by canvas, the new image described above is drawn onto the canvas, and finally the pixel data of the image is acquired by GETIMAGEDATA () function. The regions are identified by using color similarity or an algorithm based on pixel adjacency, so that a plurality of color regions are obtained, which can ensure that the same color region is identified as a whole, and not just the color with the highest occurrence frequency is extracted.
The algorithm based on pixel adjacency can be a Flood Fill algorithm, which is an image region filling algorithm suitable for identifying a large region in an image. Areas of similar color can be identified by the Flood Fill algorithm, with the goal of finding one pixel area and applying the same color decision rule to adjacent pixels until a different color is encountered. After identification, each color region may be marked with its current region color and current region size.
Specifically, the Flood File uses a stack to implement region filling, and similar to depth-first search, starting from a starting point, checking whether the adjacent pixel is the same as the current pixel in color, and if so, adding to the stack to continue processing. The accessed pixels are recorded by a set to avoid repetitive computation and all pixel coordinates belonging to the same color area are stored in an array.
Optionally, for each color region, the area, that is, the number of pixels, is calculated, so that the duty ratio of the color region can be displayed according to the area, and finally, the current region size corresponding to each color region is obtained.
Step 208, for each color region, acquiring a target region color determined by a user from a preset color selector corresponding to the color region, and replacing the current region color based on the target region color and the current region size of the color region to obtain a target image.
After a plurality of color areas are identified, a target area color determined by a user from a preset color selector corresponding to the color areas can be obtained for each color area, and the current area color is replaced based on the target area color and the current area size of the color area, so that a target image is obtained.
Specifically, after the color region is identified, the current region color and the current region size can be displayed for the user to select. Optionally, color regions that allow replacement may also be highlighted, enabling the user to clearly see which color regions in the image are to be replaced, and quickly select the target region color for replacement.
And each color zone may be followed by a pre-set color selector to allow the user to select a new target zone color to replace. It should be noted that, the current area color and the target area color of each area can be displayed on the page at the same time, so that the user can make more visual selection and operation.
When the user selects the target area color on the page, the current area color needs to be replaced by the target area color designated by the user, and the pixel data of the image can be updated in a similar manner to the Flood Fill tree algorithm to realize the color replacement process.
In some alternative embodiments, after the image color replacement is completed, the next step is to export the processed target image into multiple formats. The characteristics of each format are different, and taking common JPEG, PNG, SVG as an example, different processing methods are adopted for different formats are shown below.
PNG is a lossless compressed image format supporting a transparent background, suitable for images requiring transparency or retaining details. For output in PNG format, the main step is to draw the processed image onto a < canvas > element, which is then converted into PNG data. The principle of operation is to use canvas.todataurl ("img/PNG") to convert the image data in < canvas > to Base64 encoded PNG data URL. In this way, the user can directly download the image. PNG has the advantage of preserving image detail, not causing quality loss, and supporting transparency. It is necessary to ensure proper processing of the transparent areas of the image during output.
JPEG is a lossy compression format suitable for situations where the image is rich in color and does not require transparency. It reduces file size by losing a portion of the image information and is therefore suitable for use with photographs and complex images. The principle of operation is that a canvas.todataurl ("img/JPEG", quality) method is used to generate a data URL in JPEG format by drawing the processed image onto < canvas >. quality parameters can be used to control the compression level, typically selecting between 0 and 1, the higher the value the better the image quality, but the larger the file size. The JPEG has the advantage of smaller format file, and is suitable for images with rich colors such as photos.
SVG is a vector graphics format suitable for simple graphics and icons. Unlike bitmap formats, SVG images are XML-based and can be scaled indefinitely without distortion. And thus are suitable for graphics, icons, and certain illustration types. The operation principle is that for an image to be converted into SVG, vectorization processing is needed to be carried out on the image first. This is typically done by image segmentation, color extraction and path generation algorithms. The path and color data are then saved using XML format to generate the SVG file. The advantage of SVG is that the format is lossless, infinitely scalable, applicable to icons, simplified graphics, etc.
In some alternative embodiments, a live preview function may also be added that allows the user to view effects in real time during image replacement in order to quickly adjust the color and check the results. The key for realizing the function is a real-time rendering and feedback mechanism, so that each step of change of image processing can be immediately presented, the user experience is improved, and the debugging time is shortened.
Specifically, the image uploaded by the user is loaded into the browser through file input, and the image is rendered in the page through < canvas > or other graphics processing means. At this time, the user can immediately see the original image, i.e., a preview of the image to be processed.
When the user adjusts the color, such as selecting a theme color or designating an alternate color, clicking on the alternate button, the system dynamically calculates the color alternate effect in the background. Each pixel of the image is adjusted according to the new color, and the processed target image is updated at any time and rendered on the canvas. This is achieved by real-time processing of the image data, ensuring that the user can see the changes quickly when adjusting.
And, the real-time feedback can be performed to immediately reflect the required image to the preview area every time the color is adjusted. For this reason, the system needs to calculate each color change and immediately draw a new image. During user interaction, the color difference can be calculated, namely, each time the user selects a new color, namely, a target theme color, the system calculates the difference between the image to be processed and the target theme color, and the current image color is adjusted according to the difference. For example, if the user selects a new target theme color, the color value of each pixel may be adjusted according to hue, saturation, and brightness. In addition, in order to improve user experience, the system can use gradual animation to smoothly transition to a new color state, so that gradual display is realized instead of instant replacement, and visual impact can be avoided.
The application provides an image color replacement method, which comprises the steps of obtaining a current image color corresponding to an image to be processed and a target theme color determined by a user, adjusting the current image color based on the target theme color to obtain a new image, carrying out color region identification on the new image under the condition that the new image does not meet a first preset condition to obtain a plurality of color regions, current region colors corresponding to the color regions and current region sizes, obtaining the target region color determined by the user from a preset color selector corresponding to the color regions for the color regions, and replacing the current region color based on the target region color and the current region sizes of the color regions to obtain the target image. According to the scheme, the color replacement is automatically carried out according to the target theme color selected by the user, so that the picture with uniform style and good visual effect is generated, and the efficiency of carrying out the image color replacement is improved; in addition, by further adjusting the colors of the color areas, the color of each color area can be accurately replaced, and the accuracy of image color replacement is improved.
It should be understood that, although the steps in the flowcharts related to the embodiments described above are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Fig. 9 is a block diagram of an image color replacement apparatus according to an embodiment of the present application.
As shown in fig. 9, the image color replacement apparatus 900 includes:
The obtaining module 902 is configured to obtain a current image color corresponding to the image to be processed and a target theme color determined by a user.
The adjusting module 904 is configured to adjust a current image color based on the target theme color to obtain a new image.
And the identifying module 906 is configured to identify a color area of the new image when the new image does not meet the first preset condition, so as to obtain a plurality of color areas, a current area color corresponding to each color area, and a current area size.
The replacing module 908 is configured to obtain, for each color region, a target region color determined by a user from a preset color selector corresponding to the color region, and replace a current region color based on the target region color and a current region size of the color region, to obtain a target image.
The specific manner in which the various modules perform the operations in the apparatus of the above embodiments have been described in detail in connection with the embodiments of the method, and will not be described in detail herein. The respective modules in the above-described image color replacement apparatus may be implemented in whole or in part by software, hardware, and a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may invoke and perform the operations of the above modules.
In one embodiment of the present application, there is provided a computer device including a memory and a processor, the memory having stored therein a computer program which when executed by the processor performs the steps of:
acquiring the current image color corresponding to the image to be processed and the target theme color determined by the user;
adjusting the color of the current image based on the target theme color to obtain a new image;
Under the condition that the new image does not meet the first preset condition, carrying out color region identification on the new image to obtain a plurality of color regions, the current region colors corresponding to the color regions and the current region sizes;
and aiming at each color region, acquiring a target region color determined by a user from a preset color selector corresponding to the color region, and replacing the current region color based on the target region color and the current region size of the color region to obtain a target image.
In one embodiment of the application, the processor when executing the computer program further performs the steps of:
Performing color space conversion processing on the current image color to generate a converted image color, wherein the color space of the converted image color is consistent with the color space of the target theme color;
calculating the current similarity between the converted image color and the target theme color;
And adjusting the color of the current image based on the current similarity and the target theme color to obtain a new image.
In one embodiment of the application, the processor when executing the computer program further performs the steps of:
carrying out normalization processing on RGB values of the current image color to obtain a normalization result;
Calculating to obtain the current brightness, the current tone and the current saturation based on the maximum value and the minimum value in the normalization result;
based on the current brightness, the current hue and the current saturation, a converted image color is obtained.
In one embodiment of the application, the processor when executing the computer program further performs the steps of:
acquiring a first tone corresponding to the current image color and a second tone corresponding to the target theme color, and acquiring a first similarity between the first tone and the second tone;
Under the condition that the first similarity meets a second preset condition, replacing the first tone with a second tone;
Adjusting the first saturation and the first brightness corresponding to the current image color to obtain the second saturation and the second brightness;
And adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain a new image.
In one embodiment of the application, the processor when executing the computer program further performs the steps of:
for each target pixel in the image to be processed, replacing the current image color corresponding to each target pixel with a target theme color to obtain a new pixel;
based on the second hue, the second saturation, the second brightness and each new pixel, a new image is obtained.
In one embodiment of the application, the processor when executing the computer program further performs the steps of:
For each color region in the image to be processed, replacing the current image color corresponding to each color region with a target theme color to obtain a new color region;
based on the second hue, the second saturation, the second brightness and the respective new color areas, a new image is obtained.
In one embodiment of the application, the processor when executing the computer program further performs the steps of:
adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain an intermediate image;
and acquiring an edge area of the intermediate image, and processing the edge area by adopting a preset gradual change algorithm to obtain a new image.
The implementation principle and technical effects of the computer device provided by the embodiment of the present application are similar to those of the above method embodiment, and are not described herein.
In one embodiment of the present application, there is provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of:
acquiring the current image color corresponding to the image to be processed and the target theme color determined by the user;
adjusting the color of the current image based on the target theme color to obtain a new image;
Under the condition that the new image does not meet the first preset condition, carrying out color region identification on the new image to obtain a plurality of color regions, the current region colors corresponding to the color regions and the current region sizes;
and aiming at each color region, acquiring a target region color determined by a user from a preset color selector corresponding to the color region, and replacing the current region color based on the target region color and the current region size of the color region to obtain a target image.
In one embodiment of the application, the computer program when executed by the processor further implements the steps of:
Performing color space conversion processing on the current image color to generate a converted image color, wherein the color space of the converted image color is consistent with the color space of the target theme color;
calculating the current similarity between the converted image color and the target theme color;
And adjusting the color of the current image based on the current similarity and the target theme color to obtain a new image.
In one embodiment of the application, the computer program when executed by the processor further implements the steps of:
carrying out normalization processing on RGB values of the current image color to obtain a normalization result;
Calculating to obtain the current brightness, the current tone and the current saturation based on the maximum value and the minimum value in the normalization result;
based on the current brightness, the current hue and the current saturation, a converted image color is obtained.
In one embodiment of the application, the computer program when executed by the processor further implements the steps of:
acquiring a first tone corresponding to the current image color and a second tone corresponding to the target theme color, and acquiring a first similarity between the first tone and the second tone;
Under the condition that the first similarity meets a second preset condition, replacing the first tone with a second tone;
Adjusting the first saturation and the first brightness corresponding to the current image color to obtain the second saturation and the second brightness;
And adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain a new image.
In one embodiment of the application, the computer program when executed by the processor further implements the steps of:
for each target pixel in the image to be processed, replacing the current image color corresponding to each target pixel with a target theme color to obtain a new pixel;
based on the second hue, the second saturation, the second brightness and each new pixel, a new image is obtained.
In one embodiment of the application, the computer program when executed by the processor further implements the steps of:
For each color region in the image to be processed, replacing the current image color corresponding to each color region with a target theme color to obtain a new color region;
based on the second hue, the second saturation, the second brightness and the respective new color areas, a new image is obtained.
In one embodiment of the application, the computer program when executed by the processor further implements the steps of:
adjusting the color of the current image based on the second hue, the second saturation, the second brightness and the target theme color to obtain an intermediate image;
and acquiring an edge area of the intermediate image, and processing the edge area by adopting a preset gradual change algorithm to obtain a new image.
The computer readable storage medium provided in this embodiment has similar principles and technical effects to those of the above method embodiment, and will not be described herein.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (SYNCHLINK) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any adaptations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It is to be understood that the present disclosure is not limited to the precise arrangements and instrumentalities shown in the drawings, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. An image color replacement method, the method comprising:
acquiring the current image color corresponding to the image to be processed and the target theme color determined by the user;
adjusting the color of the current image based on the target theme color to obtain a new image;
Under the condition that the new image does not meet a first preset condition, carrying out color region identification on the new image to obtain a plurality of color regions, and the color of the current region and the size of the current region corresponding to each color region;
and for each color region, acquiring a target region color determined by a user from a preset color selector corresponding to the color region, and replacing the current region color based on the target region color and the current region size of the color region to obtain a target image.
2. The method of claim 1, wherein said adjusting the current image color based on the target theme color results in a new image, comprising:
performing color space conversion processing on the current image color to generate a converted image color, wherein the color space of the converted image color is consistent with the color space of the target theme color;
calculating the current similarity between the converted image color and the target theme color;
and adjusting the color of the current image based on the current similarity and the target theme color to obtain the new image.
3. The method of claim 2, wherein performing a color space conversion process on the current image color to generate a converted image color comprises:
Normalizing the RGB value of the current image color to obtain a normalization result;
calculating to obtain the current brightness, the current hue and the current saturation based on the maximum value and the minimum value in the normalization result;
and obtaining the converted image color based on the current brightness, the current hue and the current saturation.
4. A method according to claim 2 or 3, wherein the current similarity comprises a first similarity, and the adjusting the current image color based on the current similarity and the target theme color to obtain the new image comprises:
Acquiring a first tone corresponding to the current image color and a second tone corresponding to the target theme color, and acquiring a first similarity between the first tone and the second tone;
replacing the first tone with the second tone under the condition that the first similarity meets a second preset condition;
Adjusting the first saturation and the first brightness corresponding to the current image color to obtain a second saturation and a second brightness;
and adjusting the current image color based on the second hue, the second saturation, the second brightness and the target theme color to obtain the new image.
5. The method of claim 4, wherein said adjusting the current image color based on the second hue, the second saturation, the second brightness, and the target theme color results in the new image, comprising:
for each target pixel in the image to be processed, replacing the current image color corresponding to each target pixel with the target theme color to obtain a new pixel;
and obtaining the new image based on the second hue, the second saturation, the second brightness and each new pixel.
6. The method of claim 4, wherein said adjusting the current image color based on the second hue, the second saturation, the second brightness, and the target theme color results in the new image, further comprising:
replacing the current image color corresponding to each color area with the target theme color aiming at each color area in the image to be processed to obtain a new color area;
and obtaining the new image based on the second hue, the second saturation, the second brightness and each new color region.
7. The method of claim 4, wherein said adjusting said current image color based on said second hue, said second saturation, said second brightness, and said target subject color results in said new image, further comprising:
Adjusting the current image color based on the second hue, the second saturation, the second brightness and the target theme color to obtain an intermediate image;
And acquiring an edge area of the intermediate image, and processing the edge area by adopting a preset gradual change algorithm to obtain the new image.
8. An image color replacement apparatus, the apparatus comprising:
the acquisition module is used for acquiring the current image color corresponding to the image to be processed and the target theme color determined by the user;
The adjusting module is used for adjusting the color of the current image based on the target theme color to obtain a new image;
The identification module is used for carrying out color region identification on the new image under the condition that the new image does not meet a first preset condition to obtain a plurality of color regions, the current region color corresponding to each color region and the current region size;
The replacing module is used for acquiring the color of the target area determined by the user from the preset color selector corresponding to the color area aiming at each color area, and replacing the color of the current area based on the color of the target area and the size of the current area of the color area to obtain a target image.
9. An electronic device comprising a processor and a memory having stored therein at least one instruction, at least one program, a set of codes, or a set of instructions, the at least one instruction, the at least one program, the set of codes, or the set of instructions being loaded and executed by the processor to implement the image color replacement method of any one of claims 1-7.
10. A computer readable storage medium having stored therein at least one instruction, at least one program, code set, or instruction set, the at least one instruction, the at least one program, the code set, or instruction set being loaded and executed by a processor to implement the image color replacement method of any of claims 1-7.
CN202510113962.6A 2025-01-24 2025-01-24 Image color replacement method, device, equipment and storage medium Pending CN120107409A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202510113962.6A CN120107409A (en) 2025-01-24 2025-01-24 Image color replacement method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202510113962.6A CN120107409A (en) 2025-01-24 2025-01-24 Image color replacement method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN120107409A true CN120107409A (en) 2025-06-06

Family

ID=95881693

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202510113962.6A Pending CN120107409A (en) 2025-01-24 2025-01-24 Image color replacement method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN120107409A (en)

Similar Documents

Publication Publication Date Title
Zeng et al. Learning image-adaptive 3d lookup tables for high performance photo enhancement in real-time
US11373275B2 (en) Method for generating high-resolution picture, computer device, and storage medium
US20210272236A1 (en) Image enhancement method and apparatus, and storage medium
US12165284B2 (en) Harmonizing composite images utilizing a transformer neural network
US9123085B2 (en) Optimizing the performance of an image editing system in a client-server environment
US11887277B2 (en) Removing compression artifacts from digital images and videos utilizing generative machine-learning models
US12223623B2 (en) Harmonizing composite images utilizing a semantic-guided transformer neural network
CN110728722B (en) Image color migration method and device, computer equipment and storage medium
EP2284736A1 (en) System and method for automated color scheme transformation
CN109413434B (en) Image processing method, device, system, storage medium and computer equipment
US20190205588A1 (en) Information code and information code reading method
CN111062930A (en) Image selection method, device, storage medium and computer equipment
CN111476731B (en) Image correction method, device, storage medium and electronic equipment
US20240223910A1 (en) Gain map generation, embedding, and application for high dynamic range digital image functionality
CN120107409A (en) Image color replacement method, device, equipment and storage medium
CN119625137A (en) Image expansion method, device, readable storage medium and program product
CN114449354B (en) Video editing method and system
CN118747833A (en) Light source estimation model training, light source estimation method and device
CN113822784B (en) Image processing method and device
CN116312919A (en) Medical detection report generation method, device, equipment and storage medium
CN110060310B (en) File compression methods, devices and equipment
US20250336119A1 (en) Joint framework for object-centered shadow detection, removal, and synthesis
CN114387168B (en) Image processing method, related device, storage medium, and program product
US12555276B2 (en) Image generation method and apparatus
CN121210793A (en) Method and device for optimizing picture resource volume of browser, storage medium and electronic device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination