An image matting method and related device for pixel-level information transfer
By generating color images and tripartite sets, dividing pixel regions, and using an evolutionary algorithm to calculate fitness values, the problem of pixel pair loss in traditional methods is solved, and efficient pixel pair transfer between color images is achieved.
Patent Information
- Application Number
- CN202111326665.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-10
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2041-11-10
AI Technical Summary
In traditional pixel-level information transfer methods, the quality difference between pixel pairs of similar pixels leads to the loss of the best pixel pair, especially when transferring between color images of different scales.
By acquiring color images and triangulations, a set of color images and a set of triangulations are generated. The triangulations are then used to divide the image into background, foreground, and unknown regions. An evolutionary algorithm is used to calculate the foreground and background pixel pairs and fitness values for unknown pixels, and the optimal pixel pairs are gradually replaced until the transfer between color images of different scales is completed.
This reduces the loss of optimal pixel pairs, ensuring the accuracy and integrity of pixel pair information transmission between color images.
Smart Images

Figure CN114170263B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information transmission, and in particular to an image matting method and related apparatus for pixel-level information transmission. Background Technology
[0002] Pixel-level information transmission refers to the transmission of information between pixel pairs corresponding to each pixel in an image, which is the main focus.
[0003] Currently, one image matting method based on pixel pair propagation is Pyramid matting. In pyramid matting, pixel pair information is propagated locally from the pixel scale of a small-scale color image to the pixel scale of a large-scale color image.
[0004] Before passing two color images of different scales, similar pixels in the color images may have similar pixel pair information. However, in the traditional pixel-level information passing method, only pixel pair information is passed between two color images of different scales. Pixel pair information is not passed between similar pixels in a single color image. Since the quality of pixel pairs between similar pixels is different, the loss of the best pixel pair is increased. Summary of the Invention
[0005] The first aspect of this application provides an image matting method with pixel-level information transfer to solve the problem of loss of optimal pixel pairs. This pixel-level information transfer method includes:
[0006] Obtain a color image and a triangulation, and scale them respectively to generate a color image set and a triangulation set. The triangulation is used to divide the image pixels. The color image and the triangulation are the same size. The color image set contains N color images that have been scaled uniformly. The scaling ratio between two color images at adjacent scales is h. The triangulation set contains N triangulations corresponding to the scale of the color image set, where N is an integer greater than 2.
[0007] Select the first color image and the first third image from the set of color images and the set of third images. The first color image is the color image with the smallest scale, and the first third image is the third image with the smallest scale.
[0008] Based on the first tripartite division, the first color image is divided into a background region, a foreground region, and an unknown region according to pixel opacity.
[0009] Classify the unknown pixels in the unknown region according to their grayscale values, and generate at least one set of unknown pixels of the same type. The unknown pixels are the pixels of the target color image in the unknown region.
[0010] Select the first group of unknown pixels of the same type, and determine the first unknown pixel in the first group of unknown pixels;
[0011] The first set of unknown pixels is calculated using the background region, foreground region, and unknown region. The foreground and background pixel pairs and fitness values of the first group of unknown pixels are calculated. The fitness values characterize the pixel quality of the unknown pixels.
[0012] Replace the best foreground and background pixel pair in the first group of unknown pixels with the first unknown pixel based on the fitness value;
[0013] Determine the second unknown pixel in the first group of unknown pixels, recalculate the foreground and background pixel pairs and the adaptation value, and replace them until all the unknown pixels in the first group have been replaced.
[0014] Select the second group of unknown pixels, and recalculate the foreground and background pixel pairs and the adaptation value until each group of unknown pixels is replaced.
[0015] Select a second color image and a second third image from the set of color images and the set of third images. The second color image is the color image with the second smallest scale, and the second third image is the third image with the second smallest scale.
[0016] Based on the scaling ratio, the foreground and background pixel pairs of unknown pixels on the first color image are transferred to the corresponding unknown pixels on the second color image;
[0017] The second color image is divided into pixels using the second triangulation, and the foreground and background pixel pairs and fit values are calculated again and replaced until the Nth color image with the largest scale is replaced.
[0018] Optionally, the first color image is divided into a background region, a foreground region, and an unknown region according to pixel opacity based on the first tripartite division, specifically as follows:
[0019] Based on the first three-part diagram, the region in the first color image with a pixel opacity of 0 is determined to be the background region;
[0020] Based on the first three-part diagram, the region in the first color image with a pixel opacity of 1 is determined to be the foreground region;
[0021] The region with unknown opacity in the first color image is identified as the unknown region.
[0022] Optionally, the unknown pixels in the unknown region are classified according to their grayscale values to generate at least one set of unknown pixels of the same type, specifically:
[0023] A first digital image matrix is defined based on the first color image, and the size of the first digital image matrix is equal to that of the first color image;
[0024] Obtain the RGB grayscale value of the unknown pixel in the first color image;
[0025] Unknown pixels with the same RGB grayscale value are labeled with the same type on the first digital image matrix to generate at least one set of unknown pixels of the same type.
[0026] Optionally, the foreground and background pixel pairs and fit values for the first group of unknown pixels are calculated for the first time using the background region, foreground region, and unknown region, specifically as follows:
[0027] Using background, foreground, and unknown regions, and calculating the foreground and background pixel pairs of the first group of unknown pixels for the first time according to the evolutionary algorithm, which includes particle swarm optimization and genetic algorithm;
[0028] The first set of unknown pixels is calculated using the background region, foreground region, and unknown region.
[0029] Optionally, the fitness values of the first group of unknown pixels are calculated using the background region, foreground region, and unknown region, specifically as follows:
[0030] Obtain the estimated pixel value of the first unknown pixel;
[0031] Calculate the color error of the first unknown pixel based on the pixel estimate and the unknown region;
[0032] Calculate the spatial error of the first unknown pixel based on the position information of the foreground and background pixel pairs corresponding to the first unknown pixel and the position information of the first unknown pixel.
[0033] Calculate the fitness value of the first unknown pixel based on color error and spatial error;
[0034] The fitness values of the first group of unknown pixels are calculated using the method described above.
[0035] Optionally, based on the scaling ratio, the foreground and background pixel pairs of unknown pixels on the first color image are transferred to the corresponding unknown pixels on the second color image, specifically as follows:
[0036] Select the first unknown pixel on the first color image;
[0037] Using the foreground and background pixel pairs of the first unknown pixel and the scaling factor, calculate the set of adjacent foreground and background pixel pairs of the unknown pixel at the same position as the unknown pixel in the second color image;
[0038] Select a set of adjacent foreground and background pixel pairs and replace them with unknown pixels at the same position;
[0039] The above method is used to transmit each unknown pixel of the second color image.
[0040] Optionally, acquire the color image and the three-part image, and scale them respectively to generate a set of color images and a set of three-part images, specifically:
[0041] Obtain color images and triangulations;
[0042] The color image and the triodes are scaled using the nearest neighbor method to generate a set of color images and a set of triodes.
[0043] A second aspect of this application provides an image matting apparatus for pixel-level information transmission to solve the problem of loss of optimal pixel pairs. The pixel-level information transmission apparatus includes:
[0044] The acquisition unit is used to acquire color images and triangulation images, and scale them respectively to generate a color image set and a triangulation image set. The triangulation images are used to divide the image pixels. The color images and triangulation images are the same size. The color image set contains N color images that have been scaled uniformly. The scaling ratio of two color images at adjacent scales is h. The triangulation image set contains N triangulation images corresponding to the scale of the color image set, where N is an integer greater than 2.
[0045] The first selection unit is used to select a first color image and a first third image from the set of color images and the set of third images, wherein the first color image is the color image with the smallest scale and the first third image is the third image with the smallest scale.
[0046] A segmentation unit is used to divide the first color image into a background region, a foreground region, and an unknown region according to the pixel opacity based on the first tripartite image;
[0047] The classification unit is used to classify unknown pixels in the unknown region according to their grayscale values and generate at least one set of unknown pixels of the same type. The unknown pixels are the pixels of the target color image in the unknown region.
[0048] The second selection unit is used to select the first group of unknown pixels of the same type and determine the first unknown pixel in the first group of unknown pixels;
[0049] The calculation unit is used to calculate the foreground and background pixel pairs and fitness values of the first group of unknown pixels using the background region, foreground region and unknown region. The fitness value characterizes the pixel quality of the unknown pixels.
[0050] The replacement unit is used to replace the optimal foreground and background pixel pair in the first group of unknown pixels with the first unknown pixel based on the fitness value.
[0051] The first execution unit is used to determine the second unknown pixel in the first group of unknown pixels, recalculate the foreground and background pixel pairs and the adaptation value, and perform replacement until all the unknown pixels in the first group have been replaced.
[0052] The second execution unit is used to select the second group of unknown pixels, and recalculate the foreground and background pixel pairs and the adaptation value until each group of unknown pixels is replaced.
[0053] The third selection unit is used to select the second color image and the second triangular image from the set of color images and the set of triangular images. The second color image is the color image with the second smallest scale, and the second triangular image is the triangular image with the second smallest scale.
[0054] The transfer unit is used to transfer the foreground and background pixel pairs of unknown pixels on the first color image to the unknown pixels at the corresponding positions on the second color image according to the scaling ratio.
[0055] The third execution unit is used to divide the second color image into pixels using the second tripartite diagram, and to recalculate the foreground and background pixel pairs and the adaptation value, and to perform replacement until the Nth color image with the largest scale is replaced.
[0056] Optional, divide into units, specifically:
[0057] Based on the first three-part diagram, the region in the first color image with a pixel opacity of 0 is determined to be the background region;
[0058] Based on the first three-part diagram, the region in the first color image with a pixel opacity of 1 is determined to be the foreground region;
[0059] The region with unknown opacity in the first color image is identified as the unknown region.
[0060] Optional classification units, specifically:
[0061] A first digital image matrix is defined based on the first color image, and the size of the first digital image matrix is equal to that of the first color image;
[0062] Obtain the RGB grayscale value of the unknown pixel in the first color image;
[0063] Unknown pixels with the same RGB grayscale value are labeled with the same type on the first digital image matrix to generate at least one set of unknown pixels of the same type.
[0064] Optional computing units include:
[0065] The first calculation module is used to use the background region, foreground region and unknown region, and to calculate the foreground and background pixel pairs of the first group of unknown pixels for the first time according to the evolutionary algorithm, which includes particle swarm algorithm and genetic algorithm.
[0066] The second calculation module is used to calculate the fitness values of the first group of unknown pixels using the background region, foreground region, and unknown region.
[0067] Optional, the second calculation module is as follows:
[0068] Obtain the estimated pixel value of the first unknown pixel;
[0069] Calculate the color error of the first unknown pixel based on the pixel estimate and the unknown region;
[0070] Calculate the spatial error of the first unknown pixel based on the position information of the foreground and background pixel pairs corresponding to the first unknown pixel and the position information of the first unknown pixel.
[0071] Calculate the fitness value of the first unknown pixel based on color error and spatial error;
[0072] The fitness values of the first group of unknown pixels are calculated using the method described above.
[0073] Optional, the transmission unit is as follows:
[0074] Select the first unknown pixel on the first color image;
[0075] Using the foreground and background pixel pairs of the first unknown pixel and the scaling factor, calculate the set of adjacent foreground and background pixel pairs of the unknown pixel at the same position as the unknown pixel in the second color image;
[0076] Select a set of adjacent foreground and background pixel pairs and replace them with unknown pixels at the same position;
[0077] The above method is used to transmit each unknown pixel of the second color image.
[0078] Optional, obtain the unit, specifically:
[0079] Obtain color images and triangulations;
[0080] The color image and the triodes are scaled using the nearest neighbor method to generate a set of color images and a set of triodes.
[0081] A third aspect of this application provides an electronic device, characterized in that it comprises:
[0082] Processor, memory, input / output units, and bus;
[0083] The processor is connected to memory, input / output units, and a bus;
[0084] The memory stores a program, which the processor calls to execute an image matting method such as the first aspect and any optional pixel-level information transfer method of the first aspect.
[0085] The fourth aspect of this application provides a computer-readable storage medium on which a program is stored. When the program is executed on a computer, it performs an image matting method as described in the first aspect and any optional pixel-level information transmission method of the first aspect.
[0086] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0087] First, acquire the color image and its corresponding triodes for pixel-to-pixel information transfer. Scale both the color image and the triodes to generate a color image set and a triode set. The triodes are used to divide the image pixels. The color image and triodes are the same size. The color image set contains N uniformly scaled color images, with the scaling ratio between adjacent scales. The triode set contains N triodes corresponding to the scale of the color image set, where N is an integer greater than 2. Next, select a first color image and a first triode from the color image set and the triode set, where the first color image is the smallest scaled color image, and the first triode is the smallest scaled triode. Then, based on the first triode, divide the first color image into background, foreground, and unknown regions according to pixel opacity. Classify the unknown pixels in the unknown regions according to their grayscale values, generating at least one set of unknown pixels of the same type. These unknown pixels are the pixels of the target color image in the unknown regions. Select the first set of unknown pixels of the same type and determine the first unknown pixel in the first set. The first group of unknown pixels is calculated using background, foreground, and unknown regions. The foreground-background pixel pairs and fitness values are calculated for each pixel, where fitness values characterize pixel quality. The foreground-background pixel pair of the unknown pixel with the lowest fitness value is replaced by the first unknown pixel. The second unknown pixel in the first group is determined, and the foreground-background pixel pairs and fitness values are calculated again, and replacement is performed until all pixels in the first group are replaced. The second group of unknown pixels is selected, and the foreground-background pixel pairs and fitness values are calculated again, until each group of unknown pixels is replaced. A second color image and a second third image are selected from the color image set and the third image set. The second color image is the second smallest color image, and the second third image is the second smallest third image. The foreground-background pixel pairs of unknown pixels in the first color image are transferred to the corresponding unknown pixels in the second color image according to the scaling ratio. The second third image is used to divide the second color image into pixels, and the foreground-background pixel pairs and fitness values are calculated again, and replacement is performed, until the largest color image (Nth color image) is replaced. This embodiment calculates the unknown pixels in the first color image, performs foreground and background pixel pair calculations and fitness values on pixels of the same type, and replaces the first unknown pixel with the optimal foreground and background pixel pair. This process is repeated for all unknown pixels in the first color image. The foreground and background pixel pairs of the unknown pixels are then transferred between color images of different scales, ensuring the optimal foreground and background pixel pairs are passed layer by layer until the Nth color image is completed. It can be seen that this embodiment transfers the optimal foreground and background pair information within the color image and between color images, reducing the loss of optimal pixel pairs. Attached Figure Description
[0088] Figure 1 This is a schematic diagram of an embodiment of an image matting method for pixel-level information transmission according to this application;
[0089] Figure 2-1 , Figure 2-2 and Figure 2-3 This is a schematic diagram of another embodiment of the image matting method for pixel-level information transmission according to this application;
[0090] Figure 3 This is a schematic diagram of an embodiment of an image matting device for pixel-level information transmission according to this application;
[0091] Figure 4 This is a schematic diagram of another embodiment of an image matting device for pixel-level information transmission according to this application;
[0092] Figure 5 This is a schematic diagram of one embodiment of the electronic device of this application. Detailed Implementation
[0093] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0094] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0095] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0096] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0097] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0098] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0099] In existing technologies, pixel-pair-based matting methods include Pyramid matting. In pyramid matting, pixel pair information is transferred locally from the pixel scale of a small-scale color image to the pixel scale of a large-scale color image. Before transferring information between two color images of different scales, similar pixels in the color images may have similar pixel pair information. However, in traditional pixel-level information transfer methods, only pixel pair information is transferred between two color images of different scales; similar pixels within a single color image are not transferred. Because the quality of pixel pairs between similar pixels varies, this increases the risk of losing optimal pixel pairs.
[0100] Based on this, the application embodiment discloses an image matting method and related apparatus for pixel-level information transmission, which is used to reduce the loss of optimal pixel pairs.
[0101] The technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0102] The method described in this application can be applied to servers, devices, terminals, or other devices with logical processing capabilities; therefore, this application does not limit its application. For ease of description, the following description uses a terminal as the executing entity.
[0103] Please see Figure 1 This application provides an embodiment of an image matting method for pixel-level information transmission, comprising:
[0104] 101. Obtain a color image and a triangulation, and scale them respectively to generate a color image set and a triangulation set. The triangulation is used to divide the image pixels. The color image and the triangulation are the same size. The color image set contains N color images that have been scaled uniformly. The scaling ratio of two color images at adjacent scales is h. The triangulation set contains N triangulations corresponding to the scale of the color image set, where N is an integer greater than 2.
[0105] A color image is the target image that needs to be processed by pixels, while a triangulation is an image with the function of pixel classification. A color image can be divided into pixels by a triangulation to generate multiple different pixel regions.
[0106] In this embodiment, the initial color image and the triangulation images are the same size. They need to be scaled based on the color image, using it as the original image, until a certain ratio is reached. The color image set contains N color images that have been uniformly scaled, with a scaling ratio of h between two adjacent color images. Furthermore, the triangulation images also need to be scaled. The triangulation image set contains N triangulation images corresponding to the scale of the color image set, where N is an integer greater than 2.
[0107] Specifically, the terminal acquires a color image and a three-part image, and reduces the color image and the three-part image according to a preset scaling ratio to generate a set of color images and a set of three-part images. The set of color images contains N reduced color images, and the set of three-part images contains N reduced three-part images. Each reduced color image corresponds to a reduced three-part image of the same scale in the set of three-part images.
[0108] The reason for using only scaling down is that if a color image is enlarged, it needs to be filled with blank pixels, while scaling down only requires gradually removing pixels and does not introduce new uncertainties.
[0109] 102. Select the first color image and the first third image from the set of color images and the set of third images. The first color image is the color image with the smallest scale, and the first third image is the third image with the smallest scale.
[0110] The terminal selects the first color image with the smallest scale from the set of color images, and selects the first third image with the smallest scale from the set of third images. By processing the first color image and the first third image, pixel pairs are gradually transferred to the larger scale image until the color image of the original scale is returned.
[0111] 103. Based on the first three-part diagram, the first color image is divided into a background area, a foreground area, and an unknown area according to pixel opacity;
[0112] The terminal divides the first color image into a background region, a foreground region, and an unknown region based on pixel opacity using the first three-part image. Since the first three-part image and the first color image have the same scale, they can be directly compared when dividing the pixels. The first color image is divided into background, foreground, and unknown regions by the first three-part image according to pixel opacity, and the pixels in the background, foreground, and unknown regions have different ranges of pixel opacity. The unknown region is the area where pixels with unknown opacity are located.
[0113] 104. Classify the unknown pixels in the unknown region according to their grayscale values, and generate at least one set of unknown pixels of the same type. The unknown pixels are the pixels of the target color image in the unknown region.
[0114] The terminal reclassifies the unknown pixels in the unknown regions of the first color image. First, it obtains the grayscale value of the pixel and classifies it according to the range of the grayscale value, generating at least one set of unknown pixels of the same type.
[0115] 105. Select the first group of unknown pixels of the same type, and determine the first unknown pixel in the first group of unknown pixels;
[0116] After the terminal classifies the unknown pixels in the unknown area according to their grayscale values, it generates at least one set of unknown pixels of the same type. First, the terminal selects one set of unknown pixels of the same grayscale value type and defines it as the first set of unknown pixels. Then, it selects one unknown pixel from the first set of unknown pixels and defines it as the first unknown pixel.
[0117] 106. Using the background region, foreground region, and unknown region, calculate the foreground and background pixel pairs and fitness values for the first group of unknown pixels. The fitness value represents the pixel quality of the unknown pixels.
[0118] The terminal uses the background region, foreground region, and unknown region to calculate the foreground-background pixel pairs for the first group of unknown pixels. Specifically, based on the position information of the background and foreground regions, the foreground-background pixel pairs for unknown pixels in the unknown region are determined. Each unknown pixel in the first group of unknown pixels has one foreground-background pixel pair.
[0119] Next, the terminal uses the background region, foreground region, and unknown region to calculate the fitness value of the first group of unknown pixels for the first time. The fitness value represents the pixel quality of the unknown pixels.
[0120] 107. Replace the best foreground and background pixel pair in the first group of unknown pixels with the first unknown pixel based on the fitness value;
[0121] After the terminal selects the unknown pixel with the best pixel quality from the fitness values of each unknown pixel in the first group, it can replace the best foreground and background pixel pair with the foreground and background pixel pair of the first unknown pixel, thus completing the transmission of the best foreground and background pixel pair in the image, which is to say, completing the transmission of pixel-level information.
[0122] 108. Determine the second unknown pixel in the first group of unknown pixels, recalculate the foreground and background pixel pairs and the adaptation value, and replace them until all the unknown pixels in the first group have been replaced.
[0123] 109. Select the second group of unknown pixels, and recalculate the foreground and background pixel pairs and the adaptation value until each group of unknown pixels is replaced;
[0124] The terminal recalculates the adaptation values of all unknown pixels in the first group of unknown pixels according to steps 105, 106 and 107. Since the adaptation values of all unknown pixels in the first group of unknown pixels will change after the first unknown pixel is replaced, it is necessary to repeat the calculation of the adaptation value for each unknown pixel and the replacement of the foreground and background pixel pairs.
[0125] After the terminal completes the replacement of the first group of unknown pixels, the same operation needs to be performed on other unknown pixels of the same type in the unknown area of the first color image, so that the second group of unknown pixels to the last group of unknown pixels complete the calculation of the adaptation value and the replacement of the foreground and background pixel pairs.
[0126] 110. Select the second color image and the second triad from the set of color images and the set of triads. The second color image is the second smallest color image, and the second triad is the second smallest triad.
[0127] After the terminal calculates the adaptation value of all unknown pixels in the unknown region of the first color image and replaces the optimal foreground and background pixel pairs, it needs to select the second color image and the second triad. Here, the second color image is the second smallest color image and the second triad is the second smallest triad. That is, it is necessary to transfer pixel information from the first color image to the second color image.
[0128] 111. Transfer the foreground and background pixel pairs of unknown pixels on the first color image to the corresponding unknown pixels on the second color image according to the scaling ratio;
[0129] The terminal transfers the foreground and background pixel pairs of unknown pixels on the first color image to the corresponding unknown pixels on the second color image according to the scaling ratio. Specifically, it calculates the pixel information based on the scaling ratio and the foreground and background pixel pairs of unknown pixels on the first color image, and then transfers the pixel information to the corresponding unknown pixels on the second color image.
[0130] 112. Use the second triangulation to divide the second color image into pixels, and recalculate the foreground and background pixel pairs and the fit value, and perform replacement until the Nth color image with the largest scale is replaced.
[0131] The terminal uses the second triangulation to divide the second color image into pixels, and recalculates the foreground and background pixel pairs and the adaptation value, and performs replacements until the Nth color image with the largest scale is replaced. The replacement method of the foreground and background pixel pairs in the above steps is repeated to achieve the purpose of transmitting the optimal pixel information.
[0132] First, acquire the color image and its corresponding triodes for pixel-to-pixel information transfer. Scale both the color image and the triodes to generate a color image set and a triode set. The triodes are used to divide the image pixels. The color image and triodes are the same size. The color image set contains N uniformly scaled color images, with the scaling ratio between adjacent scales. The triode set contains N triodes corresponding to the scale of the color image set, where N is an integer greater than 2. Next, select a first color image and a first triode from the color image set and the triode set, where the first color image is the smallest scaled color image, and the first triode is the smallest scaled triode. Then, based on the first triode, divide the first color image into background, foreground, and unknown regions according to pixel opacity. Classify the unknown pixels in the unknown regions according to their grayscale values, generating at least one set of unknown pixels of the same type. These unknown pixels are the pixels of the target color image in the unknown regions. Select the first set of unknown pixels of the same type and determine the first unknown pixel in the first set. The first group of unknown pixels is calculated using background, foreground, and unknown regions. The foreground-background pixel pairs and fitness values are calculated for each pixel, where fitness values characterize pixel quality. The foreground-background pixel pair of the unknown pixel with the lowest fitness value is replaced by the first unknown pixel. The second unknown pixel in the first group is determined, and the foreground-background pixel pairs and fitness values are calculated again, and replacement is performed until all pixels in the first group are replaced. The second group of unknown pixels is selected, and the foreground-background pixel pairs and fitness values are calculated again, until each group of unknown pixels is replaced. A second color image and a second third image are selected from the color image set and the third image set. The second color image is the second smallest color image, and the second third image is the second smallest third image. The foreground-background pixel pairs of unknown pixels in the first color image are transferred to the corresponding unknown pixels in the second color image according to the scaling ratio. The second third image is used to divide the second color image into pixels, and the foreground-background pixel pairs and fitness values are calculated again, and replacement is performed, until the largest color image (Nth color image) is replaced. This embodiment calculates the unknown pixels in the first color image, performs foreground and background pixel pair calculations and fitness values on pixels of the same type, and replaces the first unknown pixel with the optimal foreground and background pixel pair. This process is repeated for all unknown pixels in the first color image. The foreground and background pixel pairs of the unknown pixels are then transferred between color images of different scales, ensuring the optimal foreground and background pixel pairs are passed layer by layer until the Nth color image is completed. It can be seen that this embodiment transfers the optimal foreground and background pair information within the color image and between color images, reducing the loss of optimal pixel pairs.
[0133] Please see Figure 2-1 , Figure 2-2 and Figure 2-3 This application provides another embodiment of an image matting method that transmits pixel-level information, including:
[0134] 201. Obtain the color image and the trisection map;
[0135] 202. Scale the color image and the triodes separately using the nearest neighbor method to generate a set of color images and a set of triodes;
[0136] After acquiring the color image and the three-part image, the terminal scales the color image and the three-part image according to the nearest neighbor method to generate a set of color images and a set of three-part images. Specifically, the scaling of the color image and the three-part image is performed using a scaling formula.
[0137] I'(i',j')=I(i'=i / h,j'=j / h)
[0138] h is the scaling ratio, I(i,j) is the pixel value at coordinates (x,y) in the original color image, and I′(i',j') is the pixel value at the corresponding coordinates (x,y) in the color image after scaling once, where i and j are the pixel values respectively.
[0139] 203. Select the first color image and the first third image from the set of color images and the set of third images. The first color image is the color image with the smallest scale, and the first third image is the third image with the smallest scale.
[0140] Step 203 in this embodiment is similar to step 102 in the previous embodiment, and will not be repeated here.
[0141] 204. Based on the first three-part diagram, the region in the first color image where the pixel opacity is 0 is determined to be the background region;
[0142] 205. Based on the first three-part diagram, the region in the first color image with a pixel opacity of 1 is determined to be the foreground region;
[0143] 206. Determine the region with unknown opacity in the first color image as the unknown region;
[0144] Specifically, the terminal determines the pixel regions with an opacity value of 1, the pixel regions with an opacity value of 0, and the pixel regions with unknown opacity in the first color image based on the first three-part image, and defines them as the background region, the foreground region, and the position region, respectively.
[0145] 207. Define a first digital image matrix based on the first color image, wherein the size of the first digital image matrix is equal to that of the first color image;
[0146] 208. Obtain the RGB grayscale value of the unknown pixel in the first color image;
[0147] 209. Mark unknown pixels with the same RGB grayscale value on the first digital image matrix with the same type to generate at least one set of unknown pixels of the same type;
[0148] First, the terminal defines a digital image matrix of the same size as the first color image, obtains the RGB grayscale values of unknown pixels in the color image, and marks unknown pixels with equal RGB grayscale values as a class, recording them together on the first digital image matrix. This generates at least one set of unknown pixels of the same type. In this embodiment, using a digital image matrix for recording allows the terminal to quickly determine sets of unknown pixels of the same type, reducing computational load and eliminating the need to repeatedly obtain the RGB grayscale values of unknown pixels.
[0149] 210. Select the first group of unknown pixels of the same type, and determine the first unknown pixel in the first group of unknown pixels;
[0150] Step 210 in this embodiment is similar to step 105 in the previous embodiment, and will not be described again here.
[0151] 211. Using background region, foreground region and unknown region, and according to the evolutionary algorithm, calculate the foreground and background pixel pairs of the first group of unknown pixels for the first time. The evolutionary algorithm includes particle swarm algorithm and genetic algorithm.
[0152] The terminal uses an evolutionary algorithm to calculate the foreground and background pixel pairs for the first group of unknown pixels. The evolutionary algorithm includes particle swarm optimization and genetic algorithms. The foreground and background pixel pairs of the unknown pixels are determined through the evolutionary algorithm.
[0153] In artificial intelligence, evolutionary algorithms (EAs) are a subset of evolutionary computation, a type of metaheuristic optimization algorithm based on a general population. Evolutionary algorithms utilize mechanisms inspired by biological evolution, such as reproduction, mutation, composition, and selection. Candidate solutions to the optimization problem play individual roles within the population, and a fitness function determines the quality of the solution. The evolution of the population occurs after repeated applications of these operators.
[0154] Evolutionary algorithms typically provide good approximate solutions to all types of problems because, ideally, they make no assumptions about the underlying fitness. Techniques applied to evolutionary modeling in biological evolution are generally limited to exploring microscopic evolutionary processes based on cellular processes and planning models. Computational complexity is a major obstacle in most practical applications of evolutionary algorithms. In fact, this computational complexity stems from the evaluation of the fitness function. Fitness approximation is one solution to overcome this difficulty. However, seemingly simple evolutionary algorithms can often solve complex problems; therefore, there may not be a direct correlation between algorithmic complexity and problem complexity.
[0155] 212. Obtain the estimated pixel value of the first unknown pixel;
[0156] 213. Calculate the color error of the first unknown pixel based on the estimated pixel value and the unknown region;
[0157] 214. Calculate the spatial error of the first unknown pixel based on the position information of the foreground and background pixel pairs corresponding to the first unknown pixel and the position information of the first unknown pixel.
[0158] 215. Calculate the fitness value of the first unknown pixel based on color error and spatial error;
[0159] 216. Calculate the fitness value of each of the first group of unknown pixels using the method described above;
[0160] The terminal first obtains the pixel estimate of the first unknown pixel.
[0161] I = α * F + (1 - α) * B
[0162] Where I is the true value of the first unknown pixel, F and B are foreground and background pixel pairs, F is the foreground pixel and B is the background pixel. The regions they form are the foreground region and the background region, respectively. The estimated value of the first unknown pixel can be obtained by solving the pixel pairs using the above formula.
[0163] The terminal calculates the color error of the first unknown pixel based on the estimated pixel value and the unknown region.
[0164] a = exp(I U -I 估U )
[0165] Where a is the color error, IU is the true value of the first unknown pixel, and I_estimateU is the estimated value of the first unknown pixel.
[0166] The terminal then calculates the spatial error of the first unknown pixel based on the position information of the foreground and background pixel pairs corresponding to the first unknown pixel and the position information of the first unknown pixel.
[0167]
[0168] Where b is the spatial error, SU is the horizontal and vertical coordinates of the first unknown pixel, and Sk includes SF and SB, which represent the horizontal and vertical coordinates of the foreground pixel and the background pixel, respectively.
[0169] Finally, the adaptation value of the first unknown pixel is calculated using color error and spatial error.
[0170]
[0171] The terminal calculates the fitness values of the first group of unknown pixels using the method described above.
[0172] 217. Replace the best foreground and background pixel pair in the first group of unknown pixels with the first unknown pixel based on the fitness value;
[0173] 218. Determine the second unknown pixel in the first group of unknown pixels, recalculate the foreground and background pixel pairs and the adaptation value, and replace them until all the unknown pixels in the first group have been replaced.
[0174] 219. Select the second group of unknown pixels, and recalculate the foreground and background pixel pairs and the adaptation value until each group of unknown pixels is replaced;
[0175] 220. Select a second color image and a second triad from the set of color images and the set of triads. The second color image is the second smallest color image, and the second triad is the second smallest triad.
[0176] Steps 217 to 220 in this embodiment are similar to steps 107 to 110 in the previous embodiment, and will not be described again here.
[0177] 221. Select the first unknown pixel on the first color image;
[0178] 222. Using the foreground and background pixel pairs of the first unknown pixel and the scaling ratio, calculate the set of adjacent foreground and background pixel pairs of the unknown pixel at the same position as the unknown pixel in the second color image.
[0179] 223. Select a set of adjacent foreground and background pixel pairs and replace them with unknown pixels at the same position;
[0180] 224. Use the above method to transfer each unknown pixel of the second color image;
[0181] After selecting the first unknown pixel in the first color image, the terminal uses the foreground and background pixel pairs of the first unknown pixel and the scaling ratio to calculate the set of adjacent foreground and background pixel pairs of the unknown pixel at the same position as the unknown pixel in the second color image, as shown in the following formula:
[0182]
[0183] Assume the first color image is I(n), and the unknown region of the first color image I(n) is... and For the first color image I(n) in the unknown region, In the diagram, the foreground and background pixel pair information of the unknown pixel point located at coordinates (i, j). and This refers to the foreground and background pixel pair information for the unknown pixel point corresponding to coordinate (i, j) on the second color image I(n-1).
[0184] The terminal selects a set of unknown pixels from the set of adjacent foreground and background pixel pairs to replace the unknown pixels at the same position, and uses the above method to transmit each unknown pixel of the second color image.
[0185] 225. Use the second triangulation to divide the second color image into pixels, and recalculate the foreground and background pixel pairs and the fit value, and perform replacement until the Nth color image with the largest scale is replaced.
[0186] Step 225 in this embodiment is similar to step 112 in the previous embodiment, and will not be repeated here.
[0187] First, acquire the color image and its corresponding triodes for pixel-to-pixel information transfer. Scale both the color image and the triodes to generate a color image set and a triode set. The triodes are used to divide the image pixels. The color image and triodes are the same size. The color image set contains N uniformly scaled color images, with the scaling ratio between adjacent scales. The triode set contains N triodes corresponding to the scale of the color image set, where N is an integer greater than 2. Next, select a first color image and a first triode from the color image set and the triode set, where the first color image is the smallest scaled color image, and the first triode is the smallest scaled triode. Then, based on the first triode, divide the first color image into background, foreground, and unknown regions according to pixel opacity. Classify the unknown pixels in the unknown regions according to their grayscale values, generating at least one set of unknown pixels of the same type. These unknown pixels are the pixels of the target color image in the unknown regions. Select the first set of unknown pixels of the same type and determine the first unknown pixel in the first set. The first group of unknown pixels is calculated using background, foreground, and unknown regions. The foreground-background pixel pairs and fitness values are calculated for each pixel, where fitness values characterize pixel quality. The foreground-background pixel pair of the unknown pixel with the lowest fitness value is replaced by the first unknown pixel. The second unknown pixel in the first group is determined, and the foreground-background pixel pairs and fitness values are calculated again, and replacement is performed until all pixels in the first group are replaced. The second group of unknown pixels is selected, and the foreground-background pixel pairs and fitness values are calculated again, until each group of unknown pixels is replaced. A second color image and a second third image are selected from the color image set and the third image set. The second color image is the second smallest color image, and the second third image is the second smallest third image. The foreground-background pixel pairs of unknown pixels in the first color image are transferred to the corresponding unknown pixels in the second color image according to the scaling ratio. The second third image is used to divide the second color image into pixels, and the foreground-background pixel pairs and fitness values are calculated again, and replacement is performed, until the largest color image (Nth color image) is replaced. This embodiment calculates the unknown pixels in the first color image, performs foreground and background pixel pair calculations and fitness values on pixels of the same type, and replaces the first unknown pixel with the optimal foreground and background pixel pair. This process is repeated for all unknown pixels in the first color image. The foreground and background pixel pairs of the unknown pixels are then transferred between color images of different scales, ensuring the optimal foreground and background pixel pairs are passed layer by layer until the Nth color image is completed. It can be seen that this embodiment transfers the optimal foreground and background pair information within the color image and between color images, reducing the loss of optimal pixel pairs.
[0188] Secondly, in this embodiment, a digital image matrix is used for recording, which enables the terminal to quickly determine a set of unknown pixels of the same type, reducing the amount of computation and eliminating the need to repeatedly obtain the RGB grayscale values of unknown pixels.
[0189] Secondly, this embodiment uses an evolutionary algorithm to calculate foreground and background pixel pairs, which increases computational efficiency.
[0190] Please see Figure 3 This application provides an embodiment of an image matting device for pixel-level information transmission, comprising:
[0191] The acquisition unit 301 is used to acquire a color image and a triangulation, and scale them respectively to generate a color image set and a triangulation set. The triangulation is used to divide the image pixels. The color image and the triangulation are the same size. The color image set contains N color images that have been scaled uniformly. The scaling ratio of two color images at adjacent scales is given. The triangulation set contains N triangulations corresponding to the scale of the color image set, where N is an integer greater than 2.
[0192] The first selection unit 302 is used to select a first color image and a first third image from the set of color images and the set of third images, wherein the first color image is the color image with the smallest scale and the first third image is the third image with the smallest scale.
[0193] The segmentation unit 303 is used to divide the first color image into a background region, a foreground region, and an unknown region according to the pixel opacity based on the first three-part image.
[0194] The classification unit 304 is used to classify the unknown pixels in the unknown region according to their gray values and generate at least one set of unknown pixels of the same type. The unknown pixels are the pixels of the target color image in the unknown region.
[0195] The second selection unit 305 is used to select the first group of unknown pixels of the same type and determine the first unknown pixel in the first group of unknown pixels;
[0196] The calculation unit 306 is used to calculate the foreground and background pixel pairs and the adaptation value of the first group of unknown pixels for the first time using the background region, the foreground region and the unknown region. The adaptation value characterizes the pixel quality of the unknown pixels.
[0197] Replacement unit 307 is used to replace the optimal foreground and background pixel pair in the first group of unknown pixels with the first unknown pixel based on the fitness value;
[0198] The first execution unit 308 is used to determine the second unknown pixel in the first group of unknown pixels, recalculate the foreground and background pixel pairs and the adaptation value, and perform replacement until all the unknown pixels in the first group have been replaced.
[0199] The second execution unit 309 is used to select the second group of unknown pixels, and recalculate the foreground and background pixel pairs and the adaptation value until each group of unknown pixels is replaced.
[0200] The third selection unit 310 is used to select a second color image and a second third image from the set of color images and the set of third images, wherein the second color image is the second smallest color image and the second third image is the second smallest third image.
[0201] The transfer unit 311 is used to transfer the foreground and background pixel pairs of unknown pixels on the first color image to the unknown pixels at the corresponding positions on the second color image according to the scaling ratio.
[0202] The third execution unit 312 is used to divide the second color image into pixels using the second tripartite diagram, and to recalculate the foreground and background pixel pairs and the adaptation value, and to perform replacement until the Nth color image with the largest scale is replaced.
[0203] Please see Figure 4 This application provides another embodiment of an image matting device for pixel-level information transmission, comprising:
[0204] The acquisition unit 401 is used to acquire a color image and a triangulation, and scale them respectively to generate a color image set and a triangulation set. The triangulation is used to divide the image pixels. The color image and the triangulation are the same size. The color image set contains N color images that have been scaled uniformly. The scaling ratio of two color images at adjacent scales is given. The triangulation set contains N triangulations corresponding to the scale of the color image set, where N is an integer greater than 2.
[0205] Optionally, obtain unit 401, specifically:
[0206] Obtain color images and triangulations;
[0207] The color image and the triodes are scaled using the nearest neighbor method to generate a set of color images and a set of triodes.
[0208] The first selection unit 402 is used to select a first color image and a first third image from the set of color images and the set of third images, wherein the first color image is the color image with the smallest scale and the first third image is the third image with the smallest scale.
[0209] The segmentation unit 403 is used to divide the first color image into a background region, a foreground region, and an unknown region according to the pixel opacity based on the first three-part image.
[0210] Optionally, the subdivision is 403, specifically:
[0211] Based on the first three-part diagram, the region in the first color image with a pixel opacity of 0 is determined to be the background region;
[0212] Based on the first three-part diagram, the region in the first color image with a pixel opacity of 1 is determined to be the foreground region;
[0213] The region with unknown opacity in the first color image is identified as the unknown region.
[0214] The classification unit 404 is used to classify the unknown pixels in the unknown region according to their gray values and generate at least one set of unknown pixels of the same type. The unknown pixels are the pixels of the target color image in the unknown region.
[0215] Optional, classification unit 404, specifically:
[0216] A first digital image matrix is defined based on the first color image, and the size of the first digital image matrix is equal to that of the first color image;
[0217] Obtain the RGB grayscale value of the unknown pixel in the first color image;
[0218] Unknown pixels with the same RGB grayscale value are labeled with the same type on the first digital image matrix to generate at least one set of unknown pixels of the same type.
[0219] The second selection unit 405 is used to select the first group of unknown pixels of the same type and determine the first unknown pixel in the first group of unknown pixels;
[0220] The calculation unit 406 is used to calculate the foreground and background pixel pairs and fitness values of the first group of unknown pixels using the background region, foreground region and unknown region. The fitness value characterizes the pixel quality of the unknown pixels.
[0221] Optionally, computing unit 406 includes:
[0222] The first calculation module 4061 is used to use the background region, the foreground region and the unknown region, and to calculate the foreground and background pixel pairs of the first group of unknown pixels for the first time according to the evolutionary algorithm, which includes particle swarm algorithm and genetic algorithm.
[0223] The second calculation module 4062 is used to calculate the fitness values of the first group of unknown pixels for the first time using the background region, foreground region and unknown region.
[0224] Optional, the second calculation module 4062 is as follows:
[0225] Obtain the estimated pixel value of the first unknown pixel;
[0226] Calculate the color error of the first unknown pixel based on the pixel estimate and the unknown region;
[0227] Calculate the spatial error of the first unknown pixel based on the position information of the foreground and background pixel pairs corresponding to the first unknown pixel and the position information of the first unknown pixel.
[0228] Calculate the fitness value of the first unknown pixel based on color error and spatial error;
[0229] The fitness values of the first group of unknown pixels are calculated using the method described above.
[0230] Replacement unit 407 is used to replace the foreground and background pixel pair of the unknown pixel with the lowest fitness value to the first unknown pixel.
[0231] The first execution unit 408 is used to determine the second unknown pixel in the first group of unknown pixels, recalculate the foreground and background pixel pairs and the adaptation value, and perform replacement until all the unknown pixels in the first group have been replaced.
[0232] The second execution unit 409 is used to select the second group of unknown pixels, and recalculate the foreground and background pixel pairs and the adaptation value until each group of unknown pixels is replaced.
[0233] The third selection unit 410 is used to select a second color image and a second triangular image from the set of color images and the set of triangular images, wherein the second color image is the second smallest color image and the second triangular image is the second smallest triangular image.
[0234] The transfer unit 411 is used to transfer the foreground and background pixel pairs of unknown pixels on the first color image to the unknown pixels at the corresponding positions on the second color image according to the scaling ratio.
[0235] Optionally, the transmission unit 411 is specifically:
[0236] Select the first unknown pixel on the first color image;
[0237] Using the foreground and background pixel pairs of the first unknown pixel and the scaling factor, calculate the set of adjacent foreground and background pixel pairs of the unknown pixel at the same position as the unknown pixel in the second color image;
[0238] Select a set of adjacent foreground and background pixel pairs and replace them with unknown pixels at the same position;
[0239] The above method is used to transmit each unknown pixel of the second color image.
[0240] The third execution unit 412 is used to divide the second color image into pixels using the second tripartite diagram, and to recalculate the foreground and background pixel pairs and the adaptation value, and to perform replacement until the Nth color image with the largest scale is replaced.
[0241] Please see Figure 5 This application provides an electronic device, including:
[0242] Processor 501, memory 502, input / output unit 503, and bus 504.
[0243] The processor 501 is connected to the memory 502, the input / output unit 503, and the bus 504.
[0244] The memory 502 stores a program, and the processor 501 calls the program to execute it, such as... Figure 1 The image matting method shown in Figure 2 is a pixel-level information transmission method.
[0245] This application provides a computer-readable storage medium on which a program is stored, and when the program is executed on a computer, it performs the following... Figure 1 The image matting method shown in Figure 2 is a pixel-level information transmission method.
[0246] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0247] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0248] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0249] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0250] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
Claims
1. An image matting method for transmitting pixel-level information, characterized in that, include: A color image and a triangulation are acquired and scaled to generate a color image set and a triangulation set. The triangulation is used to divide the image pixels. The color image and the triangulation are the same size. The color image set contains N color images that have been scaled uniformly. The scaling ratio of two color images at adjacent scales is h. The triangulation set contains N triangulations corresponding to the scale of the color image set, where N is an integer greater than 2. A first color image and a first third image are selected from the set of color images and the set of third images, wherein the first color image is the color image with the smallest scale and the first third image is the third image with the smallest scale. Based on the first tripartite image, the first color image is divided into a background region, a foreground region, and an unknown region according to pixel opacity. The unknown pixels in the unknown region are classified according to their grayscale values to generate at least one set of unknown pixels of the same type, wherein the unknown pixels are the pixels of the target color image in the unknown region; Select the first group of unknown pixels of the same type, and determine the first unknown pixel in the first group of unknown pixels; The background region, the foreground region, and the unknown region are used to calculate the foreground-background pixel pair and the fitness value for the first group of unknown pixels for the first time, and the fitness value characterizes the pixel quality of the unknown pixel. The optimal foreground and background pixel pair in the first group of unknown pixels is replaced with the first unknown pixel based on the fitness value. Determine the second unknown pixel in the first group of unknown pixels, recalculate the foreground and background pixel pairs and the adaptation value, and replace them until all the unknown pixels in the first group have been replaced. Select the second group of unknown pixels, and recalculate the foreground and background pixel pairs and the adaptation value until each group of unknown pixels is replaced. A second color image and a second third image are selected from the set of color images and the set of third images, wherein the second color image is the second smallest color image and the second third image is the second smallest third image; According to the scaling ratio, the foreground and background pixel pairs of unknown pixels on the first color image are transferred to the corresponding unknown pixels on the second color image; The second triangulation is used to divide the second color image into pixels, and the foreground and background pixel pairs and adaptation values are calculated again, and replacements are performed until the Nth color image with the largest scale is replaced.
2. The image matting method according to claim 1, characterized in that, The step of dividing the first color image into a background region, a foreground region, and an unknown region according to pixel opacity based on the first three-part image is as follows: Based on the first tripartite image, the region in the first color image where the pixel opacity is 0 is determined to be the background region; Based on the first tripartite image, the region in the first color image with a pixel opacity of 1 is determined to be the foreground region; The region with unknown opacity in the first color image is identified as the unknown region.
3. The image matting method according to claim 1, characterized in that, The step of classifying the unknown pixels in the unknown region according to their grayscale values and generating at least one set of unknown pixels of the same type specifically involves: A first digital image matrix is defined based on the first color image, and the first digital image matrix is the same size as the first color image; Obtain the RGB grayscale value of the unknown pixel in the first color image; Unknown pixels with the same RGB grayscale value are marked with the same type on the first digital image matrix to generate at least one set of unknown pixels of the same type.
4. The image matting method according to claim 1, characterized in that, The first calculation of the foreground-background pixel pairs and adaptation values for the first group of unknown pixels using the background region, foreground region, and unknown region is specifically as follows: Using the background region, the foreground region, and the unknown region, and calculating the foreground and background pixel pairs of the first group of unknown pixels for the first time according to the evolutionary algorithm, the evolutionary algorithm includes particle swarm optimization and genetic algorithm; The first set of unknown pixels is first calculated using the background region, the foreground region, and the unknown region.
5. The image matting method according to claim 4, characterized in that, The process of calculating the adaptation values of the first group of unknown pixels for the first time using the background region, the foreground region, and the unknown region specifically involves: Obtain the pixel estimate of the first unknown pixel; Calculate the color error of the first unknown pixel based on the estimated pixel value and the unknown region; The spatial error of the first unknown pixel is calculated based on the position information of the foreground and background pixel pairs corresponding to the first unknown pixel and the position information of the first unknown pixel. Calculate the fitness value of the first unknown pixel based on the color error and the spatial error; The fitness values of the first group of unknown pixels are calculated using the method described above.
6. The image matting method according to claim 1, characterized in that, The step of transferring the foreground and background pixel pairs of unknown pixels on the first color image to the corresponding unknown pixels on the second color image according to the scaling ratio specifically involves: Select the first unknown pixel point on the first color image; Using the foreground and background pixel pair of the first transmitted unknown pixel and the scaling ratio, calculate the set of adjacent foreground and background pixel pairs of the unknown pixel at the same position as the transmitted unknown pixel in the second color image; Select a set of unknown pixels from the set of adjacent foreground and background pixel pairs and replace them with the unknown pixels at the same position; The above method is used to transmit each unknown pixel of the second color image.
7. The image matting method according to any one of claims 1 to 6, characterized in that, The process of acquiring the color image and the three-part image, scaling them respectively, and generating the color image set and the three-part image set specifically involves: Obtain color images and triangulations; The color image and the triangulation are scaled according to the nearest neighbor method to generate a color image set and a triangulation set.
8. An image matting device for pixel-level information transmission, characterized in that, include: An acquisition unit is used to acquire a color image and a triangulation image, and scale them respectively to generate a color image set and a triangulation image set. The triangulation image is used to divide the image pixels. The color image and the triangulation image are the same size. The color image set contains N color images that have been scaled uniformly. The scaling ratio of two color images at adjacent scales is h. The triangulation image set contains N triangulation images corresponding to the scale of the color image set, where N is an integer greater than 2. The first selection unit is used to select a first color image and a first third image from the set of color images and the set of third images, wherein the first color image is the color image with the smallest scale and the first third image is the third image with the smallest scale. A segmentation unit is used to divide the first color image into a background region, a foreground region, and an unknown region according to the pixel opacity based on the first three-part image. A classification unit is used to classify the unknown pixels in the unknown region according to their grayscale values, and generate at least one set of unknown pixels of the same type, wherein the unknown pixels are the pixels of the target color image in the unknown region; The second selection unit is used to select the first group of unknown pixels of the same type and determine the first unknown pixel in the first group of unknown pixels; The calculation unit is used to calculate the foreground-background pixel pair and adaptation value of the first group of unknown pixels for the first time using the background region, the foreground region and the unknown region, wherein the adaptation value characterizes the pixel quality of the unknown pixel. The replacement unit is used to replace the optimal foreground and background pixel pair in the first group of unknown pixels with the first unknown pixel according to the adaptation value; The first execution unit is used to determine the second unknown pixel in the first group of unknown pixels, recalculate the foreground and background pixel pairs and the adaptation value, and perform replacement until all the unknown pixels in the first group have been replaced. The second execution unit is used to select the second group of unknown pixels, and recalculate the foreground and background pixel pairs and the adaptation value until each group of unknown pixels is replaced. The third selection unit is used to select a second color image and a second third image from the set of color images and the set of third images, wherein the second color image is the second smallest color image and the second third image is the second smallest third image; The transmission unit is used to transmit the foreground and background pixel pairs of unknown pixels on the first color image to the unknown pixels at the corresponding positions on the second color image according to the scaling ratio. The third execution unit is used to divide the second color image into pixels using the second tripartite image, and to recalculate the foreground and background pixel pairs and the adaptation value, and to perform replacement until the Nth color image with the largest scale is replaced.
9. An electronic device, characterized in that, include: Processor, memory, input / output units, and bus; The processor is connected to the memory, the input / output unit, and the bus; The memory stores a program, and the processor calls the program to execute an image matting method for pixel-level information transmission as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a program stored thereon, the program, when executed on a computer, performing an image matting method for pixel-level information transmission as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Automatic matting algorithm and device
CN107452010A
Image processing method and system, and storage medium
CN111179285A