A background filling method, device and equipment
By dividing the foreground boundary region into multiple partitions and obtaining the grayscale value with the highest proportion in each partition, and filling it into the corresponding sub-region, the edge interference problem when constructing near the background region boundary by mean filtering is solved, achieving a more efficient and smoother background filling effect.
Patent Information
- Application Number
- CN202211459691.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-21
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2042-11-21
AI Technical Summary
When using mean filtering to construct the boundary near the background region, there is an edge interference problem, which leads to edge interference in the subsequent acquisition of brightness defects.
The foreground boundary region is divided into multiple partitions. The gray value with the highest proportion in each partition is obtained and filled into the corresponding sub-region, thereby reducing the probability of subsequent gray values interfering with the edge of the image filling.
It reduces the grayscale difference between the background and foreground regions, improves the efficiency and smoothness of image filling, and reduces the probability of edge interference.
Smart Images

Figure CN115861482B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to a background filling method, device and equipment. BACKGROUND
[0002] With the continuous development of artificial intelligence technology and the gradual maturity of computer vision technology, in the process of processing the photographed image, the identification and processing of the miscellaneous points in the image are involved. Since the image processing technology is applied in the fields of face recognition, disease diagnosis, artificial intelligence, intelligent manufacturing, and computer vision, etc., specifically applied to an industrial camera, a camera, a scanner and the like, a large two-dimensional array is obtained through shooting. The image processing of the photographed image is usually a technology of using a computer to analyze the image to achieve the required result. In the process of image processing, a dynamic threshold segmentation method is used to extract the defect area with different gray scales in the image, and the dynamic threshold segmentation method includes three parts of background construction, image difference and binarization. There are various ways of background construction, among which mean filtering is widely used.
[0003] In some processes of using mean filtering for background construction, when mean filtering is performed on the boundary close to the background area in the image foreground, the average value of the pixels in the window is first obtained, and the obtained average value of the pixels is set as the pixel value of the anchor point, so as to obtain and output the background area to be constructed.
[0004] When mean filtering is performed on the boundary close to the background area, the result gray value is greatly different from the original boundary gray value due to the interference of the background area gray, so a high-contrast area is generated, which causes edge interference when the brightness defect is obtained subsequently. SUMMARY
[0005] In order to solve the problem of edge interference in constructing the boundary close to the background area using mean filtering, the present application provides a background filling method, device and equipment.
[0006] Embodiments of the present application are implemented as follows:
[0007] A first aspect of an embodiment of the present application provides a background filling method, which comprises:
[0008] obtaining a foreground area and a background area of a received image, and obtaining a foreground boundary area corresponding to the foreground area;
[0009] dividing the foreground boundary area into a plurality of partitions;
[0010] obtaining a total gray scale of each partition and a gray scale value in each partition, obtaining a proportion of the gray scale value in the total gray scale in each partition, and determining a gray scale value with the highest proportion in each partition.
[0011] obtaining a background region to be filled of the image, and dividing the background region to be filled into sub-regions corresponding to the partitions, filling the highest proportion gray value determined in each partition into the corresponding sub-region, and the region composed of the plurality of sub-regions after filling is the filled background region.
[0012] In some embodiments, in the step of obtaining the foreground boundary region corresponding to the foreground region, the method comprises:
[0013] analyzing the foreground region of the image to obtain the foreground region boundary of the image;
[0014] translating the foreground region boundary of the image inward by a first distance;
[0015] subtracting the foreground region boundary of the image after translation by the first distance from the original foreground boundary of the image to obtain a first region with a width of the first distance;
[0016] outputting the first region as the foreground boundary region.
[0017] In some embodiments, in the step of dividing the foreground boundary region into a plurality of partitions, the method comprises:
[0018] obtaining position information and boundary positions of the foreground boundary region;
[0019] translating any two oppositely arranged boundaries of the foreground boundary region inward by a second distance;
[0020] subtracting the boundaries after translation by the second distance from the foreground boundary region to form a plurality of partitions.
[0021] In some embodiments, in the step of obtaining the total gray level of each partition and the gray value in each partition, and obtaining the proportion of the gray value in each partition to the total gray level, the method is implemented as:
[0022] obtaining gray distribution data in each partition, the gray distribution data being the number of pixels contained by each gray value;
[0023] dividing the gray distribution data in each partition by the total number of pixels in the corresponding partition to obtain normalized gray distribution data;
[0024] storing the normalized gray distribution data into an array corresponding to each partition, and obtaining and outputting the highest proportion gray value in the array corresponding to each partition.
[0025] In some embodiments, in the step of obtaining the background region to be filled of the image, the method comprises:
[0026] based on the image foreground region, a second region is obtained by extending the boundary of the image foreground region outward by a third distance;
[0027] a third region is obtained by subtracting the second region from the image foreground region;
[0028] the third region is output as a background region to be filled.
[0029] A second aspect of the embodiments of the present application provides a background filling device, which comprises:
[0030] a foreground boundary acquisition unit, configured to acquire a foreground region and a background region of a received image, and acquire a foreground boundary region corresponding to the foreground region;
[0031] a partition acquisition unit, configured to divide the foreground boundary region into a plurality of partitions;
[0032] a gray value acquisition unit, configured to acquire a total gray level of each of the partitions and a gray value in each of the partitions, acquire a proportion of the gray value in the total gray level in each of the partitions, and determine a gray value with the highest proportion in each of the partitions;
[0033] a background processing unit, configured to acquire a background region to be filled of an image, divide the background region to be filled into sub-regions corresponding to the partitions, fill the gray value with the highest proportion determined in each of the partitions into a corresponding sub-region, and combine the sub-regions after filling to obtain a background region after filling.
[0034] In some embodiments, the partition acquisition unit is configured to implement the following method:
[0035] acquire position information and boundary positions of the foreground boundary region;
[0036] inwardly shift any two oppositely arranged boundaries of the foreground boundary region by a second distance;
[0037] form a plurality of partitions by subtracting the boundaries after shifting by the second distance from the foreground boundary region.
[0038] In some embodiments, the gray value acquisition unit is configured to implement the following method:
[0039] acquire gray distribution data in each of the partitions, the gray distribution data being a number of pixels included by each gray value;
[0040] divide the gray distribution data in each of the partitions by a total number of pixels in the corresponding partition to obtain normalized gray distribution data;
[0041] store the normalized gray distribution data into an array corresponding to each of the partitions, acquire and output a gray value with the highest proportion in the array corresponding to each of the partitions.
[0042] In some embodiments, the background processing unit, in the step of obtaining the background region to be filled of the image, implements the following method:
[0043] Based on the foreground region of the image, the boundary of the foreground region of the image is extended outward by a third distance to obtain a second region;
[0044] The second region is subtracted from the foreground region of the image to obtain a third region;
[0045] The third region is output as the background region to be filled.
[0046] A third aspect of an embodiment of the present application provides a background filling device, comprising: at least one processor; and a memory in communication connection with the at least one processor; wherein the memory stores instructions executable by the one processor, and the instructions are executed by the at least one processor to cause the at least one processor to execute the background filling method described in the technical solutions.
[0047] The present application has the beneficial effects of dividing the foreground boundary region into multiple partitions, obtaining the highest-occupancy gray value in each partition, and then filling the background region to be filled with the highest-occupancy gray value, thereby reducing the probability of edge interference of the subsequent filled gray value on the image filling edge; at the same time, the highest-occupancy gray value in the foreground boundary region is filled in the background region to be filled, thereby obtaining a relatively smooth gray transition region, which can achieve the purpose of reducing the gray difference between the obtained background region and the foreground region boundary; further, by partitioning the foreground boundary region, the time required to obtain the gray value in each partition is reduced, thereby improving the efficiency of obtaining the background region to be filled. BRIEF DESCRIPTION OF DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed in the embodiments or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description are some embodiments of the present application, and those skilled in the art can also obtain other drawings according to these drawings without creative labor.
[0049] Figure 1 A schematic diagram for showing the position relationship between the foreground region and the background region of the image to be processed of the background filling method of an embodiment of the present application;
[0050] Figure 2 A flowchart of the background filling method of an embodiment of the present application;
[0051] Figure 3A schematic diagram of a background filling method according to an embodiment of the present application;
[0052] Figure 4 A schematic diagram of a background filling method according to another embodiment of the present application for showing a process of acquiring a foreground boundary region;
[0053] Figure 5 A schematic diagram of a background filling method according to another embodiment of the present application for showing a process of acquiring a partition and a gray value contained in each partition;
[0054] Figure 6 A schematic diagram of a background filling method according to another embodiment of the present application for showing a process of dividing the foreground boundary region into a plurality of partitions;
[0055] Figure 7 A schematic diagram of a background filling method according to another embodiment of the present application for showing a process of acquiring a gray value contained in each partition;
[0056] Figure 8 A schematic diagram of a background filling method according to another embodiment of the present application for showing a process of acquiring a background region to be filled;
[0057] Figure 9 A schematic diagram of a background filling device according to an embodiment of the present application.
[0058] Legend: 910, foreground boundary acquiring unit; 920, partition acquiring unit; 930, gray value acquiring unit; 940, background processing unit. DETAILED DESCRIPTION
[0059] In order to make the purpose, implementation and advantages of the present application more clear, the following will combine the drawings in the exemplary embodiments of the present application to clearly and completely describe the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only a part of the embodiments of the present application, but not all the embodiments of the present application.
[0060] It should be noted that the brief description of the terms in the present application is only for the convenience of understanding the following described embodiments, and is not intended to limit the embodiments of the present application. Unless otherwise specified, these terms should be understood according to their ordinary and general meanings.
[0061] The terms "first", "second", "third" and the like in the specification and claims of the present application and the above drawings are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit the specific order or sequence, unless otherwise noted. It should be understood that the terms used in this way can be interchanged under appropriate circumstances.
[0062] The terms "comprises", "comprising", "includes", "including", "has", "having" and their conjugates mean, when used to describe a product or a process, that the product or process includes but is not limited to those explicitly stated.
[0063] As shown in Figure 1 , Figure 2 and Figure 3 . Figure 1 A schematic diagram for showing the positional relationship between the foreground region and the background region of an image to be processed of a background filling method according to an embodiment of the present application; Figure 2 A flowchart of a background filling method according to an embodiment of the present application; Figure 3 A schematic diagram of a background filling method according to an embodiment of the present application.
[0064] In some embodiments, the background filling method provided by the present application specifically comprises the following steps:
[0065] The foreground region and the background region of the received image are obtained, and the foreground boundary region corresponding to the foreground region is obtained; wherein the image is obtained by using a line-scan camera, the field of view of the camera contains the foreground region and the background region of the image, the black frame is the boundary of the image, the gray frame is the foreground region, the region outside the gray frame is the background region, and the gray frame represents the boundary of the foreground region;
[0066] The foreground boundary region is divided into multiple partitions;
[0067] The total gray level of each partition and the gray value in each partition are obtained, and the proportion of each gray value in the total gray level of the partition is obtained, to determine the gray value with the highest proportion in each partition;
[0068] The background region to be filled of the image is obtained, and the background region to be filled is divided into sub-regions corresponding to the multiple partitions, and the gray value with the highest proportion determined in each partition is filled into the corresponding sub-region; the multiple sub-regions after filling are spliced to form the filled background region.
[0069] By dividing the foreground boundary region into multiple partitions and obtaining the gray value with the highest proportion in each partition, and then filling the background region to be filled with the gray value with the highest proportion, the probability of edge interference of the image filling caused by the subsequent filled gray value is reduced; at the same time, by filling the background region to be filled with the gray value with the highest proportion in the foreground boundary region, a relatively smooth gray transition region is obtained, which can reduce the gray difference between the obtained background region and the foreground region. Further, by partitioning the foreground boundary region, the time required to obtain the gray value in each partition is reduced, thereby improving the efficiency of obtaining the background region to be filled.
[0070] As shown in Figure 4 . Figure 4 The flowchart for showing the acquisition of the foreground boundary region of the background filling method of another embodiment of the present application.
[0071] In some embodiments, in the step of acquiring the foreground boundary region corresponding to the foreground region, the foreground boundary region acquisition method is specifically implemented as:
[0072] Parsing the foreground region of the image to obtain the foreground boundary of the image;
[0073] Translate the foreground boundary of the image inward by a first distance, the length of the first distance being implemented as 5 pixels, and the difference between the first distance and the original foreground boundary of the image produces a first region;
[0074] Output the obtained foreground boundary region with a width of the first distance.
[0075] By acquiring the foreground boundary region with a first distance, the efficiency of obtaining each gray value in the foreground boundary region is improved, and by filling the gray value with the highest occupancy rate in the acquired foreground boundary region to the background region to be filled, the probability of edge interference between the obtained background and the foreground region boundary is reduced, and the convenience of smooth transition between the obtained background region and the foreground region boundary is improved.
[0076] As shown in Figure 5 and Figure 6 . Figure 5 The schematic diagram for showing the acquisition of the partition and the gray value contained in each partition of the background filling method of another embodiment of the present application; Figure 6 The schematic diagram for showing the division of the foreground boundary region into multiple partitions of the background filling method of another embodiment of the present application.
[0077] In some embodiments, in the step of dividing the foreground boundary region into multiple partitions, the background filling method provided by the present application is specifically implemented as:
[0078] Acquire the position information and boundary position of the foreground boundary region;
[0079] Translate the two oppositely arranged boundaries of the foreground boundary region inward by a second distance;
[0080] The multiple partitions are formed by the difference between the second distance boundaries after translation and the foreground boundary region.
[0081] Specifically expressed as the following method:
[0082] Acquire the position information of the entire foreground boundary region, and simultaneously acquire the position information of the boundary of the foreground boundary region according to the position information of the foreground boundary region;
[0083] The upper and lower boundaries are each moved inward by a second distance, which is implemented as 50 pixels, to divide the entire foreground boundary region into four sub-regions of upper boundary, lower boundary, left boundary, and right boundary.
[0084] By dividing the foreground boundary region into multiple sub-regions using the moving boundary method, on the one hand, the time required for analyzing the gray values in each sub-region can be reduced, and the overall image background filling efficiency can be improved. On the other hand, the gray values included in the foreground boundary region can be conveniently counted, so that the gray values that match the foreground boundary region can be formed, thereby facilitating the acquisition of a region that smoothly transitions with the foreground boundary region, reducing the probability of high contrast between the gray values obtained by subsequent filling and the original boundary gray values, and thereby reducing the problem of edge interference in the image obtained near the background boundary region.
[0085] As shown in FIG. 4. Figure 7 As shown in FIG. 4. Figure 7 FIG. 4 is a schematic diagram of a background filling method according to another embodiment of the present application for displaying the gray values included in each sub-region.
[0086] In some embodiments, in the step of obtaining the total gray level of each sub-region and the gray values in each sub-region, and obtaining the proportion of the gray values in each sub-region to the total gray level, the background filling method provided by the present application comprises:
[0087] obtaining the gray distribution data in each sub-region, wherein the gray distribution data is the number of pixels included in each gray value;
[0088] dividing the gray distribution data in each sub-region by the total number of pixels in the corresponding sub-region to obtain normalized gray distribution data;
[0089] storing the normalized gray distribution data into an array corresponding to each sub-region, and obtaining and outputting the gray value with the highest proportion in the array corresponding to each sub-region.
[0090] By acquiring the gray scale distribution data in each partition, the number of pixels contained by each gray scale value in each partition is determined, thereby improving the efficiency of screening the gray scale value with the highest number of pixels in each partition. The purpose of filling the screened gray scale value with the highest number of pixels into the background region to be filled is further achieved, the area with high contrast between the obtained background image and the foreground boundary region is reduced, and the problem of subsequent existence of brightness defects leading to edge interference between the background image and the foreground image is reduced. Further, by dividing the gray scale value in each partition by the number of pixels contained in each partition, normalized gray scale distribution data is obtained. The normalized gray scale distribution data can improve the efficiency of screening the gray scale value with the highest proportion in each partition. In order to facilitate the efficiency of filling the screened gray scale value with the highest proportion in each partition into the sub-region corresponding to each partition.
[0091] As shown in Figure 8 . Figure 8 The schematic diagram for showing the acquisition of the background region to be filled is a background filling method of another embodiment of the present application.
[0092] In some embodiments, in the step of acquiring the background region to be filled of the image, the background filling method provided by the present application comprises:
[0093] Based on the foreground region of the image, the boundary of the foreground region of the image is expanded outward by a third distance to obtain a second region;
[0094] The obtained second region is subtracted from the original foreground region of the image to obtain a third region, wherein the third region is the region between the boundary of the original foreground region of the image and the boundary of the foreground region after the third distance is expanded;
[0095] The third region is output as the background region to be filled.
[0096] The minimum size of the third distance is set to half of the size of the filter kernel.
[0097] By setting the minimum width size of the background region to be filled to half of the size of the filter kernel in the process of acquiring the background region to be filled, the edge interference caused by the filter kernel in the dynamic threshold segmentation method is conveniently removed, and the purpose of obtaining a background image with less edge interference is achieved.
[0098] In some embodiments, the method for segmenting the background region to be filled is:
[0099] The position information of the background region to be filled and the boundary of the background region to be filled are acquired.
[0100] translating the two oppositely arranged boundaries of the to-be-filled background region inward by a fourth distance, wherein the fourth distance has a size that is a sum of the size of the third distance and the size of the first distance;
[0101] The boundaries of the to-be-filled background region after being translated by the fourth distance divide the to-be-filled background region into four sub-regions, i.e., an upper sub-region, a lower sub-region, a left sub-region, and a right sub-region, wherein the positions of the sub-regions are the same as the positions of the partitions.
[0102] By dividing the to-be-filled region into four sub-regions and the positions of the sub-regions being the same as the positions of the partitions, and then filling the highest-occupancy gray value obtained in each partition into the corresponding sub-region, the probability of obtaining a region with a high contrast between the background region and the foreground boundary region is reduced, and the purpose of reducing the gray difference between the obtained background region and the foreground region boundary is achieved.
[0103] As shown in FIG. 1. Figure 9 FIG. 1 is a structural schematic diagram of a background filling device according to an embodiment of the present application. Figure 9 FIG. 1 is a structural schematic diagram of a background filling device according to an embodiment of the present application.
[0104] In some embodiments, based on the background filling method disclosed in the above technical solution, the present application further provides a background filling device, which comprises:
[0105] A foreground boundary acquisition unit 910 is configured to acquire a foreground region and a background region of a received image, and acquire a foreground boundary region corresponding to the foreground region; wherein the image is acquired by a line-scan camera and transmitted to the foreground boundary acquisition unit 910, and the field of view of the camera contains the foreground region and the background region of the image.
[0106] A partition acquisition unit 920 is configured to divide the foreground boundary region into a plurality of partitions.
[0107] A gray value acquisition unit 930 is configured to acquire a total gray level of each partition and a gray value in each partition, acquire a proportion of each gray value in the total gray level of the partition, and determine a highest-occupancy gray value in each partition.
[0108] A background processing unit 940 is configured to acquire a to-be-filled background region of the image, divide the to-be-filled background region into sub-regions corresponding to the plurality of partitions, fill the highest-occupancy gray value determined in each partition into the corresponding sub-region, and combine the plurality of sub-regions after filling to obtain a filled background region.
[0109] By using the partition acquisition unit 920 to divide the foreground boundary region into multiple partitions, and by using the gray value acquisition unit 930 to obtain the highest proportion gray value in each partition, and then using the background processing unit 940 to fill the to-be-filled background region with the highest proportion gray value, thereby reducing the probability of edge interference of the subsequently filled gray value on the image filling edge; at the same time, the background processing unit 940 fills the to-be-filled background region with the highest proportion gray value in the foreground boundary region, thereby obtaining a relatively smooth gray transition region, which can achieve the purpose of reducing the gray difference between the obtained background region and the foreground region boundary; further, the partition acquisition unit 920 partitions the foreground boundary region, thereby reducing the time required to obtain the gray value in each partition, and further improving the efficiency of obtaining and outputting the to-be-filled background region filled with the corresponding gray value.
[0110] In some embodiments, the partition acquisition unit 920 is used to implement the following method:
[0111] Obtain the position information and boundary position of the foreground boundary region;
[0112] Translate the second distance inwardly to any two oppositely arranged boundaries of the foreground boundary region;
[0113] The boundaries translated by the second distance are subtracted from the foreground boundary region to form multiple partitions.
[0114] Specifically, the following method is implemented:
[0115] Obtain the position information of the entire foreground boundary region, and obtain the position information of the boundary of the foreground boundary region according to the position information of the foreground boundary region;
[0116] Move the upper and lower boundaries inwardly by a second distance, and the second distance is implemented as 50 pixels, and the entire foreground boundary region is divided into four partitions of upper boundary, lower boundary, left boundary, and right boundary.
[0117] By using the partition acquisition unit 920 to divide the foreground boundary region into multiple partitions using the moving boundary method, on the one hand, the time required to analyze the gray value in each partition can be reduced, and the purpose of improving the overall image background filling efficiency can be achieved; on the other hand, it is also convenient to count the gray values included in the foreground boundary region, so as to form a gray value matched with the foreground boundary region, thereby facilitating the acquisition of a region smoothly transitioning with the foreground boundary region, reducing the probability of high contrast between the subsequently filled gray value and the original boundary gray value, thereby achieving the purpose of reducing the edge interference problem of the image obtained near the background boundary region.
[0118] In some embodiments, in order to obtain the gray value with the highest proportion in each partition, the gray value obtaining unit 930 is configured to implement the following method:
[0119] obtain the gray distribution data in each partition, wherein the gray distribution data is the number of pixels contained by each gray value;
[0120] divide the gray distribution data in each partition by the total number of pixels in the corresponding partition to obtain normalized gray distribution data;
[0121] store the normalized gray distribution data in an array corresponding to each partition, and obtain and output the gray value with the highest proportion in the array corresponding to each partition.
[0122] The gray value obtaining unit 930 obtains the gray distribution data in each partition, thereby determining the number of pixels contained by each gray value in each partition, thereby improving the efficiency of screening the gray value with the highest number of pixels in each partition, and further achieving the purpose of filling the screened gray value with the highest number of pixels into the background region to be filled, reducing the high-contrast region between the obtained background image and the foreground boundary region, and achieving the purpose of reducing the problem of edge interference between the background image and the foreground image caused by subsequent brightness defects; further, by dividing the gray value in each partition by the number of pixels contained in each partition, the normalized gray distribution data is obtained; the normalized gray distribution data can improve the efficiency of screening the gray value with the highest proportion in each partition; so as to facilitate the efficiency of filling the screened gray value with the highest proportion in each partition into the sub-region corresponding to each partition.
[0123] In some embodiments, the background processing unit 940 provided in the present application implements the following method in the step of obtaining the background region to be filled:
[0124] based on the image foreground region, expand the boundary of the foreground region of the image outward by a third distance to obtain a second region;
[0125] obtain a third region by subtracting the obtained second region from the original foreground region of the image, wherein the third region is the region between the boundary of the original foreground region of the image and the boundary of the foreground region after expanding by the third distance;
[0126] output the third region as the background region to be filled.
[0127] wherein the minimum size of the third distance is set to half of the size of the filter kernel.
[0128] By setting the minimum width size of the to-be-filled background region as half of the filter kernel size in the process of acquiring the to-be-filled background region, edge interference caused by the filter kernel in the dynamic threshold segmentation method is facilitated to be removed, and the purpose of obtaining a background image with less edge interference is achieved.
[0129] In some embodiments, based on the background filling method disclosed in the above technical solution, the background filling device provided in the present application comprises: at least one processor; and a memory in communication connection with the at least one processor; wherein the memory stores instructions executable by the one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the background filling method described in the above technical solution.
[0130] The beneficial effects of the embodiments of the present part are that, by dividing the foreground boundary region into multiple partitions and obtaining the highest-occupancy gray value in each partition, the to-be-filled background region is then filled with the highest-occupancy gray value, thereby reducing the probability of edge interference of the subsequent filled gray value on the image filling edge; at the same time, by filling the to-be-filled background region with the highest-occupancy gray value in the foreground boundary region, a relatively smooth gray transition region is obtained, thereby achieving the purpose of reducing the gray difference between the obtained background region and the foreground region boundary; further, by partitioning the foreground boundary region, the time required for obtaining the gray value in each partition is reduced, thereby improving the efficiency of obtaining the to-be-filled background region.
[0131] The above description has been made in conjunction with specific embodiments for the convenience of explanation. However, the above description in some embodiments is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed. Various modifications and variations can be derived according to the above teachings. The selection and description of the above embodiments are to better explain the principles and practical applications, so that those skilled in the art can better use the embodiments and various different modified embodiments suitable for specific use considerations.
Claims
1. A background filling method, characterized in that, The method includes: Obtain the foreground region and background region of the received image, and obtain the foreground boundary region corresponding to the foreground region; The foreground boundary region is divided into multiple partitions; Obtain the total gray level and gray value in each partition, and obtain the proportion of each gray value in each partition to the total gray level of the partition, and determine the gray value with the highest proportion in each partition; Obtain the background region to be filled in the image, and divide the background region to be filled into sub-regions corresponding to the partitions. Fill the corresponding sub-region with the gray value with the highest proportion obtained in each partition. The area formed by combining the multiple sub-regions after filling is the filled background region. In the step of obtaining the foreground boundary region corresponding to the foreground region, the method includes: Analyze the foreground region of the image to obtain the boundary of the foreground region; Shift the boundary of the foreground region of the image inward by a first distance; The foreground region boundary of the image after translation by a first distance is subtracted from the original foreground boundary of the image to obtain a first region with a width of the first distance; Output the first region as the foreground boundary region; In the step of dividing the foreground boundary region into multiple partitions, the method includes: Obtain the location information and boundary position of the foreground boundary region; Shift any two oppositely set boundaries of the foreground boundary region inward by a second distance; After translation, the difference between the boundary of the second distance and the foreground boundary region forms multiple partitions; In the step of obtaining the background region to be filled in the image, the method includes: Based on the foreground region of the image, the boundary of the foreground region of the image is extended outward by a third distance to obtain a second region; The third region is obtained by subtracting the second region from the foreground region of the image; Output the third region as the background region to be filled.
2. The background filling method as described in claim 1, characterized in that, In the steps of obtaining the total grayscale level and grayscale value in each partition, and obtaining the proportion of grayscale value in each partition to the total grayscale level, the method includes: Obtain grayscale distribution data in each partition, wherein the grayscale distribution data is the number of pixels contained in each grayscale value; The grayscale distribution data in each partition is divided by the total number of pixels in the corresponding partition to obtain the normalized grayscale distribution data. The normalized grayscale distribution data is stored in arrays corresponding to each partition, and the grayscale value with the highest proportion in the array corresponding to each partition is obtained and output.
3. A background filling device, characterized in that, It includes: The foreground boundary acquisition unit is used to acquire the foreground region and background region of the received image, and to acquire the foreground boundary region corresponding to the foreground region; A partitioning acquisition unit is used to divide the foreground boundary region into multiple partitions; A grayscale value acquisition unit is used to acquire the total grayscale level of each partition and the grayscale value in each partition, and to acquire the proportion of the grayscale value in each partition to the total grayscale level, and to determine the grayscale value with the highest proportion in each partition; The background processing unit is used to obtain the background area to be filled in the image, divide the background area to be filled into sub-regions corresponding to the partitions, and fill the corresponding sub-region with the highest gray value determined in each partition; the area formed by combining the multiple sub-regions after filling is the filled background area. The partition acquisition unit is used to implement the following methods: Obtain the location information and boundary position of the foreground boundary region; Shift any two oppositely set boundaries of the foreground boundary region inward by a second distance; After translation, the difference between the boundary of the second distance and the foreground boundary region forms multiple partitions; In the step of acquiring the background region to be filled in the image, the background processing unit implements the following method: Based on the foreground region of the image, the boundary of the foreground region of the image is extended outward by a third distance to obtain a second region; The third region is obtained by subtracting the second region from the foreground region of the image; Output the third region as the background region to be filled.
4. The background filling device as described in claim 3, characterized in that, The grayscale value acquisition unit is used to implement the following method: Obtain grayscale distribution data in each partition, wherein the grayscale distribution data is the number of pixels contained in each grayscale value; The normalized grayscale distribution data is obtained by dividing the grayscale distribution data in each partition by the total number of pixels in the corresponding partition. The normalized grayscale distribution data is stored in arrays corresponding to each partition, and the grayscale value with the highest proportion in the array corresponding to each partition is obtained and output.
5. A background filling device, characterized in that, The background filling device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to cause the at least one processor to perform the background filling method of claim 1 or 2.
Citation Information
Patent Citations
Image expansion method and apparatus
CN108491847A