Image foreground extraction method and system

By translating in the image and combining threshold processing and intersection compensation technology, the problem of inaccurate image foreground extraction is solved, and accurate foreground area determination is achieved in complex backgrounds.

CN116128913BActive Publication Date: 2025-08-08BEIJING LUSTER LIGHTTECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211561974.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-07
Publication Date
2025-08-08
Estimated Expiration
2042-12-07

AI Technical Summary

Technical Problem

In the prior art, due to the large grayscale difference in image foreground extraction, the foreground extraction is inaccurate.

Method used

After the image is translated in the first direction and the second distance in the direction opposite to the first direction, thresholding processing is performed, the first and second foreground area images are acquired, and the real foreground area images are acquired based on the intersection and compensation areas.

Benefits of technology

Improves the accuracy of image foreground extraction, ensuring that the foreground area can be accurately determined in complex contexts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116128913B_ABST
    Figure CN116128913B_ABST
Patent Text Reader

Abstract

The present application relates to the field of image processing technology, and more specifically, to a method and system for extracting foreground from an image, which can, to a certain extent, solve the problem of poor foreground extraction accuracy. The method for extracting foreground from an image comprises: translating a first image in a first direction by a first distance to obtain a second image; translating the first image in a direction opposite to the first direction by a second distance to obtain a third image; performing threshold processing on the first image and the second image to obtain a first foreground area image; performing threshold processing on the first image and the third image to obtain a second foreground area image; and obtaining a true foreground area image of the first image based on the first foreground area image and the second foreground area image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to an image foreground extraction method and system. Background Art

[0002] In the process of image processing, it is often necessary to analyze and process the foreground and background of the image. Image foreground extraction is to quickly and accurately extract the target of interest from a given image in order to replace the background or perform other operations. The target of interest is the foreground of the image. It is an important operation in digital image processing and a research hotspot in pattern recognition and computer vision.

[0003] In the implementation of the image foreground extraction process, the neighborhood comparison method is generally used for processing, that is, the grayscale values at different positions in the same image are obtained. Since the grayscale difference between the foreground and background in the same image is large, the foreground can be identified and extracted by comparing the difference in grayscale values at different positions in an image and attributing the grayscale value difference. The area corresponding to the grayscale value difference within the preset interval is the foreground area.

[0004] However, when extracting the foreground using the above method, when the grayscale differences between different background area images in the original image are large, the range of variation of the grayscale value difference at different positions in the same image is large, which is not conducive to accurately extracting the foreground by attributing the grayscale value difference. Summary of the Invention

[0005] In order to solve the problem of poor foreground extraction accuracy, the present application provides an image foreground extraction method and system.

[0006] The embodiment of the present application is implemented as follows:

[0007] A first aspect of an embodiment of the present application provides an image foreground extraction method, comprising:

[0008] translating the first image in a first direction by a first distance to obtain a second image;

[0009] translating the first image by a second distance in a direction opposite to the first direction to obtain a third image;

[0010] Performing threshold processing on the first image and the second image to obtain a first foreground area image; performing threshold processing on the first image and the third image to obtain a second foreground area image;

[0011] Based on the first foreground area image and the second foreground area image, a true foreground area image of the first image is acquired.

[0012] In some embodiments, the first distance and the second distance are both determined according to the size of the foreground area to be extracted in the first image, and the first distance and the second distance are both larger than the foreground area to be extracted in the first image.

[0013] In some embodiments, the first distance and the second distance are the same.

[0014] In some embodiments, the step of acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image further includes:

[0015] An intersection area image of the first foreground area image and the second foreground area image is acquired, where the intersection area image is a true foreground area image of the first image.

[0016] In some embodiments, the step of acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image further includes:

[0017] Acquire an intersection area image of the first foreground area image and the second foreground area image;

[0018] acquiring a first retained area image of a periphery of a boundary line of the first image in the first direction when the first image is translated in the first direction, and a second retained area image of a periphery of a boundary line of the first image in the second direction when the first image is translated in the second direction;

[0019] Obtaining an intersection of the first reserved area image and the first foreground area image, the intersection of the first reserved area image and the first foreground area image being a first compensation area image; obtaining an intersection of the second reserved area image and the second foreground area image, the intersection of the second reserved area image and the second foreground area image being a second compensation area image;

[0020] A union of the intersection area image, the first compensation area image, and the second compensation area image is obtained, where the union is a true foreground area image of the first image.

[0021] In some embodiments, if the first image is a rectangle and the first direction is a horizontal translation to the left or right, the width of the first reserved area image and the second reserved area image are both the first distance, and the height is the same as the height of the first image.

[0022] In some embodiments, the step of performing threshold processing on the first image and the second image further includes:

[0023] subtracting the first image from the second image to obtain a first differential image;

[0024] After the first difference image is segmented by a threshold value, the first foreground area image is obtained.

[0025] A second aspect of an embodiment of the present application provides an image foreground extraction system, comprising:

[0026] A first translation module, configured to translate the first image in a first direction by a first distance to obtain a second image;

[0027] a second translation module, configured to translate the first image by a second distance in a direction opposite to the first direction to obtain a third image;

[0028] a foreground area acquisition module, configured to perform threshold processing on the first image and the second image to acquire a first foreground area image; and perform threshold processing on the first image and the third image to acquire a second foreground area image;

[0029] The real foreground area acquisition module is used to acquire the real foreground area image of the first image based on the first foreground area image and the second foreground area image.

[0030] In some embodiments, in the step of acquiring a real foreground area image of the first image based on the first foreground area image and the second foreground area image, the real foreground area acquisition module is further configured to:

[0031] An intersection area image of the first foreground area image and the second foreground area image is acquired, where the intersection area image is a true foreground area image of the first image.

[0032] In some embodiments, a regional image compensation module is further included. In the step of acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image, the regional image compensation module is configured to:

[0033] acquiring a first retained area image of a periphery of a boundary line of the first image in the first direction when the first image is translated in the first direction, and a second retained area image of a periphery of a boundary line of the first image in the second direction when the first image is translated in the second direction;

[0034] further configured to obtain an intersection of the first retained area image and the first foreground area image, the intersection of the first retained area image and the first foreground area image being a first compensation area image; and obtain an intersection of the second retained area image and the second foreground area image, the intersection of the second retained area image and the second foreground area image being a second compensation area image;

[0035] At this time, the real foreground area acquisition module is further used to:

[0036] Obtaining an intersection of the first foreground area image and the second foreground area image to obtain an intersection area image;

[0037] A union of the intersection area image, the first compensation area image, and the second compensation area image is obtained, where the union is a true foreground area image of the first image.

[0038] The beneficial effects of the present application are as follows: after translating the image in a first direction by a first distance and in a direction opposite to the first direction by a second distance, the second image and the third image obtained respectively are threshold-processed together with the first image, and based on the first foreground area image and the second foreground area image, the true foreground area image of the first image is obtained. In this process, the area range of the first image subjected to threshold processing can be expanded, which helps to accurately determine the foreground of the image, thereby effectively improving the accuracy of foreground extraction in the image. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0040] Figure 1 is a flowchart of an image foreground extraction method according to some embodiments of the present application;

[0041] Figure 2 is a flowchart of a method for extracting an image foreground according to some embodiments of the present application;

[0042] Figure 3 Schematic diagram of a first foreground area image obtained by an image foreground extraction method according to some embodiments of the present application;

[0043] Figure 4 Schematic diagram of a second foreground area image obtained by an image foreground extraction method according to some embodiments of the present application;

[0044] Figure 5 Schematic diagram of an intersection area image obtained by an image foreground extraction method according to some embodiments of the present application;

[0045] Figure 6 Schematic diagram of a first foreground area image obtained by an image foreground extraction method according to some other embodiments of the present application;

[0046] Figure 7 Schematic diagram of a second foreground area image obtained by an image foreground extraction method according to some other embodiments of the present application;

[0047] Figure 8 Schematic diagram of an intersection area image obtained by an image foreground extraction method according to other embodiments of the present application;

[0048] Figure 9 is a flowchart of an image foreground extraction method according to some other embodiments of the present application;

[0049] Figure 10 is a flowchart of an image foreground extraction method according to other embodiments of the present application;

[0050] Figure 11 Schematic diagram of a real foreground area image of a first image obtained by an image foreground extraction method according to some other embodiments of the present application;

[0051] Figure 12 is a structural diagram of an image foreground extraction system according to some embodiments of the present application;

[0052] Figure 13 is a structural schematic diagram of an image foreground extraction system according to some other embodiments of the present application;

[0053] Figure 14 Schematic diagram of the structure of an image foreground extraction device according to one or more embodiments of the present application. DETAILED DESCRIPTION

[0054] In order to make the purpose, implementation mode and advantages of the present application clearer, the exemplary implementation mode of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, not all of the embodiments.

[0055] It should be noted that the brief descriptions of terms in this application are only for the purpose of facilitating the understanding of the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their ordinary and usual meanings.

[0056] In the specification and claims of this application and the accompanying drawings, the terms "first," "second," "third," etc. are used to distinguish similar or similar objects or entities, and are not necessarily intended to limit a particular order or sequence, unless otherwise noted. It should be understood that the terms used in this manner are interchangeable under appropriate circumstances.

[0057] The terms "comprise," "comprises," and "having," and any variations thereof, are intended to cover but not exclude inclusion; for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.

[0058] Figure 1 This is a flowchart of the image foreground extraction method. Figure 1 As shown, in the first aspect, the present application provides an image foreground extraction method, which specifically includes the following steps:

[0059] In step 100, the first image is translated in a first direction by a first distance to obtain a second image.

[0060] In the present application, the first image is the image from which foreground extraction is desired. In some embodiments, after receiving the first image, a median filter may be performed on the binarized first image to change the grayscale values of pixels with a large absolute difference from those of surrounding pixels to grayscale values close to those of surrounding pixels, removing pixels with grayscale values that are brighter or darker than those of their neighboring pixels. The processed first image is then translated in a first direction by a first distance, thereby facilitating more accurate extraction of the foreground area image.

[0061] The first direction can be an oblique direction, or vertically upward, vertically downward, horizontally left, or horizontally right. When the first image moves horizontally or vertically, the movement method is simple and facilitates accurate movement. Whether the first image moves horizontally or vertically depends on the approximate location of the foreground area in the first image. Taking the first image as a rectangle as an example, when the approximate location of the foreground area is close to the bottom edge or the top edge in the first image, the first direction is leftward or rightward; when the approximate location of the foreground area is close to both sides in the first image, the first direction is upward or downward.

[0062] In some embodiments, when determining the approximate location of the foreground area, the first image may be projected in a vertical direction to obtain a projection curve of the first image. The projection curve may then be smoothed using a Gaussian filter. All troughs in the smoothed projection curve may then be located. The highest connected region between all troughs may then be found in the corresponding binarized image to obtain the approximate location of the foreground area in the first image. The first direction may then be determined based on the approximate location of the foreground area.

[0063] It should be noted that the first distance is determined according to the size of the foreground area to be extracted in the first image. When the size of the first image is large, the value of the first distance is also large; when the size of the first image is relatively small, the value of the first distance is also small, and the first distance is greater than the foreground area to be extracted in the first image.

[0064] In step 200 , the first image is translated in a direction opposite to the first direction by a second distance to obtain a third image.

[0065] The second distance is also determined according to the size of the foreground area to be extracted in the first image, and the second distance is greater than the foreground area to be extracted in the first image.

[0066] In some embodiments, the first distance and the second distance are the same. In this case, the entire processing amount can be reduced on the basis of fully covering the foreground area, which helps to improve the movement efficiency of the first image.

[0067] In step 300 , threshold processing is performed on the first image and the second image to obtain a first foreground area image; and threshold processing is performed on the first image and the third image to obtain a second foreground area image.

[0068] It should be noted that the specific steps of threshold processing the first image and the second image are as follows: differentiating the first image and the second image to obtain a first differential image; and threshold segmenting the first differential image to obtain a first foreground area image.

[0069] When threshold processing is performed on the first image and the second image, after obtaining the first image and the second image, the color value of each pixel in the first image is compared with the color value of the pixel with the corresponding coordinate in the second image in order from left to right and from bottom to top, and the coordinates of all pixels with different color values are recorded. From these coordinates, the coordinates of the bottom pixel A (X A , Y A ), the coordinates of the leftmost pixel B (X B , Y B ), the coordinates of the top pixel C (X C , Y C ), the coordinate of the rightmost pixel D (X D , Y D ). According to the coordinates of the four pixels A, B, C, and D, the coordinates of pixel A' are obtained (X B , Y A ), the coordinates of pixel B′ (X B , Y C ), the coordinates of pixel C′ (X D , Y C ), the coordinates of pixel D′ (X D , Y AThe four pixels A', B', C', and D' form a rectangular difference region. Next, the image corresponding to this difference region in the second image is extracted as the first difference image. The image corresponding to this difference region in the second image refers to the image in the second image divided by the four pixels A', B', C', and D' as vertices. This operation achieves the difference between the first and second images.

[0070] Afterwards, the grayscale mean μ and grayscale threshold T of all pixels in the first differential image are calculated, and the initialization state is set: let the grayscale step size step = 1, the left grayscale boundary I = 0, and the right grayscale boundary r = T; the initialization step is executed for the first time, the grayscale segmentation value thre = l, and the area P(thre) of the region with the grayscale value being the grayscale segmentation value thre and the area P(T) of the region with the grayscale value being the grayscale threshold T in the first differential image are obtained; if P(thre) / P(T)≥β, the current thre value is the final threshold and the calculation is completed, β is an empirical parameter, generally taken as 0.9; otherwise, thre is updated, and the updated thre = thre before updating + step, and P(thre) and P(T) are continuously calculated until the judgment condition is met, and the thre value when the condition is met is determined to be the final threshold. At this time, the image corresponding to the region with grayscale values between (-255, -thre) and (thre, 255) is the first foreground area image.

[0071] The steps for threshold processing the first image and the third image are the same as above: first, the first image and the third image are differentiated to obtain a second differential image; after the second differential image is segmented by the threshold, a second foreground area image is obtained. The specific process will not be repeated here.

[0072] In step 400, a true foreground area image of the first image is acquired based on the first foreground area image and the second foreground area image.

[0073] In some embodiments, the intersection of the first foreground area image and the second foreground area image is obtained to obtain an intersection area image, which is the true foreground area image of the first image. Figure 2As shown in the figure, the first image is translated to the left by a first distance, i.e., L1 pixels, to obtain the second image. The second image is subtracted from the first image to obtain the first differential image Sublmage1. Sublmage1 is threshold-segmented to obtain the first foreground region image Region1. The first image is translated to the right by a second distance to obtain the third image. The third image is subtracted from the first image to obtain the second differential image Sublmage2. Sublmage2 is threshold-segmented to obtain the second foreground region image Region2. The intersection of Region1 and Region2 is then calculated to obtain the true foreground region image Regionlntersection of the first image, which is the true foreground region image of the first image.

[0074] Figure 3 The first foreground region image Region1 is obtained after the first image is horizontally shifted 50 pixels to the left and thresholded. Figure 4 The second foreground region image Region2 is obtained after the first image is horizontally shifted 50 pixels to the right and thresholded. The intersection region image Regionlntersection is formed by the intersection of the first foreground region image Region1 and the second foreground region image Region2, that is, the foreground extraction result is as follows: Figure 5 The true foreground image shown in . Figure 3-5 It can be seen that, for the black target shown in the figure, the foreground area image extracted after the first image is horizontally shifted by 50 pixels is clearer and more accurate.

[0075] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. In addition, Figure 1 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The order of execution of these steps or stages is not necessarily one by one, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.

[0076] Since when the first image is larger, the first distance and the second distance are larger, at this time, if Figure 6 As shown in FIG, the first foreground region image Region1 is obtained after the first image is horizontally shifted 100 pixels to the left and then subjected to threshold segmentation. Figure 7The second foreground region image Region2 is obtained after the first image is horizontally shifted 100 pixels to the right and then segmented by threshold. The intersection region image Regionlntersection formed by the intersection of the first foreground region image Region1 and the second foreground region image Region2 is empty. The foreground extraction result is as follows: Figure 8 As shown, the foreground cannot be effectively extracted. Since the boundary area of the first image will be translated outside the first image during the translation process, the first differential area image or the second differential area image obtained after the difference will exceed the range of the first image, resulting in the intersection of the first foreground area image and the second foreground area image being empty, and therefore the true foreground area image of the first image cannot be accurately obtained. In view of this, in some embodiments, combined with Figure 9-10 As shown, step 400 includes:

[0077] Step 410: Acquire an intersection area image of the first foreground area image and the second foreground area image.

[0078] Here, referring to steps 100-300, a first foreground region image Region1 and a second foreground region image Region2 are obtained, and then an intersection region image Regionlntersection is obtained by finding the intersection.

[0079] Step 420 , obtaining a first retained area image around the boundary line of the first image in the first direction when the first image is translated in the first direction, and a second retained area image around the boundary line of the first image in the second direction when the first image is translated in the second direction.

[0080] The first retained area image is an image located outside the boundary line of the first image in the first direction after the first image is translated a first distance in the first direction. The second retained area image is an image located outside the boundary line of the first image in the second direction after the first image is translated a first distance in the second direction. The first image can be rectangular, circular, or other shapes. The first and second retained area images can also be any shape that can include the area between the first image and the second or third image.

[0081] In some embodiments, if the first image is a rectangle, and the first retained area image and the second retained area image are both rectangles, and the first direction is a horizontal translation to the left or right, then the widths of the first retained area image and the second retained area image are both the first distance, and the heights are the same as the heights of the first image, that is, the first retained area image and the second retained area image are equivalent to rectangular images with a width of the first distance L1 and a height the same as the height of the first image generated by the two side boundaries in the horizontal direction of the first image.

[0082] Step 430: Obtain the intersection of the first reserved area image and the first foreground area image, which is the first compensation area image; obtain the intersection of the second reserved area image and the second foreground area image, which is the second compensation area image.

[0083] The first reserved area image is intersected with the first foreground area image Region1, and the second reserved area image is intersected with the second foreground area image Region2 to obtain compensation parts, namely the first compensation area image Regionlntersection1 and the second compensation area image Regionlntersection2.

[0084] Step 440 : Acquire a union of the intersection area image, the first compensation area image, and the second compensation area image, wherein the union is a true foreground area image of the first image.

[0085] It can be understood that the first compensation region image RegionIntersection1 and the second compensation region image RegionIntersection2 are finally combined with the intersection region image RegionIntersection to obtain the true foreground region image RegionUnion of the first image. The processing result is as follows: Figure 11 At this time, since the situation where the intersection is empty is avoided, it is helpful to accurately obtain the foreground area of the first image. It should be noted that the process of obtaining the union and intersection in the above process can be performed by the halcon program.

[0086] In addition, it should be noted that the process of moving the image up and down is the same as the above process and will not be repeated here.

[0087] In some embodiments, the first image may be moved both vertically and horizontally to generate a second image, a third image, a fourth image, and a fifth image. The subsequent processing of the fourth image and the fifth image is the same as the above process.

[0088] In the above-mentioned image foreground extraction method, by obtaining the first compensation area image and the second compensation area image, the image boundary is compensated, which can effectively reduce the possibility of not being able to accurately extract the foreground area image due to the first image exceeding the boundary during translation.

[0089] In some embodiments, the second aspect, such as Figure 12 As shown, an image foreground extraction system is provided, which specifically includes:

[0090] A first translation module, configured to translate the first image in a first direction by a first distance to obtain a second image;

[0091] a second translation module, configured to translate the first image by a second distance in a direction opposite to the first direction to obtain a third image;

[0092] a foreground area acquisition module, configured to perform threshold processing on the first image and the second image to acquire a first foreground area image; and perform threshold processing on the first image and the third image to acquire a second foreground area image;

[0093] The real foreground area acquisition module is used to acquire the real foreground area image of the first image based on the first foreground area image and the second foreground area image.

[0094] In some embodiments, the first distance and the second distance are both determined according to the size of the foreground area to be extracted in the first image, and the first distance and the second distance are both larger than the foreground area to be extracted in the first image.

[0095] In some embodiments, the first distance and the second distance are the same.

[0096] In some embodiments, the first direction is vertically upward, vertically downward, horizontally leftward, or horizontally rightward.

[0097] In some embodiments, the real foreground area acquisition module is used to acquire an intersection area image of the first foreground area image and the second foreground area image, where the intersection area image is the real foreground area image of the first image.

[0098] In some embodiments, as Figure 13 As shown, the image foreground extraction system further includes a regional image compensation module. In the step of obtaining a true foreground area image of the first image based on the first foreground area image and the second foreground area image, the regional image compensation module is used to obtain a first retained area image of the periphery of the boundary line of the first image in the first direction when the first image is translated in the first direction, and a second retained area image of the periphery of the boundary line of the first image in the second direction when the first image is translated in the second direction;

[0099] It is also used to obtain the intersection of the first reserved area image and the first foreground area image, the intersection of the first reserved area image and the first foreground area image being the first compensation area image; obtain the intersection of the second reserved area image and the second foreground area image, the intersection of the second reserved area image and the second foreground area image being the second compensation area image;

[0100] At this time, the real foreground area acquisition module is used to obtain the intersection area image of the first foreground area image and the second foreground area image; it is also used to obtain the union of the intersection area image, the first compensation area image and the second compensation area image, and the union is the real foreground area image of the first image.

[0101] In some embodiments, if the first image is a rectangle and the first direction is a horizontal translation to the left or right, the width of the first reserved area image and the second reserved area image are both the first distance, and the height is the same as the height of the first image.

[0102] In some embodiments, in the step of performing threshold processing on the first image and the second image, the foreground area acquisition module is configured to:

[0103] subtracting the first image from the second image to obtain a first differential image;

[0104] After the first difference image is segmented by threshold value, a first foreground area image is obtained.

[0105] The specific definition of the image foreground extraction system can be found in the definition of the image foreground extraction method above and will not be repeated here. Each module in the above-mentioned image foreground extraction system can be implemented in whole or in part through software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in the form of software in a memory in the computer device so that the processor can call and execute the corresponding operations of each of the above modules.

[0106] In some embodiments, a third aspect provides an image foreground extraction device, which can be a server or a terminal. Its internal structure can be as follows: Figure 14 As shown, the system specifically includes a processor, a memory, a communication interface, and a communication bus. The processor, the memory, and the communication interface communicate with each other via the communication bus. The memory is used to store at least one executable instruction, which enables the processor to perform the operations of the image foreground extraction method described in the first aspect.

[0107] Those skilled in the art will understand that Figure 14 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the image foreground extraction device to which the solution of the present application is applied. The specific image foreground extraction device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0108] A fourth aspect of the embodiments of the present application provides a computer-readable storage medium, wherein the storage medium stores at least one executable instruction. When the executable instruction is executed on an image foreground extraction device, the image foreground extraction device performs the following operations of the image foreground extraction method:

[0109] translating the first image in a first direction by a first distance to obtain a second image;

[0110] translating the first image by a second distance in a direction opposite to the first direction to obtain a third image;

[0111] Performing threshold processing on the first image and the second image to obtain a first foreground area image; performing threshold processing on the first image and the third image to obtain a second foreground area image;

[0112] Based on the first foreground area image and the second foreground area image, a true foreground area image of the first image is acquired.

[0113] In some embodiments, the first distance and the second distance are both determined according to the size of the foreground area to be extracted in the first image, and the first distance and the second distance are both larger than the foreground area to be extracted in the first image.

[0114] In some embodiments, the first distance and the second distance are the same.

[0115] In some embodiments, the first direction is vertically upward, vertically downward, horizontally leftward, or horizontally rightward.

[0116] In some embodiments, the step of acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image further includes:

[0117] An intersection area image of the first foreground area image and the second foreground area image is obtained, where the intersection area image is the true foreground area image of the first image.

[0118] In some embodiments, the step of acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image further includes:

[0119] Acquire an intersection area image of the first foreground area image and the second foreground area image;

[0120] Acquire a first retained area image of a periphery of a boundary line of the first image in a first direction when the first image is translated in a first direction, and a second retained area image of a periphery of a boundary line of the first image in a second direction when the first image is translated in a second direction;

[0121] Obtaining the intersection of the first reserved area image and the first foreground area image, the intersection of the first reserved area image and the first foreground area image being the first compensation area image; obtaining the intersection of the second reserved area image and the second foreground area image, the intersection of the second reserved area image and the second foreground area image being the second compensation area image;

[0122] A union of the intersection area image, the first compensation area image, and the second compensation area image is obtained, where the union is a true foreground area image of the first image.

[0123] In some embodiments, if the first image is a rectangle and the first direction is a horizontal translation to the left or right, the width of the first reserved area image and the second reserved area image are both the first distance, and the height is the same as the height of the first image.

[0124] In some embodiments, the step of performing threshold processing on the first image and the second image to obtain the first foreground area image further includes:

[0125] subtracting the first image from the second image to obtain a first differential image;

[0126] After the first difference image is segmented by threshold value, a first foreground area image is obtained.

[0127] The specific limitations of the image foreground extraction system can be found in the above limitations of the image foreground extraction method, which will not be repeated here.

[0128] The beneficial effect of the embodiments of this part is that after translating the image in a first direction by a first distance and in a direction opposite to the first direction by a second distance, the second image and the third image obtained respectively are threshold-processed together with the first image, and based on the first foreground area image and the second foreground area image, the true foreground area image of the first image is obtained. In this process, the area range of the first image subjected to threshold processing can be expanded, which helps to accurately determine the foreground of the image, thereby effectively improving the accuracy of foreground extraction in the image.

[0129] Further setting the first direction to be a vertical direction or a horizontal direction helps to accurately move the first image; further setting the first distance and the second distance to be the same distance helps to include the foreground area and facilitates the calculation process.

[0130] Further, by obtaining the first compensation area image and the second compensation area image, and by obtaining the union of the intersection area image, the first compensation area image and the second compensation area image, the true foreground area image of the first image is determined, which helps to reduce the situation where the intersection is empty, and thus can accurately extract the foreground area image in the first image.

[0131] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0132] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0133] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.

Claims

1. A method for extracting foreground from an image, characterized in that: include: translating the first image in a first direction by a first distance to obtain a second image; translating the first image in a second direction by a second distance to obtain a third image; The second direction is a direction opposite to the first direction; performing threshold processing on the first image and the second image to obtain a first foreground area image; performing threshold processing on the first image and the third image to obtain a second foreground area image; acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image; In the step of acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image, the method further includes: Acquire an intersection area image of the first foreground area image and the second foreground area image; acquiring a first retained area image of a periphery of a boundary line of the first image in the first direction when the first image is translated in the first direction, and a second retained area image of a periphery of a boundary line of the first image in the second direction when the first image is translated in the second direction; Obtaining an intersection of the first reserved area image and the first foreground area image, where the intersection of the first reserved area image and the first foreground area image is a first compensation area image; obtaining an intersection of the second reserved area image and the second foreground area image, where the intersection of the second reserved area image and the second foreground area image is a second compensation area image; A union of the intersection area image, the first compensation area image, and the second compensation area image is obtained, where the union is a true foreground area image of the first image.

2. The image foreground extraction method according to claim 1, wherein: The first distance and the second distance are both determined according to the size of the foreground area to be extracted in the first image, and the first distance and the second distance are both larger than the foreground area to be extracted in the first image.

3. The image foreground extraction method according to claim 2, wherein: The first distance and the second distance are the same.

4. The image foreground extraction method according to any one of claims 1 to 3, characterized in that: In the step of acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image, the method further includes: An intersection area image of the first foreground area image and the second foreground area image is acquired, where the intersection area image is a true foreground area image of the first image.

5. The image foreground extraction method according to claim 1, wherein: If the first image is a rectangle and the first direction is a horizontal translation to the left or right, the widths of the first reserved area image and the second reserved area image are both the first distance, and the heights are the same as the height of the first image.

6. The image foreground extraction method according to claim 1, wherein: In the step of performing threshold processing on the first image and the second image, further comprising: subtracting the first image from the second image to obtain a first differential image; After the first difference image is segmented by a threshold value, the first foreground area image is obtained.

7. An image foreground extraction system, the system being applicable to the method according to any one of claims 1 to 6, characterized in that: include: A first translation module, configured to translate the first image in a first direction by a first distance to obtain a second image; A second translation module, configured to translate the first image in a second direction by a second distance to obtain a third image; The second direction is the opposite direction of the first direction; a foreground area acquisition module, configured to perform threshold processing on the first image and the second image to acquire a first foreground area image; performing threshold processing on the first image and the third image to obtain a second foreground area image; The real foreground area acquisition module is used to acquire the real foreground area image of the first image based on the first foreground area image and the second foreground area image.

8. The image foreground extraction system according to claim 7, wherein: In the step of acquiring a true foreground area image of the first image based on the first foreground area image and the second foreground area image, the true foreground area acquisition module is further configured to: An intersection area image of the first foreground area image and the second foreground area image is acquired, where the intersection area image is a true foreground area image of the first image.

9. The image foreground extraction system according to claim 7, wherein: The invention also includes a regional image compensation module, which is used to: acquiring a first retained area image of a periphery of a boundary line of the first image in the first direction when the first image is translated in the first direction, and a second retained area image of a periphery of a boundary line of the first image in the second direction when the first image is translated in the second direction; further configured to obtain an intersection of the first reserved area image and the first foreground area image, the intersection of the first reserved area image and the first foreground area image being a first compensation area image; Acquire an intersection of the second reserved area image and the second foreground area image, where the intersection of the second reserved area image and the second foreground area image is a second compensation area image; At this time, the real foreground area acquisition module is further used to: Acquire an intersection area image of the first foreground area image and the second foreground area image; A union of the intersection area image, the first compensation area image, and the second compensation area image is obtained, where the union is a true foreground area image of the first image.

Citation Information

Patent Citations

  • Image processing method and device for detecting foreground target

    CN104282013A

  • Image segmentation and defogging method and terminal

    CN106683100A