Image processing method, device and computer equipment
Patent Information
- Application Number
- CN202311400165.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-25
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2043-10-25
AI Technical Summary
[0003]本申请实施例提供一种图像处理方法、装置及计算机设备,能够解决衣服设计人工成本较高的技术问题
[0014]本申请实施例提供的图像处理方法,利用经过训练的分割模型对原始图像进行处理,得到目标对象的头部图像,用户不需要借助其他工具获取头部图像,在一定程度上可以减少人工的时间成本、提高头部图像的获取效率。基于头部图像的形状与色彩,从素材库中选取与头部图像匹配的素材图像,能够提高头部图像与素材图像的适配度。将头部图像与素材图像进行拼接,得到拼接图像,基于拼接图像与预设的载体图像,生成目标图像。在一定程度上可以提高图像生成的效率。
Smart Images

Figure CN117351207B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computer vision and relates to image processing technology, and in particular to an image processing method, apparatus and computer equipment. Background Technology
[0002] In the design field, many users want to customize clothing patterns, such as printing pictures of their pets on clothes. Typically, users provide pictures of their pets, and merchants directly print these pictures (such as pet portraits) on the clothing. While this method maximizes user satisfaction, it requires users to spend a significant amount of time cropping, stitching, or replacing the background of the image, resulting in high labor costs. Summary of the Invention
[0003] This application provides an image processing method, apparatus, and computer equipment that can solve the technical problem of high labor costs in clothing design.
[0004] The first aspect of this application provides an image processing method, comprising: receiving an original image of a target object; inputting the original image into a pre-trained segmentation model to obtain a head image of the target object; selecting a material image matching the head image from a preset material library as a body part of the head image based on the shape and color of the head image; stitching the head image and the material image together to obtain a stitched image; and generating a target image based on the stitched image and a preset carrier image.
[0005] In some optional embodiments of this application, the step of selecting a material image matching the head image from a preset material library as the body part of the head image based on the shape and color of the head image includes: matching the shape of the head image with a preset head outline, and selecting a first type of candidate image from the material library; calculating the proportion of each color in the head image, and selecting a second type of candidate image from the material library based on preset color matching rules; if there is a duplicate image between the first type of candidate image and the second type of candidate image, determining the material image based on the duplicate image; if there is no duplicate image between the first type of candidate image and the second type of candidate image, randomly selecting an image from the first type of candidate image and the second type of candidate image as the material image.
[0006] In some optional embodiments of this application, before receiving the original image containing the target object, the method further includes: obtaining training data and sample labels corresponding to the training data, wherein the training data is a training image containing the target object; training a preset initial segmentation model, including: inputting the training data into a first feature extraction layer of the initial segmentation model to obtain sub-features in the first feature extraction layer, wherein the sub-features include basic features, detail features, spatial features, and semantic features; inputting the detail features into a second feature extraction layer of the initial segmentation model to obtain edge features; fusing the edge features with the basic features to obtain a first fusion feature, fusing the edge features with the detail features to obtain a second fusion feature, fusing the edge features with the spatial features to obtain a third fusion feature, and fusing the edge features with the semantic features to obtain a fourth fusion feature; and inputting the second fusion feature, the third fusion feature, and the fourth fusion feature into a first feature fusion layer of the initial segmentation model respectively to obtain the second fusion feature. The fifth fusion feature, the sixth fusion feature corresponding to the third fusion feature, and the seventh fusion feature corresponding to the fourth fusion feature are input into the second feature fusion layer of the initial segmentation model to obtain the target fusion feature; the second fusion feature and the target fusion feature are input into the attention mechanism layer of the initial segmentation model to obtain the first feature; the first fusion feature and the first feature are input into the attention mechanism layer to obtain the second feature; the mean of the target fusion feature, the first feature, and the second feature is calculated to obtain the predicted value of the mask of the head of the target object in the training image; and the loss function of the initial segmentation model is calculated based on the predicted value and the sample label; if the loss function is less than or equal to a preset threshold, the initial segmentation model is determined as the segmentation model; if the loss function is greater than the preset threshold, the process of training the preset initial segmentation model is repeated until the loss function is less than or equal to the preset threshold.
[0007] In some optional embodiments of this application, the step of inputting the detailed features into the second feature extraction layer of the initial segmentation model to obtain edge features includes: performing a Fourier transform on the detailed features to obtain a transform result, and performing a feature mask on the detailed features to obtain a mask result; performing an inverse Fourier transform on the product of the transform result and the mask result to obtain a first convolution result and multiple second convolution results; aggregating the multiple second convolution results using an aggregation function to obtain a target aggregation result; convolving and activating the sum of the first convolution result and the target aggregation result, and then calculating the sum with the detailed features to obtain the edge features.
[0008] In some optional embodiments of this application, the step of inputting the second fusion feature, the third fusion feature, and the fourth fusion feature into the first feature fusion layer of the initial segmentation model to obtain the fifth fusion feature corresponding to the second fusion feature, the sixth fusion feature corresponding to the third fusion feature, and the seventh fusion feature corresponding to the fourth fusion feature includes: inputting the second fusion feature into the first feature fusion layer for multi-layer convolution and aggregation to obtain the fifth fusion feature; inputting the third fusion feature into the first feature fusion layer for multi-layer convolution and aggregation to obtain the sixth fusion feature; and inputting the fourth fusion feature into the first feature fusion layer for multi-layer convolution to obtain the seventh fusion feature.
[0009] In some optional embodiments of this application, the step of inputting the fifth fusion feature, the sixth fusion feature, and the seventh fusion feature into the second feature fusion layer of the initial segmentation model to obtain the target fusion feature includes: convolving the fifth fusion feature to obtain a third convolution result of the fifth fusion feature; calculating the product of the third convolution result and the sixth fusion feature to obtain a first aggregation result; calculating the product of the third convolution result and the seventh fusion feature to obtain a second aggregation result; aggregating the first aggregation result and the second aggregation result to obtain a third aggregation result; convolving the third aggregation result; and activating the convolved third aggregation result using an activation function to obtain the target fusion feature.
[0010] In some optional embodiments of this application, the step of inputting the second fused feature and the target fused feature into the attention mechanism layer of the initial segmentation model to obtain the first feature includes: activating the second fused feature using a preset activation function to obtain a first vector; obtaining a second vector based on a preset value and the first vector; calculating the product of the second vector and the first vector to obtain a third vector; calculating the product of the second vector and the target fused feature to obtain a fourth vector; and inputting the sum of the third vector and the fourth vector into the first feature fusion layer to obtain the first feature.
[0011] In some optional embodiments of this application, the step of inputting the first fused feature and the first feature into the attention mechanism layer to obtain the second feature includes: activating the first fused feature using a preset activation function to obtain a fifth vector; obtaining a sixth vector based on a preset value and the fifth vector; calculating the product of the sixth vector and the fifth vector to obtain a sixth vector; calculating the product of the sixth vector and the first feature to obtain a seventh vector; and inputting the sum of the sixth vector and the seventh vector into the first feature fusion layer to obtain the second feature.
[0012] This application also provides an image processing apparatus, comprising: a receiving module for receiving an original image of a target object; a segmentation module for inputting the original image into a pre-trained segmentation model to obtain a head image of the target object; an image selection module for selecting a material image matching the head image from a preset material library as the body part of the head image based on the shape and color of the head image; a stitching module for stitching the head image with the material image to obtain a stitched image; and a generation module for generating a target image based on the stitched image and a preset carrier image.
[0013] This application also provides a computer device, including: a memory and a processor, wherein the processor executes computer-readable instructions stored in the memory to implement the image processing method.
[0014] The image processing method provided in this application utilizes a trained segmentation model to process the original image to obtain a head image of the target object. Users do not need to use other tools to obtain the head image, which can reduce manual time costs and improve the efficiency of head image acquisition to a certain extent. Based on the shape and color of the head image, a matching source image is selected from a source image library, improving the compatibility between the head image and the source image. The head image and the source image are then stitched together to obtain a stitched image. Based on the stitched image and a preset carrier image, a target image is generated. This can improve the efficiency of image generation to a certain extent. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a schematic diagram of the application environment of the image processing method provided in the embodiments of this application.
[0017] Figure 2 This is a flowchart of a data processing method provided in an embodiment of this application.
[0018] Figure 3 This is a flowchart of an image processing method provided in another embodiment of this application.
[0019] Figure 4 This is a flowchart illustrating the training process of the segmentation model provided in this embodiment.
[0020] Figure 5This is a schematic diagram of training the initial segmentation model provided in an embodiment of this application.
[0021] Figure 6 This is a flowchart of the processing of the second feature extraction layer provided in the embodiments of this application.
[0022] Figure 7 This is a flowchart of the processing of the first feature fusion layer provided in the embodiments of this application.
[0023] Figure 8 This is a flowchart of the processing of the second feature fusion layer provided in the embodiments of this application.
[0024] Figure 9 This is a flowchart of the attention mechanism layer provided in the embodiments of this application.
[0025] Figure 10 This is a schematic diagram illustrating the application of the segmentation model provided in the embodiments of this application.
[0026] Figure 11 This is a schematic diagram of the image processing apparatus provided in the embodiments of this application.
[0027] Figure 12 This is a schematic diagram of the structure of the computer device provided in the embodiments of this application. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of this application clearer, the application will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0029] It should be noted that in this application, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and drawings of this application are used to distinguish similar objects, not to describe a specific order or sequence.
[0030] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner. Unless otherwise specified, the following embodiments and features described herein can be combined with each other.
[0031] Please see Figure 1This is a schematic diagram illustrating the application environment of the image processing method provided in the embodiments of this application. For example... Figure 1 As shown, computer device 10 is communicatively connected to target device 20 and user terminal 30, respectively. The network can be a wired network or a wireless network. The wired network can be any of a local area network (LAN), metropolitan area network (MAN), or wide area network (WAN). The wireless network can be any of the following technologies: Bluetooth (BT), Wireless Fidelity (Wi-Fi), Near Field Communication (NFC), ZigBee Wireless Networks (ZigBee), Infrared (IR), Ultra Wideband (UWB), Universal Serial Bus (USB), etc.
[0032] Computer device 10 can be an electronic device such as a computer or a personal computer (PC).
[0033] The target device 20 can be a machine used to print images on clothing, bags, toys, such as an inkjet printer or a heat press printing machine.
[0034] User terminal 30 can be an electronic device such as a mobile phone, tablet computer, multimedia playback device, personal computer (PC), or wearable device.
[0035] In one example, computer device 10 and target device 20 can be devices used by the merchant; for example, computer device 10 can be a computer, and target device 20 can be an inkjet printer. User terminal 30 can be a device used by the buyer, such as a mobile phone. The computer can receive the original image sent by the mobile phone. The original image may contain pictures of animals. The computer can segment and stitch the original image to obtain a stitched image. Based on the stitched image and a preset carrier image, a target image is generated. The computer can send the obtained stitched image and target image to the inkjet printer. The inkjet printer can print the stitched image on a carrier, such as clothing, based on the target image.
[0036] It is understood that the application scenarios illustrated in the embodiments of this application do not constitute specific limitations. In other embodiments of this application, the original image received by the computer device 10 may also be acquired through a card reader, memory card, etc.
[0037] Figure 2 This is a flowchart of a data processing method provided in an embodiment of this application, such as... Figure 2As shown, the data processing method provided in this application embodiment is applied to computer devices (such as...). Figure 1 In computer equipment 10). Depending on different needs, the order of steps in this flowchart can be changed, and some steps can be omitted. For example... Figure 2 As shown, it includes the following steps: Step S201: Receive the original image of the target object.
[0038] In some embodiments of this application, the target object can be a pet, such as a kitten, puppy, or piglet. The target object can also be other animals, such as a calf, pony, or lamb. The original image can be a picture generated after the user takes a picture of the target object, or it can be an image formed by randomly extracting a frame from a video recording containing the target object. Practical applications are not limited to these limitations.
[0039] In one example, assume the computer is the computing device and the mobile phone is the terminal device. The computer can receive the raw image sent by the user via the mobile phone. In another example, the computer can obtain the raw image through an inserted card reader.
[0040] Step S202: Input the original image into the pre-trained segmentation model to obtain the head image of the target object.
[0041] In some embodiments of this application, the head image can be an image containing the head of the target object but excluding the background image of the original image. After obtaining the original image, the computer device can input the original image into a pre-trained segmentation model to segment the head of the target object, thereby obtaining the head image of the target object. Since the target object is a pet or other animal, the edge features of its head are not obvious. Therefore, to improve its edge detection capability, the pre-trained segmentation model utilizes edge features to assist in model training, thereby enhancing the segmentation model's edge detection ability and enabling it to better detect the animal's edge features. The specific training process of the segmentation model can be found in... Figure 4 The illustrated embodiment.
[0042] Step S203: Based on the shape and color of the head image, select a material image that matches the head image from a preset material library as the body part of the head image.
[0043] In some embodiments of this application, the shape of the head image can be determined based on a preset head contour. This preset head contour can be designed based on the head characteristics of pets or other animals. For example, a kitten's head is round with two ears, while a puppy's head is cone-shaped with ears. In another example, the preset head contour can also be designed based on the emotions of pets or other animals. For instance, some puppies droop their ears when expressing happiness to the user; therefore, a cone-shaped head contour without ears can be designed based on this characteristic. These are just examples, and practical applications are not limited to them. The color of the head image can be determined based on a preset color model, such as a red-green-blue (RGB) model, a hue-saturation-value (HSV) model, etc.
[0044] In some embodiments of this application, the preset material library may include an anime material library, a cartoon material library, etc. The preset material library may include body parts of cartoon characters, and there are no restrictions on the actions of the cartoon characters. The material library may also include human anatomy diagrams designed by designers. After determining the shape and color of the head image, a material image matching the head image can be selected from the material library as the body part of the head image.
[0045] In other embodiments of this application, if the computer device receives a selection instruction from the user, it obtains the user's image requirements from the selection instruction and obtains the selected image material from the material library according to the image requirements. This application does not limit this.
[0046] In another embodiment of this application, in order to improve the matching efficiency of the head image, an image can be randomly selected from the material library as the material image to match the head image. This application does not limit this.
[0047] In some embodiments of this application, the detailed description of step S203 can also be found as follows: Figure 3 Description of the illustrated embodiment.
[0048] Step S204: The head image and the source image are stitched together to obtain a stitched image.
[0049] In some embodiments of this application, after determining the head image and the source image, the head image and the source image can be stitched together to obtain a stitched image of a cartoon pet head.
[0050] Step S205: Generate a target image based on the stitched image and the preset carrier image.
[0051] In some embodiments of this application, the carrier image can be an image of an object such as a clothing template, a bag, or a toy; practical applications are not limited to this. Taking a clothing template as an example, a computer can provide different styles of clothing templates, and the preset clothing template can be a clothing style specified by the user. Each clothing template can provide multiple different pattern printing areas according to the clothing style design, and these pattern printing areas can be used to design clothing patterns. For example, based on the user-specified location, the area in the preset clothing template to be printed is determined, and the spliced image is placed in the determined area to generate the target image. If no user-specified location is received, the spliced image is designed in the default area of the clothing template, such as the middle area of the clothing. If a user-specified location is received, the spliced image is designed in the user-specified location according to the user's selection instruction.
[0052] In other embodiments of this application, after obtaining the target image, the computer device can send the target image to a user terminal, allowing the user to view and confirm whether clothing is to be made based on the style of the target image. If the computer device receives a confirmation instruction from the user terminal, it sends the target image and the stitched image to the target device. The target device can then print the stitched image onto the clothing based on its position within the target image, thus meeting the user's need for personalized clothing design.
[0053] In the embodiments of this application, the head recognition of pets or other animals is improved based on a pre-trained segmentation model. By inputting the head image into the segmentation model, the head image of the target object is obtained. Users do not need to use other tools to crop the original image to obtain the head image, reducing the user's time cost and improving the processing efficiency of the original image. Based on the shape and color of the head image, a matching material image is selected from the material library as the body part of the head image. This improves the matching degree between the head image and the material image from the perspective of shape and color, thereby improving the aesthetics of the stitched image after the head image and the material image are stitched together. Combining the stitched image with a preset carrier image to generate the target image meets the user's need for personalized clothing design and can improve user satisfaction to a certain extent.
[0054] Figure 3 This is a flowchart of another embodiment of the image processing method provided in this application. To improve the matching degree between the head image and the source image, the following method is provided: Figure 3 The illustrated embodiment includes the following steps: Step S301: Match the shape of the head image with the preset head contour and select the first type of candidate image from the material library.
[0055] In some embodiments of this application, the preset head outline can be designed based on the head characteristics of pets or other animals. For example, a kitten's head is round with two ears, while a puppy's head is cone-shaped with ears. In another example, the preset head outline can also be designed based on the emotions of pets or other animals. For instance, some puppies droop their ears when expressing happiness to a user; therefore, a cone-shaped head outline without ears can be designed based on this characteristic. These are just examples, and practical applications are not limited to them.
[0056] In some embodiments of this application, in a computer device, a head outline can be pre-bound to a first type of candidate image. For example, if the pre-defined head outline is the head outline corresponding to a kitten, then the first type of candidate image can be a body image of an animated character such as Black Cat Detective, Rainbow Cat, or Jerry. If the pre-defined head outline is a head outline representing a happy emotion, then the first type of candidate image can be a body image in a dancing pose. The above are just examples, and practical applications are not limited to these.
[0057] In one example, if the shape of the head image successfully matches the head outline of the kitten, then the body images of cartoon characters such as Black Cat Detective, Rainbow Cat, and Jerry are selected as the first category of candidate images.
[0058] Step S302: Calculate the proportion of each color in the head image, and select the second type of candidate image from the material library based on the preset color matching rules.
[0059] In some embodiments of this application, the color model can be an RGB model, an HSV model, etc. Each color in the head image is identified using the color model, and the proportion of each color is obtained based on its percentage of the total colors. Color matching rules can be analogous color matching rules, contrasting color matching rules, primary color matching rules, warm and cool color matching rules, and approximate grayscale matching rules, etc. Analogous color matching rules can combine adjacent colors, such as blue and green, which can create a harmonious and warm atmosphere. Contrasting color matching rules can combine opposite colors, such as red and green, yellow and purple, which can create a bright and eye-catching atmosphere. Primary color matching rules can combine red, yellow, and blue, which can produce a strong contrast effect and a strong visual impact. Warm and cool color matching rules can combine warm and cool tones, such as red and blue, yellow and purple, which can produce a strong contrast effect and create a vivid visual experience. Approximate grayscale matching rules can combine colors with similar grayscale levels, such as gray and beige, dark gray and light gray, etc. This combination can create a soft and elegant atmosphere. The above is just an example; practical applications are not limited to this.
[0060] In some embodiments of this application, the color with the largest color proportion is determined from each color proportion, and this color is determined as the target color of the head image. Based on the target color and the preset color matching rules, a second type of candidate image is selected from the animation material.
[0061] In one example, since pets or other animals often have brown fur, brown will dominate the head image, making it a suitable target color. If the color scheme follows a warm / cool color matching rule, and since brown is a neutral tone, colors that pair well with brown could include red, orange, and yellow. Images containing red, orange, and yellow can be selected from anime source material. This is just an example; color matching rules can be set according to actual circumstances, and this application does not impose any restrictions on them.
[0062] Step S303: Determine whether there are duplicate images between the first type of candidate image and the second type of candidate image.
[0063] In some embodiments of this application, if there is a duplicate image between the first type of candidate image and the second type of candidate image, then step S304 is executed; if there is a non-duplicate image between the first type of candidate image and the second type of candidate image, then step S305 is executed.
[0064] Step S304: If there are duplicate images in the first type of candidate images and the second type of candidate images, determine the source image based on the duplicate images.
[0065] In some embodiments of this application, if there are duplicate images between the first type of candidate images obtained based on the head contour and the second type of candidate images obtained based on the color ratio, the number of duplicate images is obtained. If the number of duplicate images is equal to a preset threshold, the duplicate image is used as the source image. If the number of duplicate images is greater than the preset threshold, one image is randomly selected from the duplicate images as the source image. The preset threshold can be 1.
[0066] In this embodiment, duplicate images indicate that there are overlapping images between the first type of candidate images and the second type of candidate images. By finding duplicate images as source images, source images with higher relevance to user needs can be obtained, thereby improving the matching rate and user satisfaction.
[0067] Step S305: If there are no duplicate images in the first type of candidate image and the second type of candidate image, randomly select one image from the first type of candidate image and the second type of candidate image as the source image.
[0068] In some embodiments of this application, if there is no duplicate image between the first type of candidate image obtained based on the head contour and the second type of candidate image obtained based on the color ratio, an image can be randomly selected from the first type of candidate image and the second type of candidate image as a source image, or an image can be randomly selected from the first type of candidate image as a source image, or an image can be randomly selected from the second type of candidate image as a source image.
[0069] In the embodiments of this application, material images matching the head image are selected from the material library based on the head outline and color of the head image, which improves the compatibility between the material images and the head images to a certain extent.
[0070] Reference Figure 4 This is a flowchart of the training process of the segmentation model provided in the embodiments of this application, such as... Figure 4 As shown, it includes the following steps: Step S401: Obtain the training data and the corresponding sample labels.
[0071] In some embodiments of this application, the training data may be an image containing a target object, which may be a pet or other animal. The sample label corresponding to the training data may be the sample label value of the training data, that is, the true value of the mask of the head corresponding to the above training data, which is used for the verification of model training.
[0072] Step S402: Train the preset initial segmentation model.
[0073] Figure 5 This is a schematic diagram illustrating the training of the initial segmentation model provided in an embodiment of this application. For example... Figure 5 As shown, the initial segmentation model includes a first feature extraction layer, a second feature extraction layer, a first feature fusion layer, a second feature fusion layer, and an attention mechanism layer. The first feature extraction layer can employ the EfficientNet neural network algorithm to extract features from images of different sizes. The second feature extraction layer is used to extract edge features of the image. In one embodiment of this application, the second feature extraction layer is used to further optimize the edge features of the features output by the first feature extraction layer. The first feature fusion layer is used to fuse features of the same type, the second feature fusion layer is used to fuse features of different types, and the attention mechanism layer is used to enhance the robustness of the model.
[0074] In some embodiments of this application, training data is input into the first feature extraction layer of the initial segmentation model to obtain sub-features in the first feature extraction layer. These sub-features include basic features, detail features, spatial features, and semantic features. Basic features are those extracted by the first layer of the first feature extraction layer. These basic features are obtained by performing initial convolution and downsampling operations on the images in the training data, such as features with general meaning and basic descriptions in the image, like color, texture, and shape. Detail features are those extracted by the second layer of the first feature extraction layer. These details involve adding more convolution and downsampling operations on top of the first layer, resulting in a smaller output feature map size and containing more image detail information, such as edges, corners, and texture details. Spatial features are those extracted by the third layer of the first feature extraction layer. These spatial features further involve adding convolution and downsampling operations on top of the second layer, resulting in a smaller output feature map size and containing more spatial information, such as texture distribution, color distribution, and shape size. The semantic features are the features of the fourth layer of the first feature extraction layer. The semantic features continue to undergo convolution and downsampling operations on the basis of the third layer, and the output feature map will be smaller in size and contain more abstract and semantic information, such as object category, behavior and motion, scene information, etc.
[0075] In some embodiments of this application, since the detail features contain more detailed information about the image, in order to further optimize the detail features, the detail features are input into the second feature extraction layer to obtain edge features. Specifically, this includes: performing a Fourier transform on the detail features to obtain a transform result, and performing a feature mask on the detail features to obtain a mask result; performing an inverse Fourier transform on the product of the transform result and the mask result and then performing a convolution to obtain a first convolution result and multiple second convolution results; using an aggregation function to aggregate the multiple second convolution results to obtain a target aggregation result; and convolving the sum of the first convolution result and the target aggregation result and activating it, and then calculating the sum with the detail features to obtain the edge features.
[0076] Figure 6 This is a flowchart of the processing of the second feature extraction layer provided in the embodiments of this application. Figure 6As shown, a Fourier Transform (FFT) is performed on the detail features, followed by a feature mask. The feature mask indicates that positions greater than 10 pixels from the image center are set to 1, and other positions are set to 0. The product of the transform and the mask (Multi) is then subjected to an Inverse Fourier Transform (iFFT) followed by convolution, for example, DWConv3_1, DWConv101, DWConv311, DWConv355, and DWConv333. Here, DWConv3_1 represents a standard convolution with a kernel size of 3 and a stride of 1; DWConv101 represents a convolution with a kernel size of 1, a stride of 0, and a dilatation rate of 1; DWConv311 represents a convolution with a kernel size of 3, a stride of 1, and a dilatation rate of 1; DWConv355 represents a convolution with a kernel size of 3, a stride of 5, and a dilatation rate of 5; and DWConv333 represents a convolution with a kernel size of 3, a stride of 3, and a dilatation rate of 3. After convolution, we obtain the first convolution result and multiple second convolution results. We then use the aggregation function `Concat` to aggregate the second convolution results obtained from `DWConv101`, `DWConv311`, `DWConv355`, and `DWConv333`. We then convolve the sum of the first convolution result obtained from `DWConv3_1` and the target aggregated result, activate it (Conv+ReLU), and calculate the sum with the detail features. The output is the edge features. `Add` indicates addition.
[0077] In some embodiments of this application, after determining the edge features, the edge features are re-input into the first feature extraction layer, thereby fusing the edge features with basic features to obtain the first fused feature, fusing the edge features with detail features to obtain the second fused feature, fusing the edge features with spatial features to obtain the third fused feature, and fusing the edge features with semantic features to obtain the fourth fused feature, thereby enhancing the diversity of features, and further training the model based on the first fused feature, the second fused feature, the third fused feature, and the fourth fused feature.
[0078] In some embodiments of this application, the second, third, and fourth fusion features are respectively input into the first feature fusion layer of the initial segmentation model to obtain the fifth fusion feature corresponding to the second fusion feature, the sixth fusion feature corresponding to the third fusion feature, and the seventh fusion feature corresponding to the fourth fusion feature. Specifically, the second fusion feature is input into the first feature fusion layer for multi-layer convolution and aggregation to obtain the fifth fusion feature; the third fusion feature is input into the first feature fusion layer for multi-layer convolution and aggregation to obtain the sixth fusion feature; and the fourth fusion feature is input into the first feature fusion layer for multi-layer convolution to obtain the seventh fusion feature.
[0079] Figure 7 This is a flowchart of the processing of the first feature fusion layer provided in the embodiments of this application. Figure 7 As shown, multi-layer convolution is performed on the second, third, or fourth fusion feature, which can be divided into three convolutional branches: the first branch, the second branch, and the third branch. Each branch contains Conv_kij, representing a convolutional kernel containing i*j units. The first branch includes Conv_k11, Conv_k13, Conv_k31, and Conv_k33; the second branch includes Conv_k11, Conv_k15, Conv_k51, and Conv_k33; and the third branch includes Conv_k11, Conv_k17, Conv_k71, and Conv_k33. The aggregation function Concat is used to aggregate, convolve, and activate (Conv+ReLU) the three branches, thereby outputting the fifth, sixth, or seventh fusion feature.
[0080] In some embodiments of this application, after determining the fifth, sixth, and seventh fusion features, in order to enhance feature diversity, multiple different features can be fused. The fifth, sixth, and seventh fusion features can be input into the second feature fusion layer of the initial segmentation model to obtain the target fusion feature. This includes: convolving the fifth fusion feature to obtain a third convolution result of the fifth fusion feature; calculating the product of the third convolution result and the sixth fusion feature to obtain a first aggregation result; calculating the product of the third convolution result and the seventh fusion feature to obtain a second aggregation result; aggregating the first aggregation result and the second aggregation result to obtain a third aggregation result; convolving the third aggregation result; and activating the convolved third aggregation result using an activation function to obtain the target fusion feature.
[0081] Figure 8 This is a flowchart of the processing of the second feature fusion layer provided in the embodiments of this application. Figure 8 As shown, to ensure dimensionality consistency, the fifth fusion feature (Feature1) can be upsampled and then convolved to obtain the third convolution result. The product (Multi) of the third convolution result and the sixth fusion feature (Feature2) is calculated to obtain the first aggregation result. The third convolution result is upsampled and then the product (Multi) of the third convolution result and the seventh fusion feature (Feature3) is calculated to obtain the second aggregation result. The first aggregation result is upsampled and then concatenated with the second aggregation result to obtain the third aggregation result. The third aggregation result is convolved (Conv), and an activation function (ReLU) is applied to the convolved third aggregation result to output the Outut target fusion feature.
[0082] In some embodiments of this application, in order to enhance the robustness of the model, after determining the target fusion feature, the second fusion feature and the target fusion feature are input into the attention mechanism layer of the initial segmentation model to obtain the first feature, including: activating the second fusion feature with a preset activation function to obtain a first vector; obtaining a second vector based on a preset value and the first vector; calculating the product of the second vector and the first vector to obtain a third vector; calculating the product of the second vector and the target fusion feature to obtain a fourth vector; and inputting the sum of the third vector and the fourth vector into the first feature fusion layer to obtain the first feature.
[0083] Figure 9 This is a flowchart of the attention mechanism layer provided in an embodiment of this application. Figure 9 As shown, the second fusion feature FeatureA is activated using a preset activation function, Sigmoid. Based on the preset value and the first vector, a second vector is obtained, where the preset value can be (Y×(-1)+1), and Y is the first vector. The product Multi of the second vector and the first vector is calculated to obtain the third vector. The product Multi of the second vector and the target fusion feature FeatureB is calculated to obtain the fourth vector. The sum Add of the third and fourth vectors is input into the first feature fusion layer to obtain the first feature.
[0084] In some embodiments of this application, after obtaining the first feature, the first fused feature and the first feature are input into the attention mechanism layer to obtain the second feature, including: activating the first fused feature using a preset activation function to obtain a fifth vector; obtaining a sixth vector based on a preset value and the fifth vector; calculating the product of the sixth vector and the fifth vector to obtain a sixth vector; calculating the product of the sixth vector and the first feature to obtain a seventh vector; and inputting the sum of the sixth vector and the seventh vector into the first feature fusion layer to obtain the second feature. The processing procedure of the attention mechanism layer can be found in [reference needed]. Figure 9 The processing procedure shown will be as follows: Figure 9 The second fusion feature in the text is replaced with the first fusion feature, as shown below. Figure 9 The target fusion feature in the first feature is replaced with the first feature to obtain the second feature, which will not be described again here.
[0085] In some embodiments of this application, after obtaining the target fusion features, the first feature, and the second feature, the mean of the target fusion features, the first feature, and the second feature can be calculated to obtain the predicted value of the mask of the head of the target object in the training image, which is the result output after training the initial segmentation model.
[0086] Step S403: Determine whether the loss function of the initial segmentation model is greater than a preset threshold.
[0087] In some embodiments of this application, to determine the training effect of the model, the loss function of the initial segmentation model is calculated based on preset values and sample labels. If the loss function is greater than a preset threshold, the process returns to step S401. If the loss function is less than or equal to the preset threshold, the process continues to step S404.
[0088] Step S404: If the loss function is less than or equal to a preset threshold, the initial segmentation model is determined as the segmentation model.
[0089] In some embodiments of this application, if the loss function is less than or equal to a preset threshold, it is determined that the training of the initial segmentation model is complete, indicating that the initial segmentation model has achieved a certain level of robustness. In this case, the initial segmentation model is determined as the segmentation model and used to achieve, for example... Figure 2 The example shown.
[0090] In the embodiments of this application, the edge features obtained by optimizing the details enhance the extraction of edge features from the input image, which can enhance the robustness of the trained segmentation model to a certain extent.
[0091] Figure 10 This is a schematic diagram illustrating the application of the segmentation model provided in the embodiments of this application. For example... Figure 10 As shown, the original image is input into the first feature extraction layer to obtain the target's basic features, detailed features, spatial features, and semantic features. By introducing multiple features, the model's generalization ability can be enhanced. Furthermore, since the segmentation model incorporates edge features to assist feature extraction during training, inputting the original image into the first feature extraction layer can better capture the edge features of the original image, making the extracted target's basic features, detailed features, spatial features, and semantic features more accurate. After passing through the first feature fusion layer, the second feature fusion layer, and the attention mechanism layer, the head image of the target object in the original image is finally obtained.
[0092] Please see Figure 11This is a schematic diagram of an image processing apparatus provided in an embodiment of this application. It functionally embodies the image processing method of this application. The image processing apparatus includes a receiving module 101, a segmentation module 102, an image selection module 103, a stitching module 104, and a generation module 105, wherein: the receiving module 101 is used to receive the original image of the target object; the segmentation module 102 is used to input the original image into a pre-trained segmentation model to obtain a head image of the target object; the image selection module 103 is used to select a material image matching the head image from a preset material library as the body part of the head image based on the shape and color of the head image; the stitching module 104 is used to stitch the head image with the material image to obtain a stitched image; and the generation module 105 is used to generate a target image based on the stitched image and a preset carrier image.
[0093] Based on any embodiment of this application, the step of selecting a material image matching the head image from a preset material library as the body part of the head image based on the shape and color of the head image includes: matching the shape of the head image with a preset head outline, and selecting a first type of candidate image from the material library; calculating the proportion of each color in the head image, and selecting a second type of candidate image from the material library based on preset color matching rules; if there is a duplicate image between the first type of candidate image and the second type of candidate image, determining the material image based on the duplicate image; if there is no duplicate image between the first type of candidate image and the second type of candidate image, randomly selecting an image from the first type of candidate image and the second type of candidate image as the material image.
[0094] Based on any embodiment of this application, before receiving the original image containing the target object, the method further includes: obtaining training data and sample labels corresponding to the training data, wherein the training data is a training image containing the target object; training a preset initial segmentation model, including: inputting the training data into a first feature extraction layer of the initial segmentation model to obtain sub-features in the first feature extraction layer, wherein the sub-features include basic features, detail features, spatial features, and semantic features; inputting the detail features into a second feature extraction layer of the initial segmentation model to obtain edge features; fusing the edge features with the basic features to obtain a first fusion feature, fusing the edge features with the detail features to obtain a second fusion feature, fusing the edge features with the spatial features to obtain a third fusion feature, and fusing the edge features with the semantic features to obtain a fourth fusion feature; inputting the second fusion feature, the third fusion feature, and the fourth fusion feature into the first feature fusion layer of the initial segmentation model respectively to obtain the second fusion feature corresponding to the sample label. The fifth fusion feature, the sixth fusion feature corresponding to the third fusion feature, and the seventh fusion feature corresponding to the fourth fusion feature are input into the second feature fusion layer of the initial segmentation model to obtain the target fusion feature; the second fusion feature and the target fusion feature are input into the attention mechanism layer of the initial segmentation model to obtain the first feature; the first fusion feature and the first feature are input into the attention mechanism layer to obtain the second feature; the mean of the target fusion feature, the first feature, and the second feature is calculated to obtain the predicted value of the mask of the head of the target object in the training image; and the loss function of the initial segmentation model is calculated based on the predicted value and the sample label; if the loss function is less than or equal to a preset threshold, the initial segmentation model is determined as the segmentation model; if the loss function is greater than the preset threshold, the process of training the preset initial segmentation model is repeated until the loss function is less than or equal to the preset threshold.
[0095] Based on any embodiment of this application, the step of inputting the detailed features into the second feature extraction layer of the initial segmentation model to obtain edge features includes: performing a Fourier transform on the detailed features to obtain a transform result, and performing a feature mask on the detailed features to obtain a mask result; performing an inverse Fourier transform on the product of the transform result and the mask result to obtain a first convolution result and multiple second convolution results; aggregating the multiple second convolution results using an aggregation function to obtain a target aggregation result; convolving and activating the sum of the first convolution result and the target aggregation result, and then calculating the sum with the detailed features to obtain the edge features.
[0096] Based on any embodiment of this application, the step of inputting the second fusion feature, the third fusion feature, and the fourth fusion feature into the first feature fusion layer of the initial segmentation model to obtain the fifth fusion feature corresponding to the second fusion feature, the sixth fusion feature corresponding to the third fusion feature, and the seventh fusion feature corresponding to the fourth fusion feature includes: inputting the second fusion feature into the first feature fusion layer for multi-layer convolution and aggregation to obtain the fifth fusion feature; inputting the third fusion feature into the first feature fusion layer for multi-layer convolution and aggregation to obtain the sixth fusion feature; and inputting the fourth fusion feature into the first feature fusion layer for multi-layer convolution to obtain the seventh fusion feature.
[0097] Based on any embodiment of this application, the step of inputting the fifth fusion feature, the sixth fusion feature, and the seventh fusion feature into the second feature fusion layer of the initial segmentation model to obtain the target fusion feature includes: convolving the fifth fusion feature to obtain a third convolution result of the fifth fusion feature; calculating the product of the third convolution result and the sixth fusion feature to obtain a first aggregation result; calculating the product of the third convolution result and the seventh fusion feature to obtain a second aggregation result; aggregating the first aggregation result and the second aggregation result to obtain a third aggregation result; convolving the third aggregation result; and activating the convolved third aggregation result using an activation function to obtain the target fusion feature.
[0098] Based on any embodiment of this application, the step of inputting the second fused feature and the target fused feature into the attention mechanism layer of the initial segmentation model to obtain the first feature includes: activating the second fused feature using a preset activation function to obtain a first vector; obtaining a second vector based on a preset value and the first vector; calculating the product of the second vector and the first vector to obtain a third vector; calculating the product of the second vector and the target fused feature to obtain a fourth vector; and inputting the sum of the third vector and the fourth vector into the first feature fusion layer to obtain the first feature.
[0099] Based on any embodiment of this application, the step of inputting the first fused feature and the first feature into the attention mechanism layer to obtain the second feature includes: activating the first fused feature using a preset activation function to obtain a fifth vector; obtaining a sixth vector based on a preset value and the fifth vector; calculating the product of the sixth vector and the fifth vector to obtain a sixth vector; calculating the product of the sixth vector and the first feature to obtain a seventh vector; and inputting the sum of the sixth vector and the seventh vector into the first feature fusion layer to obtain the second feature.
[0100] Another embodiment of this application also provides a computer device. Figure 12 This is a schematic diagram of the structure of the computer device provided in the embodiments of this application, such as... Figure 12 As shown, in one embodiment of this application, the computer device 10 can be a tablet computer, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, a netbook, or other devices. This application embodiment does not impose any restrictions on the specific type of the computer device 10.
[0101] like Figure 12 As shown, the computer device 10 may include, but is not limited to, a communication module 1001, a memory 1002, a processor 1003, an input / output (I / O) interface 1004, and a bus 1005. The processor 1003 is coupled to the communication module 1001, the memory 1002, and the I / O interface 1004 via the bus 1005.
[0102] Those skilled in the art will understand that the schematic diagram is merely an example of the computer device 10 and does not constitute a limitation on the computer device 10. It may include more or fewer components than shown, or combine certain components, or different components. For example, the computer device 10 may also include network access devices, etc.
[0103] Communication module 1001 may include a wired communication module and / or a wireless communication module. The wired communication module may provide one or more wired communication solutions such as Universal Serial Bus (USB) and Controller Area Network (CAN). The wireless communication module may provide one or more wireless communication solutions such as Wireless Fidelity (Wi-Fi), Bluetooth (BT), mobile communication networks, Frequency Modulation (FM), Near Field Communication (NFC), and Infrared (IR) technologies.
[0104] The memory 1002 can be used to store computer-readable instructions and / or modules. The processor 1003 implements various functions of the computer device 10 by running or executing the computer-readable instructions and / or modules stored in the memory 1002 and by calling the data stored in the memory 1002. The memory 1002 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device 10, etc. The memory 1002 may include non-volatile and volatile memory, such as: hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other storage device.
[0105] The memory 1002 may be the external memory and / or internal memory of the computer device 10. Furthermore, the memory 1002 may be a memory in physical form, such as a memory stick, a TF card (Trans-flash Card), etc.
[0106] Processor 1003 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. Processor 1003 is the computing core and control center of computer device 10, connecting various parts of computer device 10 via various interfaces and lines, and executing the operating system of computer device 10, as well as various installed application programs and program code.
[0107] For example, computer-readable instructions can be divided into one or more modules / submodules / units, one or more of which are stored in memory 1002 and executed by processor 1003 to complete this application. One or more modules / submodules / units can be a series of computer-readable instruction segments capable of performing a specific function, which describe the execution process of the computer-readable instructions in computer device 10.
[0108] If the modules / units integrated in the computer device 10 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by instructing related hardware through computer-readable instructions. The computer-readable instructions can be stored in a computer-readable storage medium, and when executed by a processor, they can implement the steps of the various method embodiments described above.
[0109] Computer-readable instructions include computer-readable instruction code, which can be in the form of source code, object code, executable file, or some intermediate form. Computer-readable media can include: any entity or device capable of carrying computer-readable instruction code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), and random access memory (RAM).
[0110] Combination Figures 2 to 4 The memory 1002 in the computer device 10 stores computer-readable instructions, and the processor 1003 can execute the computer-readable instructions stored in the memory 1002 to achieve, for example, Figures 2 to 10 The image processing method shown. Specifically, the specific implementation method of the processor 1003 for the above-mentioned computer-readable instructions can be found in [reference needed]. Figures 2 to 4 The descriptions of the relevant steps in the corresponding embodiments are not repeated here.
[0111] I / O interface 1004 is used to provide a channel for user input or output. For example, I / O interface 1004 can be used to connect various input and output devices, such as mouse, keyboard, touch device, display screen, etc., so that users can enter information or visualize information.
[0112] Bus 1005 is used at least to provide a channel for communication between communication modules 1001, memory 1002, processor 1003, and I / O interface 1004 in computer device 10.
[0113] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.
[0114] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0115] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.
[0116] Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within this application. No appended diagram markings in the claims should be construed as limiting the scope of the claims.
[0117] Furthermore, it is clear that the word "including" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices can also be implemented by a single unit or device through software or hardware. Terms such as "first," "second," etc., are used to indicate names and do not indicate any specific order.
[0118] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this application without departing from the spirit and scope of the technical solutions of this application.
Claims
1. An image processing method, characterized in that, include: Obtain the training data and the sample labels corresponding to the training data, wherein the training data is a training image containing the target object; Training a pre-defined initial segmentation model includes: inputting the training data into a first feature extraction layer of the initial segmentation model to obtain sub-features in the first feature extraction layer, wherein the sub-features include basic features, detail features, spatial features, and semantic features; inputting the detail features into a second feature extraction layer of the initial segmentation model to obtain edge features; fusing the edge features with the basic features to obtain a first fusion feature, fusing the edge features with the detail features to obtain a second fusion feature, fusing the edge features with the spatial features to obtain a third fusion feature, and fusing the edge features with the semantic features to obtain a fourth fusion feature; inputting the second fusion feature, the third fusion feature, and the fourth fusion feature into the first feature fusion layer of the initial segmentation model respectively to obtain a fifth fusion feature corresponding to the second fusion feature, a sixth fusion feature corresponding to the third fusion feature, and a sixth fusion feature corresponding to the fourth fusion feature. The seventh fusion feature; the fifth, sixth, and seventh fusion features are input into the second feature fusion layer of the initial segmentation model to obtain the target fusion feature; the second fusion feature and the target fusion feature are input into the attention mechanism layer of the initial segmentation model to obtain the first feature; the first fusion feature and the first feature are input into the attention mechanism layer to obtain the second feature; the mean of the target fusion feature, the first feature, and the second feature is calculated to obtain the predicted value of the mask of the head of the target object in the training image; and the loss function of the initial segmentation model is calculated based on the predicted value and the sample label; if the loss function is less than or equal to a preset threshold, the initial segmentation model is determined as a segmentation model; if the loss function is greater than the preset threshold, the process of training the preset initial segmentation model is repeated until the loss function is less than or equal to the preset threshold; Receive the original image of the target object; The original image is input into the segmentation model to obtain the head image of the target object; Based on the shape and color of the head image, a material image matching the head image is selected from a preset material library as the body part of the head image; The head image is stitched together with the source image to obtain a stitched image; A target image is generated based on the stitched image and the preset carrier image.
2. The image processing method according to claim 1, characterized in that, The step of selecting a matching image from a preset image library as the body part of the head image based on the shape and color of the head image includes: The shape of the head image is matched with a preset head contour, and a first type of candidate image is selected from the material library; Calculate the proportion of each color in the head image, and select a second type of candidate image from the material library based on preset color matching rules; If there are duplicate images between the first type of candidate images and the second type of candidate images, the source image is determined based on the duplicate images; If there are no duplicate images between the first type of candidate images and the second type of candidate images, one image is randomly selected from the first type of candidate images and the second type of candidate images as the source image.
3. An image processing method, characterized in that, The method includes: Obtain the training data and the sample labels corresponding to the training data, wherein the training data is a training image containing the target object; Training a pre-defined initial segmentation model includes: The training data is input into the first feature extraction layer of the initial segmentation model to obtain sub-features in the first feature extraction layer. The sub-features include basic features, detailed features, spatial features and semantic features. The detailed features are input into the second feature extraction layer of the initial segmentation model to obtain edge features; the edge features are fused with the basic features to obtain a first fused feature, the edge features are fused with the detailed features to obtain a second fused feature, the edge features are fused with the spatial features to obtain a third fused feature, and the edge features are fused with the semantic features to obtain a fourth fused feature; The second fusion feature, the third fusion feature, and the fourth fusion feature are respectively input into the first feature fusion layer of the initial segmentation model to obtain the fifth fusion feature corresponding to the second fusion feature, the sixth fusion feature corresponding to the third fusion feature, and the seventh fusion feature corresponding to the fourth fusion feature; The fifth, sixth, and seventh fusion features are input into the second feature fusion layer of the initial segmentation model to obtain the target fusion feature; The second fusion feature and the target fusion feature are input into the attention mechanism layer of the initial segmentation model to obtain the first feature; The first fused feature and the first feature are input into the attention mechanism layer to obtain the second feature; Calculate the mean of the target fusion feature, the first feature, and the second feature to obtain the predicted value of the mask of the target object's head in the training image; and Calculate the loss function of the initial segmentation model based on the predicted value and the sample label; If the loss function is less than or equal to a preset threshold, the initial segmentation model is determined as the segmentation model; if the loss function is greater than the preset threshold, the process of training the preset initial segmentation model is repeated until the loss function is less than or equal to the preset threshold.
4. The image processing method according to claim 3, characterized in that, The step of inputting the detailed features into the second feature extraction layer of the initial segmentation model to obtain edge features includes: The detailed features are subjected to Fourier transform to obtain the transform result, and the detailed features are subjected to feature masking to obtain the masking result; After performing an inverse Fourier transform on the product of the transformation result and the masking result, convolution is performed to obtain a first convolution result and multiple second convolution results. The first convolution result is obtained by ordinary convolution, and the multiple second convolution results are obtained by dilated convolution. The multiple second convolution results are aggregated using an aggregation function to obtain the target aggregation result; After convolving and activating the sum of the first convolution result and the target aggregation result, the sum is calculated with the detail features to obtain the edge features.
5. The image processing method according to claim 3, characterized in that, The step of inputting the second fusion feature, the third fusion feature, and the fourth fusion feature into the first feature fusion layer of the initial segmentation model to obtain the fifth fusion feature corresponding to the second fusion feature, the sixth fusion feature corresponding to the third fusion feature, and the seventh fusion feature corresponding to the fourth fusion feature includes: The second fusion feature is input into the first feature fusion layer for multi-layer convolution and aggregation to obtain the fifth fusion feature; The third fusion feature is input into the first feature fusion layer for multi-layer convolution and aggregation to obtain the sixth fusion feature; The fourth fusion feature is input into the first feature fusion layer for multi-layer convolution to obtain the seventh fusion feature and then aggregated.
6. The image processing method according to claim 3, characterized in that, The step of inputting the fifth, sixth, and seventh fusion features into the second feature fusion layer of the initial segmentation model to obtain the target fusion features includes: The fifth fusion feature is convolved to obtain the third convolution result of the fifth fusion feature; The product of the third convolution result and the sixth fusion feature is calculated to obtain the first aggregation result; The product of the third convolution result and the seventh fusion feature is calculated to obtain the second aggregation result; The first aggregation result is aggregated with the second aggregation result to obtain the third aggregation result; The third aggregation result is convolved, and an activation function is applied to activate the convolved third aggregation result to obtain the target fusion feature.
7. The image processing method according to claim 3, characterized in that, The step of inputting the second fused feature and the target fused feature into the attention mechanism layer of the initial segmentation model to obtain the first feature includes: The second fused feature is activated using a preset activation function to obtain a first vector; Based on the preset value and the first vector, the second vector is obtained; Calculate the product of the second vector and the first vector to obtain the third vector; Calculate the product of the second vector and the target fused feature to obtain the fourth vector; The sum of the third vector and the fourth vector is input into the first feature fusion layer to obtain the first feature.
8. The image processing method according to claim 3, characterized in that, The step of inputting the first fused feature and the first feature into the attention mechanism layer to obtain the second feature includes: The first fused feature is activated using a preset activation function to obtain the fifth vector; Based on the preset value and the fifth vector, the sixth vector is obtained; Calculate the product of the sixth vector and the fifth vector to obtain the sixth vector; Calculate the product of the sixth vector and the first feature to obtain the seventh vector; The sum of the sixth vector and the seventh vector is input into the first feature fusion layer to obtain the second feature.
9. An image processing apparatus, characterized in that, include: The receiving module is used to acquire training data and sample labels corresponding to the training data, wherein the training data is a training image containing the target object; Training a pre-defined initial segmentation model includes: inputting the training data into a first feature extraction layer of the initial segmentation model to obtain sub-features in the first feature extraction layer, wherein the sub-features include basic features, detail features, spatial features, and semantic features; inputting the detail features into a second feature extraction layer of the initial segmentation model to obtain edge features; fusing the edge features with the basic features to obtain a first fusion feature, fusing the edge features with the detail features to obtain a second fusion feature, fusing the edge features with the spatial features to obtain a third fusion feature, and fusing the edge features with the semantic features to obtain a fourth fusion feature; and inputting the second fusion feature, the third fusion feature, and the fourth fusion feature into a first feature fusion layer of the initial segmentation model to obtain a fifth fusion feature corresponding to the second fusion feature, a sixth fusion feature corresponding to the third fusion feature, and a seventh fusion feature corresponding to the fourth fusion feature. The fifth, sixth, and seventh fusion features are input into the second feature fusion layer of the initial segmentation model to obtain the target fusion feature; the second fusion feature and the target fusion feature are input into the attention mechanism layer of the initial segmentation model to obtain the first feature; the first fusion feature and the first feature are input into the attention mechanism layer to obtain the second feature; the mean of the target fusion feature, the first feature, and the second feature is calculated to obtain the predicted value of the mask of the head of the target object in the training image; and the loss function of the initial segmentation model is calculated based on the predicted value and the sample label; if the loss function is less than or equal to a preset threshold, the initial segmentation model is determined as a segmentation model; if the loss function is greater than the preset threshold, the process of training the preset initial segmentation model is repeated until the loss function is less than or equal to the preset threshold; the original image of the target object is received. The segmentation module is used to input the original image into the segmentation model to obtain the head image of the target object; The image selection module is used to select a material image that matches the head image from a preset material library as the body part of the head image based on the shape and color of the head image. The stitching module is used to stitch the head image with the source image to obtain a stitched image; The generation module is used to generate a target image based on the stitched image and a preset carrier image.
10. A computer device, characterized in that, include: Memory; and A processor; the processor executes computer-readable instructions stored in the memory to implement the image processing method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Method and system for privately customizing toys according to pictures provided by clients
CN104268910A
Cartoon image generation method and device based on portraits, equipment and storage medium
CN111260763A