Image processing method and electronic device
AssigneePing An Technology (Shenzhen) Co., Ltd.
InventorsJinghong Miao, Yuchuan Gou, Bo Gong, Mei Han
Life of this patent
Estimating the term…
Abstract
An image processing method and an electronic device are provided, the method extracts a first object mask of a texture image and a second object mask of a to-be-optimized image. An image recognition model is used to obtain a first content matrix, a first texture matrix, a second content matrix, a second texture matrix, a first mask matrix, and a second mask matrix. A total loss of the to-be-optimized image is determined, and the total loss is minimized by adjusting a value of each pixel of the to-be-optimized image, thereby an optimized image is obtained. By utilizing the image processing method, quality of final image is improved.
Claims20
An image processing method, comprising:
- obtaining a content image, a texture image, and a to-be-optimized image, contents of the to-be-optimized image is consistent with contents of the content image;
- extracting a first object mask of the texture image and a second object mask of the to-be-optimized image;
- inputting the content image, the texture image, the to-be-optimized image, the first object mask, and the second object mask into an image recognition model;
- obtaining a first content matrix corresponding to the content image, a first texture matrix corresponding to the texture image, a second content matrix and a second texture matrix corresponding to the to-be-optimized image, a first mask matrix corresponding to the first object mask, and a second mask matrix corresponding to the second object mask by the image recognition model;
- dividing the first texture matrix into a plurality of first sub-matrices, and the second texture matrix into a plurality of second sub-matrices;
- calculating object loss and background loss according to the plurality of first sub-matrices, the plurality of second sub-matrices, the first mask matrix, and the second mask matrix, and calculating texture loss according to the object loss and the background loss:
- calculating content loss according to the first content matrix and the second content matrix;
- determining a total loss according to the texture loss and the content loss;
- transmitting the total loss to the image recognition model by using a gradient descent algorithm, and obtaining pixel loss of each pixel of the to-be-optimized image;
- adjusting a value of each pixel of the to-be-optimized image to minimize the total loss according to the pixel loss, and obtaining an optimized image.
An electronic device, comprising:
- at least one processor;
- and
- a storage device storing one or more programs which when executed by the at least one processor, causes the at least one processor to:
- obtain a content image, a texture image, and a to-be-optimized image, contents of the to-be-optimized image is consistent with contents of the content image;
- extract a first object mask of the texture image and a second object mask of the to-be-optimized image;
- input the content image, the texture image, the to-be-optimized image, the first object mask, and the second object mask into an image recognition model;
- obtain a first content matrix corresponding to the content image, a first texture matrix corresponding to the texture image, a second content matrix and a second texture matrix corresponding to the to-be-optimized image, a first mask matrix corresponding to the first object mask, and a second mask matrix corresponding to the second object mask by the image recognition model;
- divide the first texture matrix into a plurality of first sub-matrices, and the second texture matrix into a plurality of second sub-matrices;
- calculate object loss and background loss according to the plurality of first sub-matrices, the plurality of second sub-matrices, the first mask matrix, and the second mask matrix, and calculate texture loss according to the object loss and the background loss;
- calculate content loss according to the first content matrix and the second content matrix;
- determine a total loss according to the texture loss and the content loss;
- transmit the total loss to the image recognition model by using a gradient descent algorithm, and obtain pixel loss of each pixel of the to-be-optimized image;
- adjust a value of each pixel of the to-be-optimized image to minimize the total loss according to the pixel loss, and obtain an optimized image.
A non-transitory storage medium having stored thereon instructions that, when executed by a processor of an electronic device, causes the electronic device to perform an image processing method, the method comprising:
- obtaining a content image, a texture image, and a to-be-optimized image, wherein contents of the to-be-optimized image is consistent with contents of the content image;
- extracting a first object mask of the texture image and a second object mask of the to-be-optimized image;
- inputting the content image, the texture image, the to-be-optimized image, the first object mask, and the second object mask into an image recognition model;
- obtaining a first content matrix corresponding to the content image, a first texture matrix corresponding to the texture image, a second content matrix and a second texture matrix corresponding to the to-be-optimized image, a first mask matrix corresponding to the first object mask, and a second mask matrix corresponding to the second object mask by the image recognition model;
- dividing the first texture matrix into a plurality of first sub-matrices, and the second texture matrix into a plurality of second sub-matrices;
- calculating object loss and background loss according to the plurality of first sub-matrices, the plurality of second sub-matrices, the first mask matrix, and the second mask matrix, and calculating texture loss according to the object loss and the background loss;
- calculating content loss according to the first content matrix and the second content matrix;
- determining a total loss according to the texture loss and the content loss;
- transmitting the total loss to the image recognition model by using a gradient descent algorithm, and obtaining pixel loss of each pixel of the to-be-optimized image;
- adjusting a value of each pixel of the to-be-optimized image to minimize the total loss according to the pixel loss, and obtaining an optimized image.
Dependencies are inferred from the claim text.