Target object segmentation method and related device
Disclosed is a target object segmentation method and a related device, the target object segmentation method comprises: obtaining an input image containing a target object in a video; inputting the input image to a preset target object segmentation model, outputting a first target object segmentation image after segmentation is performed by the target object segmentation model; performing a target object contour segmentation on the input image to obtain a second target object segmentation image; performing a merging operation on corresponding pixels in the first target object segmentation image and the second target object segmentation image to obtain a final target object segmentation image. If one of the corresponding pixels is a target object pixel, the target object pixel is presented as a pixel located at a corresponding position in the final target object segmentation image after the merging operation is performed. Target object segmentation accuracy is improved.
1 . A target object segmentation method, comprising:
obtaining an input image containing a target object in a video;
inputting the input image to a preset target object segmentation model, and outputting a first target object segmentation image after a segmentation is performed on the input image by the target object segmentation model, wherein the target object segmentation model is a trained neural network which has learned a target object segmentation function;
performing a target object contour segmentation on the input image to obtain a second target object segmentation image, wherein the second target object segmentation image is generated according to a difference between the input image and a previous frame in the video;
performing a merging operation on corresponding pixels in the first target object segmentation image and the second target object segmentation image, to obtain a final target object segmentation image as a binary image, which only contains black and white pixels and represents the target object by using object pixels with a first logic value different from background pixels with a second logic value;
wherein, if one of a pixel in the first target object segmentation image and a corresponding pixel in the second target object segmentation image, which are subjected to the merging operation, is a target object pixel, that target object pixel is presented as a pixel located at a corresponding position in the final target object segmentation image after the merging operation is performed,
wherein after the merging operation, the target object segmentation method further performs an image expansion processing on the binary image, wherein the image expansion processing comprises: setting a center pixel of a lattice array in the binary image as one of the object pixels when at least one other pixel in that lattice array is determined as a pixel of the target object.
2 . The target object segmentation method according to claim 1 , wherein the target object segmentation model is configured to perform steps comprising:
extracting a low-level semantic feature information and a high-level semantic feature information from the input image;
performing an information fusion processing on the low-level semantic feature information and the high-level semantic feature information to obtain a fused feature information;
performing an up-sampling processing on the fused feature information to obtain the first target object segmentation image.
3 . The target object segmentation method according to claim 2 , wherein the target object segmentation model is configured to extract the low-level semantic feature information and the high-level semantic feature information from the input image by performing steps comprising:
extracting the low-level semantic feature information from the input image; and
extracting the high-level semantic feature information from the extracted low-level semantic feature information.
4 . The target object segmentation method according to claim 2 , wherein the target object segmentation model is further configured to adjust the extracted high-level semantic feature information for the information fusion processing.
5 . The target object segmentation method according to claim 1 , wherein the step of inputting the input image to the preset target object segmentation model comprises: performing a scaling processing on the input image to scale the input image to a predetermined size of an image processed by the target object segmentation model to obtain a scaled input image, and inputting the scaled input image into the target object segmentation model;
step of outputting the first target object segmentation image after the segmentation is performed on the input image by the target object segmentation model comprises: outputting a segmentation image after the segmentation is performed by the target object segmentation model, and obtaining the first target object segmentation image by performing an inverse processing of the scaling processing on the segmentation image.
6 . The target object segmentation method according to claim 1 , wherein the step of determining the second target object segmentation image according to the difference between the input image and the previous frame in the video comprises:
performing a gray-scaling processing on the input image to obtain a first grayscale image;
performing a gray-scaling processing on the previous frame of the input image to obtain a second grayscale image;
calculating a difference between corresponding pixels of the first grayscale image and the second grayscale image, and calculating an absolute value of that difference to obtain a difference grayscale image;
binarizing the difference grayscale image to obtain the second target object segmentation image.
7 . The target object segmentation method according to claim 1 , wherein the target object in the first target object segmentation image and the second target object segmentation image are in white, backgrounds in the first target object segmentation image and the second target object segmentation image are in black, and performing the merging operation on corresponding pixels in the first target object segmentation image and the second target object segmentation image comprises: performing an addition operation or an OR operation on corresponding pixels in the first target object segmentation image and the second target object segmentation image.
8 . An electronic device, comprising: a processor, a memory, and a program which is stored in the memory and executable by the processor, wherein when the program is executed by the processor, steps of a method according to claim 1 are implemented.
9 . A non-transitory computer readable storage medium, storing a computer program or an instruction that when executed by a processor, causes the processor to perform the method according to claim 1 .
10 . The target object segmentation method according to claim 1 , wherein the image expansion processing comprises: for at least one pixel in the binary image, considering that pixel as the center pixel which corresponds to the lattice array having 9 pixels arranged in a 3 by 3 array, including the center pixel and 8 surrounding pixels adjacent to the center pixel.