Method, device, equipment and storage medium for matching foreground image and background image
By extracting and matching the main colors of the foreground image and background image, and calculating the matching degree, the problem of poor color matching in the prior art is solved, and the overall color coordination matching between the foreground image and the background image is achieved.
Patent Information
- Application Number
- CN202111050342.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-08
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2041-09-08
AI Technical Summary
When calculating the color similarity between the foreground image and the background image, the prior art ignores the content characteristic composition of the picture, resulting in poor matching of the main color on pictures with distinctive subject areas, and it is impossible to effectively match the overall color of the foreground image and the background image.
By acquiring the foreground image and the background image, the multiple foreground main colors of the foreground image and the multiple background main colors of the background image are extracted respectively. The preset color quantization algorithm and color space conversion are used to calculate the degree of matching between the main colors, and finally the background image with the highest degree of matching is obtained as the candidate background image.
The overall color matching coordination between the foreground image and the background image is realized, allowing users to select a background image that matches the foreground image from the candidate background image, which is suitable for scenes where the color matching of asymmetric content features is colored.
Smart Images

Figure CN113936150B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, device, equipment and storage medium for matching a foreground image and a background image. Background Art
[0002] In order to achieve harmonious color matching between the foreground image and the background image, it is necessary to accurately calculate the color similarity relationship between the two. The existing scheme is mainly based on global color distribution for calculation. The similarity calculation based on global color distribution is derived from the classic "perceptual hash algorithm", which generates a "fingerprint" for each image and finds similar images by calculating the similarity of fingerprints of different images. Any pixel of an image can be decomposed into three primary colors of RGB, each of which has 256 values, and a total of more than 16 million colors can be combined. In order to simplify the amount of calculation, the partition quantization calculation method is usually adopted, such as reducing the number of color combinations to 64 colors, and then counting the number of pixels contained in each combination to form a 64-dimensional vector, which is the fingerprint of the image. The distance between the color fingerprints of the two images is further calculated using algorithms such as the Pearson correlation coefficient or cosine similarity, which is used as the color similarity of the two images. Similarly, the HSV color space or LAB color space that is more in line with human visual perception can be used to replace the RGB color space to improve the consistency between numerical calculation results and intuitive visual perception; and the image color quantization histogram can be constructed from the bottom to the top, and the image color similarity can be obtained by directly calculating the histogram similarity.
[0003] Existing solutions essentially calculate image fingerprints based on global color distribution, while ignoring the content feature composition of the image. They are more suitable for images with relatively even content feature distribution. In images with distinct subject area divisions, it is easy to cause the extracted main color to not match the main subject color, so it cannot be directly used to calculate the similarity between the foreground image and the background image. Summary of the invention
[0004] The main technical problem solved by the present application is to provide a foreground image and background image matching method, device, equipment and storage medium, which can make the overall color matching of the foreground image and the background image coordinated.
[0005] In order to solve the above problems, the first aspect of the present application provides a method for matching a foreground image and a background image, and the method for matching a foreground image and a background image includes: obtaining the foreground image and several background images; respectively extracting multiple foreground main colors corresponding to the foreground image and multiple background main colors corresponding to each background image; obtaining the degree of matching between the foreground image and each background image based on the multiple foreground main colors and their weights and the multiple background main colors and their weights corresponding to each background image; and obtaining at least one background image with the highest degree of matching as a candidate background image.
[0006] Among them, the extracting of multiple foreground main colors corresponding to the foreground image and multiple background main colors corresponding to each background image respectively includes: using a preset color quantization algorithm to extract the main color of the background image to obtain multiple background main colors corresponding to each background image; using a preset color quantization algorithm to extract the main color of the foreground image to obtain multiple foreground main colors corresponding to the foreground image.
[0007] Among them, the method of using a preset color quantization algorithm to extract the main color of the foreground image to obtain multiple foreground main colors corresponding to the foreground image includes: dividing the foreground image into regions to obtain a number of target regions; using the preset color quantization algorithm to extract the main color of each target region to obtain multiple regional main colors corresponding to each target region; and using the multiple regional main colors corresponding to all target regions as the multiple foreground main colors corresponding to the foreground image.
[0008] Among them, the obtaining of multiple background primary colors corresponding to each background image, or the obtaining of multiple foreground primary colors corresponding to the foreground image, includes: taking the extracted multiple background primary colors or multiple foreground primary colors as target primary colors, performing color space conversion on the target primary colors, converting the RGB color space into the LAB color space, and obtaining the converted target primary colors; calculating the color difference of the converted target primary colors, merging the target primary colors whose color difference is less than a preset color difference tolerance, so as to deduplicate the target primary colors.
[0009] Among them, the degree of matching between the foreground image and each background image is obtained based on the multiple foreground main colors and their weights and the multiple background main colors corresponding to each background image and their weights, including: obtaining the basic weights of the multiple foreground main colors extracted by the preset color quantization algorithm and the basic weights of the multiple background main colors corresponding to each background image; adjusting the basic weights to obtain adjusted weights; obtaining the degree of matching between the foreground image and each background image based on the main color vectors of the multiple foreground main colors corresponding to the foreground image and the adjusted weights, and the main color vectors of the multiple background main colors corresponding to each background image and the adjusted weights.
[0010] Among them, the obtaining of the basic weights of the multiple foreground main colors extracted by the preset color quantization algorithm and the basic weights of the multiple background main colors corresponding to each background image includes: obtaining the sub-color space corresponding to the multiple foreground main colors extracted by the preset color quantization algorithm and the multiple background main colors corresponding to each background image; normalizing the spatial proportions using the sub-color space to obtain the basic weights of the multiple foreground main colors and the basic weights of the multiple background main colors corresponding to each background image.
[0011] Among them, the adjusting of the basic weights to obtain the adjusted weights includes: in the HSV color space, using the color palette saturation vector and the lightness vector to adjust the basic weights of the multiple foreground main colors and the basic weights of the multiple background main colors corresponding to each background image; and / or, in the HSV color space, adjusting the basic weights of the foreground main colors within a set skin color range; and / or, in the LAB color space, adjusting the basic weights of the foreground main colors or the background main colors within the grayscale range.
[0012] Among them, obtaining at least one background image with the highest matching degree as the candidate background image includes: sorting all background images according to the matching degree between the foreground image and each background image, and selecting at least one background image with the highest matching degree with the foreground image as the candidate background image.
[0013] In order to solve the above-mentioned problem, the second aspect of the present application provides a matching device for a foreground image and a background image, comprising: an image acquisition module, the image acquisition module is used to acquire the foreground image and several background images; a main color extraction module, the main color extraction module is used to respectively extract multiple foreground main colors corresponding to the foreground image and multiple background main colors corresponding to each background image; a matching calculation module, the matching calculation module is used to obtain the degree of matching between the foreground image and each background image according to the multiple foreground main colors and their weights and the multiple background main colors and their weights corresponding to each background image; an image determination module, the image determination module is used to acquire at least one background image with the highest degree of matching as a candidate background image.
[0014] In order to solve the above problem, the third aspect of the present application provides an electronic device, including a memory and a processor coupled to each other, and the processor is used to execute program instructions stored in the memory to implement the foreground image and background image matching method of the first aspect above.
[0015] In order to solve the above-mentioned problem, the fourth aspect of the present application provides a computer-readable storage medium having program instructions stored thereon, and when the program instructions are executed by a processor, the method for matching a foreground image and a background image of the above-mentioned first aspect is implemented.
[0016] The beneficial effect of the present invention is: different from the prior art, the foreground image and background image matching method of the present application, by obtaining the foreground image and several background images, can then respectively extract multiple foreground main colors corresponding to the foreground image and multiple background main colors corresponding to each background image, and obtain the matching degree between the foreground image and each background image according to the multiple foreground main colors and their weights and the multiple background main colors and their weights corresponding to each background image, so that at least one background image with the highest matching degree can be obtained as a candidate background image, so that the user can select a background image that is coordinated with the overall color matching of the foreground image from the candidate background images, and can be applied to scenes where the foreground image and the background image have asymmetric content feature color matching. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a flow chart of an embodiment of a method for matching a foreground image and a background image of the present application;
[0018] Figure 2 yes Figure 1 A schematic diagram of a flow chart of an embodiment of step S12;
[0019] Figure 3 yes Figure 2 A schematic diagram of a flow chart of an embodiment of step S122;
[0020] Figure 4 yes Figure 2 A flowchart of an embodiment of obtaining a plurality of background main colors corresponding to each background image or obtaining a plurality of foreground main colors corresponding to a foreground image;
[0021] Figure 5 yes Figure 1 A schematic diagram of a flow chart of an embodiment of step S13;
[0022] Figure 6 yes Figure 5 A schematic diagram of a flow chart of an embodiment of step S131;
[0023] Figure 7 It is a display schematic diagram of an application scenario of a method for matching a foreground image and a background image of the present application;
[0024] Figure 8 It is a schematic diagram of a framework of an embodiment of a device for matching a foreground image and a background image of the present application;
[0025] Fig. 9 It is a schematic diagram of the framework of an embodiment of the electronic device of the present application;
[0026] Fig.10 It is a schematic diagram of a framework of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0027] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.
[0028] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.
[0029] The terms "system" and "network" are often used interchangeably in this article. The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship. In addition, "many" in this article means two or more than two.
[0030] See also Figure 1 , Figure 1 1 is a flow chart of an embodiment of a method for matching a foreground image and a background image of the present application. Specifically, the method for matching a foreground image and a background image in this embodiment may include the following steps:
[0031] Step S11: Acquire the foreground image and several background images.
[0032] Step S12: extracting a plurality of foreground main colors corresponding to the foreground image and a plurality of background main colors corresponding to each background image respectively.
[0033] In this application, the foreground image is generally an image of a target object displayed in a game or live broadcast scene, or the main image displayed in the web page content when browsing the web, or the main image displayed in a software application such as a mobile phone application interface. The foreground image includes multiple display units, and the display unit can be the smallest pixel unit displayed by the foreground image, the smallest array of the foreground image, or the display area of the foreground image divided according to application requirements.
[0034] The foreground main color corresponding to the foreground image is the keynote of the entire image and determines the theme of the entire image. When the foreground image is displayed, it needs to match the background image of the display interface. Therefore, the foreground main color corresponding to the foreground image and the background main color corresponding to the background image of the display interface should be harmonious, so that the foreground image and the background image have a good visual effect when displayed together, giving the user a sense of harmony and consistency. Therefore, when selecting a matching background image based on a given foreground image, it is necessary to obtain the main colors of the foreground image and each background image. For example, by scanning all pixel values of the foreground image and the background image, and using clustering or difference methods, the main colors of the foreground image and the background image can be extracted, and then the foreground image and the background image with matching main colors can be selected to make the overall color matching of the foreground image and the background image coordinated.
[0035] Step S13: Obtaining the degree of matching between the foreground image and each background image according to the plurality of foreground main colors and their weights and the plurality of background main colors and their weights corresponding to each background image.
[0036] It is understandable that there is continuity in color perception between the foreground image and the background image with similar main colors, which often gives people a pleasing, harmonious and soft feeling, and the corresponding foreground image and background image are matched. Therefore, by obtaining multiple foreground main colors of the foreground image and multiple background main colors of each background image, and determining the weight proportion corresponding to each main color, the similarity between the main color of the foreground image and the main color of each background image can be determined, and then the degree of matching between the foreground image and each background image can be determined.
[0037] Step S14: obtaining at least one background image with the highest matching degree as a candidate background image.
[0038] After determining the degree of match between the foreground image and each background image, all background images that meet the required degree of match can be used as candidate background images. The user can then select the final background image from the candidate background images according to his or her preferences, thereby making the overall color matching of the foreground image and the background image coordinated.
[0039] The above scheme, by acquiring the foreground image and several background images, can then respectively extract multiple foreground main colors corresponding to the foreground image and multiple background main colors corresponding to each background image, and obtain the degree of matching between the foreground image and each background image based on the multiple foreground main colors and their weights and the multiple background main colors and their weights corresponding to each background image, so that at least one background image with the highest matching degree can be obtained as a candidate background image, so that the user can select a background image that is coordinated with the overall color of the foreground image from the candidate background images, and can be applied to scenes where the foreground image and the background image have asymmetric content feature color matching.
[0040] Please combine Figure 2 , Figure 2 yes Figure 1 FIG. 1 is a flow chart of an embodiment of step S12 in FIG. 1. In one embodiment, the above step S12 may specifically include:
[0041] Step S121: extracting the main color of the background image using a preset color quantization algorithm to obtain a plurality of background main colors corresponding to each background image.
[0042] Step S122: extracting the main color of the foreground image using a preset color quantization algorithm to obtain a plurality of foreground main colors corresponding to the foreground image.
[0043] It can be understood that, in actual application, the execution order of step S121 and step S122 can be swapped or performed simultaneously; in the embodiment of the present application, the main colors of the foreground image and the background image are extracted using a preset color quantization algorithm, and the number of the main colors of the foreground image and the background image may be one or more, so the number of the main colors can be determined according to the actual image content; for example, 8 background main colors and 8 foreground main colors can be extracted from the background image and the foreground image using a preset color quantization algorithm. The preset color quantization algorithm can be a median cut algorithm (MMCQ), which maps the image to the RGB color space using the median cut algorithm, and regards the image color as a cuboid in the color space. Starting from the initial entire image as a cuboid, the longest side of RGB is cut in half from the median of the color statistics, so that the number of pixels contained in the two cuboids is the same, and the above steps are repeated until the number of cuboids obtained by the final cut is equal to the number of main colors. Therefore, by using a preset color quantization algorithm, the main colors of the background image and the foreground image can be extracted to obtain a plurality of foreground main colors corresponding to the foreground image and a plurality of background main colors corresponding to each background image.
[0044] Please combine Figure 3 , Figure 3 yes Figure 2FIG. 1 is a flow chart of an embodiment of step S122 in FIG. 1. In one embodiment, the above step S122 may specifically include:
[0045] Step S1221: Divide the foreground image into regions to obtain a plurality of target regions.
[0046] Step S1222: extracting the main color of each target area by using the preset color quantization algorithm to obtain multiple area main colors corresponding to each target area.
[0047] Step S1223: taking the multiple regional main colors corresponding to all target regions as the multiple foreground main colors corresponding to the foreground image.
[0048] Specifically, the foreground image can be a virtual image to be displayed. Since the center of attention of the human eye will fall on the hair and clothing of the virtual image, taking this feature into consideration, the 2 / 5 point in the vertical direction of the virtual image can be selected as the boundary to divide the virtual image into target areas such as the "head" area and the "torso" area, and then use MMCQ to extract the main color of each target area to obtain multiple regional main colors corresponding to each target area, among which 3 main colors are extracted from the "head" area and 5 main colors are extracted from the "torso" area, totaling 8 main colors. Then, the 8 regional main colors corresponding to all target areas are used as the 8 foreground main colors corresponding to the foreground image to ensure that the main color of the virtual image is covered.
[0049] Please combine Figure 4 , Figure 4 yes Figure 2 1 is a flow chart of an embodiment of obtaining multiple background main colors corresponding to each background image or obtaining multiple foreground main colors corresponding to a foreground image. In one embodiment, obtaining multiple background main colors corresponding to each background image in step S121 or obtaining multiple foreground main colors corresponding to the foreground image in step S122 may specifically include:
[0050] Step S41: taking the extracted multiple background primary colors or multiple foreground primary colors as target primary colors, performing color space conversion on the target primary colors, converting the RGB color space into the LAB color space, and obtaining the converted target primary colors.
[0051] Step S42: calculating the color difference of the converted target primary colors, and merging the target primary colors whose color difference is less than a preset color difference tolerance to remove duplication of the target primary colors.
[0052] After extracting the main colors of the foreground image and the background image using a preset color quantization algorithm, the extracted multiple background main colors or multiple foreground main colors are used as the target main colors. Since color quantization algorithms such as the median segmentation algorithm extract the main colors based on the principle of color space distribution, the resulting color palette will inevitably have two or more similar colors. Therefore, all target main colors corresponding to the same foreground image or background image can be converted to color space, and the RGB color space can be converted to the LAB color space, and the color difference can be calculated. Given two RGB pixels, the color difference corresponding to the LAB color space can be calculated based on the R / G / B channels of the two RGB pixels. The specific calculation formulas (1) to (4) are as follows:
[0053]
[0054] ΔR=C 1,R -C 2,R (2)
[0055] ΔG=C 1,G -C 2,G (3)
[0056] ΔB=C 1,B -C 2,B (4)
[0057] Therefore, the color difference ΔE of two given RGB pixels can be calculated:
[0058]
[0059] Then, a plurality of target primary colors whose color difference is less than a preset color difference tolerance may be merged to remove duplicate target primary colors with similar colors.
[0060] Please combine Figure 5 , Figure 5 yes Figure 1 FIG. 1 is a flow chart of an embodiment of step S13 in FIG. 1. In one embodiment, the above step S13 may specifically include:
[0061] Step S131: acquiring basic weights of the plurality of foreground main colors extracted by the preset color quantization algorithm and basic weights of the plurality of background main colors corresponding to each background image.
[0062] Step S132: adjusting the basic weight to obtain an adjusted weight.
[0063] Step S133: Obtain the degree of matching between the foreground image and each background image according to the main color vectors of the multiple foreground main colors corresponding to the foreground image and the adjusted weights, and the main color vectors of the multiple background main colors corresponding to each background image and the adjusted weights.
[0064] It can be understood that the degree of matching between the foreground image and the background image is mainly reflected by the degree of matching between the foreground main color and the background main color, and the accuracy of calculating the degree of matching between the foreground main color and the background main color greatly depends on the accurate extraction of the foreground main color and the background main color. The color palette order of the main colors extracted by the color quantization algorithm such as MMCQ already contains the proportion information of each main color in the original image, but the subjective visual significance cannot be accurately described by the information of a single dimension. The human eye's perceptual cognition of the image representative color will be inclined to a certain extent towards more colorful colors. Therefore, in the embodiment of the present application, in the process of extracting multiple foreground main colors corresponding to the foreground image and multiple background main colors corresponding to each background image using a preset color quantization algorithm, the basic weight of each foreground main color and the basic weight of each background main color can be obtained, so that the basic weights of at least part of the main colors can be selectively adjusted to obtain the adjusted weights, and then the degree of matching between the foreground image and each background image is obtained according to the main color vectors and the adjusted weights of the multiple foreground main colors corresponding to the foreground image, and the main color vectors and the adjusted weights of the multiple background main colors corresponding to each background image. Specifically, for example, after weight adjustment, the background main color vector corresponding to the given background image is and main color weight The foreground dominant color vector corresponding to the foreground image and main color weight The final score of the matching degree between the foreground image and the background image is calculated as follows:
[0065]
[0066] Here, ε is a small constant, for example, set to 10 -7 , to prevent division by zero errors during calculations.
[0067] Please combine Figure 6 , Figure 6 yes Figure 5 FIG. 1 is a flow chart of an embodiment of step S131 in FIG. 1. In one embodiment, the above step S131 may specifically include:
[0068] Step S1311: obtaining the sub-color space corresponding to the multiple foreground main colors extracted by the median segmentation algorithm and the multiple background main colors corresponding to each background image.
[0069] Step S1312: normalizing the spatial proportions using the sub-color space to obtain basic weights of the multiple foreground main colors and basic weights of the multiple background main colors corresponding to each background image.
[0070] For example, by using the MMCQ algorithm to divide the color space, the sub-color space corresponding to the extracted primary color can be obtained. For example, when 8 primary colors are extracted, the MMCQ algorithm will divide the RGB color space into 8 sub-color spaces, and then these 8 sub-color spaces can be normalized for spatial proportion, so that the basic weight of each primary color can be obtained, that is, the basic weights of multiple foreground primary colors and the basic weights of multiple background primary colors corresponding to each background image can be obtained.
[0071] In one embodiment, the above step S132 may specifically include: in the HSV color space, using the palette saturation vector and the lightness vector, adjusting the basic weights of the multiple foreground main colors and the basic weights of the multiple background main colors corresponding to each background image.
[0072] Specifically, in the HSV color space, given the initial weight vector of the primary color obtained by MMCQ Swatch Saturation Vector and the brightness vector You can use the color palette saturation vector and the brightness vector To initialize the weight vector Make adjustments, the specific adjustments are as follows:
[0073]
[0074] Therefore, in the HSV color space, the weight of the prominent color in the main color can be increased according to formula (7).
[0075] In one embodiment, the above step S132 may specifically include: in the HSV color space, adjusting the basic weight of the foreground main color within the set skin color range.
[0076] It is understandable that when the foreground image is a virtual image, the skin color is generally not covered by the concept of the primary color and needs to be filtered out. Therefore, the skin color range can be defined in the HSV color space, and then the basic weight of the foreground primary color that falls within the skin color range can be halved.
[0077] In one embodiment, the above step S132 may specifically include: in the LAB color space, adjusting the basic weight of the foreground primary color or the background primary color within the grayscale color range.
[0078] Specifically, the color difference between the color and the grayscale color is calculated according to formulas (1) to (5) in the LAB color space, and then the basic weight of the foreground main color or the background main color within the grayscale color interval is halved.
[0079] The above scheme comprehensively considers multiple aspects such as color space proportion, color saliency and skin color filtering, dynamically adjusts the weights of each color in the color palette extracted by the main color, and calculates the color difference matrix in the LAB color space in combination with the weight information. It can accurately and quantitatively give the matching degree of image pairs (foreground images and background images) with asymmetric content characteristics.
[0080] In one embodiment, the above step S14 may specifically include: sorting all background images according to the matching degree between the foreground image and each background image, and selecting at least one background image with the highest matching degree with the foreground image as the candidate background image.
[0081] It can be understood that based on a given foreground image, multiple corresponding background images can be obtained, and then the degree of matching between the foreground image and each background image can be determined. Then all background images can be sorted according to the degree of matching, and at least one background image with the highest degree of matching with the foreground image can be selected as a candidate background image for user selection.
[0082] See also Figure 7 , Figure 7 It is a display schematic diagram of an application scenario of the foreground image and background image matching method of the present application. In practical applications, the selection of background images is a 1 to N problem. In the embodiment of the present application, the search logic of candidate background images can be further constructed, which mainly includes an offline construction stage, a real-time matching stage and an incremental addition stage; in the offline construction stage, for each foreground image, according to the above-mentioned foreground image and background image matching method, MMCQ is used to extract multiple foreground primary colors corresponding to the foreground image and multiple background primary colors corresponding to each background image, and weighted color rearrangement is performed to realize customized object primary color extraction, and then the primary color matching degree is calculated to obtain the matching degree between the foreground image and each background image, and its matching degree with all background images is exhaustively enumerated through multiple processes. The matching degree is scored and arranged in descending order, and the index of the foreground image to the background image is constructed according to the matching degree, and serialized and stored in the database; in the real-time matching stage, the n most matching background images can be indexed from the database according to the matching degree as candidate background images for the user to choose; in the incremental addition stage, since the sorting information is already available in the offline construction stage, if a new background image is added, it is only necessary to insert a new index in the corresponding sorting position in the data of each foreground image, and the complexity is O(log2(N)); if a new foreground image is added, it is only necessary to add a list information containing the index of the new foreground image to the background image, and the complexity is O(N). It can be found that the solution of the present application has the characteristics of small computational complexity, offline construction, real-time search, one-time resource consumption, and low-cost incremental expansion.
[0083] See also Figure 8 , Figure 8 It is a schematic diagram of the framework of an embodiment of the foreground image and background image matching device of the present application. The foreground image and background image matching device 80 comprises: an image acquisition module 800, the image acquisition module 800 is used to acquire the foreground image and a plurality of background images; a main color extraction module 802, the main color extraction module 802 is used to respectively extract a plurality of foreground main colors corresponding to the foreground image and a plurality of background main colors corresponding to each background image; a matching calculation module 804, the matching calculation module 804 is used to obtain the matching degree between the foreground image and each background image according to the plurality of foreground main colors and their weights and the plurality of background main colors and their weights corresponding to each background image; an image determination module 806, the image determination module 806 is used to acquire at least one background image with the highest matching degree as a candidate background image.
[0084] In some embodiments, the primary color extraction module 802 executes the steps of respectively extracting multiple foreground primary colors corresponding to the foreground image and multiple background primary colors corresponding to each background image, including: using a preset color quantization algorithm to perform primary color extraction on the background image to obtain multiple background primary colors corresponding to each background image; using a preset color quantization algorithm to perform primary color extraction on the foreground image to obtain multiple foreground primary colors corresponding to the foreground image.
[0085] In some embodiments, the primary color extraction module 802 performs primary color extraction on the foreground image using a preset color quantization algorithm to obtain multiple foreground primary colors corresponding to the foreground image, including: dividing the foreground image into regions to obtain a number of target regions; performing primary color extraction on each target region using the preset color quantization algorithm to obtain multiple regional primary colors corresponding to each target region; and using the multiple regional primary colors corresponding to all target regions as the multiple foreground primary colors corresponding to the foreground image.
[0086] In some embodiments, the primary color extraction module 802 executes the acquisition of multiple background primary colors corresponding to each background image, or the acquisition of multiple foreground primary colors corresponding to the foreground image, including: taking the extracted multiple background primary colors or multiple foreground primary colors as the target primary colors, performing color space conversion on the target primary colors, converting the RGB color space to the LAB color space, and obtaining the converted target primary colors; calculating the color difference of the converted target primary colors, merging the target primary colors whose color difference is less than a preset color difference tolerance, so as to deduplicate the target primary colors.
[0087] In some embodiments, the matching calculation module 804 executes the steps of obtaining the degree of matching between the foreground image and each background image based on the multiple foreground main colors and their weights and the multiple background main colors corresponding to each background image and their weights, including: obtaining the basic weights of the multiple foreground main colors extracted by the preset color quantization algorithm and the basic weights of the multiple background main colors corresponding to each background image; adjusting the basic weights to obtain adjusted weights; obtaining the degree of matching between the foreground image and each background image based on the main color vectors of the multiple foreground main colors corresponding to the foreground image and the adjusted weights, and the main color vectors of the multiple background main colors corresponding to each background image and the adjusted weights.
[0088] In some embodiments, the matching calculation module 804 executes the acquisition of the basic weights of the multiple foreground main colors extracted by the preset color quantization algorithm and the basic weights of the multiple background main colors corresponding to each background image, including: acquiring the sub-color space corresponding to the multiple foreground main colors extracted by the median segmentation algorithm and the multiple background main colors corresponding to each background image; performing spatial proportion normalization with the sub-color space to obtain the basic weights of the multiple foreground main colors and the basic weights of the multiple background main colors corresponding to each background image.
[0089] In some embodiments, the matching calculation module 804 performs adjustment on the basic weights to obtain adjusted weights, including: in the HSV color space, using the palette saturation vector and the brightness vector to adjust the basic weights of the multiple foreground main colors and the basic weights of the multiple background main colors corresponding to each background image; and / or, in the HSV color space, adjusting the basic weights of the foreground main colors within a set skin color range; and / or, in the LAB color space, adjusting the basic weights of the foreground main colors or the background main colors within the grayscale range.
[0090] In some embodiments, the image determination module 806 executes the step of obtaining at least one background image with the highest degree of matching as a candidate background image, including: sorting all background images according to the degree of matching between the foreground image and each background image, and selecting at least one background image with the highest degree of matching with the foreground image as the candidate background image.
[0091] See also Fig. 9 , Fig. 91 is a schematic diagram of a framework of an embodiment of an electronic device of the present application. The electronic device 90 includes a memory 91 and a processor 92 coupled to each other, and the processor 92 is used to execute program instructions stored in the memory 91 to implement the steps of any of the above-mentioned foreground image and background image matching method embodiments. In a specific implementation scenario, the electronic device 90 may include but is not limited to: a microcomputer, a server.
[0092] Specifically, the processor 92 is used to control itself and the memory 91 to implement the steps of any of the above-mentioned foreground image and background image matching method embodiments. The processor 92 can also be called a CPU (Central Processing Unit). The processor 92 may be an integrated circuit chip with signal processing capabilities. The processor 92 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 92 can be implemented by an integrated circuit chip.
[0093] See also Fig.10 , Fig.10 The computer-readable storage medium 100 stores program instructions 1000 that can be executed by a processor, and the program instructions 1000 are used to implement the steps of any of the above-mentioned foreground image and background image matching method embodiments.
[0094] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0095] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0096] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0097] If the integrated unit is implemented in the form of 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 the present application is essentially 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
Claims
1. A method for matching a foreground image and a background image, characterized in that: The method for matching the foreground image and the background image includes: Acquire the foreground image and several background images; Respectively extracting a plurality of foreground main colors corresponding to the foreground image and a plurality of background main colors corresponding to each background image; According to the multiple foreground main colors and their weights and the multiple background main colors corresponding to each background image and their weights, obtaining the degree of matching between the foreground image and each background image; including: obtaining the basic weights of the multiple foreground main colors extracted by a preset color quantization algorithm and the basic weights of the multiple background main colors corresponding to each background image; The basic weight is adjusted to obtain an adjusted weight; wherein, in the HSV color space, the color palette saturation vector is used and the brightness vector By formula The basic weights of the plurality of foreground main colors and the basic weights of the plurality of background main colors corresponding to each background image are adjusted; wherein, is the weight vector after adjusting the main color, is the initial weight vector of the main color; Obtaining a matching degree between the foreground image and each background image according to the main color vectors of the plurality of foreground main colors corresponding to the foreground image and the adjusted weights, and the main color vectors of the plurality of background main colors corresponding to each background image and the adjusted weights; At least one background image with the highest matching degree is obtained as a candidate background image.
2. The method for matching a foreground image and a background image according to claim 1, characterized in that: The step of respectively extracting a plurality of foreground main colors corresponding to the foreground image and a plurality of background main colors corresponding to each background image comprises: Extracting the main color of the background image using a preset color quantization algorithm to obtain multiple background main colors corresponding to each background image; The primary color of the foreground image is extracted using a preset color quantization algorithm to obtain a plurality of foreground primary colors corresponding to the foreground image.
3. The method for matching a foreground image and a background image according to claim 2, characterized in that: The extracting the main color of the foreground image by using a preset color quantization algorithm to obtain a plurality of foreground main colors corresponding to the foreground image includes: Dividing the foreground image into regions to obtain a plurality of target regions; Extracting the main color of each target area using the preset color quantization algorithm to obtain multiple area main colors corresponding to each target area; The multiple area main colors corresponding to all target areas are used as the multiple foreground main colors corresponding to the foreground image.
4. The method for matching a foreground image and a background image according to claim 2, characterized in that: The obtaining of a plurality of background main colors corresponding to each background image, or the obtaining of a plurality of foreground main colors corresponding to the foreground image, comprises: Taking the extracted multiple background primary colors or multiple foreground primary colors as target primary colors, performing color space conversion on the target primary colors, converting the RGB color space into the LAB color space, and obtaining the converted target primary colors; The color difference of the converted target main colors is calculated, and the target main colors whose color difference is less than a preset color difference tolerance are merged to remove duplication of the target main colors.
5. The method for matching a foreground image and a background image according to claim 1, characterized in that: The obtaining of the basic weights of the plurality of foreground main colors extracted by a preset color quantization algorithm and the basic weights of the plurality of background main colors corresponding to each background image includes: Acquire the sub-color spaces of the plurality of foreground main colors extracted by the median segmentation algorithm and the sub-color spaces corresponding to the plurality of background main colors corresponding to each background image; The spatial proportion is normalized using the sub-color space to obtain basic weights of the multiple foreground main colors and basic weights of the multiple background main colors corresponding to each background image.
6. The method for matching a foreground image and a background image according to claim 1, characterized in that: The obtaining of at least one background image with the highest matching degree as a candidate background image includes: All background images are sorted according to the matching degree between the foreground image and each background image, and at least one background image with the highest matching degree with the foreground image is selected as the candidate background image.
7. A device for matching a foreground image and a background image, characterized in that: include: An image acquisition module, the image acquisition module is used to acquire the foreground image and a plurality of background images; A main color extraction module, the main color extraction module is used to respectively extract a plurality of foreground main colors corresponding to the foreground image and a plurality of background main colors corresponding to each background image; A matching calculation module, the matching calculation module is used to obtain the matching degree between the foreground image and each background image according to the multiple foreground main colors and their weights and the multiple background main colors corresponding to each background image and their weights; including: obtaining the basic weights of the multiple foreground main colors extracted by a preset color quantization algorithm and the basic weights of the multiple background main colors corresponding to each background image; adjusting the basic weights to obtain adjusted weights; wherein, in the HSV color space, the color palette saturation vector is used and the brightness vector By formula The basic weights of the plurality of foreground main colors and the basic weights of the plurality of background main colors corresponding to each background image are adjusted; wherein, is the weight vector after adjusting the main color, an initial weight vector of the main color; obtaining a matching degree between the foreground image and each background image according to the main color vectors of the multiple foreground main colors corresponding to the foreground image and the adjusted weights, and the main color vectors of the multiple background main colors corresponding to each background image and the adjusted weights; An image determination module is used to obtain at least one background image with the highest matching degree as a candidate background image.
8. An electronic device, characterized in that: It comprises a memory and a processor coupled to each other, wherein the processor is used to execute program instructions stored in the memory to implement the method for matching a foreground image and a background image as described in any one of claims 1 to 6.
9. A computer-readable storage medium having program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the method for matching a foreground image and a background image described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Image processing device and method
CN110634169A
Self-adaptive camouflage online design method and system
CN111798539A