Image processing method and device, nonvolatile storage medium and computer equipment
By identifying and removing the original style of the image and applying the target style on the basis of it, the problem of poor pixel color fusion method is solved, and a better style conversion effect is achieved.
Patent Information
- Application Number
- CN202411116349.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-14
- Publication Date
- 2024-12-03
AI Technical Summary
The existing pixel color fusion method is not effective in style conversion and cannot effectively match the target image style.
By obtaining the image to be processed and the target image style, determine the original style and corresponding conversion strategy of the image, first remove the original style, and then apply the target style to achieve style conversion.
It improves the effect of style conversion, can recognize and restore the original image style, thereby superimposing styles on the basis of the original image, significantly improving the quality of image style conversion.
Smart Images

Figure CN119067838A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to an image processing method, an apparatus, a non-volatile storage medium and a computer device. Background Art
[0002] Style transfer refers to processing an image and keeping the content of the target image unchanged during the processing, while changing its visual style to match the style of the content image. At present, when performing style transfer, it is usually based on the method of pixel color fusion, selecting a content image, then selecting a style image, and then fusing the style image with the content image to achieve the style transfer of the image. If the original image cannot be obtained, it will be processed based on the existing style image, and the conversion effect is not good.
[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiments of the present invention provide an image processing method, apparatus, non-volatile storage medium and computer equipment to at least solve the technical problem that the style conversion effect is not good when the pixel color fusion method is used in the related art.
[0005] According to one aspect of an embodiment of the present invention, there is provided an image processing method, comprising: obtaining an image to be processed and a target image style; determining the original image style of the image to be processed according to the pixel colors in the image to be processed; determining a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style; based on the first conversion strategy, processing the image to be processed to obtain a restored image with the original image style removed; based on the second conversion strategy, processing the restored image to obtain a target image matching the target image style.
[0006] Optionally, determining the original image style of the image to be processed based on the pixel color in the image to be processed includes: extracting image features of the image to be processed based on the pixel color in the image to be processed, wherein the image features include at least one of the following: image brightness, image contrast and texture features, and the texture features characterize the distribution characteristics of pixels in the image to be processed; matching the respective features of a plurality of predetermined image styles with the image features to obtain a plurality of matching results; and determining the original image style from the plurality of image styles based on the matching results.
[0007] Optionally, in the case where the image features include texture features, the image features of the image to be processed are extracted according to the pixel colors in the image to be processed, including: converting the image to be processed into a grayscale image according to the pixel colors in the image to be processed; using the following processing method for the target pixel in the grayscale image, the pixels in the grayscale image are processed as follows to obtain the image features: determining the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood, wherein the distance between the pixels in the neighborhood and the target pixel is less than a predetermined pixel distance; determining the image features according to the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood.
[0008] Optionally, determining the original image style of the image to be processed based on the pixel color in the image to be processed also includes: inputting the image to be processed into a pre-trained classification model, extracting the pixel color in the image to be processed by the classification model, and outputting the original image style, wherein the classification model is obtained by training the original classification model through training samples, and the training samples include sample images and corresponding sample styles.
[0009] Optionally, determining a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style includes: obtaining a pre-set correspondence relationship, wherein the correspondence relationship is a correspondence relationship between style conversion strategies of multiple image styles, and the style conversion strategy is a strategy for converting the original image into an image of the corresponding image style; based on the correspondence relationship, determining the first conversion strategy corresponding to the original image style and the second conversion strategy corresponding to the target image style.
[0010] Optionally, in a case where the first conversion strategy is a strategy for converting an original image into an image in the style of the original image, the image to be processed is processed based on the first conversion strategy to obtain a restored image with the style of the original image removed, including: determining an inverse operation strategy of the first conversion strategy; and using the inverse operation strategy to process the image to be processed to obtain a restored image.
[0011] According to another aspect of an embodiment of the present invention, there is also provided an image processing device, including: an acquisition module, used to acquire an image to be processed, and a target image style; a first determination module, used to determine the original image style of the image to be processed according to the pixel color in the image to be processed; a second determination module, used to determine a first conversion strategy corresponding to the original image style, and a second conversion strategy corresponding to the target image style; a first processing module, used to process the image to be processed based on the first conversion strategy to obtain a restored image with the original image style removed; and a second processing module, used to process the restored image based on the second conversion strategy to obtain a target image matching the target image style.
[0012] According to another aspect of an embodiment of the present invention, a non-volatile storage medium is provided. The non-volatile storage medium includes a stored program, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute any one of the above-mentioned image processing methods.
[0013] According to yet another aspect of an embodiment of the present invention, a computer device is provided. The computer device includes a processor, and the processor is used to run a program. When the program is run, any one of the above-mentioned image processing methods is executed.
[0014] According to yet another aspect of the embodiments of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, any one of the above-mentioned image processing methods is implemented.
[0015] In an embodiment of the present invention, by obtaining an image to be processed and a target image style; determining the original image style of the image to be processed according to the pixel color in the image to be processed; determining a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style; processing the image to be processed based on the first conversion strategy to obtain a restored image with the original image style removed; processing the restored image based on the second conversion strategy to obtain a target image matching the target image style, the purpose of identifying the style of the image to be processed and restoring the original image is achieved, and then style superposition is performed on the basis of the original image, thereby improving the effect of style conversion, and thus solving the technical problem that the style conversion effect is not good when the pixel color fusion method is used in the related technology. This solution identifies the original image style, adds a process of restoring the original image, and then performs style superposition on the restored image, and the image style conversion effect is better. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0017] Figure 1 A hardware structure block diagram of a computer terminal for implementing an image processing method is shown;
[0018] Figure 2 is a flowchart of an image processing method provided according to an embodiment of the present invention;
[0019] Figure 3 is a structural block diagram of an image processing device provided according to an embodiment of the present invention. DETAILED DESCRIPTION
[0020] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0022] According to an embodiment of the present invention, an embodiment of a method for image processing is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0023] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 FIG. 1 shows a hardware structure block diagram of a computer terminal for implementing an image processing method. Figure 1 As shown, the computer terminal 10 may include one or more (102a, 102b, ..., 102n are used to illustrate) processors (the processor may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1Different configurations are shown.
[0024] It should be noted that the one or more processors and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10. As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0025] The memory 104 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the image processing method in the embodiment of the present invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, the image processing method of the above-mentioned application is realized. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0026] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 .
[0027] Figure 2 is a flow chart of an image processing method according to an embodiment of the present invention. Figure 2 As shown, the method comprises the following steps:
[0028] Step S201, obtaining an image to be processed and a target image style.
[0029] In this step, you can select the image to be processed from the user or the data set, that is, the original image that needs to be style-converted. Then you can determine the target image style, which is the style that needs to be generated. This can be a specific style description that can be selected based on user needs or specific application scenarios, such as oil painting, watercolor painting, sketch painting, cartoon painting, etc.
[0030] Step S202: determining the original image style of the image to be processed according to the pixel colors in the image to be processed.
[0031] In this step, the pixel colors in the image to be processed can be analyzed to obtain analysis results. Specifically, the color distribution, contrast, brightness and other properties of the image can be analyzed. Then, the original image style of the image to be processed can be determined based on the analysis results. For example, if the image has high contrast and saturation, it may be an oil painting style. If the color is only black and white, it may be a sketch style. Furthermore, the color change trend in the image can also be analyzed. If the color change is gradual, it may be a watercolor style. If the color changes suddenly, it is likely to be an oil painting.
[0032] Step S203: determining a first conversion strategy corresponding to the style of the original image and a second conversion strategy corresponding to the style of the target image.
[0033] In this step, a first conversion strategy can be determined based on the determined original image style to remove the original image style. Specifically, it can include adjusting the contrast, brightness, color balance, etc. of the image. Then, a second conversion strategy can be determined based on the target image style to apply the target style to the image. Specifically, it can include applying a specific filter, texture, or color mapping.
[0034] Step S204: based on the first conversion strategy, the image to be processed is processed to obtain a restored image after the style of the original image is removed.
[0035] In this step, the parameters and operations in the first conversion strategy can be applied to process the original image to remove its original style. The processed image is called a restored image, which retains the basic structure of the original image, but the style has been removed or weakened.
[0036] Step S205: Based on the second conversion strategy, the restored image is processed to obtain a target image that matches the style of the target image.
[0037] In this step, the parameters and operations in the second conversion strategy are applied to apply the target image style to the restored image. The processed image is called the target image, which combines the structure of the original image and the style of the target image.
[0038] Through the above steps, the image style can be recognized, restored and converted, so as to achieve the purpose of identifying the style of the image to be processed and restoring the original image, and then superimposing the style on the basis of the original image, thereby improving the effect of style conversion, and thus solving the technical problem of poor effect when using pixel color fusion method for style conversion in related technologies.
[0039] As an optional embodiment, determining the original image style of the image to be processed according to the pixel color in the image to be processed includes: extracting image features of the image to be processed according to the pixel color in the image to be processed, wherein the image features include at least one of the following: image brightness, image contrast and texture features, and the texture features characterize the distribution characteristics of pixels in the image to be processed; matching the respective features of a plurality of predetermined image styles with the image features to obtain a plurality of matching results; and determining the original image style from the plurality of image styles according to the matching results.
[0040] Optionally, in this optional embodiment, image features are first extracted based on the pixel colors in the image to be processed, and the image features include at least one of the following: image brightness, contrast, and texture features. Texture features can help characterize the distribution characteristics of pixels in the image. Among them, texture features can reflect the properties of the image surface such as roughness, smoothness, and granularity.
[0041] Then, the features of the preset multiple image styles are matched with the features of the image to be processed. Specifically, the similarity between the features of the multiple image styles and the features of the image to be processed can be calculated to obtain multiple matching results. Finally, the style of the original image is determined based on these matching results. Specifically, the image style corresponding to the feature with the highest similarity can be determined as the style of the original image.
[0042] As an optional embodiment, in the case where the image features include texture features, the image features of the image to be processed are extracted according to the pixel colors in the image to be processed, including: converting the image to be processed into a grayscale image according to the pixel colors in the image to be processed; using the following processing method for the target pixel in the grayscale image, the pixels in the grayscale image are processed as follows to obtain the image features: determining the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood, wherein the distance between the pixels in the neighborhood and the target pixel is less than a predetermined pixel distance; determining the image features according to the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood.
[0043] Optionally, the brightness difference between the pixel and the surrounding pixels can be determined to obtain texture features. First, the pixel color in the image to be processed can be converted into a grayscale image. A grayscale image is an image that only contains brightness information but not color information. By converting a color image into a grayscale image, the complexity of image processing can be simplified. Secondly, in the grayscale image, the target pixel can be processed to extract image features. The specific processing method is to determine the difference between the grayscale value of the target pixel and the grayscale values of other pixels in its neighborhood, where the distance between the pixels in the neighborhood and the target pixel is less than a predetermined pixel distance. Then the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood can be directly used as a texture feature in the image feature.
[0044] In addition, this optional embodiment also provides some other texture feature extraction methods: by calculating the normal direction of each pixel in the image, the degree of concavity and texture direction of the image surface can be obtained; by filtering the image using Gabor filters of different directions and scales, features describing the texture characteristics of the image can be obtained; by performing Fourier transform on the image, the frequency distribution of the image can be obtained, thereby describing the periodicity and repeatability of the texture; Hough transform (Hough Transform) is used to detect geometric shapes such as straight lines and curves in the image, which can reflect the arrangement pattern of the image texture; by detecting the edges in the image, the boundaries and shapes of the texture can be described; by analyzing the regional shapes in the image, the distribution and arrangement of the texture can be described.
[0045] As an optional embodiment, determining the original image style of the image to be processed based on the pixel color in the image to be processed also includes: inputting the image to be processed into a pre-trained classification model, extracting the pixel color in the image to be processed by the classification model, and outputting the original image style, wherein the classification model is obtained by training the original classification model through training samples, and the training samples include sample images and corresponding sample styles.
[0046] Optionally, a neural network model can also be used for style recognition. First, the image to be processed can be input into a pre-trained classification model. This classification model is trained with a large amount of sample data to learn the characteristics of different styles. When the image to be processed is input into the classification model, the classification model can extract the pixel color in the image to be processed and judge the style corresponding to the image based on the distribution of the pixel color, and finally output it to obtain the style of the original image.
[0047] As an optional embodiment, determining a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style includes: obtaining a pre-set corresponding relationship, wherein the corresponding relationship is a corresponding relationship between style conversion strategies of multiple image styles, and the style conversion strategy is a strategy for converting the original image into an image of the corresponding image style; based on the corresponding relationship, determining the first conversion strategy corresponding to the original image style and the second conversion strategy corresponding to the target image style.
[0048] Optionally, when determining the style transfer strategy, first, a pre-set corresponding relationship needs to be obtained. This corresponding relationship can be a mapping relationship, which includes multiple image styles and their corresponding style transfer strategies. Each style transfer strategy defines how to convert an original image into an image of a specific image style. Secondly, the corresponding first conversion strategy and second conversion strategy can be determined based on the determined original image style and target image style.
[0049] Optionally, determining the above correspondence, that is, the correspondence between multiple image styles and their respective style transfer strategies, can be achieved through the following steps: first, a set of image styles needs to be defined, which can be based on visual features (such as color, texture, composition, etc.) or art genres (such as impressionism, realism, etc.); second, for each defined image style, a corresponding style transfer strategy is selected or designed, which can be a series of algorithms or operations for converting the original image into the target style; finally, a mapping table can be created to associate each image style with its corresponding style transfer strategy. This mapping table can be a simple data structure, such as a dictionary or a table. In some cases, expert knowledge can be used to determine and optimize the correspondence. The advice of artists, designers or image processing experts can provide valuable insights. Through the above steps, a reliable correspondence can be established to associate different image styles with corresponding style transfer strategies, thereby achieving high-quality image style transfer.
[0050] Specifically, the conversion strategy corresponding to the cartoon style can be: adjust the pixel colors within a certain area so that the pixel colors close to a certain standard color in the certain area are adjusted to the standard color, that is, adjust the delicate color changes to large blocks of color with relatively uniform colors, so as to obtain a cartoon image; the conversion strategy corresponding to the pixel style can be: set a pixel size, and divide the image into areas that match the pixel size, and determine the color of the entire area based on the average color value or the maximum color value in each area, so as to obtain a pixel-style image.
[0051] As an optional embodiment, when the first conversion strategy is a strategy for converting an original image into an image in the style of the original image, based on the first conversion strategy, the image to be processed is processed to obtain a restored image with the style of the original image removed, including: determining an inverse operation strategy of the first conversion strategy; and using the inverse operation strategy to process the image to be processed to obtain a restored image.
[0052] Optionally, in order to restore the image, an inverse operation strategy of the first conversion strategy can be determined. The inverse operation strategy is an operation opposite to the first conversion strategy, and its purpose is to undo the changes made to the image by the first conversion strategy, thereby restoring the original style of the image. Among them, determining the inverse operation strategy may involve an in-depth analysis of the first conversion strategy to understand its specific operations on the image. Once the inverse operation strategy is determined, this method can be used to process the image to be processed (i.e., the image to which the first conversion strategy has been applied). The purpose of this process is to gradually undo the impact of the first conversion strategy and make the image as close to its original state as possible. The image finally obtained by processing with the inverse operation strategy is called a restored image. This image retains the style and characteristics of the original image as much as possible, while removing any changes introduced by the first conversion strategy.
[0053] Specifically, the inverse operation strategy can be predetermined. For example, the inverse operation strategy of the conversion strategy corresponding to the cartoon style can be set as: identifying the same colors in a certain area, and then adjusting these same colors to different colors. The adjustment process can be random, and the difference between the adjusted colors and the original colors can be limited to be small; the conversion strategy corresponding to the pixel style can be similar to the inverse operation strategy of the cartoon style, so as to achieve the effect of restoring the original image as much as possible.
[0054] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0055] Through the description of the above implementation methods, those skilled in the art can clearly understand that the image processing method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0056] According to an embodiment of the present invention, there is also provided an image processing device for implementing the above image processing method. Figure 3 is a structural block diagram of an image processing device provided according to an embodiment of the present invention. Figure 3 As shown, the image processing device includes: an acquisition module 31, a first determination module 32, a second determination module 33, a first processing module 34 and a second processing module 35. The image processing device is described below.
[0057] The acquisition module 31 is used to acquire the image to be processed and the target image style.
[0058] The first determining module 32 is connected to the acquiring module 31 and is used to determine the original image style of the image to be processed according to the pixel colors in the image to be processed.
[0059] The second determination module 33 is connected to the first determination module 32 and is used to determine a first conversion strategy corresponding to the style of the original image and a second conversion strategy corresponding to the style of the target image.
[0060] The first processing module 34 is connected to the second determining module 33, and is used to process the image to be processed based on the first conversion strategy to obtain a restored image without the style of the original image.
[0061] The second processing module 35 is connected to the first processing module 34, and is used to process the restored image based on the second conversion strategy to obtain a target image that matches the style of the target image.
[0062] It should be noted that the acquisition module 31, the first determination module 32, the second determination module 33, the first processing module 34 and the second processing module 35 correspond to steps S201 to S205 in the embodiment, and the examples and application scenarios implemented by the multiple modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above embodiment. It should be noted that the above modules, as part of the device, can be run in the computer terminal 10 provided in the embodiment.
[0063] An embodiment of the present invention may provide a computer device. Optionally, in this embodiment, the computer device may be located in at least one network device among multiple network devices of a computer network. The computer device includes a memory and a processor.
[0064] Among them, the memory can be used to store software programs and modules, such as program instructions / modules corresponding to the image processing method and device in the embodiment of the present invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned image processing method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0065] The processor can call the information and application stored in the memory through the transmission device to execute the following steps: obtain the image to be processed and the target image style; determine the original image style of the image to be processed according to the pixel color in the image to be processed; determine a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style; based on the first conversion strategy, process the image to be processed to obtain a restored image with the original image style removed; based on the second conversion strategy, process the restored image to obtain a target image that matches the target image style.
[0066] Optionally, the processor may also execute program code for the following steps: determining the original image style of the image to be processed based on the pixel color in the image to be processed, including: extracting image features of the image to be processed based on the pixel color in the image to be processed, wherein the image features include at least one of the following: image brightness, image contrast and texture features, and the texture features characterize the distribution characteristics of pixels in the image to be processed; matching the features of each of a plurality of predetermined image styles with the image features to obtain a plurality of matching results; and determining the original image style from the plurality of image styles based on the matching results.
[0067] Optionally, the processor may also execute program code of the following steps: when the image features include texture features, extracting the image features of the image to be processed according to the pixel colors in the image to be processed, including: converting the image to be processed into a grayscale image according to the pixel colors in the image to be processed; processing the pixels in the grayscale image in the following manner to obtain image features by: determining the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood, wherein the distance between the pixels in the neighborhood and the target pixel is less than a predetermined pixel distance; determining the image features according to the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood.
[0068] Optionally, the processor may also execute the following program code: determining the original image style of the image to be processed based on the pixel color in the image to be processed, and also including: inputting the image to be processed into a pre-trained classification model, extracting the pixel color in the image to be processed by the classification model, and outputting the original image style, wherein the classification model is obtained by training the original classification model through training samples, and the training samples include sample images and corresponding sample styles.
[0069] Optionally, the processor may also execute program code for the following steps: determining a first conversion strategy corresponding to the original image style, and a second conversion strategy corresponding to the target image style, including: obtaining a pre-set correspondence relationship, wherein the correspondence relationship is a correspondence relationship between style conversion strategies of multiple image styles, and the style conversion strategy is a strategy for converting the original image into an image of the corresponding image style; determining, based on the correspondence relationship, the first conversion strategy corresponding to the original image style, and the second conversion strategy corresponding to the target image style.
[0070] Optionally, the processor may also execute program code of the following steps: when the first conversion strategy is a strategy for converting an original image into an image in the style of the original image, based on the first conversion strategy, processing the image to be processed to obtain a restored image with the style of the original image removed, including: determining an inverse operation strategy of the first conversion strategy; and using the inverse operation strategy to process the image to be processed to obtain a restored image.
[0071] By adopting the embodiment of the present invention, a solution for image processing is provided. By obtaining an image to be processed and a target image style; determining the original image style of the image to be processed according to the pixel color in the image to be processed; determining a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style; processing the image to be processed based on the first conversion strategy to obtain a restored image with the original image style removed; processing the restored image based on the second conversion strategy to obtain a target image matching the target image style, the purpose of identifying the style of the image to be processed and restoring the original image is achieved, and then style superposition is performed on the basis of the original image, thereby improving the effect of style conversion, and thus solving the technical problem that the style conversion effect is not good when the pixel color fusion method is used in the related art.
[0072] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a non-volatile storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0073] The embodiment of the present invention further provides a non-volatile storage medium. Optionally, in this embodiment, the non-volatile storage medium can be used to store the program code executed by the image processing method provided by the embodiment.
[0074] Optionally, in this embodiment, the non-volatile storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0075] Optionally, in this embodiment, the non-volatile storage medium is configured to store program codes for executing the following steps: obtaining an image to be processed and a target image style; determining the original image style of the image to be processed based on the pixel color in the image to be processed; determining a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style; based on the first conversion strategy, processing the image to be processed to obtain a restored image with the original image style removed; based on the second conversion strategy, processing the restored image to obtain a target image that matches the target image style.
[0076] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for executing the following steps: determining the original image style of the image to be processed based on the pixel color in the image to be processed, including: extracting image features of the image to be processed based on the pixel color in the image to be processed, wherein the image features include at least one of the following: image brightness, image contrast and texture features, and the texture features characterize the distribution characteristics of pixels in the image to be processed; matching the respective features of a plurality of predetermined image styles with the image features to obtain a plurality of matching results; and determining the original image style from the plurality of image styles based on the matching results.
[0077] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for executing the following steps: when the image features include texture features, extracting the image features of the image to be processed according to the pixel colors in the image to be processed, including: converting the image to be processed into a grayscale image according to the pixel colors in the image to be processed; using the following processing method for the target pixel in the grayscale image, performing the following processing on the pixels in the grayscale image to obtain image features: determining the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood, wherein the distance between the pixels in the neighborhood and the target pixel is less than a predetermined pixel distance; determining the image features according to the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood.
[0078] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for executing the following steps: determining the original image style of the image to be processed based on the pixel color in the image to be processed, and also including: inputting the image to be processed into a pre-trained classification model, extracting the pixel color in the image to be processed by the classification model, and outputting the original image style, wherein the classification model is obtained by training the original classification model through training samples, and the training samples include sample images and corresponding sample styles.
[0079] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for executing the following steps: determining a first conversion strategy corresponding to the original image style, and a second conversion strategy corresponding to the target image style, including: obtaining a predetermined correspondence relationship, wherein the correspondence relationship is a correspondence relationship between style conversion strategies of multiple image styles, and the style conversion strategy is a strategy for converting the original image into an image of the corresponding image style; based on the correspondence relationship, determining the first conversion strategy corresponding to the original image style, and the second conversion strategy corresponding to the target image style.
[0080] Optionally, in this embodiment, the non-volatile storage medium is configured to store program code for executing the following steps: when the first conversion strategy is a strategy for converting an original image into an image in the style of the original image, based on the first conversion strategy, processing the image to be processed to obtain a restored image with the style of the original image removed, including: determining an inverse operation strategy of the first conversion strategy; and using the inverse operation strategy to process the image to be processed to obtain a restored image.
[0081] An embodiment of the present invention further provides a computer program product, including a computer program, which implements the steps of the image processing method in each embodiment of the present application when the computer program is executed by a processor.
[0082] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0083] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0084] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0085] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0086] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0087] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0088] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. An image processing method, characterized in that: include: Get the image to be processed and the target image style; Determining the original image style of the image to be processed according to the pixel colors in the image to be processed; Determining a first conversion strategy corresponding to the style of the original image and a second conversion strategy corresponding to the style of the target image; Based on the first conversion strategy, the image to be processed is processed to obtain a restored image with the style of the original image removed; Based on the second conversion strategy, the restored image is processed to obtain a target image that matches the style of the target image.
2. The method according to claim 1, characterized in that The step of determining the original image style of the image to be processed according to the pixel colors in the image to be processed includes: Extracting image features of the image to be processed according to pixel colors in the image to be processed, wherein the image features include at least one of the following: image brightness, image contrast, and texture features, wherein the texture features characterize distribution characteristics of pixels in the image to be processed; Matching the features of each of the predetermined multiple image styles with the image features to obtain multiple matching results; The original image style is determined from the multiple image styles according to the matching result.
3. The method according to claim 2, characterized in that In the case where the image feature includes the texture feature, extracting the image feature of the image to be processed according to the pixel color in the image to be processed includes: Converting the image to be processed into a grayscale image according to pixel colors in the image to be processed; The following processing method is adopted for the target pixel in the grayscale image, and the pixels in the grayscale image are processed as follows to obtain the image feature: determining the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood, wherein the distance between the pixels in the neighborhood and the target pixel is less than a predetermined pixel distance; determining the image feature according to the difference between the grayscale value of the target pixel and the grayscale values of other pixels in the neighborhood.
4. The method according to claim 1, characterized in that The determining the original image style of the image to be processed according to the pixel colors in the image to be processed also includes: The image to be processed is input into a pre-trained classification model, and the classification model extracts the pixel color in the image to be processed and outputs the style of the original image, wherein the classification model is obtained by training the original classification model through training samples, and the training samples include sample images and corresponding sample styles.
5. The method according to claim 2, characterized in that: The determining of a first conversion strategy corresponding to the style of the original image and a second conversion strategy corresponding to the style of the target image includes: Acquire a preset corresponding relationship, wherein the corresponding relationship is a corresponding relationship between the style conversion strategies of the plurality of image styles, and the style conversion strategy is a strategy for converting an original image into an image of a corresponding image style; According to the corresponding relationship, a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style are determined.
6. The method according to claim 1, characterized in that In the case where the first conversion strategy is a strategy for converting an original image into an image in the style of the original image, the step of processing the image to be processed based on the first conversion strategy to obtain a restored image after removing the style of the original image includes: determining a reverse operation strategy of the first conversion strategy; The image to be processed is processed using the inverse operation strategy to obtain the restored image.
7. An image processing device, characterized in that: include: The acquisition module is used to obtain the image to be processed and the target image style; A first determination module, used to determine the original image style of the image to be processed according to the pixel colors in the image to be processed; A second determination module, used to determine a first conversion strategy corresponding to the original image style and a second conversion strategy corresponding to the target image style; A first processing module, configured to process the image to be processed based on the first conversion strategy to obtain a restored image after removing the style of the original image; The second processing module is used to process the restored image based on the second conversion strategy to obtain a target image that matches the style of the target image.
8. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored program, wherein when the program is executed, the device where the non-volatile storage medium is located is controlled to execute the image processing method according to any one of claims 1 to 6.
9. A computer device, characterized in that: include: Memory and processor, The memory stores a computer program; The processor is used to execute the computer program stored in the memory, and when the computer program is run, the processor executes the image processing method according to any one of claims 1 to 6.
10. A computer program product comprising computer instructions, characterized in that: The computer instructions are executed by a processor to execute the image processing method according to any one of claims 1 to 6.
Citation Information
Cited By
Stylized image rendering method and system, electronic equipment and storage medium
CN122473332A
