Image processing method and electronic device
This application relates to the field of image processing, and provides an image processing method and an electronic device. The electronic device captures a first image—that is an image captured by a camera lens. The first image includes a first shot object and a second shot object. The electronic device determines a first scene corresponding to the first shot object and a second scene corresponding to the second shot object. The electronic device determines a first LUT based on the first scene, and determines a second LUT based on the second scene. The electronic device processes the first image based on the first LUT to obtain a second image, and processes the first image based on the second LUT to obtain a third image. The electronic device displays a fourth image. The fourth image includes a part of the second image and a part of the third image.
1 . An image processing method, wherein the method comprises:
obtaining, by an electronic device, a first image, wherein the first image is an image captured by a camera lens of the electronic device, and the first image comprises a first shot object and a second shot object;
determining, by the electronic device, that the first shot object is corresponding to a first scene and the second shot object is corresponding to a second scene, wherein the first scene is used to recognize a first shooting scene category corresponding to the first shot object, the second scene is used to recognize a second shooting scene category corresponding to the second shot object, and the first shooting scene category and the second shooting scene category are selected from a plurality of pre-configured object categories;
determining, by the electronic device, a first look up table (LUT) based on the first scene and a second LUT based on the second scene, wherein the second LUT is different from the first LUT, the first LUT and the second LUT are color mapping tables for color adjustment of a pixel, the first LUT and the second LUT are selected from a plurality of pre-configured LUTs based on a one-to-one mapping relationship between the plurality of pre-configured LUTs and the plurality of pre-configured object categories, and each of the plurality of pre-configured LUTs is associated with a respective display effect and converts input RGB color values to output RGB color values;
processing, by the electronic device, the first image based on the first LUT to obtain a second image, and processing, by the electronic device, the first image based on the second LUT to obtain a third image, wherein a display effect of the second image is corresponding to the first LUT, and a display effect of the third image is corresponding to the second LUT;
obtaining, by the electronic device, a first mask image of the first shot object and a second mask image of the second shot object based on the first image;
performing, by the electronic device, image composition on the second image and the third image based on the first mask image and the second mask image, to obtain a fourth image; and
displaying, by the electronic device, the fourth image, wherein the fourth image comprises a part of the second image and a part of the third image, wherein the part of the second image is an image corresponding to the first mask image in the second image; and the part of the third image is an image corresponding to the second mask image in the third image, and
wherein the part of the second image comprises the first shot object, a display effect of the part of the second image is corresponding to the first LUT, the part of the third image comprises the second shot object, and a display effect of the part of the third image is corresponding to the second LUT.
2 . The method according to claim 1 , wherein the method further comprises:
performing, by the electronic device, tone mapping on the first image to obtain a first image on which tone mapping is performed; and
the processing, by the electronic device, the first image based on the first LUT to obtain a second image, and processing, by the electronic device, the first image based on the second LUT to obtain a third image comprises:
processing, by the electronic device, the first image on which tone mapping is performed based on the first LUT to obtain the second image, and processing, by the electronic device, the first image on which tone mapping is performed based on the second LUT to obtain the third image.
3 . The method according to claim 2 , wherein the performing, by the electronic device, tone mapping on the first image to obtain a first image on which tone mapping is performed comprises:
performing, by the electronic device, tone mapping on the first image by using a gamma curve, to obtain the first image on which tone mapping is performed.
4 . The method according to claim 3 , wherein before the performing, by the electronic device, tone mapping on the first image by using a gamma curve, to obtain the first image on which tone mapping is performed, the method further comprises:
normalizing, by the electronic device, luminance values of pixels in the first image, to obtain a normalized first image,
wherein the electronic device performs tone mapping on the normalized first image by using the gamma curve, to obtain a second image on which tone mapping is performed.
5 . The method according to claim 1 , wherein before the determining, by the electronic device, that the first shot object is corresponding to a first scene and the second shot object is corresponding to a second scene, the method further comprises:
performing ratio-based subsampling, by the electronic device, on the first image at a first preset ratio, to obtain a subsampled first image,
wherein the electronic device recognizes the subsampled first image and determines that the first shot object is corresponding to the first scene and the second shot object is corresponding to the second scene; and the electronic device processes the subsampled first image, to obtain the first mask image of the first shot object and the second mask image of the second shot object.
6 . The method according to claim 5 , wherein before the performing, by the electronic device, image composition on the second image and the third image based on the first mask image and the second mask image, to obtain the fourth image, the method further comprises:
performing ratio-based upsampling, by the electronic device, on the first mask image and the second mask image at a second preset ratio respectively, to obtain an upsampled first mask image and an upsampled second mask image,
wherein the electronic device performs image composition on the second image and the third image based on the upsampled first mask image and the upsampled second mask image, to obtain the fourth image.
7 . The method according to claim 5 , wherein the performing, by the electronic device, image composition on the second image and the third image based on the first mask image and the second mask image, to obtain the fourth image comprises:
determining, by the electronic device, a first mask region from the second image based on the first mask image, and determining, by the electronic device, a second mask region from the third image based on the second mask image; and
composing, by the electronic device, an image in the first mask region and an image in the second mask region, to obtain the fourth image.
8 . The method according to claim 7 , wherein the composing, by the electronic device, an image in the first mask region and an image in the second mask region, to obtain the fourth image comprises:
feathering, by the electronic device, an edge region of the image in the first mask region and an edge region of the image in the second mask region, to obtain an image on which feathering is performed in the first mask region and an image on which feathering is performed in the second mask region; and
composing, by the electronic device, the image on which feathering is performed in the first mask region and the image on which feathering is performed in the second mask region, to obtain the fourth image.
9 . An electronic device, wherein the electronic device comprises a memory, a display, one or more camera lenses, and one or more processors; and the memory, the display, and the one or more camera lenses are coupled to the one or more processors, wherein the memory stores computer program code, the computer program code comprises computer instructions, and when the computer instructions are executed by the one or more processors, the electronic device is enabled to perform operations comprising:
obtaining a first image, wherein the first image is an image captured by the one or more camera lenses, and the first image comprises a first shot object and a second shot object;
determining that the first shot object is corresponding to a first scene and the second shot object is corresponding to a second scene, wherein the first scene is used to recognize a first shooting scene category corresponding to the first shot object, the second scene is used to recognize a second shooting scene category corresponding to the second shot object, and the first shooting scene category and the second shooting scene category are selected from a plurality of pre-configured object categories;
determining a first look up table (LUT) based on the first scene and a second LUT based on the second scene, wherein the second LUT is different from the first LUT, the first LUT and the second LUT are color mapping tables for color adjustment of a pixel, the first LUT and the second LUT are selected from a plurality of pre-configured LUTs based on a one-to-one mapping relationship between the plurality of pre-configured LUTs and the plurality of pre-configured object categories, and each of the plurality of pre-configured LUTs is associated with a respective display effect and converts input RGB color values to output RGB color values;
processing the first image based on the first LUT to obtain a second image, and processing, by the electronic device, the first image based on the second LUT to obtain a third image, wherein a display effect of the second image is corresponding to the first LUT, and a display effect of the third image is corresponding to the second LUT;
obtaining a first mask image of the first shot object and a second mask image of the second shot object based on the first image;
performing image composition on the second image and the third image based on the first mask image and the second mask image, to obtain a fourth image; and
displaying the fourth image, wherein the fourth image comprises a part of the second image and a part of the third image, wherein the part of the second image is an image corresponding to the first mask image in the second image; and the part of the third image is an image corresponding to the second mask image in the third image, and
wherein the part of the second image comprises the first shot object, a display effect of the part of the second image is corresponding to the first LUT, the part of the third image comprises the second shot object, and a display effect of the part of the third image is corresponding to the second LUT.
10 . The electronic device according to claim 9 , wherein the operations further comprise:
performing, by the electronic device, tone mapping on the first image to obtain a first image on which tone mapping is performed; and
the processing, by the electronic device, the first image based on the first LUT to obtain a second image, and processing, by the electronic device, the first image based on the second LUT to obtain a third image comprises:
processing, by the electronic device, the first image on which tone mapping is performed based on the first LUT to obtain the second image, and processing, by the electronic device, the first image on which tone mapping is performed based on the second LUT to obtain the third image.
11 . The electronic device according to claim 10 , wherein the performing, by the electronic device, tone mapping on the first image to obtain a first image on which tone mapping is performed comprises:
performing, by the electronic device, tone mapping on the first image by using a gamma curve, to obtain the first image on which tone mapping is performed.
12 . The electronic device according to claim 11 , wherein before the performing, by the electronic device, tone mapping on the first image by using a gamma curve, to obtain the first image on which tone mapping is performed, the operations further comprise:
normalizing, by the electronic device, luminance values of pixels in the first image, to obtain a normalized first image,
wherein the electronic device performs tone mapping on the normalized first image by using the gamma curve, to obtain a second image on which tone mapping is performed.
13 . A non-transitory computer-readable storage medium, comprising computer instructions, wherein when the computer instructions are run on an electronic device, the electronic device is enabled to perform operations comprising:
obtaining a first image, wherein the first image is an image captured by one or more camera lenses, and the first image comprises a first shot object and a second shot object;
determining that the first shot object is corresponding to a first scene and the second shot object is corresponding to a second scene, wherein the first scene is used to recognize a first shooting scene category corresponding to the first shot object, and the second scene is used to recognize a second shooting scene category corresponding to the second shot object, and the first shooting scene category and the second shooting scene category are selected from a plurality of pre-configured object categories;
determining a first look up table (LUT) based on the first scene and a second LUT based on the second scene, wherein the second LUT is different from the first LUT, the first LUT and the second LUT are color mapping tables for color adjustment of a pixel, the first LUT and the second LUT are selected from a plurality of pre-configured LUTs based on a one-to-one mapping relationship between the plurality of pre-configured LUTs and the plurality of pre-configured object categories, and each of the plurality of pre-configured LUTs is associated with a respective display effect and converts input RGB color values to output RGB color values;
processing the first image based on the first LUT to obtain a second image, and processing, by the electronic device, the first image based on the second LUT to obtain a third image, wherein a display effect of the second image is corresponding to the first LUT, and a display effect of the third image is corresponding to the second LUT;
obtaining a first mask image of the first shot object and a second mask image of the second shot object based on the first image;
performing image composition on the second image and the third image based on the first mask image and the second mask image, to obtain a fourth image; and
displaying the fourth image, wherein the fourth image comprises a part of the second image and a part of the third image, wherein the part of the second image is an image corresponding to the first mask image in the second image; and the part of the third image is an image corresponding to the second mask image in the third image, and
wherein the part of the second image comprises the first shot object, a display effect of the part of the second image is corresponding to the first LUT, the part of the third image comprises the second shot object, and a display effect of the part of the third image is corresponding to the second LUT.
14 . The non-transitory computer-readable storage medium according to claim 13 , wherein the operations further comprise:
performing, by the electronic device, tone mapping on the first image to obtain a first image on which tone mapping is performed; and
the processing, by the electronic device, the first image based on the first LUT to obtain a second image, and processing, by the electronic device, the first image based on the second LUT to obtain a third image comprises:
processing, by the electronic device, the first image on which tone mapping is performed based on the first LUT to obtain the second image, and processing, by the electronic device, the first image on which tone mapping is performed based on the second LUT to obtain the third image.
15 . The non-transitory computer-readable storage medium according to claim 14 , wherein the performing, by the electronic device, tone mapping on the first image to obtain a first image on which tone mapping is performed comprises:
performing, by the electronic device, tone mapping on the first image by using a gamma curve, to obtain the first image on which tone mapping is performed.
16 . The non-transitory computer-readable storage medium according to claim 15 , wherein before the performing, by the electronic device, tone mapping on the first image by using a gamma curve, to obtain the first image on which tone mapping is performed, the operations further comprise:
normalizing, by the electronic device, luminance values of pixels in the first image, to obtain a normalized first image,
wherein the electronic device performs tone mapping on the normalized first image by using the gamma curve, to obtain a second image on which tone mapping is performed.
17 . The non-transitory computer-readable storage medium according to claim 13 , wherein before the determining, by the electronic device, that the first shot object is corresponding to a first scene and the second shot object is corresponding to a second scene, the operations further comprise:
performing ratio-based subsampling, by the electronic device, on the first image at a first preset ratio, to obtain a subsampled first image,
wherein the electronic device recognizes the subsampled first image and determines that the first shot object is corresponding to the first scene and the second shot object is corresponding to the second scene; and the electronic device processes the subsampled first image, to obtain the first mask image of the first shot object and the second mask image of the second shot object.
18 . The non-transitory computer-readable storage medium according to claim 17 , wherein before the performing, by the electronic device, image composition on the second image and the third image based on the first mask image and the second mask image, to obtain the fourth image, the operations further comprise:
performing ratio-based upsampling, by the electronic device, on the first mask image and the second mask image at a second preset ratio respectively, to obtain an upsampled first mask image and an upsampled second mask image,
wherein the electronic device performs image composition on the second image and the third image based on the upsampled first mask image and the upsampled second mask image, to obtain the fourth image.
19 . The non-transitory computer-readable storage medium according to claim 17 , wherein the performing, by the electronic device, image composition on the second image and the third image based on the first mask image and the second mask image, to obtain the fourth image comprises:
determining, by the electronic device, a first mask region from the second image based on the first mask image, and determining, by the electronic device, a second mask region from the third image based on the second mask image; and
composing, by the electronic device, an image in the first mask region and an image in the second mask region, to obtain the fourth image.
20 . The non-transitory computer-readable storage medium according to claim 19 , wherein the composing, by the electronic device, an image in the first mask region and an image in the second mask region, to obtain the fourth image comprises:
feathering, by the electronic device, an edge region of the image in the first mask region and an edge region of the image in the second mask region, to obtain an image on which feathering is performed in the first mask region and an image on which feathering is performed in the second mask region; and
composing, by the electronic device, the image on which feathering is performed in the first mask region and the image on which feathering is performed in the second mask region, to obtain the fourth image.