WO2022142219A1 - 图像背景处理方法、装置、电子设备及存储介质 - Google Patents

图像背景处理方法、装置、电子设备及存储介质 Download PDF

Info

Publication number
WO2022142219A1
WO2022142219A1 PCT/CN2021/103535 CN2021103535W WO2022142219A1 WO 2022142219 A1 WO2022142219 A1 WO 2022142219A1 CN 2021103535 W CN2021103535 W CN 2021103535W WO 2022142219 A1 WO2022142219 A1 WO 2022142219A1
Authority
WO
WIPO (PCT)
Prior art keywords
pixel
information
target
original image
pixel information
Prior art date
Application number
PCT/CN2021/103535
Other languages
English (en)
French (fr)
Inventor
程俊奇
四建楼
Original Assignee
上海商汤智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 上海商汤智能科技有限公司 filed Critical 上海商汤智能科技有限公司
Publication of WO2022142219A1 publication Critical patent/WO2022142219A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/194Segmentation; Edge detection involving foreground-background segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/22Matching criteria, e.g. proximity measures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T3/00Geometric image transformations in the plane of the image
    • G06T3/40Scaling of whole images or parts thereof, e.g. expanding or contracting
    • G06T3/4007Scaling of whole images or parts thereof, e.g. expanding or contracting based on interpolation, e.g. bilinear interpolation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/11Region-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/136Segmentation; Edge detection involving thresholding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/90Determination of colour characteristics
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10024Color image

Definitions

  • the present disclosure relates to the technical field of image processing, and in particular, to an image background processing method, apparatus, electronic device, and storage medium.
  • Image segmentation technology refers to the technology of dividing an image into non-overlapping regions with their own characteristics. Image segmentation technology can be applied to a variety of scenarios. For example, image segmentation technology can be applied to image background replacement scenarios.
  • the background image in the live broadcast screen needs to be replaced.
  • the background image of the live broadcast screen is a green image
  • the green image in the live broadcast screen needs to be replaced with Set the background image to increase the flexibility of the live screen display. Therefore, it is very important to propose an image background processing method.
  • the present disclosure provides at least an image background processing method, apparatus, electronic device, and storage medium.
  • the present disclosure provides an image background processing method, including:
  • the original image is segmented to obtain segmentation results of at least three types of areas, the at least three types of areas include foreground areas and background areas and the border area between the foreground area and the background area;
  • the target image is generated based on the transparency information of the pixel points respectively included in the at least three types of regions and the pixel information of the target background to be replaced.
  • the original image can be divided into at least three types of areas, at least three types of areas include foreground area, background area, and the boundary area between the foreground area and the background area, the pixels located at the intersection of the foreground area and the background area are divided into Dividing points into boundary regions can improve the accuracy of segmentation results.
  • the transparency information of the background area can be set to 1 (opaque), reduce the interference of the background color represented by the sampling pixel information to the pixel information of the target background to be replaced, make the target background area and foreground area in the target image obtained by background replacement more accurate, and optimize the image processing effect.
  • the method before using the sampling pixel information of the sampling pixel points on the background area of the original image to perform segmentation processing on the original image to obtain segmentation results of at least three types of areas, the method further includes:
  • the method further includes:
  • the segmentation results of the at least three types of regions are mapped back to the original image before the size reduction process.
  • the capacity of the original image after the reduction in size is small, so when the original image after the reduction in size is used for segmentation processing, the resource consumption of the execution device can be reduced. And the obtained segmentation result is mapped back to the size of the original image, so that the target image obtained by using the segmentation result for background replacement is more accurate.
  • the original image is segmented by using the sampling pixel information of the sampling pixel points on the background area of the original image to obtain at least three types of area segmentation results, including:
  • the original image is segmented to obtain segmentation results of at least three types of regions.
  • the colors corresponding to the pixels in the background area are located in the same color gamut, and the color similarity between pixels located in the same color gamut is high, and the color similarity between pixels located in different color gamuts is low, so
  • the original image can be segmented by using the color similarity corresponding to each pixel point, and the segmentation results of at least three types of regions can be obtained more accurately.
  • the sampled pixels are pixels located in the background area of the original image, and the color corresponding to the sampled pixel information of the sampled pixels can represent the color of the background area in the original image.
  • the color similarity between the sampled pixel information of the sampled pixel points can more accurately determine the similarity between the color corresponding to the pixel information of each pixel point in the original image and the color of the background area.
  • the determining the color similarity between the pixel information of each pixel in the original image and the sampling pixel information of the sampling pixel respectively includes:
  • the target color space is determined based on the sampling pixel information of the sampling pixel
  • the target color space can be determined based on the sampled pixel information of the sampled pixel points, so that relatively abundant pixel features in the original image can be obtained in the corresponding target color space. Furthermore, the color similarity between the target pixel information of each pixel in the determined target color space and the target sampling pixel information of the sampled pixels in the target color space can be more accurately determined. For example, when the color of the sampling pixel is bright colors such as red and green, the target color space can be the YCRCB color space, that is, when the color corresponding to the sampling pixel is bright, the original image can be obtained in the YCRCB color space. richer pixel features.
  • the method further includes:
  • the determining the color similarity between the target pixel information of each pixel in the target color space and the target sampling pixel information of the sampling pixel in the target color space including:
  • the pixel information of each pixel in the first pixel set matches the sampling pixel information of the sampling pixel, for example, the color corresponding to the pixel information of each pixel in the first pixel set, and the sampling pixel.
  • the colors corresponding to the sampled pixel information of are in the same color gamut. Since the sampling pixel points are located in the background area, it can be determined that each pixel point in the first pixel point set is also located in the background area, so that the generated target color space is generated by using the first pixel information of the first pixel point in the target color space.
  • the Gaussian color model below is more accurate, and further, the color similarity of each pixel in the original image can be more accurately determined.
  • the determining of the first pixel point set whose pixel information in the original image matches the sampling pixel information of the sampling pixel point includes:
  • the sampling pixel information of the sampling pixel under the HSV color space is the first sampling pixel information
  • the filtered pixel point set is the first pixel point set.
  • the HSV color space can divide the entire color space into different color gamuts, after converting the pixel information of each pixel of the original image to the pixel information in the HSV color space, it can be more accurate from each pixel in the HSV color space.
  • a set of pixel points located in the same color gamut as the first sampled pixel information is selected from the pixel information.
  • the original image is segmented by using the color similarity corresponding to each pixel to obtain segmentation results of at least three types of regions, including:
  • the segmentation processing includes:
  • the segmentation results of the pixels are more accurately determined, so that the generated segmentation results of at least three types of regions are more accurate.
  • determining the transparency information of the pixels respectively included in the at least three types of areas based on the segmentation results of the at least three types of areas includes:
  • the transparency information of the pixel points in the boundary area is determined.
  • different transparency information is set for pixels in different areas, and the set transparency information can control the pixel information of pixels in different areas, and the degree of influence of the pixel information of the target background to be replaced, so as to improve the generated target image processing effect.
  • determining the transparency information of the pixel points in the boundary area based on the pixel information of the pixel points in the boundary area and the sampled pixel information of the sampled pixel points includes:
  • the transparency information of each pixel point in the border area is determined.
  • the color similarity corresponding to each pixel in the boundary area can be determined, and the transparency information of each pixel in the boundary area can be more accurately determined by using the determined color similarity and the first and second thresholds.
  • determining the transparency information of each pixel point in the border area based on the color similarity corresponding to each pixel point in the border area, and the first limit value and the second limit value including: :
  • the color similarity corresponding to the pixel point is greater than or equal to the first limit value and less than the second limit value
  • the color similarity of the pixel points is normalized, and the normalized color similarity is determined as the transparency information of the pixel point.
  • the transparency information of each pixel in the boundary area may be determined based on the color similarity of each pixel in the boundary area. For example, when the color similarity of the pixels in the boundary area is less than the first threshold value, it indicates that the pixel is more likely to belong to the foreground area, so the transparency information of the pixel can be set as the first transparency value; When the color similarity of the pixels in the area is greater than or equal to the second threshold value, it indicates that the pixel is more likely to belong to the background area, so the transparency information of the pixel can be set as the second transparency value, thereby realizing the Each pixel in the border area is screened again to improve the accuracy of the transparency information of each pixel in the border area.
  • generating the target image based on the transparency information of the pixel points contained in the at least three types of areas respectively and the pixel information of the target background to be replaced includes:
  • the target image is generated.
  • the intermediate pixel information corresponding to the pixel points can be determined first, and the intermediate image formed by the intermediate pixel information can be an image in which the background color corresponding to the sampling pixel information is eliminated and the target background is roughly superimposed, that is, the intermediate pixel information is eliminated. Then, based on the intermediate pixel information, transparency information of each pixel, and the pixel information of the target background corresponding to the position of the pixel, the determined target pixel information of each pixel is the elimination Therefore, based on the target pixel information of each pixel point, the effect of the generated target image can be better.
  • the transparency information based on the pixel point, the pixel information of the pixel point, the sampled pixel information of the sampled pixel point, and the The pixel information of the target background, and the intermediate pixel information of the pixel is determined, including:
  • the pixel information of the pixel point is subtracted from the first product information, and then the obtained difference is added to the second product information to obtain the intermediate pixel information of the pixel point.
  • the determination of each pixel is based on the intermediate pixel information, the transparency information, and the pixel information of the target background corresponding to the position of each pixel.
  • Pixel target pixel information including:
  • the sum of the third product information and the fourth product information is determined as the target pixel information of the pixel point.
  • an image background processing apparatus including:
  • the acquisition module is used to acquire the original image
  • a segmentation module configured to perform segmentation processing on the original image by using the sampling pixel information of the sampling pixel points selected from the background portion of the original image to obtain segmentation results of at least three types of regions, and the at least three types of regions include a foreground area, a background area, and a border area between the foreground area and the background area;
  • a first determination module configured to determine the transparency information of the pixels respectively included in the at least three types of areas based on the segmentation results of the at least three types of areas;
  • a generating module is configured to generate a target image based on the transparency information of the pixel points respectively included in the at least three types of regions and the pixel information of the target background to be replaced.
  • the present disclosure provides an electronic device, comprising: a processor, a memory, and a bus, the memory stores machine-readable instructions executable by the processor, and when the electronic device runs, the processor communicates with the The memory communicates with each other through a bus, and when the machine-readable instructions are executed by the processor, the steps of the image background processing method according to the first aspect or any one of the implementation manners are executed.
  • the present disclosure provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and the computer program executes the image according to the first aspect or any one of the embodiments when the computer program is run by a processor.
  • the steps of the background processing method are described in detail below.
  • FIG. 1 shows a schematic flowchart of an image background processing method provided by an embodiment of the present disclosure
  • FIG. 2 shows a schematic diagram of a ternary image including at least three types of regions in an image background processing method provided by an embodiment of the present disclosure
  • FIG. 3 shows a schematic flowchart of a manner for obtaining segmentation results of at least three types of regions in an image background processing method provided by an embodiment of the present disclosure
  • FIG. 4 shows a schematic diagram of the architecture of an image background processing apparatus provided by an embodiment of the present disclosure
  • FIG. 5 shows a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
  • the background image in the live broadcast screen needs to be replaced.
  • the background image of the live broadcast screen is a green image
  • the green image in the live broadcast screen needs to be replaced with Set the background image to increase the flexibility of the live screen display.
  • the live scene image can be segmented, the background area and foreground area included in the live scene image can be determined, and then the background color of the background area of the live scene image can be replaced with the set color to be replaced.
  • the pixel information corresponding to the color the pixel information of the pixels located in the background area on the live scene image is replaced with the pixel information corresponding to the set color to be replaced, so as to realize the background color replacement of the live scene image.
  • the background color is replaced according to the above method, it is easy to cause the background area and the foreground area to be wrongly segmented. Occurs, for example, the segmented foreground area includes pixels belonging to the background area.
  • the pixel information of the pixels belonging to the background area included in the foreground area cannot be replaced. , so that the original background color before the replacement exists in the foreground area of the image generated after the background color replacement, so that the effect of the image generated after the background color replacement is poor.
  • the execution subject of the image background processing method provided by the embodiments of the present disclosure is generally a computer device with a certain computing capability. ), mobile devices, user terminals, terminals, cellular phones, cordless phones, personal digital assistants (Personal Digital Assistant, PDA), handheld devices, computing devices, in-vehicle devices, wearable devices, etc.
  • the image background processing method may be implemented by the processor calling computer-readable instructions stored in the memory.
  • FIG. 1 is a schematic flowchart of an image background processing method provided by an embodiment of the present disclosure, the method includes S101-S104, wherein:
  • S102 using the sampling pixel information of the sampling pixel points selected from the background portion of the original image, perform segmentation processing on the original image to obtain segmentation results of at least three types of regions, where the at least three types of regions include foreground regions, a background area and a boundary area between the foreground area and the background area;
  • S104 Generate a target image based on the transparency information of the pixel points respectively included in the at least three types of regions and the pixel information of the target background to be replaced.
  • the original image can be divided into at least three types of areas, at least three types of areas include foreground area, background area, and the boundary area between the foreground area and the background area, the pixels located at the intersection of the foreground area and the background area are divided into Dividing points into boundary regions can improve the accuracy of segmentation results.
  • the transparency information of the background area can be set to 1 (opaque), reduce the interference of the background color represented by the sampling pixel information to the pixel information of the target background to be replaced, make the target background area and foreground area in the target image obtained by background replacement more accurate, and optimize the image processing effect.
  • the original image may be any image that needs to be background processed, for example, the original image may be a certificate photo that needs to be background processed; or, the original image may be a live image in a live broadcast scene, or the like.
  • the original image may be an image in any color space, for example, the original image may be a red green blue (red green blue, RGB) image.
  • the sampling pixel points can be determined from the background part of the original image, and the original image can be segmented according to the sampling pixel information of the sampling pixel points to obtain segmentation results of at least three types of regions, that is, the foreground on the original image is determined. regions, background regions, and border regions between foreground and background regions.
  • a ternary image corresponding to the segmentation result and having the same size as the original image may be generated based on the segmentation results of at least three types of areas, wherein the pixel information of the pixels located in the foreground area in the ternary image may be The first pixel value (for example, the first pixel value may be 0), the pixel information of the pixels located in the border area may be the second pixel value (for example, the second pixel value may be 2), and the pixel information of the pixels located in the background area
  • the pixel information may be a third pixel value (eg, the third pixel value may be 255).
  • FIG. 2 Referring to a schematic diagram of a ternary image including at least three types of regions in an image background processing method shown in FIG. 2 .
  • the area corresponding to black is the foreground area
  • the area corresponding to white is the background area
  • the area corresponding to gray between white and black is the border area.
  • the location information of the sampled pixel can be determined in response to the triggered sampling pixel determination operation, and then based on the location information of the sampled pixel, the sampled pixel information of the sampled pixel can be determined, wherein the sampled pixel information of the sampled pixel is It can be the pixel information of the sampled pixels in the original image. For example, a sampling pixel point selected by the user from the background part of the original image can be detected, and then the sampling pixel information of the sampling pixel point can be determined according to the position information of the sampling pixel point.
  • a neural network for image segmentation can also be used to determine the background area on the original image, and randomly determine the location information of the sampling pixels from the background area, and then determine the location of the sampling pixels based on the location information of the sampling pixels. Sample pixel information.
  • a clustering algorithm can also be used to obtain a plurality of pixels with a small deviation of color information on the original image; and based on the position information of the plurality of pixels obtained by the clustering on the original image, the sampling pixels are determined. location information.
  • the position information of multiple pixel points obtained by clustering can be averaged to obtain the position information of sampling pixel points; or, a pixel point can be randomly selected from multiple pixel points with the same color information as the sampling point.
  • pixel point and determine the position information of the selected pixel point as the position information of the sampling pixel point; and then determine the sampling pixel information of the sampling pixel point based on the position information of the sampling pixel point.
  • the sampling pixel information of the sampling pixel is the pixel information of the sampling pixel on the original image.
  • the sampling pixel information may include pixels on three color channels of red R, green G, and blue B. value.
  • the method before using the sampling pixel information of the sampling pixel points on the background area of the original image to perform segmentation processing on the original image to obtain segmentation results of at least three types of areas, the method further includes:
  • the original image is reduced in size.
  • the original image may be reduced in size by means of down-sampling or down-sampling, so as to obtain the original image after the reduction in size.
  • the size of the original image after the size reduction process can be set according to actual needs.
  • the method further includes: mapping the segmentation results of the at least three types of regions back to the original image before the size reduction processing.
  • an interpolation algorithm may be used to map the segmentation results of at least three types of regions onto the original image before the size reduction process.
  • the pixels in the background area can be interpolated and mapped to the original image before the size reduction processing, and the background area on the original image before the size reduction processing can be determined.
  • the determination process of the foreground area and the boundary area on the original image before the size reduction process reference may be made to the above-mentioned determination process of the background area on the original image before the size reduction process, which will not be described in detail here.
  • the capacity of the original image after the reduction in size is small. Therefore, when the original image after the reduction in size is used for segmentation processing, the resource consumption of the execution device can be reduced. And the obtained segmentation result is mapped back to the size of the original image, so that the target image obtained by using the segmentation result for background replacement is more accurate.
  • the step of S102 can be specifically implemented in the following manner:
  • the colors corresponding to the pixels in the background area are located in the same color gamut, and the color similarity between pixels located in the same color gamut is high, and the color similarity between pixels located in different color gamuts is low, so
  • the original image can be segmented by using the color similarity corresponding to each pixel point, and the segmentation results of at least three types of regions can be obtained more accurately.
  • the sampled pixels are pixels located in the background area of the original image, and the color corresponding to the sampled pixel information of the sampled pixels can represent the color of the background area in the original image.
  • the color similarity between the sampled pixel information of the sampled pixel points can more accurately determine the similarity between the color corresponding to the pixel information of each pixel point in the original image and the color of the background area.
  • the original image determines the color similarity between the pixel information of the pixel and the sampling pixel information of the sampling pixel; that is, obtain the color similarity of each pixel in the original image .
  • the original image may be the original image before size reduction processing, or may be the original image after size reduction processing.
  • the color similarity corresponding to each pixel in the original image after the size reduction process can be determined, and then the color similarity corresponding to each pixel point can be used to perform the original size reduction process.
  • the original image obtained by the size reduction process is segmented to obtain segmentation results of at least three types of regions; finally, the segmentation results of at least three types of regions can be mapped back to the original image before the size reduction process to obtain the foreground included in the original image before the size reduction process. area, background area, and border area.
  • determining the color similarity between the pixel information of each pixel in the original image and the sampled pixel information of the sampled pixel respectively includes:
  • S3011 converting the pixel information of each pixel in the original image to target pixel information in a target color space; the target color space is determined based on the sampling pixel information of the sampling pixel;
  • S3012 Determine the color similarity between the target pixel information of each pixel in the target color space and the target sampling pixel information of the sampling pixel in the target color space.
  • the target color space can be determined based on the sampled pixel information of the sampled pixel points, so that relatively abundant pixel features in the original image can be obtained in the corresponding target color space. Furthermore, the color similarity between the target pixel information of each pixel in the determined target color space and the target sampling pixel information of the sampled pixels in the target color space can be more accurately determined. For example, when the color of the sampling pixel is bright colors such as red and green, the target color space can be the YCRCB color space, that is, when the color corresponding to the sampling pixel is bright, the original image can be obtained in the YCRCB color space. richer pixel features.
  • the target color space corresponding to the original image may be determined based on the sampling pixel information of the sampling pixel points.
  • the sampling pixel information indicates that the color of the sampling pixel is relatively bright (for example, the color corresponding to the sampling pixel is red, green, etc.), then it is determined that the target color space corresponding to the original image can be the YCRCB color space; in the sampling pixel information If the color representing the sampling pixel is relatively dim (for example, the color of the sampling pixel is black, gray, white, etc.), it is determined that the target color space corresponding to the original image may be the RGB color space.
  • the target color space may also be determined in response to a triggered selection operation.
  • the target color space in response to a triggered selection operation, may be determined to be the RGB color space, or the target color space may be determined to be the Hue Saturation Value (HSV) color space, or the target color space may be determined to be the YCRCB color space, etc. .
  • HSV Hue Saturation Value
  • the pixel information of each pixel in the original image is consistent with the target pixel information.
  • the pixel information of each pixel in the original image can be converted into the YCRCB color space to generate the target pixel information of each pixel in the YCRCB color space.
  • the method further includes: S105 , determining a first set of pixel points whose pixel information in the original image matches the sampling pixel information of the sampling pixel point.
  • the pixel information of each pixel included in the first pixel set in the original image is pixel information that belongs to the same color gamut as the sampling pixel information of the sampling pixel. For example, if the sampled pixel information of the sampled pixel points is within the cyan color gamut, the pixel information of each pixel point included in the first pixel point set is the pixel information within the cyan color gamut.
  • a first set of pixel points whose pixel information in the original image matches the sampled pixel information of the sampled pixel point may be determined according to the following steps:
  • S1051 converting the pixel information of each pixel of the original image into pixel information in the hue saturation lightness HSV color space; the sampling pixel information of the sampling pixel in the HSV color space is the first sampling pixel information;
  • the screened out pixel point set is the first pixel point set.
  • the HSV color space can divide the entire color space into different color gamuts, after converting the pixel information of each pixel of the original image to the pixel information in the HSV color space, it can be more accurate from each pixel in the HSV color space.
  • a set of pixel points located in the same color gamut as the first sampled pixel information is selected from the pixel information.
  • the pixel information of the pixel can be converted into the HSV color space according to the pixel conversion formula between RGB and HSV to obtain the original image.
  • the pixel information of each pixel of the image in the HSV color space includes the first sampled pixel information of the sampled pixel in the HSV color space.
  • the color gamut to which the first sampled pixel information of the sampled pixels belongs can be determined, and a set of pixels located in the same color gamut as the first sampled pixel information is selected from the pixel information of each pixel in the HSV color space. For example, when it is determined that the first sampled pixel information of the sampled pixel points belongs to the blue color gamut, the set of pixel points located in the blue color gamut is selected from the pixel information of each pixel point in the HSV color space; Determined as the first set of pixels.
  • the pixel information of the first pixels can be used to determine the target pixel information of each pixel in the target color space and the sampling pixels in the target color space respectively.
  • the color similarity between the pixel information of the target sampled below.
  • S3012 may be implemented in the following manner:
  • Step 1 Convert the pixel information of each first pixel in the first pixel set to the first pixel information in the target color space;
  • Step 2 based on the first pixel information of each first pixel, generate a Gaussian color model under the target color space;
  • Step 3 Input the target pixel information of each pixel in the original image and the target sampling pixel information of the sampling pixel into the Gaussian color model, and obtain the target pixel information of each pixel and the sampling pixel respectively.
  • the color similarity between the target sampled pixel information of the point is the color similarity between the target sampled pixel information of the point.
  • the pixel information of each pixel in the first pixel set matches the sampling pixel information of the sampling pixel, for example, the color corresponding to the pixel information of each pixel in the first pixel set, and the sampling pixel.
  • the color corresponding to the sampled pixel information of the point is in the same color gamut. Since the sampling pixel points are located in the background area, it can be determined that each pixel point in the first pixel point set is also located in the background area, so that the generated target color space is generated by using the first pixel information of the first pixel point in the target color space.
  • the Gaussian color model below is more accurate, and further, the color similarity of each pixel in the original image can be more accurately determined.
  • the pixel information of each first pixel point in the first pixel point set may be converted into a target color space to generate the first pixel information of each first pixel point in the first pixel point set.
  • the pixel information of each first pixel in the first pixel set may be pixel information on the original image.
  • the Gaussian color model is a model composed of one or more normal distribution curves used to characterize the first pixel information of each first pixel point.
  • the constructed Gaussian color model uses the constructed Gaussian color model to process the target pixel information and target sampling pixel information of each pixel in the original image, and obtain the color similarity between the target pixel information of each pixel and the target sampling pixel information of the sampling pixel respectively.
  • Spend For example, for the target pixel information of the first pixel in the original image, the target mean and target variance indicated by the determined Gaussian color model can be used to determine the difference between the target pixel information of the first pixel and the target sampling pixel information of the sampling pixel. color similarity.
  • the target sampling pixel information is the pixel information of the target pixel in the target color space.
  • the color similarity can be the color corresponding to the target pixel information of the pixel point, the color corresponding to the target sampling pixel information of the sampling pixel point (which can represent the background in the original image) The degree of similarity between the colors corresponding to the regions).
  • performing segmentation processing on the original image by using the color similarity corresponding to each of the pixel points to obtain segmentation results of at least three types of regions which may include: traversing the pixel points in the original image, Perform segmentation processing on the traversed pixel points to obtain the segmentation results of the traversed pixel points; after obtaining the segmentation results of all the traversed pixel points, generate the segmentation results of the at least three types of regions.
  • the target area to which the pixel belongs determine the target area to which the pixel belongs (the segmentation result of the pixel), and the target area is at least One of three regions (foreground region, border region, background region).
  • segmentation results of at least three types of regions may be generated by using the segmentation results of all the traversed pixels.
  • the segmentation processing includes:
  • the segmentation results of the pixels are more accurately determined, so that the generated segmentation results of at least three types of regions are more accurate.
  • the similarity between the color corresponding to the traversed pixel and the color corresponding to the sampled pixel (which can represent the color corresponding to the background area in the original image) If the degree is low, the possibility that the traversed pixel belongs to the background area is low, so it is determined that the traversed pixel is in the foreground area.
  • the color similarity of the traversed pixel points is greater than or equal to the second threshold, it indicates that the color corresponding to the traversed pixel point and the color corresponding to the sampled pixel point have a high degree of similarity, and the traversed pixel point has a high degree of similarity.
  • the possibility of belonging to the background area is high, so it is determined that the traversed pixel is in the background area.
  • the color similarity of the traversed pixel is greater than or equal to the first threshold and less than the second threshold, it cannot be accurately determined that the pixel belongs to the foreground area or the background area, then it can be determined that the traversed pixel belongs to the foreground Boundary region between region and background region.
  • the first threshold and the second threshold may be set according to actual needs, and the first threshold is smaller than the second threshold.
  • the set first threshold can be 0.3
  • the second threshold can be 0.8.
  • the color similarity of the traversed pixel is detected to be less than 0.3, the pixel is in the foreground area; when the traversed pixel is detected When the color similarity of the point is greater than or equal to 0.8, the pixel is in the background area; when it is detected that the traversed pixel is greater than or equal to 0.3 and less than 0.8, the pixel is in the boundary area.
  • the determined boundary area can be morphologically
  • the expansion operation in the learning operation is used to obtain the segmentation results of at least three types of regions after the expansion operation.
  • the dilation operation is the basic operation used to expand the area of the target area in the image in the morphological operation.
  • an expansion operation may be performed on the boundary areas indicated by the obtained at least three types of areas, Obtain the segmentation results of at least three types of regions corresponding to the original image after the size reduction process and after the expansion operation; and then map the segmentation results of at least three types of regions corresponding to the original image after the size reduction process and after the expansion operation back to the size downscaled on the original image before processing.
  • the boundary region indicated by the at least three types of regions corresponding to the original image before the size reduction process may be expanded to obtain the size reduction process. Segmentation results of at least three types of regions corresponding to the original image before processing and after the dilation operation.
  • Case 1 Determine the transparency information of the pixels in the foreground area as the preset first transparency value
  • Case 2 Determine the transparency information of the pixels in the background area as the preset second transparency value
  • the transparency information of the pixel points in the boundary area is determined based on the pixel information of the pixel points in the boundary area and the sampled pixel information of the sampled pixel points.
  • different transparency information is set for pixels in different areas, and the set transparency information can control the pixel information of pixels in different areas, and the degree of influence of the pixel information of the target background to be replaced, so as to improve the generated target image processing effect.
  • first transparency value and the second transparency value can be set as required.
  • first transparency value may be set to 0, and the second transparency value may be set to 1.
  • determining the transparency information of the pixels in the boundary area based on the pixel information of the pixels in the boundary area and the sampled pixel information of the sampled pixels may include:
  • S1032 Determine the transparency information of each pixel in the boundary area based on the color similarity corresponding to each pixel in the boundary area, and the first threshold value and the second threshold value.
  • the color similarity corresponding to each pixel in the boundary area can be determined, and the transparency information of each pixel in the boundary area can be more accurately determined by using the determined color similarity and the first and second thresholds.
  • the target pixel information of the pixel information of each pixel in the boundary area in the target color space can be determined; and then input the target pixel information of each pixel in the boundary area into the Gaussian color model to obtain each pixel in the boundary area.
  • the color similarity between the pixel information of the pixel point and the sampled pixel information of the sampled pixel point in the target color space can be determined; and then input the target pixel information of each pixel in the boundary area into the Gaussian color model to obtain each pixel in the boundary area.
  • the first threshold A threshold value and the second threshold value determine the transparency information of the pixel point.
  • the transparency information of each pixel in the boundary area may be determined based on the color similarity of each pixel in the boundary area. For example, when the color similarity of the pixels in the boundary area is less than the first threshold value, it indicates that the pixel is more likely to belong to the foreground area, so the transparency information of the pixel can be set as the first transparency value; When the color similarity of the pixels in the area is greater than or equal to the second threshold value, it indicates that the pixel is more likely to belong to the background area, so the transparency information of the pixel can be set as the second transparency value, thereby realizing the Each pixel in the border area is screened again to improve the accuracy of the transparency information of each pixel in the border area.
  • the first limit value and the second limit value can be set as required, wherein the first limit value is smaller than the second limit value; the first limit value and the first threshold value can be consistent or inconsistent; and the second limit value and the second limit value Thresholds can be consistent or inconsistent.
  • the transparency information of the pixel can be set as the preset first threshold.
  • a transparency value when the color similarity corresponding to the pixel point is greater than or equal to the second threshold value, the pixel point representing the border area is more likely to belong to the background area, so the transparency information of the pixel point can be set as a preset The second transparency value of .
  • the first limit value and the second limit value can be used to normalize the color similarity of the pixel point Processing, the normalized color similarity is determined as the transparency information of the pixel.
  • the transparency information of the pixel point can be determined according to the following formula:
  • x t is the transparency information of the pixel point
  • x in is the color similarity of the pixel point
  • x min is the first limit value
  • x max is the second limit value.
  • the target background to be replaced can be selected as required.
  • the target background to be replaced can be the determined background image to be replaced, and the background image can be a non-solid color image including multiple colors, or a solid color including a single color. image.
  • the size of the background image to be replaced is the same as that of the original image.
  • the pixel information of the target background corresponding to the position of the pixel point may be determined from the background image to be replaced.
  • the target image is then generated based on the transparency information of the pixels respectively included in the at least three types of regions and the pixel information of the target background to be replaced corresponding to each pixel respectively.
  • S104 can be specifically implemented according to the following manner:
  • the intermediate pixel information corresponding to the pixel points can be determined first, and the intermediate image formed by the intermediate pixel information can be an image in which the background color corresponding to the sampling pixel information is eliminated and the target background is roughly superimposed, that is, the intermediate pixel information is eliminated. Then, based on the intermediate pixel information, transparency information of each pixel, and the pixel information of the target background corresponding to the position of the pixel, the determined target pixel information of each pixel is the elimination Therefore, based on the target pixel information of each pixel point, the effect of the generated target image can be better.
  • the transparency information corresponding to the pixel point may be multiplied by the sampled pixel information to obtain first product information; and the target background corresponding to the position of the pixel point may be multiplied by the transparency information Multiply the pixel information of the pixel to obtain the second product information; further, subtract the pixel information of the pixel point from the first product information, and then add the obtained difference to the second product information to obtain the The intermediate pixel information of the pixel point.
  • the intermediate pixel information corresponding to the pixel can be determined according to the following formula:
  • p m is the intermediate pixel information of the pixel
  • p in is the pixel information of the corresponding pixel on the original image
  • x t is the transparency information of the corresponding pixel, which is the mixing coefficient
  • c s is the sampling pixel of the sampling pixel information
  • ct is the pixel information of the target background corresponding to the position of the pixel point.
  • a target pixel matching the pixel can be determined from the background image to be replaced, and the target pixel can be assigned to the pixel on the background image to be replaced.
  • information which is determined as the target color information corresponding to the pixel.
  • the target pixel information of the pixel can be determined according to the following formula:
  • p t is the target pixel information of each pixel point
  • p m is the intermediate pixel information of the corresponding pixel point
  • the preset reference value is set to 1.
  • a target image is generated based on the determined target pixel information corresponding to each pixel point.
  • the original image may be an image including a solid color background, that is, the background area of the original image includes one background color; or, the original image may be an image including multiple background colors, and the background colors included in the original image are different.
  • the number is small, for example, the original image may be an image including a red background and a blue background.
  • the image background processing method provided by the present disclosure can be used to perform background processing on the original image once to generate a target image.
  • the sampling pixel information of the sampling pixel points can be determined based on each background color of the multiple background colors, and then the image background processing method provided by the present disclosure can be used to process the original image. Perform multiple background processing to generate the target image.
  • the image background processing method provided by the present disclosure can be used to determine the sampling pixel information of the first sampling pixel point from the red background, and perform background processing on the original image once. Generate an intermediate image after the first background processing; then use the image background processing method provided by the present disclosure to determine the sampling pixel information of the second sampling pixel point from the blue background, perform background processing on the intermediate image once, and generate a target image.
  • the writing order of each step does not mean a strict execution order but constitutes any limitation on the implementation process, and the specific execution order of each step should be based on its function and possible Internal logic is determined.
  • an embodiment of the present disclosure also provides an image background processing apparatus.
  • a schematic diagram of the architecture of the image background processing apparatus provided by the embodiment of the present disclosure includes an acquisition module 401 , a segmentation module 402 , a first A determination module 403 and a generation module 404, specifically:
  • an acquisition module 401 for acquiring an original image
  • the segmentation module 402 is configured to perform segmentation processing on the original image by using the sampling pixel information of the sampling pixel points selected from the background portion of the original image to obtain segmentation results of at least three types of regions, the at least three types of regions Including a foreground area, a background area, and a boundary area between the foreground area and the background area;
  • a first determination module 403, configured to determine the transparency information of the pixels respectively included in the at least three types of areas based on the segmentation results of the at least three types of areas;
  • the generating module 404 is configured to generate a target image based on the transparency information of the pixel points respectively included in the at least three types of regions and the pixel information of the target background to be replaced.
  • the method before using the sampling pixel information of the sampling pixel points on the background area of the original image to perform segmentation processing on the original image to obtain segmentation results of at least three types of areas, the method further includes:
  • a processing module 405, configured to perform size reduction processing on the original image
  • the method further includes:
  • the mapping module 406 is configured to map the segmentation results of the at least three types of regions back to the original image before the size reduction process.
  • the segmentation module 402 uses the sampling pixel information of the sampling pixel points on the background area of the original image to perform segmentation processing on the original image to obtain at least three types of area segmentation results. , for:
  • the original image is segmented to obtain segmentation results of at least three types of regions.
  • the segmentation module 402 when determining the color similarity between the pixel information of each pixel in the original image and the sampled pixel information of the sampled pixel, is used to:
  • the target color space is determined based on the sampling pixel information of the sampling pixel
  • the device further includes:
  • a second determination module 407 configured to determine a first set of pixels whose pixel information in the original image matches the sampled pixel information of the sampled pixels
  • the segmentation module 402 when determining the color similarity between the target pixel information of each pixel in the target color space and the target sampling pixel information of the sampled pixel in the target color space, use: At:
  • the second determining module 407 when determining the first pixel point set in the original image whose pixel information matches the sampling pixel information of the sampling pixel point, is used for:
  • the sampling pixel information of the sampling pixel under the HSV color space is the first sampling pixel information
  • the filtered pixel point set is the first pixel point set.
  • the segmentation module 402 when performing segmentation processing on the original image by using the color similarity corresponding to each of the pixel points to obtain segmentation results of at least three types of regions, is used for: traversing the For the pixels in the original image, perform segmentation processing on the traversed pixels to obtain the segmentation results of the traversed pixels; after obtaining the segmentation results of all the traversed pixels, generate the at least three types of regions. segmentation result;
  • the segmentation processing includes:
  • the first determining module 403 when determining the transparency information of the pixels respectively included in the at least three types of areas based on the segmentation results of the at least three types of areas, is used to:
  • the transparency information of the pixel points in the boundary area is determined.
  • the first determination module 403 determines, based on the pixel information of the pixel points in the boundary area and the sampled pixel information of the sampled pixel points, the value of the pixel point in the boundary area.
  • transparency information is used:
  • the transparency information of each pixel point in the border area is determined.
  • the first determination module 403 determines, based on the color similarity corresponding to each pixel in the boundary area, the first limit value and the second limit value, each pixel in the boundary area.
  • the transparency information of the pixel it is used to:
  • the color similarity corresponding to the pixel point is greater than or equal to the first limit value and less than the second limit value
  • the color similarity of the pixel points is normalized, and the normalized color similarity is determined as the transparency information of the pixel point.
  • the generation module 404 when generating the target image based on the transparency information of the pixels respectively included in the at least three types of regions and the pixel information of the target background to be replaced, is used for:
  • the generation module 404 is based on the transparency information corresponding to the pixel point, the pixel information of the pixel point, the sampled pixel information of the sampled pixel point, and the correlation with the pixel point.
  • the pixel information of the target background corresponding to the position, when determining the intermediate pixel information of the pixel point, is used for:
  • the pixel information of the pixel point is subtracted from the first product information, and then the obtained difference is added to the second product information to obtain the intermediate pixel information of the pixel point.
  • the generation module 404 is based on the intermediate pixel information of each of the pixel points, the transparency information, and the pixel of the target background corresponding to the position of the pixel point. information, when determining the target pixel information of each pixel point, it is used to:
  • the sum of the third product information and the fourth product information is determined as the target pixel information of the pixel point.
  • the functions or templates included in the apparatus provided by the embodiments of the present disclosure may be used to execute the methods described in the above method embodiments.
  • the functions or templates included in the apparatus provided by the embodiments of the present disclosure may be used to execute the methods described in the above method embodiments.
  • FIG. 5 a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure includes a processor 501 , a memory 502 , and a bus 503 .
  • the memory 502 is used to store execution instructions, including the memory 5021 and the external memory 5022; the memory 5021 here is also called the internal memory, and is used to temporarily store the operation data in the processor 501 and the data exchanged with the external memory 5022 such as the hard disk,
  • the processor 501 exchanges data with the external memory 5022 through the memory 5021.
  • the processor 501 communicates with the memory 502 through the bus 503, so that the processor 501 executes the following instructions: obtain the original image;
  • the original image is segmented to obtain segmentation results of at least three types of areas, where the at least three types of areas include a foreground area, a background area and all the boundary area between the foreground area and the background area;
  • the target image is generated based on the transparency information of the pixel points respectively included in the at least three types of regions and the pixel information of the target background to be replaced.
  • an embodiment of the present disclosure further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and the computer program is executed by a processor to execute the image background processing methods described in the above method embodiments. step.
  • the storage medium may be a volatile or non-volatile computer-readable storage medium.
  • Embodiments of the present disclosure further provide a computer program product, where the computer program product carries program code, and the program code includes instructions that can be used to execute the steps of the image background processing method described in the above method embodiments.
  • the computer program product carries program code
  • the program code includes instructions that can be used to execute the steps of the image background processing method described in the above method embodiments.
  • the above-mentioned computer program product can be specifically implemented by means of hardware, software or a combination thereof.
  • the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (Software Development Kit, SDK), etc. Wait.
  • the units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
  • each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
  • the functions, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a processor-executable non-volatile computer-readable storage medium.
  • the computer software products are stored in a storage medium, including Several instructions are used to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure.
  • the aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program codes .

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Data Mining & Analysis (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Evolutionary Biology (AREA)
  • Evolutionary Computation (AREA)
  • Artificial Intelligence (AREA)
  • General Engineering & Computer Science (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Image Processing (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

一种图像背景处理方法、装置、电子设备及存储介质,方法包括:获取原始图像(S101);利用从所述原始图像的背景部分上选取的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果,所述至少三类区域包括前景区域、背景区域和所述前景区域与所述背景区域之间的边界区域(S102);基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息(S103);基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像(S104)。

Description

图像背景处理方法、装置、电子设备及存储介质
相关申请的交叉引用
本专利申请要求于2020年12月31日提交的、申请号为2020116197763、发明名称为“图像背景处理方法、装置、电子设备及存储介质”的中国专利申请的优先权,该申请以引用的方式并入文本中。
技术领域
本公开涉及图像处理技术领域,具体而言,涉及一种图像背景处理方法、装置、电子设备及存储介质。
背景技术
图像分割技术是指将图像分成互不重叠、具有各自特征的区域的技术,图像分割技术可以应用于多种场景,比如,图像分割技术可以应用于图像背景替换场景。
在直播行业中,在设置了直播背景之后,存在需要对直播画面中的背景图像进行替换的情况,比如,在直播画面的背景图像为绿色图像时,需要将该直播画面中的绿色图像替换为设置的背景图像,增加直播画面展示的灵活性。因此提出一种图像背景处理方法尤为重要。
发明内容
有鉴于此,本公开至少提供一种图像背景处理方法、装置、电子设备及存储介质。
第一方面,本公开提供了一种图像背景处理方法,包括:
获取原始图像;
利用从所述原始图像的背景部分上选取的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果,所述至少三类区域包括前景区域、背景区域和所述前景区域与所述背景区域之间的边界区域;
基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息;
基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像。
在将图像划分为前景区域和背景区域时,由于像素点的分布较为稠密,使得对图像进行前景区域和背景区域的分割时不可避免的会产生误差,造成位于前景区域和背景区域交接处的部分像素点的分割错误,比如,将实质上位于背景区域上的像素点,分割到了前景区域上。为了避免上述问题,可以将原始图像分割为至少三类区域,至少三类区域包括前景区域、背景区域、和前景区域与背景区域之间的边界区域,将位于前景区域和背景区域交接处的像素点划分至边界区域中,可以提高分割结果的准确度。
进一步,基于至少三类区域的分割结果,确定至少三类区域中包括的像素点的透明度信息,通过设置的透明度信息控制不同区域内像素点的透明程度,比如可以将背景区域的透明度信息设置为1(不透明),减少采样像素信息表征的背景颜色对待替换的目 标背景的像素信息的干扰,使得经过背景替换得到的目标图像中目标背景区域和前景区域更加精确,优化图像处理效果。
一种可能的实施方式中,在利用所述原始图像的背景区域上的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果之前,还包括:
对所述原始图像进行尺寸缩小处理;
在对尺寸缩小处理后的原始图像进行分割处理,得到至少三类区域的分割结果之后,还包括:
将所述至少三类区域的分割结果映射回尺寸缩小处理前的原始图像上。
上述实施方式中,对原始图像进行尺寸缩小处理后,尺寸缩小处理后的原始图像的容量较小,故在利用尺寸缩小处理后的原始图像进行分割处理时,可以减少执行设备的资源消耗。且得到的分割结果又映射回原始图像的尺寸,使得利用分割结果进行背景替换得到的目标图像更为精确。
一种可能的实施方式中,所述利用所述原始图像的背景区域上的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域分割结果,包括:
确定所述原始图像中各像素点的像素信息分别与所述采样像素点的采样像素信息之间的颜色相似度;
利用各所述像素点对应的颜色相似度,对所述原始图像进行分割处理,得到至少三类区域的分割结果。
一般的,背景区域内像素点对应的颜色位于同一色域内,而位于同一色域内的像素点之间的颜色相似度较高,位于不同色域内的像素点之间的颜色相似度较低,故可以利用各个像素点对应的颜色相似度,对原始图像进行分割处理,较准确的得到至少三类区域的分割结果。同时,采样像素点为位于原始图像背景区域内的像素点,采样像素点的采样像素信息对应的颜色能够表征原始图像中背景区域的颜色,故通过确定原始图像中各像素点的像素信息分别与采样像素点的采样像素信息之间的颜色相似度,可以较准确的确定原始图像中各像素点的像素信息对应的颜色、与背景区域的颜色之间的相似度。
一种可能的实施方式中,所述确定所述原始图像中各像素点的像素信息分别与所述采样像素点的采样像素信息之间的颜色相似度,包括:
将所述原始图像中各像素点的像素信息转换到目标颜色空间下的目标像素信息;所述目标颜色空间基于所述采样像素点的采样像素信息确定;
确定各像素点在所述目标颜色空间下的目标像素信息分别与所述采样像素点在所述目标颜色空间下的目标采样像素信息之间的颜色相似度。
上述实施方式中,目标颜色空间可以基于采样像素点的采样像素信息确定,使得在对应的目标颜色空间下能够获取到原始图像中较为丰富的像素特征。进而,可以较准确的确定各像素点在确定的目标颜色空间下的目标像素信息分别与采样像素点在目标颜色空间下的目标采样像素信息之间的颜色相似度。比如,在采样像素点的颜色为红、绿等明亮的颜色时,目标颜色空间可以为YCRCB颜色空间,即在采样像素点对应的颜色较为明亮时,在YCRCB颜色空间下能够获取到原始图像中较为丰富的像素特征。
一种可能的实施方式中,所述方法还包括:
确定所述原始图像中像素信息与所述采样像素点的采样像素信息匹配的第一像素点集合;
所述确定各像素点在所述目标颜色空间下的目标像素信息分别与所述采样像素点在所述目标颜色空间下的目标采样像素信息之间的颜色相似度,包括:
将所述第一像素点集合中各第一像素点的像素信息转换为目标颜色空间下的第一像素信息;
基于各第一像素点的第一像素信息,生成所述目标颜色空间下的高斯颜色模型;
将所述原始图像中各像素点的目标像素信息以及所述采样像素点的目标采样像素信息输入至所述高斯颜色模型中,得到各像素点的目标像素信息分别与所述采样像素点的目标采样像素信息之间的颜色相似度。
上述方法中,第一像素点集合中的各个像素点的像素信息与采样像素点的采样像素信息匹配,比如,第一像素点集合中的各个像素点的像素信息对应的颜色、与采样像素点的采样像素信息对应的颜色位于同一色域内。由于采样像素点位于背景区域内,故可以确定第一像素点集合中的各个像素点也位于背景区域内,使得利用第一像素点在目标颜色空间下的第一像素信息,生成的目标颜色空间下的高斯颜色模型较为精准,进一步的可以较准确的确定原始图像中各个像素点的颜色相似度。
一种可能的实施方式中,所述确定所述原始图像中像素信息与所述采样像素点的采样像素信息匹配的第一像素点集合,包括:
将所述原始图像各像素点的像素信息转换为色调饱和度明度HSV颜色空间下的像素信息;所述采样像素点在HSV颜色空间下的采样像素信息为第一采样像素信息;
从各所述像素点在HSV颜色空间下的像素信息中筛选出与所述第一采样像素信息位于同一色域内的像素点集合;
所述筛选出的像素点集合为所述第一像素点集合。
由于HSV颜色空间可以将整个颜色空间分成不同的色域,故将原始图像各像素点的像素信息转换为HSV颜色空间下的像素信息后,可以较准确的从各像素点在HSV颜色空间下的像素信息中筛选出与第一采样像素信息位于同一色域内的像素点集合。
一种可能的实施方式中,所述利用各所述像素点对应的颜色相似度,对所述原始图像进行分割处理,得到至少三类区域的分割结果,包括:
遍历所述原始图像中的像素点,对遍历到的像素点执行分割处理,得到遍历到的像素点的分割结果;在得到遍历到的全部像素点的分割结果后,生成所述至少三类区域的分割结果;
其中,所述分割处理包括:
在检测到所述遍历到的像素点的颜色相似度小于第一阈值的情况下,确定所述遍历到的像素点在前景区域;
在检测到所述遍历到的像素点的颜色相似度大于或等于第二阈值的情况下,确定所述遍历到的像素点在背景区域;
在检测到所述遍历到的像素点的颜色相似度大于或等于所述第一阈值,且小于所述第二阈值的情况下,确定所述遍历到的像素点在边界区域。
这里,通过遍历原始图像中的像素点,根据像素点的颜色相似度,较准确的确定像素点的分割结果,使得生成的至少三类区域的分割结果较为精准。
一种可能的实施方式中,所述基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息,包括:
将在前景区域中的像素点的透明度信息确定为预设的第一透明度值;以及,将在背景区域中的像素点的透明度信息确定为预设的第二透明度值;
以及,基于在边界区域中的像素点的像素信息以及所述采样像素点的采样像素信息,确定所述在边界区域中的像素点的透明度信息。
这里,为不同区域内的像素点设置不同的透明度信息,通过设置的透明度信息可以控制不同区域内的像素点的像素信息,对待替换的目标背景的像素信息的影响程度,以提高生成的目标图像的处理效果。
一种可能的实施方式中,所述基于在边界区域中的像素点的像素信息以及所述采样像素点的采样像素信息,确定所述在边界区域中的像素点的透明度信息,包括:
确定在边界区域中的各像素点的像素信息分别与所述采样像素点的采样像素信息在目标颜色空间下的颜色相似度;
基于在边界区域中各像素点对应的颜色相似度、以及第一界限值和第二界限值,确定在所述边界区域中各像素点的透明度信息。
这里,可以确定边界区域中各像素点对应的颜色相似度,通过确定的颜色相似度、和第一界限值、第二界限值,较准确的确定边界区域中各像素点的透明度信息。
一种可能的实施方式中,所述基于在边界区域中各像素点对应的颜色相似度、以及第一界限值和第二界限值,确定在所述边界区域中各像素点的透明度信息,包括:
针对所述边界区域中的每个像素点,在所述像素点对应的所述颜色相似度小于所述第一界限值的情况下,将所述像素点的透明度信息设置为所述预设的第一透明度值;
在所述像素点对应的所述颜色相似度大于或等于所述第二界限值的情况下,将所述像素点的透明度信息设置为所述预设的第二透明度值;
在所述像素点对应的所述颜色相似度大于或等于所述第一界限值,且小于所述第二界限值的情况下,利用所述第一界限值和所述第二界限值,对所述像素点的颜色相似度进行归一化处理,将归一化处理后的颜色相似度,确定为所述像素点的透明度信息。
这里,可以基于边界区域内的各个像素点的颜色相似度,确定边界区域内每个像素点的透明度信息。比如,在边界区域中像素点的颜色相似度小于第一界限值时,表征该像素点属于前景区域的可能性较高,故可以将该像素点的透明度信息设置为第一透明度值;在边界区域中像素点的颜色相似度大于或等于第二界限值时,表征该像素点属于背景区域的可能性较高,故可以将该像素点的透明度信息设置为第二透明度值,进而实现了对边界区域内的各个像素点的再一次筛选,以提高边界区域中各个像素点的透明度信息的准确度。
一种可能的实施方式中,所述基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像,包括:
针对所述至少三类区域中的每个像素点,基于所述像素点对应的透明度信息、所述像素点的像素信息、所述采样像素点的采样像素信息、以及与所述像素点的位置对应的所述目标背景的像素信息,确定所述像素点的中间像素信息;
基于每个所述像素点的所述中间像素信息、所述透明度信息、和与所述像素点的位置对应的所述目标背景的像素信息,确定每个像素点的目标像素信息;
基于各个像素点的目标像素信息,生成所述目标图像。
采用上述方法,可以先确定像素点对应的中间像素信息,该中间像素信息构成的中 间图像可以为消除了采样像素信息对应的背景颜色、并粗略叠加了目标背景的图像,即中间像素信息为消除了采样像素信息影响后的像素信息;进而基于每个像素点的中间像素信息、透明度信息、和与像素点的位置对应的目标背景的像素信息,确定的每个像素点的目标像素信息为消除了采样像素信息影响后的像素信息;故基于各个像素点的目标像素信息,可以使得生成的目标图像的效果较好。
一种可能的实施方式中,所述基于所述像素点对应的透明度信息、所述像素点的像素信息、所述采样像素点的采样像素信息、以及与所述像素点的位置对应的所述目标背景的像素信息,确定所述像素点的中间像素信息,包括:
将所述像素点对应的所述透明度信息与所述采样像素信息相乘,得到第一乘积信息;以及将所述透明度信息与所述像素点的位置对应的所述目标背景的像素信息相乘,得到第二乘积信息;
将所述像素点的像素信息与所述第一乘积信息相减,再将得到的差值与所述第二乘积信息相加,得到所述像素点的中间像素信息。
一种可能的实施方式中,所述基于每个所述像素点的所述中间像素信息、所述透明度信息、和与所述像素点的位置对应的所述目标背景的像素信息,确定每个像素点目标像素信息,包括:
将所述像素点的透明度信息与所述像素点的位置对应的所述目标背景的像素信息相乘,得到第三乘积信息;将预设基准值与所述像素点的透明度信息相减,再将得到的差值与所述中间像素信息相乘,得到第四乘积信息;
将所述第三乘积信息与所述第四乘积信息的和,确定为所述像素点的目标像素信息。
以下装置、电子设备等的效果描述参见上述方法的说明,这里不再赘述。
第二方面,本公开提供了一种图像背景处理装置,包括:
获取模块,用于获取原始图像;
分割模块,用于利用从所述原始图像的背景部分上选取的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果,所述至少三类区域包括前景区域、背景区域和所述前景区域与所述背景区域之间的边界区域;
第一确定模块,用于基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息;
生成模块,用于基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像。
第三方面,本公开提供一种电子设备,包括:处理器、存储器和总线,所述存储器存储有所述处理器可执行的机器可读指令,当电子设备运行时,所述处理器与所述存储器之间通过总线通信,所述机器可读指令被所述处理器执行时执行如上述第一方面或任一实施方式所述的图像背景处理方法的步骤。
第四方面,本公开提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序被处理器运行时执行如上述第一方面或任一实施方式所述的图像背景处理方法的步骤。
为使本公开的上述目的、特征和优点能更明显易懂,下文特举较佳实施例,并配合所附附图,作详细说明如下。
附图说明
为了更清楚地说明本公开实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,此处的附图被并入说明书中并构成本说明书中的一部分,这些附图示出了符合本公开的实施例,并与说明书一起用于说明本公开的技术方案。应当理解,以下附图仅示出了本公开的某些实施例,因此不应被看作是对范围的限定,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他相关的附图。
图1示出了本公开实施例所提供的一种图像背景处理方法的流程示意图;
图2示出了本公开实施例所提供的一种图像背景处理方法中,包括至少三类区域的三值图像的示意图;
图3示出了本公开实施例所提供的一种图像背景处理方法中,得到至少三类区域的分割结果的方式的流程示意图;
图4示出了本公开实施例所提供的一种图像背景处理装置的架构示意图;
图5示出了本公开实施例所提供的一种电子设备的结构示意图。
具体实施方式
为使本公开实施例的目的、技术方案和优点更加清楚,下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本公开一部分实施例,而不是全部的实施例。通常在此处附图中描述和示出的本公开实施例的组件可以以各种不同的配置来布置和设计。因此,以下对在附图中提供的本公开的实施例的详细描述并非旨在限制要求保护的本公开的范围,而是仅仅表示本公开的选定实施例。基于本公开的实施例,本领域技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本公开保护的范围。
诸如直播行业中,在设置了直播背景之后,存在需要对直播画面中的背景图像进行替换的情况,比如,在直播画面的背景图像为绿色图像时,需要将该直播画面中的绿色图像替换为设置的背景图像,增加直播画面展示的灵活性。一般的,可以对直播场景图像进行分割,确定直播场景图像中包括的背景区域和前景区域,再将直播场景图像的背景区域的背景颜色,替换为设置的待替换颜色,比如,可以确定待替换颜色对应的像素信息,将直播场景图像上位于背景区域内的像素点的像素信息,替换为设置的待替换颜色对应的像素信息,实现直播场景图像的背景颜色替换。
但是,直播场景图像中会存在光线不均、背景不平整、前景图像中存在与背景颜色相同的区域等问题,在根据上述方法进行背景颜色替换时,容易造成背景区域和前景区域错误分割的情况发生,比如,造成分割后的前景区域中包括属于背景区域的像素点,在对直播场景图像的背景区域进行颜色替换时,无法对前景区域中包括的属于背景区域的像素点的像素信息进行替换,使得背景颜色替换后生成的图像的前景区域中存在替换前的原始背景颜色,使得背景颜色替换后生成的图像的效果较差。
针对以上方案所存在的缺陷,均是发明人在经过实践并仔细研究后得出的结果,因此,上述问题的发现过程以及下文中本公开针对上述问题所提出的解决方案,都应该是发明人在本公开过程中对本公开做出的贡献。
下面将结合本公开中附图,对本公开中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本公开一部分实施例,而不是全部的实施例。通常在此处附图中 描述和示出的本公开的组件可以以各种不同的配置来布置和设计。因此,以下对在附图中提供的本公开的实施例的详细描述并非旨在限制要求保护的本公开的范围,而是仅仅表示本公开的选定实施例。基于本公开的实施例,本领域技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本公开保护的范围。
应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。
为便于对本公开实施例进行理解,首先对本公开实施例所公开的一种图像背景处理方法进行详细介绍。本公开实施例所提供的图像背景处理方法的执行主体一般为具有一定计算能力的计算机设备,该计算机设备例如包括:终端设备或服务器或其它处理设备,终端设备可以为用户设备(User Equipment,UE)、移动设备、用户终端、终端、蜂窝电话、无绳电话、个人数字助理(Personal Digital Assistant,PDA)、手持设备、计算设备、车载设备、可穿戴设备等。在一些可能的实现方式中,该图像背景处理方法可以通过处理器调用存储器中存储的计算机可读指令的方式来实现。
参见图1所示,为本公开实施例所提供的图像背景处理方法的流程示意图,该方法包括S101-S104,其中:
S101,获取原始图像;
S102,利用从所述原始图像的背景部分上选取的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果,所述至少三类区域包括前景区域、背景区域和所述前景区域与所述背景区域之间的边界区域;
S103,基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息;
S104,基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像。
在将图像划分为前景区域和背景区域时,由于像素点的分布较为稠密,使得对图像进行前景区域和背景区域的分割时不可避免的会产生误差,造成位于前景区域和背景区域交接处的部分像素点的分割错误,比如,将实质上位于背景区域上的像素点,分割到了前景区域上。为了避免上述问题,可以将原始图像分割为至少三类区域,至少三类区域包括前景区域、背景区域、和前景区域与背景区域之间的边界区域,将位于前景区域和背景区域交接处的像素点划分至边界区域中,可以提高分割结果的准确度。
进一步,基于至少三类区域的分割结果,确定至少三类区域中包括的像素点的透明度信息,通过设置的透明度信息控制不同区域内像素点的透明程度,比如可以将背景区域的透明度信息设置为1(不透明),减少采样像素信息表征的背景颜色对待替换的目标背景的像素信息的干扰,使得经过背景替换得到的目标图像中目标背景区域和前景区域更加精确,优化图像处理效果。
下述对S101-S104进行具体说明。
针对S101:
原始图像可以为任一需要进行背景处理的图像,比如,原始图像可以为需要进行背景处理的证件照;或者,原始图像可以为直播场景中的直播图像等。其中,原始图像可以为在任一颜色空间下的图像,比如,原始图像可以为红绿蓝(red green blue,RGB)图像。
针对S102:
这里,可以先从原始图像的背景部分中确定采样像素点,根据该采样像素点的采样像素信息,对原始图像进行分割处理,得到至少三类区域的分割结果,即确定了原始图像上的前景区域、背景区域、和前景区域与背景区域之间的边界区域。具体实施时,可以基于至少三类区域的分割结果,生成分割结果对应的、与原始图像的尺寸一致的三值图像,其中,该三值图像中位于前景区域内的像素点的像素信息可以为第一像素值(比如第一像素值可以为0),位于边界区域内的像素点的像素信息可以为第二像素值(比如第二像素值可以为2),位于背景区域内的像素点的像素信息可以为第三像素值(比如第三像素值可以为255)。
参见图2所示的一种图像背景处理方法中,包括至少三类区域的三值图像的示意图。该图中,黑色对应的区域为前景区域,白色对应的区域为背景区域,位于白色与黑色之间的灰色对应的区域为边界区域。
具体实施时,可以响应触发的采样像素点确定操作,确定采样像素点的位置信息,再基于采样像素点的位置信息,确定采样像素点的采样像素信息,其中,该采样像素点的采样像素信息可以为原始图像中采样像素点的像素信息。比如,可以检测用户从原始图像的背景部分中选择的一采样像素点,再可以根据采样像素点的位置信息,确定采样像素点的采样像素信息。
或者,也可以利用用于图像分割的神经网络,确定原始图像上的背景区域,并随机从背景区域中确定采样像素点的位置信息,再可以基于采样像素点的位置信息,确定采样像素点的采样像素信息。
再或者,还可以使用聚类算法,聚类得到原始图像上颜色信息偏差较小的多个像素点;并基于聚类得到的多个像素点分别在原始图像上的位置信息,确定采样像素点的位置信息。比如,可以将聚类得到的多个像素点的位置信息求平均值,得到采样像素点的位置信息;或者,也可以随机从颜色信息一致的多个像素点中,选择一个像素点,作为采样像素点,并将选择的像素点的位置信息,确定为采样像素点的位置信息;再可以基于采样像素点的位置信息,确定采样像素点的采样像素信息。
其中,采样像素点的采样像素信息为采样像素点在原始图像上的像素信息,在原始图像为RGB图像时,该采样像素信息可以包括红R、绿G、蓝B三个颜色通道上的像素值。
一种可选实施方式中,在利用所述原始图像的背景区域上的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果之前,还包括:对所述原始图像进行尺寸缩小处理。比如,可以通过下采样或降采样的方式,对原始图像进行尺寸缩小处理,得到尺寸缩小处理后的原始图像。其中,尺寸缩小处理后的原始图像的尺寸可以根据实际需要进行设置。
在对尺寸缩小处理后的原始图像进行分割处理,得到至少三类区域的分割结果之后,还包括:将所述至少三类区域的分割结果映射回尺寸缩小处理前的原始图像上。
示例性的,可以利用插值算法,将至少三类区域的分割结果映射会尺寸缩小处理前的原始图像上。比如,针对背景区域,可以将背景区域内的像素点进行插值处理,映射到尺寸缩小处理前的原始图像上,确定尺寸缩小处理前的原始图像上的背景区域。其中,尺寸缩小处理前的原始图像上的前景区域、和边界区域的确定过程,可参考上述尺寸缩小处理前的原始图像上的背景区域的确定过程,此处不再进行详述。
上述实施方式中,对原始图像进行尺寸缩小处理后,尺寸缩小处理后的原始图像的容量较小,故在利用尺寸缩小处理后的原始图像进行分割处理时,可以减少执行设备的资源消耗。且得到的分割结果又映射回原始图像的尺寸,使得利用分割结果进行背 景替换得到的目标图像更为精确。
一种可选实施方式中,参见图3所示,S102的步骤具体可通过如下方式实现:
S301,确定所述原始图像中各像素点的像素信息分别与所述采样像素点的采样像素信息之间的颜色相似度;
S302,利用各所述像素点对应的颜色相似度,对所述原始图像进行分割处理,得到至少三类区域的分割结果。
一般的,背景区域内像素点对应的颜色位于同一色域内,而位于同一色域内的像素点之间的颜色相似度较高,位于不同色域内的像素点之间的颜色相似度较低,故可以利用各个像素点对应的颜色相似度,对原始图像进行分割处理,较准确的得到至少三类区域的分割结果。同时,采样像素点为位于原始图像背景区域内的像素点,采样像素点的采样像素信息对应的颜色能够表征原始图像中背景区域的颜色,故通过确定原始图像中各像素点的像素信息分别与采样像素点的采样像素信息之间的颜色相似度,可以较准确的确定原始图像中各像素点的像素信息对应的颜色、与背景区域的颜色之间的相似度。
在S301中,针对原始图像中的每个像素点,确定该像素点的像素信息与采样像素点的采样像素信息之间的颜色相似度;即得到原始图像中的每个像素点的颜色相似度。其中,该原始图像可以为尺寸缩小处理前的原始图像,也可以为尺寸缩小处理后的原始图像。
在该原始图像为尺寸缩小处理后的原始图像时,可以确定尺寸缩小处理后的原始图像中各个像素点对应的颜色相似度,再利用各个像素点对应的颜色相似度,对原尺寸缩小处理后的原始图像进行分割处理,得到至少三类区域的分割结果;最后,可以将至少三类区域的分割结果映射回尺寸缩小处理前的原始图像上,得到尺寸缩小处理前的原始图像中包括的前景区域、背景区域和边界区域。
一种可选实施方式中,S301中,确定所述原始图像中各像素点的像素信息分别与所述采样像素点的采样像素信息之间的颜色相似度,包括:
S3011,将所述原始图像中各像素点的像素信息转换到目标颜色空间下的目标像素信息;所述目标颜色空间基于所述采样像素点的采样像素信息确定;
S3012,确定各像素点在所述目标颜色空间下的目标像素信息分别与所述采样像素点在所述目标颜色空间下的目标采样像素信息之间的颜色相似度。
上述实施方式中,目标颜色空间可以基于采样像素点的采样像素信息确定,使得在对应的目标颜色空间下能够获取到原始图像中较为丰富的像素特征。进而,可以较准确的确定各像素点在确定的目标颜色空间下的目标像素信息分别与采样像素点在目标颜色空间下的目标采样像素信息之间的颜色相似度。比如,在采样像素点的颜色为红、绿等明亮的颜色时,目标颜色空间可以为YCRCB颜色空间,即在采样像素点对应的颜色较为明亮时,在YCRCB颜色空间下能够获取到原始图像中较为丰富的像素特征。
在S3011中,可以基于采样像素点的采样像素信息,确定原始图像对应的目标颜色空间。比如,在采样像素信息表征该采样像素点的颜色较为鲜艳(比如,采样像素点对应的颜色为红色、绿色等),则确定原始图像对应的目标颜色空间可以为YCRCB颜色空间;在采样像素信息表征该采样像素点的颜色较为暗淡(比如,采样像素点的颜色为黑色、灰色、白色等),则确定原始图像对应的目标颜色空间可以为RGB颜色空间。
或者,还可以响应于触发的选择操作,确定目标颜色空间。比如,可以响应于 触发的选择操作,确定目标颜色空间为RGB颜色空间,或者确定目标颜色空间为色调饱和度明度(Hue Saturation Value,HSV)颜色空间,再或者确定目标颜色空间为YCRCB颜色空间等。
这里,在原始图像为RGB图像、目标颜色空间为RGB颜色空间时,则原始图像中各像素点的像素信息与目标像素信息一致。在原始图像为RGB图像、目标颜色空间为YCRCB颜色空间时,可以将原始图像中各像素点的像素信息转换到YCRCB颜色空间下,生成各像素点在YCRCB颜色空间下的目标像素信息。
一种可选实施方式中,所述方法还包括:S105,确定所述原始图像中像素信息与所述采样像素点的采样像素信息匹配的第一像素点集合。
示例性的,第一像素点集合中包括的各个像素点在原始图像中的像素信息为与采样像素点的采样像素信息属于同一色域内的像素信息。比如,在采样像素点的采样像素信息位于青色色域内,则第一像素点集合中包括的各个像素点的像素信息均为处于青色色域内的像素信息。
在一种可选实施方式中,S105中,可以根据下述步骤确定所述原始图像中像素信息与所述采样像素点的采样像素信息匹配的第一像素点集合:
S1051,将所述原始图像各像素点的像素信息转换为色调饱和度明度HSV颜色空间下的像素信息;所述采样像素点在HSV颜色空间下的采样像素信息为第一采样像素信息;
S1052,从各所述像素点在HSV颜色空间下的像素信息中筛选出与所述第一采样像素信息位于同一色域内的像素点集合;
S1053,所述筛选出的像素点集合为所述第一像素点集合。
由于HSV颜色空间可以将整个颜色空间分成不同的色域,故将原始图像各像素点的像素信息转换为HSV颜色空间下的像素信息后,可以较准确的从各像素点在HSV颜色空间下的像素信息中筛选出与第一采样像素信息位于同一色域内的像素点集合。
示例性说明,在原始图像为RGB图像时,针对原始图像中的每个像素点,可以根据RGB与HSV之间的像素转换公式,将该像素点的像素信息转换至HSV颜色空间下,得到原始图像各像素点在HSV颜色空间下的像素信息。其中,原始图像各像素点在HSV颜色空间下的像素信息中包括采样像素点在HSV颜色空间下的第一采样像素信息。
再可以确定采样像素点的第一采样像素信息所属的色域,从各像素点在HSV颜色空间下的像素信息中筛选出与第一采样像素信息位于同一色域内的像素点集合。比如,在确定采样像素点的第一采样像素信息属于蓝色色域,则从各像素点在HSV颜色空间下的像素信息中筛选位于蓝色色域内的像素点集合;并将筛选出的像素点集合确定为第一像素点集合。
进而,在确定了第一像素点集合之后,可以利用第一像素点的像素信息,确定各像素点在所述目标颜色空间下的目标像素信息分别与所述采样像素点在所述目标颜色空间下的目标采样像素信息之间的颜色相似度。
在一种可选实施方式中,S3012可以根据下述方式实现:
步骤一、将所述第一像素点集合中各第一像素点的像素信息转换为目标颜色空间下的第一像素信息;
步骤二、基于各第一像素点的第一像素信息,生成所述目标颜色空间下的高斯 颜色模型;
步骤三、将所述原始图像中各像素点的目标像素信息以及所述采样像素点的目标采样像素信息输入至所述高斯颜色模型中,得到各像素点的目标像素信息分别与所述采样像素点的目标采样像素信息之间的颜色相似度。
上述实施方式中,第一像素点集合中的各个像素点的像素信息与采样像素点的采样像素信息匹配,比如,第一像素点集合中的各个像素点的像素信息对应的颜色、与采样像素点的采样像素信息对应的颜色位于同一色域内。由于采样像素点位于背景区域内,故可以确定第一像素点集合中的各个像素点也位于背景区域内,使得利用第一像素点在目标颜色空间下的第一像素信息,生成的目标颜色空间下的高斯颜色模型较为精准,进一步的可以较准确的确定原始图像中各个像素点的颜色相似度。
可以将第一像素点集合中各第一像素点的像素信息转换为目标颜色空间下,生成第一像素点集合中各个第一像素点的第一像素信息。其中,第一像素点集合中各第一像素点的像素信息可以为在原始图像上的像素信息。
利用各第一像素点的第一像素信息,构建目标颜色空间下的高斯颜色模型。其中,高斯颜色模型是由用于表征各第一像素点的第一像素信息的一个或多个正态分布曲线构成的模型。
再使用构建的高斯颜色模型,对原始图像中各像素点的目标像素信息和目标采样像素信息进行处理,得到各像素点的目标像素信息分别与采样像素点的目标采样像素信息之间的颜色相似度。比如,针对原始图像中的第一像素点的目标像素信息,可以利用确定的高斯颜色模型指示的目标均值和目标方差,确定第一像素点的目标像素信息与采样像素点的目标采样像素信息之间的颜色相似度。
其中,目标采样像素信息为目标像素点在目标颜色空间下的像素信息。在原始图像为背景颜色相同的纯色背景图像时,颜色相似度可以为像素点的目标像素信息所对应的颜色、与采样像素点的目标采样像素信息所对应的颜色(可以表征原始图像中的背景区域对应的颜色)之间的相似程度。
在S302中,利用各所述像素点对应的颜色相似度,对所述原始图像进行分割处理,得到至少三类区域的分割结果,可以包括:遍历所述原始图像中的像素点,对遍历到的像素点执行分割处理,得到遍历到的像素点的分割结果;在得到遍历到的全部像素点的分割结果后,生成所述至少三类区域的分割结果。
遍历原始图像中的像素点,利用像素点对应的颜色相似度,对遍历到的像素点执行分割处理,得到遍历到的像素点的分割结果。示例性的,可以针对原始图像中的遍历到的每个像素点,根据该像素点对应的颜色相似度,确定该像素点所属的目标区域(该像素点的分割结果),该目标区域为至少三种区域(前景区域、边界区域、背景区域)中的一种。进而,可以使用遍历到的全部像素点的分割结果,生成至少三类区域的分割结果。
其中,所述分割处理包括:
S3021,在检测到所述遍历到的像素点的颜色相似度小于第一阈值的情况下,确定所述遍历到的像素点在前景区域;
S3022,在检测到所述遍历到的像素点的颜色相似度大于或等于第二阈值的情况下,确定所述遍历到的像素点在背景区域;
S3023,在检测到所述遍历到的像素点的颜色相似度大于或等于所述第一阈值,且小于所述第二阈值的情况下,确定所述遍历到的像素点在边界区域。
这里,通过遍历原始图像中的像素点,根据像素点的颜色相似度,较准确的确定像素点的分割结果,使得生成的至少三类区域的分割结果较为精准。
在检测到遍历到的像素点的颜色相似度小于第一阈值时,表征遍历到的像素点对应的颜色、与采样像素点对应的颜色(可以表征原始图像中背景区域对应的颜色)之间相似程度较低,遍历到的该像素点属于背景区域内的可能性较低,故确定遍历到的该像素点在前景区域。
在检测到遍历到的像素点的颜色相似度大于或等于第二阈值时,表征遍历到的像素点对应的颜色、与采样像素点对应的颜色之间相似程度较高,遍历到的该像素点属于背景区域内的可能性较高,故确定遍历到的该像素点在背景区域。
在检测到遍历到的像素点的颜色相似度大于或等于第一阈值,且小于第二阈值时,无法准确的确定该像素点属于前景区域或背景区域,则可以确定遍历到的像素点属于前景区域和背景区域之间的边界区域。
其中,第一阈值和第二阈值可以根据实际需要进行设置,第一阈值小于第二阈值。比如,设置的第一阈值可以为0.3,第二阈值可以为0.8,在检测到遍历到的像素点的颜色相似度小于0.3时,则该像素点在前景区域;在检测到遍历到的该像素点的颜色相似度大于或等于0.8时,则该像素点在背景区域;在检测到遍历到的该像素点大于或等于0.3、且小于0.8时,则该像素点在边界区域。
为了较全面的确定原始图像中的边界区域,避免前景区域中残留背景区域中的像素点,造成颜色替换后生成的目标图像中残留有原始背景颜色的情况发生,可以对确定的边界区域进行形态学操作中的膨胀操作,得到膨胀操作后的至少三类区域的分割结果。其中,膨胀操作为形态学操作中用于扩大图像中目标区域面积的基本运算。
在使用尺寸缩小处理后的原始图像确定分割结果时,可以在得到尺寸缩小处理后的原始图像对应的至少三类区域的分割结果后,对得到的至少三类区域指示的边界区域进行膨胀操作,得到尺寸缩小处理后的原始图像对应的、膨胀操作后的至少三类区域的分割结果;再将尺寸缩小处理后的原始图像对应的、膨胀操作后的至少三类区域的分割结果,映射回尺寸缩小处理前的原始图像上。
或者,也可以在将至少三类区域的分割结果映射回尺寸缩小处理前的原始图像上之后,对尺寸缩小处理前的原始图像对应的至少三类区域指示的边界区域进行膨胀操作,得到尺寸缩小处理前的原始图像对应的、膨胀操作后的至少三类区域的分割结果。
针对S103:
在S103中,基于至少三类区域的分割结果,确定至少三类区域中分别包括的像素点的透明度信息,可以包括下述三种情况:
情况一、将在前景区域中的像素点的透明度信息确定为预设的第一透明度值;
情况二、将在背景区域中的像素点的透明度信息确定为预设的第二透明度值;
情况三,基于在边界区域中的像素点的像素信息以及所述采样像素点的采样像素信息,确定所述在边界区域中的像素点的透明度信息。
这里,为不同区域内的像素点设置不同的透明度信息,通过设置的透明度信息可以控制不同区域内的像素点的像素信息,对待替换的目标背景的像素信息的影响程度,以提高生成的目标图像的处理效果。
这里,第一透明度值、第二透明度值可以根据需要进行设置。比如,第一透明度值可以设置为0,第二透明度值可以设置为1。
在情况三中,基于在边界区域中的像素点的像素信息以及所述采样像素点的采样像素信息,确定所述在边界区域中的像素点的透明度信息,可以包括:
S1031,确定在边界区域中的各像素点的像素信息分别与所述采样像素点的采样像素信息在目标颜色空间下的颜色相似度;
S1032,基于在边界区域中各像素点对应的颜色相似度、以及第一界限值和第二界限值,确定在所述边界区域中各像素点的透明度信息。
这里,可以确定边界区域中各像素点对应的颜色相似度,通过确定的颜色相似度、和第一界限值、第二界限值,较准确的确定边界区域中各像素点的透明度信息。
在S1031中,可以确定边界区域中的各像素点的像素信息在目标颜色空间下的目标像素信息;再将边界区域中各像素点的目标像素信息输入至高斯颜色模型中,得到边界区域中各像素点的像素信息分别与采样像素点的采样像素信息在目标颜色空间下的颜色相似度。
在S1032中,基于在边界区域中各像素点对应的颜色相似度、以及第一界限值和第二界限值,确定在所述边界区域中各像素点的透明度信息,包括:
针对所述边界区域中的每个像素点,在所述像素点对应的所述颜色相似度小于所述第一界限值的情况下,将所述像素点的透明度信息设置为所述预设的第一透明度值;
在所述像素点对应的所述颜色相似度大于或等于所述第二界限值的情况下,将所述像素点的透明度信息设置为所述预设的第二透明度值;
在所述像素点对应的所述颜色相似度大于或等于所述第一界限值,且小于所述第二界限值的情况下,基于所述像素点对应的所述颜色相似度、所述第一界限值以及所述第二界限值,确定所述像素点的透明度信息。
这里,可以基于边界区域内的各个像素点的颜色相似度,确定边界区域内每个像素点的透明度信息。比如,在边界区域中像素点的颜色相似度小于第一界限值时,表征该像素点属于前景区域的可能性较高,故可以将该像素点的透明度信息设置为第一透明度值;在边界区域中像素点的颜色相似度大于或等于第二界限值时,表征该像素点属于背景区域的可能性较高,故可以将该像素点的透明度信息设置为第二透明度值,进而实现了对边界区域内的各个像素点的再一次筛选,以提高边界区域中各个像素点的透明度信息的准确度。
第一界限值和第二界限值可以根据需要进行设置,其中,第一界限值小于第二界限值;第一界限值与第一阈值可以一致,也可以不一致;以及第二界限值与第二阈值可以一致,也可以不一致。
在边界区域中的像素点的颜色相似度小于第一界限值时,表征边界区域中的该像素点属于前景区域的可能性较高,故可以将该像素点的透明度信息设置为预设的第一透明度值;在该像素点对应的颜色相似度大于或等于第二界限值时,表征该边界区域的像素点属于背景区域的可能性较高,故可以将像素点的透明度信息设置为预设的第二透明度值。
在该像素点对应的颜色相似度大于或等于第一界限值,且小于第二界限值时,可以利用第一界限值、和第二界限值,对该像素点的颜色相似度进行归一化处理,将归一化处理后的颜色相似度,确定为该像素点的透明度信息。
具体实施时,在该像素点对应的颜色相似度大于或等于第一界限值、且小于第 二界限值时,可以根据下述公式确定像素点的透明度信息:
Figure PCTCN2021103535-appb-000001
其中,x t为像素点的透明度信息,x in为像素点的颜色相似度;x min为第一界限值;x max为第二界限值。
针对S104:
待替换的目标背景可以根据需要进行选择,比如,待替换的目标背景可以为确定的待替换的背景图像,该背景图像可以为包括多种颜色的非纯色图像,也可以为包括单一颜色的纯色图像。其中,该待替换的背景图像与原始图像的尺寸一致。
具体实施时,针对原始图像上的每个像素点,可以从待替换的背景图像中确定与像素点的位置对应的目标背景的像素信息。再基于至少三类区域中分别包含的像素点的透明度信息、和各个像素点分别对应的待替换的目标背景的像素信息,生成目标图像。
一种可选实施方式中,S104可以根据下述方式具体实现:
S1041,针对所述至少三类区域中的每个像素点,基于所述像素点对应的透明度信息、所述像素点的像素信息、所述采样像素点的采样像素信息、以及与所述像素点的位置对应的所述目标背景的像素信息,确定所述像素点的中间像素信息;
S1042,基于每个像素点的所述中间像素信息、所述透明度信息、和与所述像素点的位置对应的所述目标背景的像素信息,确定每个像素点的目标像素信息;
S1043,基于各个像素点的目标像素信息,生成所述目标图像。
采用上述方法,可以先确定像素点对应的中间像素信息,该中间像素信息构成的中间图像可以为消除了采样像素信息对应的背景颜色、并粗略叠加了目标背景的图像,即中间像素信息为消除了采样像素信息影响后的像素信息;进而基于每个像素点的中间像素信息、透明度信息、和与像素点的位置对应的目标背景的像素信息,确定的每个像素点的目标像素信息为消除了采样像素信息影响后的像素信息;故基于各个像素点的目标像素信息,可以使得生成的目标图像的效果较好。
在S1041中,可以将所述像素点对应的所述透明度信息与所述采样像素信息相乘,得到第一乘积信息;以及将所述透明度信息与所述像素点的位置对应的所述目标背景的像素信息相乘,得到第二乘积信息;进而,将所述像素点的像素信息与所述第一乘积信息相减,再将得到的差值与所述第二乘积信息相加,得到所述像素点的中间像素信息。
具体实施时,针对原始图像中的每个像素点,可以根据下述公式,确定该像素点对应的中间像素信息:
p n=p in-x t×c s+x t×c t
其中,p m为像素点的中间像素信息;p in为对应像素点在原始图像上的像素信息;x t为对应像素点的透明度信息,即为混合系数;c s为采样像素点的采样像素信息;c t为与像素点的位置对应的目标背景的像素信息。
针对原始图像上的每个像素点,基于该像素点的位置信息,可以从待替换背景图像中确定与该像素点匹配的目标像素点,并将该目标像素点在待替换背景图像上的像素信息,确定为该像素点对应的目标颜色信息。
在S1042中,将所述像素点的透明度信息与所述像素点的位置对应的所述目标背景的像素信息相乘,得到第三乘积信息;将预设基准值与所述像素点的透明度信息相减,再将得到的差值与所述中间像素信息相乘,得到第四乘积信息;将所述第三乘积信息与所述第四乘积信息的和,确定为所述像素点的目标像素信息。
具体实施时,针对原始图像中的每个像素点,可以根据下述公式确定像素点的目标像素信息:
p t=(1-x t)×p m+x t×c t
其中,p t为每个像素点的目标像素信息,p m为对应像素点的中间像素信息,
此处预设基准值设置为1。
在S1043中,基于确定的各个像素点对应的目标像素信息,生成了目标图像。
示例性的,原始图像可以为包括纯色背景的图像,即原始图像的背景区域中包括一种背景颜色;或者,原始图像可以为包括多种背景颜色的图像,且原始图像中包括的背景颜色的数量较少,比如,原始图像可以为包括红色背景和蓝色背景的图像。
在原始图像为纯色背景的图像时,可以利用本公开提供的图像背景处理方法,对原始图像进行一次背景处理,生成目标图像。在原始图像为包括多种背景颜色的图像时,可以分别基于多种背景颜色中的每种背景颜色,确定采样像素点的采样像素信息,再利用本公开提供的图像背景处理方法,对原始图像进行多次背景处理,生成目标图像。
比如,原始图像为包括红色背景和蓝色背景的图像时,可以利用本公开提供的图像背景处理方法,从红色背景中确定第一采样像素点的采样像素信息,对原始图像进行一次背景处理,生成第一次背景处理后的中间图像;再利用本公开提供的图像背景处理方法,从蓝色背景中确定第二采样像素点的采样像素信息,对中间图像进行一次背景处理,生成目标图像。
本领域技术人员可以理解,在具体实施方式的上述方法中,各步骤的撰写顺序并不意味着严格的执行顺序而对实施过程构成任何限定,各步骤的具体执行顺序应当以其功能和可能的内在逻辑确定。
基于相同的构思,本公开实施例还提供了一种图像背景处理装置,参见图4所示,为本公开实施例提供的图像背景处理装置的架构示意图,包括获取模块401、分割模块402、第一确定模块403、生成模块404,具体的:
获取模块401,用于获取原始图像;
分割模块402,用于利用从所述原始图像的背景部分上选取的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果,所述至少三类区域包括前景区域、背景区域和所述前景区域与所述背景区域之间的边界区域;
第一确定模块403,用于基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息;
生成模块404,用于基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像。
一种可能的实施方式中,在利用所述原始图像的背景区域上的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果之前,还包括:
处理模块405,用于对所述原始图像进行尺寸缩小处理;
在对尺寸缩小处理后的原始图像进行分割处理,得到至少三类区域的分割结果之后,还包括:
映射模块406,用于将所述至少三类区域的分割结果映射回尺寸缩小处理前的原始图像上。
一种可能的实施方式中,所述分割模块402,在利用所述原始图像的背景区域上的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域分割结果时,用于:
确定所述原始图像中各像素点的像素信息分别与所述采样像素点的采样像素信息之间的颜色相似度;
利用各所述像素点对应的颜色相似度,对所述原始图像进行分割处理,得到至少三类区域的分割结果。
一种可能的实施方式中,所述分割模块402,在确定所述原始图像中各像素点的像素信息分别与所述采样像素点的采样像素信息之间的颜色相似度时,用于:
将所述原始图像中各像素点的像素信息转换到目标颜色空间下的目标像素信息;所述目标颜色空间基于所述采样像素点的采样像素信息确定;
确定各像素点在所述目标颜色空间下的目标像素信息分别与所述采样像素点在所述目标颜色空间下的目标采样像素信息之间的颜色相似度。
一种可能的实施方式中,所述装置还包括:
第二确定模块407,用于确定所述原始图像中像素信息与所述采样像素点的采样像素信息匹配的第一像素点集合;
所述分割模块402,在确定各像素点在所述目标颜色空间下的目标像素信息分别与所述采样像素点在所述目标颜色空间下的目标采样像素信息之间的颜色相似度时,用于:
将所述第一像素点集合中各第一像素点的像素信息转换为目标颜色空间下的第一像素信息;
基于各第一像素点的第一像素信息,生成所述目标颜色空间下的高斯颜色模型;
将所述原始图像中各像素点的目标像素信息以及所述采样像素点的目标采样像素信息输入至所述高斯颜色模型中,得到各像素点的目标像素信息分别与所述采样像素点的目标采样像素信息之间的颜色相似度。
一种可能的实施方式中,所述第二确定模块407,在确定所述原始图像中像素信息与所述采样像素点的采样像素信息匹配的第一像素点集合时,用于:
将所述原始图像各像素点的像素信息转换为色调饱和度明度HSV颜色空间下的像素信息;所述采样像素点在HSV颜色空间下的采样像素信息为第一采样像素信息;
从各所述像素点在HSV颜色空间下的像素信息中筛选出与所述第一采样像素信息位于同一色域内的像素点集合;
所述筛选出的像素点集合为所述第一像素点集合。
一种可能的实施方式中,所述分割模块402,在利用各所述像素点对应的颜色相似度,对所述原始图像进行分割处理,得到至少三类区域的分割结果时,用于:遍历所述原始图像中的像素点,对遍历到的像素点执行分割处理,得到遍历到的像素点的分割 结果;在得到遍历到的全部像素点的分割结果后,生成所述至少三类区域的分割结果;
其中,所述分割处理包括:
在检测到所述遍历到的像素点的颜色相似度小于第一阈值的情况下,确定所述遍历到的像素点在前景区域;
在检测到所述遍历到的像素点的颜色相似度大于或等于第二阈值的情况下,确定所述遍历到的像素点在背景区域;
在检测到所述遍历到的像素点的颜色相似度大于或等于所述第一阈值,且小于所述第二阈值的情况下,确定所述遍历到的像素点在边界区域。
一种可能的实施方式中,所述第一确定模块403,在基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息时,用于:
将在前景区域中的像素点的透明度信息确定为预设的第一透明度值;以及,将在背景区域中的像素点的透明度信息确定为预设的第二透明度值;
以及,基于在边界区域中的像素点的像素信息以及所述采样像素点的采样像素信息,确定所述在边界区域中的像素点的透明度信息。
一种可能的实施方式中,所述第一确定模块403,在基于在边界区域中的像素点的像素信息以及所述采样像素点的采样像素信息,确定所述在边界区域中的像素点的透明度信息时,用于:
确定在边界区域中的各像素点的像素信息分别与所述采样像素点的采样像素信息在目标颜色空间下的颜色相似度;
基于在边界区域中各像素点对应的颜色相似度、以及第一界限值和第二界限值,确定在所述边界区域中各像素点的透明度信息。
一种可能的实施方式中,所述第一确定模块403,在基于在边界区域中各像素点对应的颜色相似度、以及第一界限值和第二界限值,确定在所述边界区域中各像素点的透明度信息时,用于:
针对所述边界区域中的每个像素点,在所述像素点对应的所述颜色相似度小于所述第一界限值的情况下,将所述像素点的透明度信息设置为所述预设的第一透明度值;
在所述像素点对应的所述颜色相似度大于或等于所述第二界限值的情况下,将所述像素点的透明度信息设置为所述预设的第二透明度值;
在所述像素点对应的所述颜色相似度大于或等于所述第一界限值,且小于所述第二界限值的情况下,利用所述第一界限值和所述第二界限值,对所述像素点的颜色相似度进行归一化处理,将归一化处理后的颜色相似度,确定为所述像素点的透明度信息。
一种可能的实施方式中,所述生成模块404,在基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像时,用于:
针对所述至少三类区域中的每个像素点,基于所述像素点对应的透明度信息、所述像素点的像素信息、所述采样像素点的采样像素信息、以及与所述像素点的位置对应的所述目标背景的像素信息,确定所述像素点的中间像素信息;
基于每个所述像素点的所述中间像素信息、所述透明度信息、和与所述像素点的位置对应的所述目标背景的像素信息,确定每个像素点的目标像素信息;基于各个像素点的目标像素信息,生成所述目标图像。
一种可能的实施方式中,所述生成模块404,在基于所述像素点对应的透明度信息、所述像素点的像素信息、所述采样像素点的采样像素信息、以及与所述像素点的位置对应的所述目标背景的像素信息,确定所述像素点的中间像素信息时,用于:
将所述像素点对应的所述透明度信息与所述采样像素信息相乘,得到第一乘积信息;以及将所述透明度信息与所述像素点的位置对应的所述目标背景的像素信息相乘,得到第二乘积信息;
将所述像素点的像素信息与所述第一乘积信息相减,再将得到的差值与所述第二乘积信息相加,得到所述像素点的中间像素信息。
一种可能的实施方式中,所述生成模块404,在基于每个所述像素点的所述中间像素信息、所述透明度信息、和与所述像素点的位置对应的所述目标背景的像素信息,确定每个像素点目标像素信息时,用于:
将所述像素点的透明度信息与所述像素点的位置对应的所述目标背景的像素信息相乘,得到第三乘积信息;将预设基准值与所述像素点的透明度信息相减,再将得到的差值与所述中间像素信息相乘,得到第四乘积信息;
将所述第三乘积信息与所述第四乘积信息的和,确定为所述像素点的目标像素信息。
在一些实施例中,本公开实施例提供的装置具有的功能或包含的模板可以用于执行上文方法实施例描述的方法,其具体实现可以参照上文方法实施例的描述,为了简洁,这里不再赘述。
基于同一技术构思,本公开实施例还提供了一种电子设备。参照图5所示,为本公开实施例提供的电子设备的结构示意图,包括处理器501、存储器502、和总线503。其中,存储器502用于存储执行指令,包括内存5021和外部存储器5022;这里的内存5021也称内存储器,用于暂时存放处理器501中的运算数据,以及与硬盘等外部存储器5022交换的数据,处理器501通过内存5021与外部存储器5022进行数据交换,当电子设备500运行时,处理器501与存储器502之间通过总线503通信,使得处理器501在执行以下指令:获取原始图像;
利用所述原始图像的背景区域上的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果,所述至少三类区域包括前景区域、背景区域和所述前景区域与所述背景区域之间的边界区域;
基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息;
基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像。
此外,本公开实施例还提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序被处理器运行时执行上述方法实施例中所述的图像背景处理方法的步骤。其中,该存储介质可以是易失性或非易失的计算机可读取存储介质。
本公开实施例还提供一种计算机程序产品,该计算机程序产品承载有程序代码,所述程序代码包括的指令可用于执行上述方法实施例中所述的图像背景处理方法的步骤,具体可参见上述方法实施例,在此不再赘述。
其中,上述计算机程序产品可以具体通过硬件、软件或其结合的方式实现。在 一个可选实施例中,所述计算机程序产品具体体现为计算机存储介质,在另一个可选实施例中,计算机程序产品具体体现为软件产品,例如软件开发包(Software Development Kit,SDK)等等。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统和装置的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。在本公开所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,又例如,多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些通信接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本公开各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个处理器可执行的非易失的计算机可读取存储介质中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
以上仅为本公开的具体实施方式,但本公开的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本公开揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本公开的保护范围之内。因此,本公开的保护范围应以权利要求的保护范围为准。

Claims (16)

  1. 一种图像背景处理方法,其特征在于,包括:
    获取原始图像;
    利用从所述原始图像的背景部分上选取的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果,所述至少三类区域包括前景区域、背景区域和所述前景区域与所述背景区域之间的边界区域;
    基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息;
    基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像。
  2. 根据权利要求1所述的方法,其特征在于,在利用所述原始图像的背景区域上的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果之前,还包括:
    对所述原始图像进行尺寸缩小处理;
    在对尺寸缩小处理后的原始图像进行分割处理,得到至少三类区域的分割结果之后,还包括:
    将所述至少三类区域的分割结果映射回尺寸缩小处理前的原始图像上。
  3. 根据权利要求1或2所述的方法,其特征在于,所述利用所述原始图像的背景区域上的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域分割结果,包括:
    确定所述原始图像中各像素点的像素信息分别与所述采样像素点的采样像素信息之间的颜色相似度;
    利用各所述像素点对应的颜色相似度,对所述原始图像进行分割处理,得到至少三类区域的分割结果。
  4. 根据权利要求3所述的方法,其特征在于,所述确定所述原始图像中各像素点的像素信息分别与所述采样像素点的采样像素信息之间的颜色相似度,包括:
    将所述原始图像中各像素点的像素信息转换到目标颜色空间下的目标像素信息;所述目标颜色空间基于所述采样像素点的采样像素信息确定;
    确定各像素点在所述目标颜色空间下的目标像素信息分别与所述采样像素点在所述目标颜色空间下的目标采样像素信息之间的颜色相似度。
  5. 根据权利要求4所述的方法,其特征在于,所述方法还包括:
    确定所述原始图像中像素信息与所述采样像素点的采样像素信息匹配的第一像素点集合;
    所述确定各像素点在所述目标颜色空间下的目标像素信息分别与所述采样像素点在所述目标颜色空间下的目标采样像素信息之间的颜色相似度,包括:
    将所述第一像素点集合中各第一像素点的像素信息转换为目标颜色空间下的第一像素信息;
    基于各第一像素点的第一像素信息,生成所述目标颜色空间下的高斯颜色模型;
    将所述原始图像中各像素点的目标像素信息以及所述采样像素点的目标采样像素信息输入至所述高斯颜色模型中,得到各像素点的目标像素信息分别与所述采样像素点的目标采样像素信息之间的颜色相似度。
  6. 根据权利要求5所述的方法,其特征在于,所述确定所述原始图像中像素信息与所述采样像素点的采样像素信息匹配的第一像素点集合,包括:
    将所述原始图像各像素点的像素信息转换为色调饱和度明度HSV颜色空间下的像素信息;所述采样像素点在HSV颜色空间下的采样像素信息为第一采样像素信息;
    从各所述像素点在HSV颜色空间下的像素信息中筛选出与所述第一采样像素信息位于同一色域内的像素点集合;
    所述筛选出的像素点集合为所述第一像素点集合。
  7. 根据权利要求3至6任一所述的方法,其特征在于,所述利用各所述像素点对应的颜色相似度,对所述原始图像进行分割处理,得到至少三类区域的分割结果,包括:
    遍历所述原始图像中的像素点,对遍历到的像素点执行分割处理,得到遍历到的像素点的分割结果;在得到遍历到的全部像素点的分割结果后,生成所述至少三类区域的分割结果;
    其中,所述分割处理包括:
    在检测到所述遍历到的像素点的颜色相似度小于第一阈值的情况下,确定所述遍历到的像素点在前景区域;
    在检测到所述遍历到的像素点的颜色相似度大于或等于第二阈值的情况下,确定所述遍历到的像素点在背景区域;
    在检测到所述遍历到的像素点的颜色相似度大于或等于所述第一阈值,且小于所述第二阈值的情况下,确定所述遍历到的像素点在边界区域。
  8. 根据权利要求1至7任一所述的方法,其特征在于,所述基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息,包括:
    将在前景区域中的像素点的透明度信息确定为预设的第一透明度值;以及,将在背景区域中的像素点的透明度信息确定为预设的第二透明度值;
    以及,基于在边界区域中的像素点的像素信息以及所述采样像素点的采样像素信息,确定所述在边界区域中的像素点的透明度信息。
  9. 根据权利要求8所述的方法,其特征在于,所述基于在边界区域中的像素点的像素信息以及所述采样像素点的采样像素信息,确定所述在边界区域中的像素点的透明度信息,包括:
    确定在边界区域中的各像素点的像素信息分别与所述采样像素点的采样像素信息在目标颜色空间下的颜色相似度;
    基于在边界区域中各像素点对应的颜色相似度、以及第一界限值和第二界限值,确定在所述边界区域中各像素点的透明度信息。
  10. 根据权利要求9所述的方法,其特征在于,所述基于在边界区域中各像素点对应的颜色相似度、以及第一界限值和第二界限值,确定在所述边界区域中各像素点的透明度信息,包括:
    针对所述边界区域中的每个像素点,在所述像素点对应的所述颜色相似度小于所述 第一界限值的情况下,将所述像素点的透明度信息设置为所述预设的第一透明度值;
    在所述像素点对应的所述颜色相似度大于或等于所述第二界限值的情况下,将所述像素点的透明度信息设置为所述预设的第二透明度值;
    在所述像素点对应的所述颜色相似度大于或等于所述第一界限值,且小于所述第二界限值的情况下,利用所述第一界限值和所述第二界限值,对所述像素点的颜色相似度进行归一化处理,将归一化处理后的颜色相似度,确定为所述像素点的透明度信息。
  11. 根据权利要求1至10任一所述的方法,其特征在于,所述基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像,包括:
    针对所述至少三类区域中的每个像素点,基于所述像素点对应的透明度信息、所述像素点的像素信息、所述采样像素点的采样像素信息、以及与所述像素点的位置对应的所述目标背景的像素信息,确定所述像素点的中间像素信息;
    基于每个所述像素点的所述中间像素信息、所述透明度信息、和与所述像素点的位置对应的所述目标背景的像素信息,确定每个像素点的目标像素信息;
    基于各个像素点的目标像素信息,生成所述目标图像。
  12. 根据权利要求11所述的方法,其特征在于,所述基于所述像素点对应的透明度信息、所述像素点的像素信息、所述采样像素点的采样像素信息、以及与所述像素点的位置对应的所述目标背景的像素信息,确定所述像素点的中间像素信息,包括:
    将所述像素点对应的所述透明度信息与所述采样像素信息相乘,得到第一乘积信息;以及将所述透明度信息与所述像素点的位置对应的所述目标背景的像素信息相乘,得到第二乘积信息;
    将所述像素点的像素信息与所述第一乘积信息相减,再将得到的差值与所述第二乘积信息相加,得到所述像素点的中间像素信息。
  13. 根据权利要求11或12所述的方法,其特征在于,所述基于每个所述像素点的所述中间像素信息、所述透明度信息、和与所述像素点的位置对应的所述目标背景的像素信息,确定每个像素点目标像素信息,包括:
    将所述像素点的透明度信息与所述像素点的位置对应的所述目标背景的像素信息相乘,得到第三乘积信息;将预设基准值与所述像素点的透明度信息相减,再将得到的差值与所述中间像素信息相乘,得到第四乘积信息;
    将所述第三乘积信息与所述第四乘积信息的和,确定为所述像素点的目标像素信息。
  14. 一种图像背景处理装置,其特征在于,包括:
    获取模块,用于获取原始图像;
    分割模块,用于利用从所述原始图像的背景部分上选取的采样像素点的采样像素信息,对所述原始图像进行分割处理,得到至少三类区域的分割结果,所述至少三类区域包括前景区域、背景区域和所述前景区域与所述背景区域之间的边界区域;
    第一确定模块,用于基于所述至少三类区域的分割结果,确定所述至少三类区域中分别包括的像素点的透明度信息;
    生成模块,用于基于所述至少三类区域中分别包含的像素点的透明度信息以及待替换的目标背景的像素信息,生成目标图像。
  15. 一种电子设备,其特征在于,包括:处理器、存储器和总线,所述存储器存储有所述处理器可执行的机器可读指令,当电子设备运行时,所述处理器与所述存储器之间通过总线通信,所述机器可读指令被所述处理器执行时执行如权利要求1至13任一所述的图像背景处理方法的步骤。
  16. 一种计算机可读存储介质,其特征在于,该计算机可读存储介质上存储有计算机程序,该计算机程序被处理器运行时执行如权利要求1至13任一所述的图像背景处理方法的步骤。
PCT/CN2021/103535 2020-12-31 2021-06-30 图像背景处理方法、装置、电子设备及存储介质 WO2022142219A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011619776.3A CN112634312B (zh) 2020-12-31 2020-12-31 图像背景处理方法、装置、电子设备及存储介质
CN202011619776.3 2020-12-31

Publications (1)

Publication Number Publication Date
WO2022142219A1 true WO2022142219A1 (zh) 2022-07-07

Family

ID=75287336

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/103535 WO2022142219A1 (zh) 2020-12-31 2021-06-30 图像背景处理方法、装置、电子设备及存储介质

Country Status (3)

Country Link
CN (1) CN112634312B (zh)
TW (1) TW202228073A (zh)
WO (1) WO2022142219A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115797345A (zh) * 2023-02-06 2023-03-14 青岛佳美洋食品有限公司 一种海鲜烘烤异常识别方法

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112634312B (zh) * 2020-12-31 2023-02-24 上海商汤智能科技有限公司 图像背景处理方法、装置、电子设备及存储介质
CN113436284A (zh) * 2021-07-30 2021-09-24 上海商汤智能科技有限公司 一种图像处理方法、装置、计算机设备和存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100061658A1 (en) * 2008-09-08 2010-03-11 Hideshi Yamada Image processing apparatus, method, and program
CN101777180A (zh) * 2009-12-23 2010-07-14 中国科学院自动化研究所 基于背景建模和能量最小化的复杂背景实时替换方法
CN109978890A (zh) * 2019-02-25 2019-07-05 平安科技(深圳)有限公司 基于图像处理的目标提取方法、装置及终端设备
CN112634312A (zh) * 2020-12-31 2021-04-09 上海商汤智能科技有限公司 图像背景处理方法、装置、电子设备及存储介质

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB201217721D0 (en) * 2012-10-03 2012-11-14 Holition Ltd Video image processing
CN103996189B (zh) * 2014-05-05 2017-10-03 小米科技有限责任公司 图像分割方法及装置
CN105139415A (zh) * 2015-09-29 2015-12-09 小米科技有限责任公司 图像前后景分割方法、装置及终端
CN107452010B (zh) * 2017-07-31 2021-01-05 中国科学院长春光学精密机械与物理研究所 一种自动抠图算法和装置
CN109344724B (zh) * 2018-09-05 2020-09-25 深圳伯奇科技有限公司 一种证件照自动背景替换方法、系统及服务器

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100061658A1 (en) * 2008-09-08 2010-03-11 Hideshi Yamada Image processing apparatus, method, and program
CN101777180A (zh) * 2009-12-23 2010-07-14 中国科学院自动化研究所 基于背景建模和能量最小化的复杂背景实时替换方法
CN109978890A (zh) * 2019-02-25 2019-07-05 平安科技(深圳)有限公司 基于图像处理的目标提取方法、装置及终端设备
CN112634312A (zh) * 2020-12-31 2021-04-09 上海商汤智能科技有限公司 图像背景处理方法、装置、电子设备及存储介质

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115797345A (zh) * 2023-02-06 2023-03-14 青岛佳美洋食品有限公司 一种海鲜烘烤异常识别方法

Also Published As

Publication number Publication date
TW202228073A (zh) 2022-07-16
CN112634312B (zh) 2023-02-24
CN112634312A (zh) 2021-04-09

Similar Documents

Publication Publication Date Title
WO2022142219A1 (zh) 图像背景处理方法、装置、电子设备及存储介质
US11373275B2 (en) Method for generating high-resolution picture, computer device, and storage medium
US9275281B2 (en) Mobile image capture, processing, and electronic form generation
WO2018068304A1 (zh) 一种图像匹配的方法及装置
US20170289405A1 (en) Content aware improvement of captured document images
US10602026B2 (en) Image processing apparatus, image processing method, and non-transitory computer readable medium
JP2010278708A (ja) 画像処理装置及び方法、及びコンピュータプログラム
CN113132695B (zh) 镜头阴影校正方法、装置及电子设备
KR101624801B1 (ko) 전경 물체 추출을 위한 매팅 방법 및 이를 수행하는 장치
EP3855387A1 (en) Image processing method and apparatus, electronic device, and readable storage medium
US20170309003A1 (en) Removing artifacts from document images
CN111626967A (zh) 图像增强方法、装置、计算机装置及可读存储介质
JP6779688B2 (ja) 画像処理装置、画像処理方法、コンピュータプログラム
JP2021043874A (ja) 画像処理装置、画像処理方法、およびプログラム
EP3685346A1 (en) System and method for image dynamic range adjusting
US7796827B2 (en) Face enhancement in a digital video
CN111311500A (zh) 一种对图像进行颜色还原的方法和装置
CN109934783B (zh) 图像处理方法、装置、计算机设备和存储介质
WO2023151210A1 (zh) 图像处理方法、电子设备及计算机可读存储介质
CN108470327B (zh) 图像增强方法、装置、电子设备及存储介质
US11508034B2 (en) White background protection in SRGAN based super resolution
WO2021078276A1 (zh) 连拍照片获取方法、智能终端及存储介质
KR102215607B1 (ko) 어두운 이미지의 밝기를 개선하기 위한 보정 처리가 가능한 전자 장치 및 그 동작 방법
CN112070096B (zh) 颜色识别方法、装置、终端设备和存储介质
CN114266803A (zh) 图像处理方法、装置、电子设备及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21912975

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 21.11.2023)