Foreground image extraction method, device, equipment and storage medium

By determining the grayscale extreme points of the foreground and background in the target image and matching it, the problem of inaccurate recognition of foreground image in the prior art is solved, and higher accuracy is achieved.

CN114037829BActive Publication Date: 2025-09-02MIGU INTERACTIVE ENTERTAINMENT CO LTD +2
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111251366.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-26
Publication Date
2025-09-02
Estimated Expiration
2041-10-26

AI Technical Summary

Technical Problem

The prior art cannot accurately identify the foreground image, resulting in misjudgment.

Method used

By obtaining the foreground area and background area in the target image, determine the foreground grayscale extreme point and background grayscale extreme point, and match it, and re-dividing the areas to improve accuracy.

Benefits of technology

Improve the accuracy of foreground image extraction and avoid misjudgment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114037829B_ABST
    Figure CN114037829B_ABST
Patent Text Reader

Abstract

The present invention discloses a foreground image extraction method, device, equipment, and storage medium, belonging to the field of image processing technology. The present invention obtains a foreground area and a background area in a target image; determines a foreground grayscale extreme point based on the foreground area and determines a background grayscale extreme point based on the background area; matches the foreground grayscale extreme point with the background grayscale extreme point; and re-divides the foreground area and the background area in the target image according to the matching result to obtain a target foreground image. By matching the foreground grayscale extreme point obtained in the foreground area with the background grayscale extreme point obtained in the background area, the foreground area and the background area in the target image are re-divided, thereby avoiding misjudgment and improving the accuracy of foreground image extraction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to a foreground image extraction method, device, equipment and storage medium. Background Art

[0002] Existing techniques use background subtraction to extract moving object regions. This method primarily uses a difference calculation between two frames in the current scene, binarizes the resulting difference image, and then extracts the moving object region. However, the threshold value selected in this method is empirical and is set based on the experience of different users. This can lead to some misjudgments, where some moving objects are considered background, making it impossible to accurately identify the foreground image.

[0003] The above content is only used to assist in understanding the technical solution of the present invention and does not constitute an admission that the above content is prior art. Summary of the Invention

[0004] The main purpose of the present invention is to provide a foreground image extraction method, device, equipment and storage medium, aiming to solve the technical problem that the existing technology cannot accurately identify the foreground image.

[0005] To achieve the above object, the present invention provides a foreground image extraction method, which comprises the following steps:

[0006] Get the foreground area and background area in the target image;

[0007] Determine a foreground grayscale extreme value point based on the foreground area and determine a background grayscale extreme value point based on the background area;

[0008] Matching the foreground grayscale extreme value point with the background grayscale extreme value point;

[0009] The foreground area and the background area in the target image are re-divided according to the matching result to obtain a target foreground image.

[0010] Optionally, before obtaining the foreground area and the background area in the target image, the method further includes:

[0011] determining a differential image based on an initial image and adjacent frame images of the initial image;

[0012] performing binarization processing on the difference image to obtain a first foreground image;

[0013] Performing background modeling on the initial image to obtain a second foreground image;

[0014] determining a foreground image to be divided according to the first foreground image and the second foreground image;

[0015] The initial image is divided into regions according to the foreground image to be divided to obtain a target image.

[0016] Optionally, performing background modeling on the initial image to obtain a second foreground image includes:

[0017] Obtaining the pixel value of each pixel in the initial image;

[0018] Match pixel values ​​with a preset Gaussian distribution;

[0019] Filtering a target Gaussian distribution from the preset Gaussian distribution according to the matching result, and using the target Gaussian distribution as a background image;

[0020] Performing differential processing on the background image and the initial image to obtain a differential image to be processed;

[0021] Threshold segmentation is performed on the difference image to be processed to obtain a second foreground image.

[0022] Optionally, determining the foreground grayscale extreme value point according to the foreground area and determining the background grayscale extreme value point according to the background area includes:

[0023] Selecting corresponding reference areas from the foreground area and the background area according to preset sizes;

[0024] Determine a grayscale extreme value region according to the reference region, wherein the grayscale extreme value region includes a foreground grayscale extreme value region and a background grayscale extreme value region;

[0025] Grayscale extreme value points are determined according to the grayscale extreme value area, and the grayscale extreme value points include foreground grayscale extreme value points and background grayscale extreme value points.

[0026] Optionally, determining the grayscale extreme value region according to the reference region includes:

[0027] Calculating a target pixel value for each pixel in the reference area, and obtaining a set of pixel values ​​corresponding to each pixel in an adjacent area of ​​the reference area;

[0028] When the target pixel value and the pixel value set meet a preset condition, the reference area is used as a grayscale extreme value area.

[0029] Optionally, determining the grayscale extreme value point according to the grayscale extreme value area includes:

[0030] Performing grayscale local fitting on the grayscale extreme value region to obtain target parameters;

[0031] Determine the grayscale extreme value point according to the target parameter.

[0032] Optionally, matching the foreground grayscale extreme value point with the background grayscale extreme value point includes:

[0033] Calculating the extreme point distance between the foreground grayscale extreme point and the background grayscale extreme point;

[0034] Determine the similarity between the foreground grayscale extreme value point and the background grayscale extreme value point according to the extreme value point distance and a preset distance threshold;

[0035] The foreground grayscale extreme value point is matched with the background grayscale extreme value point according to the similarity.

[0036] In addition, to achieve the above-mentioned object, the present invention further provides a foreground image extraction device, the foreground image extraction device comprising:

[0037] An acquisition module, used for acquiring a foreground area and a background area in a target image;

[0038] a calculation module, configured to determine a foreground grayscale extreme value point based on the foreground area and a background grayscale extreme value point based on the background area;

[0039] A matching module, configured to match the foreground grayscale extreme value point with the background grayscale extreme value point;

[0040] The determination module is used to re-divide the foreground area and the background area in the target image according to the matching result to obtain a target foreground image.

[0041] In addition, to achieve the above-mentioned purpose, the present invention also proposes a foreground image extraction device, which includes: a memory, a processor, and a foreground image extraction program stored in the memory and runnable on the processor, and the foreground image extraction program is configured to implement the foreground image extraction method described above.

[0042] In addition, to achieve the above-mentioned purpose, the present invention further proposes a storage medium, on which a foreground image extraction program is stored. When the foreground image extraction program is executed by a processor, the foreground image extraction method described above is implemented.

[0043] The present invention obtains a foreground area and a background area in a target image; determines a foreground grayscale extreme point based on the foreground area and determines a background grayscale extreme point based on the background area; matches the foreground grayscale extreme point with the background grayscale extreme point; and re-divides the foreground area and the background area in the target image according to the matching result to obtain a target foreground image. By matching the foreground grayscale extreme point obtained in the foreground area with the background grayscale extreme point obtained in the background area, the foreground area and the background area in the target image are re-divided to avoid misjudgment and improve the accuracy of foreground image extraction. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 Schematic diagram of the structure of a foreground image extraction device in a hardware operating environment according to an embodiment of the present invention;

[0045] Figure 2 1 is a flow chart of a first embodiment of a foreground image extraction method according to the present invention;

[0046] Figure 3 2 is a flow chart of a second embodiment of a foreground image extraction method according to the present invention;

[0047] Figure 4 2 is a flow chart of a third embodiment of a foreground image extraction method according to the present invention;

[0048] Figure 5 A schematic diagram of selecting reference areas in the foreground area and background area in an embodiment of a foreground image extraction method of the present invention;

[0049] Figure 6 This is a structural block diagram of the first embodiment of the foreground image extraction device of the present invention.

[0050] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION

[0051] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0052] Reference Figure 1 , Figure 1 This is a schematic diagram of the structure of a foreground image extraction device in the hardware operating environment involved in an embodiment of the present invention.

[0053] like Figure 1As shown, the foreground image extraction device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to implement communication between these components. The user interface 1003 may include a display screen and an input unit such as a keyboard. Optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a wireless fidelity (Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (RAM) or a stable non-volatile memory (NVM), such as a disk storage. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0054] Those skilled in the art will understand that Figure 1 The structure shown in does not constitute a limitation on the foreground image extraction device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0055] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a foreground image extraction program.

[0056] exist Figure 1 In the foreground image extraction device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the foreground image extraction device of the present invention can be set in the foreground image extraction device, and the foreground image extraction device calls the foreground image extraction program stored in the memory 1005 through the processor 1001 and executes the foreground image extraction method provided by the embodiment of the present invention.

[0057] The embodiment of the present invention provides a foreground image extraction method, referring to Figure 2 , Figure 2 FIG. 4 is a flow chart of a first embodiment of a foreground image extraction method according to the present invention.

[0058] In this embodiment, the foreground image extraction method includes the following steps:

[0059] Step S10: Acquire the foreground area and background area in the target image.

[0060] In this embodiment, the execution subject of this embodiment can be a foreground image extraction device, which can be an electronic device such as a personal computer, a server or a vehicle-mounted terminal, or other devices or servers that can achieve the same or similar functions. This embodiment does not limit this. In this embodiment and the following embodiments, the foreground image extraction method of the present invention is explained by taking the foreground image extraction device as an example.

[0061] It should be noted that an image includes a foreground part and a background part. For example, in a person image, the person is the foreground part, that is, the foreground image, and other objects such as mountains, trees, and buildings belong to the background part, that is, the background image.

[0062] In the specific implementation, the target image in this embodiment has completed the division of the foreground area and the background area. It should be emphasized that the division of the foreground area and the background area in the target image is a preliminary division, but the preliminary division may have the situation of misjudgment of the foreground and the background, that is, the objects in the foreground are divided into the background. In order to improve the accuracy of foreground image recognition in this embodiment, the target image will be further processed based on the target image to extract a more accurate foreground image.

[0063] In a specific implementation, this embodiment first determines, after preliminary division, the foreground area and background area contained in the target image. The target image is the image for which foreground image extraction is required and can be selected by the user. Furthermore, this embodiment can obtain the foreground area and background area in the target image based on an acquisition instruction input by the user. A preset time can also be set. When the preset time is reached, the image that the user has preset and needs for foreground image extraction is automatically selected from the image collection and the foreground area and background area of ​​the image are obtained. In addition, this embodiment can also adopt a method to obtain the foreground area and background area in the target image, which is not limited in this embodiment.

[0064] Step S20: determining a foreground grayscale extreme value point according to the foreground area and determining a background grayscale extreme value point according to the background area.

[0065] In a specific implementation, after obtaining the foreground area and background area from the target image, the foreground grayscale extreme point can be obtained based on the foreground area, and the background grayscale extreme point can be obtained based on the background area. Specifically, the image corresponding to the foreground area is first converted into a foreground grayscale image, and the area corresponding to the background area is converted into a foreground grayscale image, and then the foreground grayscale extreme point and the background grayscale extreme point are determined. In this embodiment, a region can be selected from the foreground grayscale image, and calculations can be performed based on the grayscale values ​​of each pixel in the region, and then the foreground grayscale extreme point is calculated based on the calculated parameters.

[0066] It should be emphasized that the size of the region selected in this embodiment can be set arbitrarily. If the foreground region is 16×16, the selected region can be set to 4×4. Specifically, it can be adjusted accordingly according to actual needs, and this is not limited in this embodiment. In addition, the process of calculating the parameters based on the grayscale value of each pixel in the region can be to substitute the grayscale value of each pixel in the region into a preset relationship for calculation, wherein the form of the preset relationship can be set to a quadratic polynomial. Of course, the preset relationship can also be set in other ways according to actual needs, and this is not limited in this embodiment.

[0067] Step S30: Matching the foreground grayscale extreme value point with the background grayscale extreme value point.

[0068] It should be noted that due to the possibility of misjudgment of the foreground and background areas divided in the target image, after obtaining the foreground grayscale extreme points and the background grayscale extreme points, the foreground grayscale extreme points and the background grayscale extreme points are matched. The matching in this embodiment is similarity matching, that is, the background grayscale extreme points similar to the foreground grayscale extreme points are determined by matching the background grayscale extreme points.

[0069] Furthermore, in order to improve the accuracy of grayscale extreme point matching in this embodiment, it can be achieved in the following manner.

[0070] In a specific implementation, this embodiment determines the similarity between the foreground grayscale extreme point and the background grayscale extreme point based on the extreme point distance and a preset distance threshold, and then matches the foreground grayscale extreme point with the background grayscale extreme point based on the similarity. The matching process in this embodiment is to determine the background grayscale extreme point that is similar to the foreground grayscale extreme point. Specifically, the distance calculation formula between grayscale extreme points in this embodiment is as follows: Where Dmm represents the distance between the foreground grayscale extreme point and the background grayscale extreme point, (x′, y′) is the pixel coordinate corresponding to the background grayscale extreme point, and (X, Y) is the pixel coordinate corresponding to the foreground grayscale extreme point.

[0071] Furthermore, after calculating the extreme point distance, the extreme point distance is compared with a preset distance threshold. Based on the comparison result, it can be determined whether the foreground grayscale extreme point and the background grayscale extreme point are similar. If the extreme point distance is less than the preset distance threshold, it means that the background grayscale extreme point and the foreground grayscale extreme point are similar. Conversely, if the extreme point distance is greater than or equal to the preset distance threshold, it means that the background grayscale extreme point and the foreground grayscale extreme point are not similar. In this embodiment, the preset distance threshold can be set to 2. Of course, the preset distance threshold can also be adjusted accordingly according to actual conditions. This is not limited in this embodiment. The area where the background grayscale extreme point corresponding to the extreme point distance less than the preset distance threshold is located can be used as the new foreground area.

[0072] Step S40: Re-dividing the foreground area and the background area in the target image according to the matching result to obtain a target foreground image.

[0073] In a specific implementation, after completing the matching, the background grayscale extreme points similar to the foreground grayscale extreme points are determined based on the matching results. In this embodiment, the foreground and background regions are re-divided by using the background regions corresponding to these similar background grayscale extreme points as the foreground region. Furthermore, after re-dividing the regions, new foreground and background regions corresponding to the target image can be determined, and the image corresponding to the new foreground region is used as the target foreground image.

[0074] This embodiment obtains a foreground area and a background area in a target image; determines a foreground grayscale extreme point based on the foreground area and determines a background grayscale extreme point based on the background area; matches the foreground grayscale extreme point with the background grayscale extreme point; and re-divides the foreground area and the background area in the target image according to the matching result to obtain a target foreground image. By matching the foreground grayscale extreme point obtained in the foreground area with the background grayscale extreme point obtained in the background area, the foreground area and the background area in the target image are re-divided to avoid misjudgment and improve the accuracy of foreground image extraction.

[0075] refer to Figure 3 , Figure 3 FIG. 4 is a flow chart of a second embodiment of a foreground image extraction method according to the present invention.

[0076] Based on the first embodiment, the foreground image extraction method of this embodiment further includes, before step S10:

[0077] Step S00: determining a differential image based on an initial image and adjacent frame images of the initial image.

[0078] In a specific implementation, the target image is an image that has undergone preliminary region division, and the preliminary region division is performed on the basis of the initial image. In this embodiment, a differential image is obtained based on the initial image and adjacent frame images of the initial image by image difference.

[0079] In a specific implementation, three consecutive frames of images are selected, and then the difference image is calculated using the following formula:

[0080] D1(x,y)=f(x,y,t)-f(x,y,t-1)

[0081] D2(x,y)=f(x,y,t+1)-f(x,y,t)

[0082] Among them, D1(x,y) represents the difference image between the initial image and the previous frame image, D2(x,y) represents the difference image between the subsequent frame image and the initial image, f(x,y,t-1) represents the previous frame image of the initial image, f(x,y,t) represents the current frame image, that is, the initial image, f(x,y,t+1) represents the subsequent frame image of the initial image, and (x,y) represents the pixel coordinates of any point on the image.

[0083] Step S01: binarizing the difference image to obtain a first foreground image.

[0084] In a specific implementation, after obtaining the difference image, this embodiment adopts a binarization processing method to further process the difference image. The binarization processing formula is as follows:

[0085]

[0086] Among them, D j (x, y) represents the jth difference image. The threshold Th can be preset by the user. Different values ​​will result in different foreground images being detected. The value of Th can be set accordingly based on actual needs and is not limited in this embodiment. However, it should be emphasized in this embodiment that if Th is too small, holes and missed detections will occur, while if Th is too large, noise will be generated.

[0087] In a specific implementation, in this embodiment, the two obtained foreground images are subjected to an AND operation to obtain a final foreground image, that is, the first foreground image. j (x,y)=R j-1 (x,y)&R j (x,y), where FR j (x, y) is the first foreground image, R j (x,y) and R j-1(x, y) are two foreground images obtained based on the two differential images, and j represents the number of differential images.

[0088] Step S02: performing background modeling on the initial image to obtain a second foreground image.

[0089] It should be noted that the above-mentioned method for obtaining the first foreground image is image differencing and binarization. In this embodiment, the initial image is processed again by background modeling to obtain the second foreground image. Among them, the background modeling can select a mixed Gaussian background model. Of course, other background models can be used to perform background modeling on the initial image according to actual needs. This is not limited in this embodiment.

[0090] Furthermore, the step S02 specifically includes: obtaining the pixel value of each pixel point in the initial image; matching the pixel value with a preset Gaussian distribution; filtering out a target Gaussian distribution from the preset Gaussian distribution according to the matching result, and using the target Gaussian distribution as a background image; performing differential processing on the background image and the initial image to obtain a differential image to be processed; and performing threshold segmentation on the differential image to be processed to obtain a second foreground image.

[0091] In a specific implementation, the time corresponding to each pixel point can be determined based on the time when the initial image is obtained, so that the position of each pixel point in the entire time series is {X1, X2..., X t The number of preset Gaussian distributions selected in this embodiment can be set to k. The specific number setting can be adjusted accordingly according to actual needs and is not limited in this embodiment. Then the pixel value is matched with the preset Gaussian distribution, and whether to update the model is determined based on the matching result. If a match is found, the weight adjustment rules of each Gaussian distribution are as follows:

[0092] w i,t =(1-α)w i,t-1 +αM i,t

[0093] Among them, α is the learning factor, which varies from 0 to 1. The matching weight is obtained by M i,t Control, M i,t =1, the matching weight increases, M i,t = 0, the matching weight decreases, M i,t is the matching pattern of the i-th Gaussian distribution weight at time t, and the rate of increase or decrease is determined by α.

[0094] It should be noted that the preset Gaussian distribution is adjusted according to the above-mentioned weight adjustment rule, and then the target Gaussian distribution is screened out from the adjusted Gaussian distribution. The screening conditions in this embodiment are as follows:

[0095]

[0096] The value of T is determined by the application context; simple backgrounds have a small value for T, while complex backgrounds have a large value for T. K is the number of Gaussian distributions. It should be noted that the Gaussian distribution that meets the above conditions is the target Gaussian distribution, and b is the number of target Gaussian distributions that meet the above conditions. In this embodiment, these Gaussian distributions are used as the background image. Furthermore, the background image is differentially calculated from the initial image to obtain a differential image, which is then thresholded to obtain the foreground image.

[0097] Step S03: determining a foreground image to be divided according to the first foreground image and the second foreground image.

[0098] In specific implementations, there will be certain differences between the foreground images obtained by the above two methods. In this embodiment, the foreground images obtained by the two methods are combined to obtain a more accurate foreground image, that is, the first foreground image and the second foreground image are combined to obtain the foreground image to be divided.

[0099] In a specific implementation, in this embodiment, the first foreground image and the second foreground image are ORed to obtain the foreground image to be divided, for example, R k (x,y)=FR k (x,y)&BR k (x,y) foreground image, where R k (x,y) is the foreground image to be divided, FR k (x, y) is the first foreground image, BR k (x,y) is the second foreground image.

[0100] Step S04: performing region division on the initial image according to the foreground image to be divided to obtain a target image.

[0101] In a specific implementation, after obtaining the foreground image to be divided, the area corresponding to the foreground image to be divided is used as the foreground area, and the other areas are used as the background area. Then, the initial image is divided into regions according to these foreground areas and background areas to obtain the target image.

[0102] This embodiment determines a differential image based on an initial image and adjacent frame images of the initial image; binarizes the differential image to obtain a first foreground image; performs background modeling on the initial image to obtain a second foreground image; determines a foreground image to be divided based on the first foreground image and the second foreground image; and performs region division on the initial image based on the foreground image to be divided to obtain a target image. A preliminary foreground image is extracted from the initial image using the images obtained by the two methods to improve the accuracy of subsequent foreground image extraction.

[0103] refer to Figure 4 , Figure 4 FIG. 4 is a flow chart of a third embodiment of a foreground image extraction method according to the present invention.

[0104] Based on the above first and second embodiments, a third embodiment of a foreground image extraction method of the present invention is proposed.

[0105] Taking the first embodiment as an example, in this embodiment, step S20 specifically includes:

[0106] Step S201: selecting corresponding reference areas from the foreground area and the background area according to preset sizes.

[0107] In a specific implementation, this embodiment selects corresponding reference areas from the foreground area and the background area respectively. The reference areas in this embodiment include a first reference area and a second reference area. Specifically, for the foreground area, the first reference area is randomly selected from the foreground area, and the second reference area is randomly selected from the background area. Figure 5 As shown, the first reference area and the second reference area are selected in the same way. Figure 5 The distance is explained using the foreground area as an example. For example, if B is the foreground area, then A is the first reference area, and the remaining area between A and B is the adjacent area of ​​A. The size of the first reference area can be set accordingly based on actual needs and is not limited in this embodiment. For example, if the size of the foreground area is 16×16, the size of the first reference area can be set to 4×4. The process of selecting the second reference area is the same as that of the first reference area and will not be repeated in this embodiment.

[0108] Step S202: determining a grayscale extreme value region according to the reference region.

[0109] Step S203: determining a grayscale extreme point according to the grayscale extreme area.

[0110] In a specific implementation, in this embodiment, the grayscale extreme value region is first determined through the reference region, and then the grayscale extreme value point is determined through the grayscale extreme value region.

[0111] In a specific implementation, after selecting the reference region, the reference region is judged, and the reference region that meets the conditions is directly used as the grayscale extreme value region. The grayscale extreme value region includes the foreground grayscale extreme value region and the background grayscale extreme value region. In this embodiment, the process of determining the foreground grayscale extreme value region is described using the first reference region as an example.

[0112] In a specific implementation, a first target pixel value is calculated based on the pixel values ​​corresponding to each pixel point. In this embodiment, the first target pixel value is the pixel average value of each pixel point in the first reference area. At the same time, the pixel values ​​of each pixel point within the first reference area are obtained to generate a pixel value set. Furthermore, after obtaining the first target pixel value and the first pixel value set, the first target pixel value and the first pixel value set are judged according to preset conditions to determine whether to use the first reference area as a foreground grayscale extreme value area. The preset conditions are as follows:

[0113] Min{S val}-{C val}>ε or {C val}-Max{S val}>ε

[0114] Among them, {C val} is the pixel average value of each pixel in the first reference area, that is, the first target pixel value, {S val} is the first pixel value set, Min{S val} is the minimum pixel value in the first pixel value set, Max{S val} is the maximum pixel value in the first pixel value set, and ε is the difference threshold value. This can be set accordingly based on actual needs and is not limited in this embodiment. If the above-mentioned preset conditions are met, the first reference region is the foreground grayscale extreme value region. The process of determining the background grayscale extreme value region corresponding to the background region using the second reference region is the same as described above and will not be repeated in this embodiment.

[0115] In a specific implementation, the grayscale extreme value area of ​​the foreground is locally fitted using a preset relationship. The preset relationship adopted in this embodiment is a perfect quadratic polynomial. The formula of the quadratic polynomial is as follows:

[0116] I(x,y)=Ax 2 +By 2 +Cxy+Dx+Ey+F

[0117] Where I(x,y) is the grayscale value of the pixel with the relative coordinates (x,y) in the foreground grayscale extreme value area, A, B, ..., F are the parameters of the quadratic polynomial, that is, the target parameters, which can be calculated by the least squares method:

[0118]

[0119] In the above formula, n = 16 × 16, which is the size of the grayscale extreme value area. The values ​​of the target parameters A, B, ..., F can be obtained through the above calculation. These parameters are then substituted into the following equation for calculation:

[0120]

[0121] The (x, y) obtained by calculation is the foreground grayscale extreme point. The above distance is explained using the foreground grayscale extreme area as an example. The grayscale extreme points include the foreground grayscale extreme points and the background grayscale extreme points. In this embodiment, the process of determining the background grayscale extreme point from the background grayscale extreme area is the same as the above process and will not be repeated in this embodiment.

[0122] This embodiment selects corresponding reference areas from the foreground area and the background area according to preset sizes, determines the grayscale extreme area based on the reference area, and determines the grayscale extreme point based on the grayscale extreme area, so as to obtain accurate grayscale extreme points and indirectly improve the accuracy of foreground image extraction.

[0123] In addition, an embodiment of the present invention further provides a storage medium, on which a foreground image extraction program is stored. When the foreground image extraction program is executed by a processor, the steps of the foreground image extraction method described above are implemented.

[0124] Since the storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.

[0125] Reference Figure 6 , Figure 6 This is a structural block diagram of the first embodiment of the foreground image extraction device of the present invention.

[0126] like Figure 6 As shown, the foreground image extraction device proposed in the embodiment of the present invention includes:

[0127] The acquisition module 10 is used to acquire the foreground area and the background area in the target image.

[0128] The calculation module 20 is configured to determine a foreground grayscale extreme value point based on the foreground area and a background grayscale extreme value point based on the background area.

[0129] The matching module 30 is configured to match the foreground grayscale extreme value point with the background grayscale extreme value point.

[0130] The determination module 40 is configured to re-divide the foreground area and the background area in the target image according to the matching result to obtain a target foreground image.

[0131] This embodiment obtains a foreground area and a background area in a target image; determines a foreground grayscale extreme point based on the foreground area and determines a background grayscale extreme point based on the background area; matches the foreground grayscale extreme point with the background grayscale extreme point; and re-divides the foreground area and the background area in the target image according to the matching result to obtain a target foreground image. By matching the foreground grayscale extreme point obtained in the foreground area with the background grayscale extreme point obtained in the background area, the foreground area and the background area in the target image are re-divided to avoid misjudgment and improve the accuracy of foreground image extraction.

[0132] In one embodiment, the foreground image extraction device further includes a processing module;

[0133] The processing module is used to determine a differential image based on an initial image and adjacent frame images of the initial image; perform binarization processing on the differential image to obtain a first foreground image; perform background modeling on the initial image to obtain a second foreground image; determine a foreground image to be divided based on the first foreground image and the second foreground image; and perform region division on the initial image based on the foreground image to be divided to obtain a target image.

[0134] In one embodiment, the processing module is further used to obtain the pixel value of each pixel point in the initial image; match the pixel value with a preset Gaussian distribution; filter out a target Gaussian distribution from the preset Gaussian distribution based on the matching result, and use the target Gaussian distribution as a background image; perform differential processing on the background image and the initial image to obtain a differential image to be processed; and perform threshold segmentation on the differential image to be processed to obtain a second foreground image.

[0135] In one embodiment, the calculation module 20 is further used to select corresponding reference areas from the foreground area and the background area according to preset sizes; determine the grayscale extreme area based on the reference area, and the grayscale extreme area includes the foreground grayscale extreme area and the background grayscale extreme area; determine the grayscale extreme point based on the grayscale extreme area, and the grayscale extreme point includes the foreground grayscale extreme point and the background grayscale extreme point.

[0136] In one embodiment, the calculation module 20 is also used to calculate the target pixel value of each pixel point in the reference area, and obtain the pixel value set corresponding to each pixel point in the adjacent area of ​​the reference area; when the target pixel value and the pixel value set meet the preset conditions, the reference area is used as the grayscale extreme value area.

[0137] In one embodiment, the calculation module 20 is further configured to perform grayscale local fitting on the grayscale extreme value region to obtain target parameters; and determine the grayscale extreme value point according to the target parameters.

[0138] In one embodiment, the matching module 30 is further used to calculate the extreme point distance between the foreground grayscale extreme point and the background grayscale extreme point; determine the similarity between the foreground grayscale extreme point and the background grayscale extreme point based on the extreme point distance and a preset distance threshold; and match the foreground grayscale extreme point with the background grayscale extreme point based on the similarity.

[0139] It should be understood that the above is only an example and does not constitute any limitation to the technical solution of the present invention. In specific applications, those skilled in the art can make settings as needed, and the present invention does not impose any limitation on this.

[0140] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of it according to actual needs to achieve the purpose of the embodiment scheme, and no limitation is made here.

[0141] In addition, for technical details not fully described in this embodiment, reference can be made to the foreground image extraction method provided in any embodiment of the present invention, and will not be repeated here.

[0142] In addition, it should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.

[0143] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.

[0144] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, or of course by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0145] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A foreground image extraction method, characterized in that: The foreground image extraction method comprises: Acquiring a foreground area and a background area in a target image, wherein the foreground area and the background area of ​​the target image are acquired based on an acquisition instruction input by a user, or when a preset time is reached, selecting an image preset by the user for foreground image extraction from an image collection, and acquiring the foreground area and the background area of ​​the image; Determine a foreground grayscale extreme value point based on the foreground area and determine a background grayscale extreme value point based on the background area; Matching the foreground grayscale extreme value point with the background grayscale extreme value point; The foreground area and the background area in the target image are re-divided according to the matching result to obtain a target foreground image.

2. The foreground image extraction method according to claim 1, wherein: Before obtaining the foreground area and the background area in the target image, the method further includes: determining a differential image based on an initial image and adjacent frame images of the initial image; performing binarization processing on the difference image to obtain a first foreground image; Performing background modeling on the initial image to obtain a second foreground image; determining a foreground image to be divided according to the first foreground image and the second foreground image; The initial image is divided into regions according to the foreground image to be divided to obtain a target image.

3. The foreground image extraction method according to claim 2, wherein: The performing background modeling on the initial image to obtain a second foreground image includes: Obtaining the pixel value of each pixel in the initial image; Match pixel values ​​with a preset Gaussian distribution; Filtering a target Gaussian distribution from the preset Gaussian distribution according to the matching result, and using the target Gaussian distribution as a background image; Performing differential processing on the background image and the initial image to obtain a differential image to be processed; Threshold segmentation is performed on the difference image to be processed to obtain a second foreground image.

4. The foreground image extraction method according to claim 1, wherein: The step of determining a foreground grayscale extreme value point based on the foreground area and determining a background grayscale extreme value point based on the background area comprises: Selecting corresponding reference areas from the foreground area and the background area according to preset sizes; Determine a grayscale extreme value region according to the reference region, wherein the grayscale extreme value region includes a foreground grayscale extreme value region and a background grayscale extreme value region; Grayscale extreme value points are determined according to the grayscale extreme value area, and the grayscale extreme value points include foreground grayscale extreme value points and background grayscale extreme value points.

5. The foreground image extraction method according to claim 4, wherein: The determining of the grayscale extreme value region according to the reference region includes: Calculating a target pixel value for each pixel in the reference area, and obtaining a set of pixel values ​​corresponding to each pixel in an adjacent area of ​​the reference area; When the target pixel value and the pixel value set meet a preset condition, the reference area is used as a grayscale extreme value area.

6. The foreground image extraction method according to claim 4, wherein: The step of determining the grayscale extreme value point according to the grayscale extreme value area includes: Performing grayscale local fitting on the grayscale extreme value region to obtain target parameters; Determine the grayscale extreme value point according to the target parameter.

7. The foreground image extraction method according to any one of claims 1 to 6, wherein: The matching of the foreground grayscale extreme value point with the background grayscale extreme value point includes: Calculating the extreme point distance between the foreground grayscale extreme point and the background grayscale extreme point; Determine the similarity between the foreground grayscale extreme value point and the background grayscale extreme value point according to the extreme value point distance and a preset distance threshold; The foreground grayscale extreme value point is matched with the background grayscale extreme value point according to the similarity.

8. A foreground image extraction device, characterized in that: The foreground image extraction device comprises: an acquisition module, configured to acquire a foreground region and a background region of a target image, wherein the foreground region and the background region of the target image are acquired based on an acquisition instruction input by a user, or when a preset time is reached, select an image preset by the user for foreground image extraction from an image collection, and acquire the foreground region and the background region of the image; a calculation module, configured to determine a foreground grayscale extreme value point based on the foreground area and a background grayscale extreme value point based on the background area; A matching module, configured to match the foreground grayscale extreme value point with the background grayscale extreme value point; The determination module is used to re-divide the foreground area and the background area in the target image according to the matching result to obtain a target foreground image.

9. A foreground image extraction device, characterized in that: The foreground image extraction device includes: a memory, a processor, and a foreground image extraction program stored in the memory and executable on the processor, wherein the foreground image extraction program is configured to implement the foreground image extraction method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium stores a foreground image extraction program, which, when executed by a processor, implements the foreground image extraction method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Foreground image extraction method and device, and moving vehicle recognition method and device

    CN109035287A