Image processing method and device, electronic equipment and storage medium
By performing thresholding processing and connection domain analysis on the image, determining the target pixel points and adding special effects, the problem of low accuracy of special effects points in the prior art is solved, and the presentation effect of special effects images is improved.
Patent Information
- Application Number
- CN202510119426.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-05-27
AI Technical Summary
When performing special effects processing on images, the accuracy of determining the pixel points that add special effects is low, resulting in poor final special effects image effects.
By thresholding the image to be processed, the connecting domain is acquired, and the target pixel point is determined based on the area, aspect ratio or outline pixel point of the connecting domain, and then special effects are added.
Improve the accuracy of determining the target pixel points, ensure the presentation effect of the special effect image, and avoid overlapping and insufficient effects of special effects.
Smart Images

Figure CN120047577A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image processing method, device, electronic device and storage medium. Background Art
[0002] As the application of images becomes more and more extensive, special effects can be applied to images to enhance the presentation effect of images, which is conducive to improving the fun and visual experience of users. For example, when applying special effects to images, corresponding special effects are added to some pixels in the image to obtain special effects images. However, in this method, these pixels to which special effects are added are randomly selected, or the selection accuracy is low, resulting in poor effects of the final special effects images. Summary of the invention
[0003] The present application provides an image processing method, device, electronic device and storage medium, which improve the accuracy of determining the pixel points for adding special effects, thereby ensuring the effect of the generated special effect image.
[0004] In a first aspect, the present application provides an image processing method, the method comprising:
[0005] Get the image to be processed;
[0006] Performing threshold processing on the image to be processed to obtain a first image;
[0007] Determine a target pixel point corresponding to the connected domain based on the area of the connected domain in the first image;
[0008] Add corresponding special effects to the target pixel points in the image to be processed to obtain a target special effect image.
[0009] In a second aspect, the present application provides another image processing method, the method comprising:
[0010] Get the image to be processed;
[0011] Performing threshold processing on the image to be processed to obtain a first image;
[0012] If the area of the connected domain in the first image is smaller than the first threshold, determining the target pixel point corresponding to the connected domain based on the aspect ratio of the connected domain;
[0013] If the area of the connected domain is greater than the first threshold, determining the target pixel point corresponding to the connected domain based on the contour pixel points of the connected domain;
[0014] Add corresponding special effects to the target pixel points in the image to be processed to obtain a target special effect image.
[0015] In a third aspect, the present application provides an image processing device, the device comprising: a first acquisition unit and a first processing unit;
[0016] A first acquisition unit, used for acquiring an image to be processed;
[0017] A first processing unit, configured to perform threshold processing on the image to be processed to obtain a first image;
[0018] The first processing unit is further used to determine a target pixel point corresponding to the connected domain based on the area of the connected domain in the first image;
[0019] The first processing unit is further used to add corresponding special effects to target pixels in the image to be processed to obtain a target special effect image.
[0020] In a fourth aspect, the present application provides another image processing device, the device comprising: a second acquisition unit and a second processing unit;
[0021] A second acquisition unit, used for acquiring an image to be processed;
[0022] A second processing unit is used to perform threshold processing on the image to be processed to obtain a first image;
[0023] The second processing unit is further configured to determine a target pixel point corresponding to the connected domain based on the aspect ratio of the connected domain if the area of the connected domain in the first image is smaller than the first threshold;
[0024] The second processing unit is further configured to determine a target pixel point corresponding to the connected domain based on the contour pixel points of the connected domain if the area of the connected domain is greater than the first threshold;
[0025] The second processing unit is further used to add corresponding special effects to target pixels in the image to be processed to obtain a target special effect image.
[0026] In a fifth aspect, the present application provides an electronic device, comprising: a processor and a memory, the processor being connected to the memory, the memory being used to store a computer program, and the processor being used to execute the computer program stored in the memory, so that the electronic device executes the method of the first aspect or the second aspect.
[0027] In a sixth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program enables a computer to execute the method of the first aspect or the second aspect.
[0028] In a seventh aspect, the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and is computer-operable to cause the computer to execute the method of the first aspect or the second aspect.
[0029] The implementation of this application has the following beneficial effects:
[0030] First, an image to be processed is obtained; then, a thresholding process is performed on the image to be processed to obtain a first image; then, a connected domain is obtained from the first image, and then a target pixel point corresponding to the connected domain is determined based on the area of the connected domain. If the area of the connected domain is less than the first threshold, the target pixel point corresponding to the connected domain is determined based on the aspect ratio of the connected domain; if the area of the connected domain is greater than the first threshold, the target pixel point corresponding to the connected domain is determined based on the contour pixel point of the connected domain. This method allows the determined target pixel point to match the connected domain in the first image. Compared with directly taking all the pixels in the first image as the target pixel points, randomly selecting multiple pixels from the first image as the target pixel points, and taking the center of the contour existing in the first image as the target pixel point, the target pixel point can be determined with higher accuracy, thereby ensuring the presentation effect of the target special effect image, such as avoiding the overlap of special effects in a large range, and avoiding the special effects being relatively empty in the target special effect image, thereby enhancing the user's visual experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0032] Figure 1 A schematic diagram of an image processing system provided in an embodiment of the present application;
[0033] Figure 2 A schematic diagram of an image processing scenario provided in an embodiment of the present application;
[0034] Figure 3 A flowchart of an image processing method provided in an embodiment of the present application;
[0035] Figure 4 A schematic diagram of performing thresholding processing on an image to be processed to obtain a first image provided by an embodiment of the present application;
[0036] Figure 5 A schematic diagram of obtaining a dilated image from a first image provided by an embodiment of the present application;
[0037] Figure 6 A schematic diagram of screening target pixels provided in an embodiment of the present application;
[0038] Figure 7 A schematic diagram of adding a corresponding special effect to a target pixel point in an image to be processed to obtain a target special effect image provided by an embodiment of the present application;
[0039] Figure 8 A flowchart of another image processing method provided in an embodiment of the present application;
[0040] Fig. 9 A block diagram of the functional units of an image processing device provided in an embodiment of the present application;
[0041] Fig.10 A block diagram of the functional units of another image processing device provided in an embodiment of the present application;
[0042] Fig.11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0044] The terms "first", "second", "third" and "fourth" etc. in the specification, claims and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0045] Reference to "embodiments" herein means that a particular feature, result, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0046] From the above background technology, it can be known that when performing special effects processing on an image, the target special effects image is obtained by determining the highlight points in the image and then adding corresponding special effects to the highlight points. However, the accuracy of the highlight points determined by the existing method is low. For example, all pixel points belonging to the highlight area after thresholding are directly used as target pixel points, or multiple pixel points are randomly selected from the highlight area as target pixel points, or the center of the contour in the highlight area is used as the target pixel point. After the special effects are subsequently added to the target pixel points, the effect of the target special effects image finally obtained will be poor. For example, adding special effects to all pixel points in the highlight area will cause large-scale overlap of special effects, which will affect the visual effect. For example, adding special effects only to the center of the contour in the highlight area will result in insufficient special effects presentation, which is relatively empty and lacks a strong sense of richness at the visual level.
[0047] Therefore, the present application obtains an image to be processed; then performs thresholding processing on the image to be processed to obtain a first image; then obtains a connected domain from the first image, and then determines the target pixel points corresponding to the connected domain based on the area of the connected domain. If the area of the connected domain is less than the first threshold, the target pixel points corresponding to the connected domain are determined based on the aspect ratio of the connected domain; if the area of the connected domain is greater than the first threshold, the target pixel points corresponding to the connected domain are determined based on the contour pixel points of the connected domain. This method allows the determined target pixel points to match the connected domain. Compared with directly taking all the pixels belonging to the first image as target pixels, randomly selecting multiple pixels from the first image as target pixels, and taking the center of the contour in the first image as the target pixel point, the target pixel points can be determined with higher accuracy, thereby ensuring the presentation effect of the target special effect image, such as avoiding the overlap of special effects in a large range, and avoiding the target special effect image from presenting a relatively empty special effect, thereby enhancing the user's visual experience.
[0048] First of all, it should be noted that the special effects in the embodiments of the present application may include but are not limited to highlight effects, star effects, halo effects, glare effects, and other special effects that can be used to add to pixel points, which are not listed one by one in this application. For ease of understanding, the embodiments of the present application mainly use the special effect of highlight effects as an example for illustration, that is, the target pixel points in the embodiments below can be understood as highlight pixels, the special effects material images can be understood as highlight special effects material images, the target special effects images can be understood as highlight special effects images, and so on. The same is true for other special effects, which are not described one by one here.
[0049] See also Figure 1 , Figure 1 A schematic diagram of an image processing system provided in an embodiment of the present application.
[0050] Figure 1The image processing system shown includes a user end and an image processing device, wherein the user end can be a smart phone, tablet computer, laptop computer, desktop computer, smart TV, desktop computer, smart watch, smart car or other smart terminal, which is not specifically limited in this application; the image processing device can be a server, such as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, as well as basic cloud computing services such as big data and artificial intelligence platforms, which is not specifically limited in this application.
[0051] The target application software may be installed on the user end, and the target application software includes various types of special effect templates (for example, including special effect templates). When the user wants to add special effects to the image to be processed, the user can click to use the special effect template and upload the image to be processed to the user end; then the user end sends an image processing request to the image processing device, wherein the image processing request may include the image to be processed and a special effect algorithm identifier corresponding to the special effect template, and accordingly, the image processing device obtains the image to be processed; then, the image processing device executes the special effect algorithm corresponding to the special effect algorithm identifier based on the special effect algorithm identifier, performs special effect processing on the image to be processed, and obtains a target special effect image, specifically:
[0052] The image processing device performs threshold processing on the image to be processed to obtain a first image; then the image processing device obtains a connected domain from the first image; then the image processing device determines the target pixel point corresponding to the connected domain based on the area of the connected domain; then the image processing device adds corresponding special effects to the target pixel point in the image to be processed to obtain a target special effect image.
[0053] The image processing device then sends the target special effects image to the user terminal, and accordingly, the user terminal displays the target special effects image; further, the user can also perform other image editing processing on the target special effects image through the user terminal (such as cropping, brightness adjustment, saturation adjustment, etc., which are not limited in this application), and the user can also save the target special effects image to the local of the user terminal (such as a local photo album, a draft box in the target application software, etc.), and can also publish the target special effects image in an Internet community, etc., which are not specifically limited in this application.
[0054] To facilitate understanding, the main scenarios involved in the embodiments of the present application are introduced below.
[0055] See also Figure 2 , Figure 2 A schematic diagram of an image processing scenario provided in an embodiment of the present application. Figure 2As shown, the target application software on the user side includes a variety of special effect templates, such as Figure 2 , wherein the template page corresponds to the cover image of each special effect template displayed; when the user wants to use the special effect template (i.e., 4) to add special effects to the image, the user can touch the "Use" function button corresponding to the 4 special effect template; then the user terminal can display the album selection page in response to the "Use" touch operation, and the user can select the image to be processed on the album selection page; then the user touches the "Next" function button on the album selection page, and accordingly, the user terminal obtains the image to be processed; then the user terminal sends an image processing request to the image processing device, at which time the image processing request includes the image to be processed and the special effect algorithm identifier corresponding to the 4 special effect template; then the image processing device executes the special effect algorithm corresponding to the special effect algorithm identifier based on the special effect algorithm identifier, processes the image to be processed, and obtains the target special effect image; then the image processing device sends the target special effect image to the user terminal, and accordingly, the user terminal displays the target special effect image, and optionally, the user can also use the image editing function ( Figure 2 (not shown) edit the target special effect image; then the user touches the "Next" function button in the special effect image page, and the user terminal responds to the touch operation and displays the publishing page; then the user can touch the "Publish" function button to publish the target special effect image in the publishing page. Optionally, the user can also edit the text on the publishing page ( Figure 2 (not shown), and then by touching the "Publish" function button, the target special effect image and text are published together, that is, the graphic note is published. Optionally, the user can also choose to add target audio on the special effect image page or the publishing page, and then the user can touch the "Publish" function button to publish the target special effect image and target audio on the publishing page, that is, the target audio can be understood as the soundtrack at this time, and this application does not make specific limitations.
[0056] See also Figure 3 , Figure 3 A flowchart of an image processing method provided in an embodiment of the present application is provided. The method is applied to the image processing device in the above embodiment. The method includes but is not limited to the following steps S301-S304:
[0057] S301: Obtain an image to be processed.
[0058] In an embodiment of the present application, a user may upload an image to be processed to a user terminal, and then the user terminal sends the image to be processed to an image processing device, and accordingly, the image processing device obtains the image to be processed.
[0059] S302 , performing threshold processing on the image to be processed to obtain a first image.
[0060] In an embodiment of the present application, the image to be processed may be subjected to thresholding processing, i.e., binarization processing. For example, a preset target threshold value may be obtained, such as 230. It should be noted that the present application does not limit the specific value of the target threshold value. Then, the pixel values of the pixels in the image to be processed whose pixel values are greater than the target threshold value are determined as the maximum grayscale value, i.e., 255, and the pixel values of the pixels in the image to be processed whose pixel values are less than the target threshold value are determined as the minimum grayscale value, i.e., 0. Thus, a first image may be obtained. At this time, the pixel values of the pixels in the first image are the maximum grayscale value or the minimum grayscale value. In other words, the first image is a binary image at this time. The area corresponding to the pixel points in the first image whose pixel values are the maximum grayscale value may be referred to as a special effect area. If the special effect is a highlight special effect, it may also be referred to as a highlight area. For example, refer to Figure 4 , Figure 4 A schematic diagram of performing threshold processing on an image to be processed to obtain a first image is provided in an embodiment of the present application, such as Figure 4 As shown, the image to be processed is thresholded to obtain a first image.
[0061] S303: Determine a target pixel point corresponding to the connected domain based on the area of the connected domain in the first image.
[0062] Before executing step S304, a connected domain is obtained from the first image. For example, connected domain identification can be performed directly from the first image to obtain a connected domain, and the number of the connected domains can be one or more. Alternatively, edge detection can be performed on the first image to obtain an edge image, and then connected domain identification can be performed on the edge image to obtain a corresponding connected domain. Optionally, edge detection can be performed on the first image to obtain an edge image, wherein the edge detection can adopt a Sobel edge detection algorithm, a Canny edge detection algorithm, etc., and the values of the dual thresholds (including both high thresholds and low thresholds) used when executing the specific edge detection algorithm can be, for example, 50 and 200 respectively. It should be noted that the present application does not specifically limit the values of the dual thresholds; then the edge image is expanded to obtain an expanded image, for example, each pixel in the edge image is directly replaced by the maximum value of the adjacent pixels of each pixel to obtain the expanded image, or the edge image can be first subjected to a Gaussian filter convolution operation to obtain a second image, wherein the size of the Gaussian kernel can be 5*5, and the present application does not specifically limit the size of the Gaussian kernel; then the second image is expanded, that is, each pixel in the second image is replaced by the maximum value of the adjacent pixels of each pixel to obtain the expanded image, and so on. The present application does not limit the specific method of expansion; further, the expanded image is identified as a connected domain to obtain a corresponding connected domain. At this time, the number of connected domains is one or more, and the embodiment of the present application is mainly explained by taking one connected domain as an example. It should be explained that, after thresholding the image to be processed, the originally connected may be broken, and after the edge image is expanded, the boundary can be expanded and the break can be eliminated, so that subsequent image analysis such as the identification of connected domains is more accurate, thereby improving the accuracy of determining target pixels. Figure 4 , see Figure 5 , Figure 5 A schematic diagram of obtaining a dilated image from a first image provided in an embodiment of the present application is as follows: Figure 5 As shown, edge detection is performed on the first image to obtain an edge image, and then a dilation operation is performed on the edge image to obtain a dilated image.
[0063] In an optional embodiment, after obtaining a connected domain from the first image, if there are multiple connected domains, the multiple connected domains can also be screened, for example, the pixel value of each pixel in each connected domain is obtained, and then based on the pixel value of each pixel in each connected domain and the area of each connected domain, the multiple connected domains are screened to obtain the screened connected domain, wherein the gray value of each pixel in the screened connected domain is within a preset gray threshold interval, and the area of the screened connected domain is greater than the second threshold and less than the third threshold, wherein the first threshold is greater than the second threshold and less than the third threshold, or the first threshold is much greater than the second threshold and much less than the third threshold. It should be explained that in this embodiment, after determining multiple connected domains, the multiple connected domains are screened to obtain the screened connected domains by the area size of the connected domain and the gray value of each pixel in the connected domain, which can avoid the connected domain from being too large, too small, too dark, too many, etc., and thus can improve the accuracy of the subsequent determination of the target pixel corresponding to the connected domain based on the area of the connected domain, that is, the accuracy of the determination of the highlight pixel, so as to ensure the presentation effect of the subsequent highlight special effect.
[0064] In the embodiments of the present application, the area of a connected domain may be the total number of pixels in the connected domain; or the minimum circumscribed figure of the connected domain (such as the minimum circumscribed rectangle, the minimum circumscribed circle, etc.) may be determined, and then the area of the minimum circumscribed figure of the connected domain may be taken as the area of the connected domain, that is, the area of the connected domain may be in pixels, and the present application does not limit the method for determining the area of the connected domain. It should be explained that since the number of connected domains obtained in the embodiments of the present application may be one or more, the principle of determining the target pixel points corresponding to each connected domain is similar, and the present application mainly uses a connected domain as an example for explanation.
[0065] Then, based on the area of the connected domain, the target pixel points corresponding to the connected domain are determined. Exemplarily, a first mapping relationship between the area of the connected domain and the sampling distance is preset, wherein the first mapping relationship indicates that the smaller the area of the connected domain, the larger the corresponding sampling distance, and the sampling distance can be in pixels; then, based on the area of the connected domain and the first mapping relationship, the sampling distance corresponding to the area of the connected domain can be obtained; then, based on the sampling distance corresponding to the connected domain, the contour pixel points of the connected domain are sampled to obtain the target pixel points corresponding to the connected domain. At this time, the number of the target pixel points is one or more, and the specific number of the target pixel points depends on the number of contour pixel points and the sampling distance. For example, if the sampling distance is 1 0 pixels, then the contour pixels are sampled every 10 pixels, and the sampled pixels are used as the corresponding target pixels. It should be explained that for the connected domain of the highlight area, the density of the sampling points reflects its importance and the highlight intensity. By setting the relationship between the sampling distance and the area of the connected domain, it is helpful to more accurately highlight the highlight features in other image processing (such as highlight detection and image enhancement), ensure the uniformity of the sampled pixels in the connected domains of different areas, and avoid too sparse or too dense sampling in the connected domains of different areas. In other words, the sampling density is adaptively adjusted according to the area of the connected domain, so as to reduce unnecessary calculations while retaining important information.
[0066] In an optional embodiment, determining the target pixel corresponding to the connected domain based on the area of the connected domain can also be obtained by the following implementation: judging the relationship between the area of the connected domain and the first threshold, and the present application does not specifically limit the first threshold; if the area of the connected domain is less than the first threshold, obtaining the aspect ratio of the connected domain, wherein the aspect ratio of the connected domain may be the aspect ratio of the minimum circumscribed rectangle of the connected domain, such as the ratio of the width to the height or the ratio of the height to the width of the minimum circumscribed rectangle. Of course, the aspect ratio may also be referred to as the length-to-width ratio, that is, the ratio of the length to the width or the ratio of the width to the length of the minimum circumscribed rectangle, and the present application does not limit it; then determining the target pixel corresponding to the connected domain based on the aspect ratio of the connected domain, exemplarily:
[0067] If the aspect ratio of the connected domain is greater than the first preset value and less than the second preset value, the centroid of the connected domain can be determined as the target pixel corresponding to the connected domain. For example, if the first preset value is less than 1 and the second preset value is greater than 1, the aspect ratio of the connected domain is greater than the first preset value and less than the second preset value, indicating that the width and height of the connected domain are relatively close, and the shape is close to a square, which is a relatively regular shape. In addition, the area of the connected domain is less than the first threshold at this time, which means that the area of the connected domain is small and the shape is relatively regular. The centroid of the connected domain can be used as the target pixel corresponding to the connected domain, which improves the accuracy of determining the target pixel, thereby increasing the matching degree between the target pixel and the connected domain, so that special effects are only added to the centroid of the connected domain in the future. This not only indicates the highlight characteristics of the highlight area where the connected domain is located, but also avoids the excessive presentation of the highlight effect due to large-scale overlap of special effects compared to adding special effects to each pixel in the connected domain, thereby making the quality of the final target special effect image better.
[0068] If the aspect ratio of the connected domain is less than the first preset value or greater than the second preset value, the target pixel point corresponding to the connected domain is determined based on the contour pixel points of the connected domain, for example, based on the above-mentioned first mapping relationship, the sampling distance corresponding to the area of the connected domain is obtained, and then the contour pixel points of the connected domain are sampled based on the sampling distance to obtain the target pixel point corresponding to the connected domain. Optionally, the first pixel point can also be determined based on the contour pixel points of the connected domain, for example, the sampling distance corresponding to the area of the connected domain is obtained, for example, the sampling distance corresponding to the area of the connected domain is obtained based on the above-mentioned first mapping relationship, wherein the smaller the area of the connected domain, the larger the corresponding sampling distance; then based on the sampling distance, the contour pixel points of the connected domain are sampled to obtain the first pixel point, and the number of the first pixel points is one or more at this time; then the centroid or center of the connected domain and the first pixel point are determined as the target pixel point corresponding to the connected domain, that is, the number of the target pixel points is multiple at this time. It should be explained that if the aspect ratio of the connected domain is less than the first preset value or greater than the second preset value, it means that the width is much greater than the height or the width is much less than the height, and the shape of the connected domain is close to a long strip. In addition, the area of the connected domain is less than the first threshold at this time, which means that the area of the connected domain is small and the shape is irregular. If each pixel point in the connected domain is used as a target pixel point, it will be too dense, resulting in a large range of overlap of subsequent special effects. Based on the sampling distance corresponding to the area of the connected domain, the contour pixels of the connected domain can be sparsely sampled, which can improve the accuracy of determining the target pixel points and ensure the presentation of special effects.
[0069] Of course, after determining the centroid or center of the connected domain and the first pixel point as the target pixel point corresponding to the connected domain, or after obtaining the target pixel point corresponding to the connected domain as mentioned above, the target pixel points corresponding to the connected domain can also be screened. For example: obtain a preset distance threshold, wherein the distance threshold is in pixels, and the present application does not limit the specific value of the distance threshold; since the number of connected domains is one or more, and the number of target pixel points corresponding to each connected domain is one or more, the target pixel points corresponding to each connected domain can be screened based on the distance threshold to obtain the target pixel points in the image to be processed, that is, the screened target pixel points in the image to be processed, at this time, the distance between any two target pixel points in the screened target pixel points is greater than or equal to the above distance threshold. For example, based on all target pixel points corresponding to one or more connected domains, one or more target pixel pairs corresponding to each target pixel point in all the target pixel points are determined, wherein each Each target pixel pair corresponding to a target pixel is constructed for each target pixel and each target pixel among all the target pixels except the target pixel; then the first distance between the target pixels in each target pixel pair is calculated, wherein the first distance may be a Euclidean distance, a block distance, a chessboard distance, etc., which is not specifically limited in the present application; if the first distance corresponding to each target pixel pair is less than the above-mentioned distance threshold, any one of the target pixel points in each target pixel pair is discarded, and the target pixel points among all the target pixel points corresponding to one or more connected domains except the above-mentioned discarded target pixel points are determined as the filtered target pixel points; if the first distance corresponding to each target pixel pair is greater than the above-mentioned distance threshold, all the target pixel points corresponding to one or more connected domains are determined as the filtered target pixel points, and then the corresponding special effects are added to the filtered target pixel points in the image to be processed to obtain a target special effect image, which can improve the effect of the target special effect image.
[0070] For example, based on Figure 5 , see Figure 6 , Figure 6 A schematic diagram of screening target pixels provided in an embodiment of the present application is as follows: Figure 6 As shown, after the expansion image is obtained based on the principle of the above embodiment, the connected domain can be identified on the expansion image to obtain the corresponding connected domain, and then the target pixel point corresponding to the connected domain is determined according to the area of the connected domain based on the above embodiment, that is, Figure 6 The target pixel points in the image to be processed are shown (that is, all target pixel points corresponding to all connected domains); then, based on the distance threshold, the target pixel points in the image to be processed are screened to obtain the screened target pixel points, and the principle will not be repeated here.
[0071] It should be explained that in an embodiment of the present application, after determining the target pixel points corresponding to each connected domain, the present application also traverses all target pixel points corresponding to all connected domains, and screens all target pixel points based on a distance threshold, so that the distance between any two target pixel points in the new target pixel points finally obtained is greater than or equal to the distance threshold, thereby avoiding the target pixel points being too close. Then, when adding special effects to each target pixel point, the impact of large-scale overlap of special effects caused by the small distance between target pixel points can be reduced accordingly, thereby improving the special effects effect of the target special effects image.
[0072] S304 , adding corresponding special effects to target pixels in the image to be processed to obtain a target special effect image.
[0073] In an embodiment of the present application, after determining the target pixel point, the texture pixel corresponding to the special effect can be obtained, and then the texture pixel corresponding to the special effect can be superimposed or mixed with the texture pixel of each target pixel point in the image to be processed, that is, the special effect is added to the target pixel point in the image to be processed to obtain the target special effect image.
[0074] In an optional embodiment, the depth value of the target pixel in the image to be processed can also be obtained. For example, based on the image to be processed, a depth map corresponding to the image to be processed is obtained, and then the depth value of the target pixel is determined based on the depth map; then, based on the depth value of the target pixel, a target special effect image corresponding to the depth value of the target pixel is obtained from a plurality of preset candidate special effect material images. In an embodiment of the present application, a plurality of candidate special effect material images can be preset, and the plurality of candidate special effect material images correspond one-to-one to a plurality of preset depth value intervals. The plurality of candidate special effect material images have different blurring degrees, and the larger the depth value interval (that is, the magnitude relationship of the depth values between the plurality of depth value intervals is a trend of gradually increasing), the larger the blurring degree of the corresponding candidate special effect material image. The blurring degree of the candidate special effect material image is positively correlated with the depth value. Therefore, the depth value interval corresponding to the target pixel can be determined based on the depth value of the target pixel, and then the corresponding target special effect image can be obtained from a plurality of candidate special effect material images based on the depth value interval corresponding to the target pixel. It should be noted that the present application does not limit the specific style of the material in the candidate special effect material image.
[0075] Then, based on the target special effect material image corresponding to the target pixel point, the target special effect material image is superimposed on the target pixel point in the image to be processed to obtain the target special effect image, exemplarily: the material area corresponding to the target pixel point in the image to be processed is obtained, for example, the center of the material area corresponding to the target pixel point is the target pixel point, and the size of the material area is the same as the size of the target special effect material image, for example, the size of the material area is 50*50; then the first texture coordinates of the vertices of the material area corresponding to the target pixel point in the image to be processed are obtained; then, based on the first texture coordinates corresponding to the vertices of the material area corresponding to the target pixel point, the second texture coordinates of the vertices of the material area corresponding to the target pixel point in the target special effect material image are determined; then, based on the second texture coordinates corresponding to the vertices of the material area corresponding to the target pixel point, the second texture coordinates of each pixel point in the material area corresponding to the target pixel point in the target special effect material image are determined; then, the texture pixels corresponding to the first texture coordinates of each pixel point in the material area corresponding to the target pixel point in the image to be processed and the texture pixels corresponding to the second texture coordinates of each pixel point in the material area corresponding to the target pixel point in the target special effect material image are superimposed to obtain the target special effect image.
[0076] For example, based on Figure 6 , see Figure 7 , Figure 7 A schematic diagram of adding a corresponding special effect to a target pixel in an image to be processed to obtain a target special effect image is provided in an embodiment of the present application, such as Figure 7 As shown, a depth map corresponding to the image to be processed is obtained based on the image to be processed, and then based on the depth map, the screened target pixel points, that is, the screened target pixel points in the image to be processed, and multiple candidate special effect material images ( Figure 7 The multiple candidate special effects material images shown have different degrees of blur), generate a target special effects image, specifically, determine the depth value of the screened target pixel based on the depth map, and then based on the depth value of the screened target pixel, obtain the target special effects material image corresponding to the depth value of the screened target pixel from the multiple candidate special effects material images, and then based on the target special effects material image corresponding to the depth value of the screened target pixel, superimpose the target special effects material image on the screened target pixel in the image to be processed to obtain the target special effects image. The principle will not be repeated here.
[0077] It should be explained that in the embodiments of the present application, for the captured image, if the object in the image is closer to the shooting device, the corresponding effect of the object in the captured image is clearer. Similarly, if the object is farther away from the shooting device, the corresponding effect of the object in the captured image is more blurred. In short, the object is clear when it is close and blurred when it is far away. Figure 7As shown in the image to be processed, the sky in the image to be processed is far away compared to the shooting device, so the closer to the sky, the blurrier the effect. For the fireworks in the image to be processed, as they are farther and farther away from the sky when viewed from top to bottom, the blurriness of the fireworks decreases from large to small when viewed from top to bottom. Therefore, in order to simulate the realism of the image taken by the shooting device, the present application pre-generates a corresponding candidate special effects material image for each depth value interval according to multiple depth value intervals of different levels, and then obtains the above-mentioned multiple candidate special effects material images, and the multiple candidate special effects material images correspond to different blurriness, that is, the larger the depth value, the greater the blurriness. Subsequently, based on the depth value of each target pixel point, the target special effects material image corresponding to each target pixel point can be determined from the multiple candidate special effects material images, and then the target special effects material image corresponding to each target pixel point can be superimposed on each target pixel point in the image to be processed. point, so that the target special effect image can present a sense of reality similar to that captured by the shooting equipment; in addition, in terms of superimposing special effect materials, the existing method generally first superimposes the initial candidate special effect material image without blur to the corresponding target pixel point to obtain a third image, and then blurs the third image, but the image blurred in this way cannot present a sense of reality similar to that captured by the shooting equipment. Even if the third image can be blurred to different degrees according to the depth values of the pixel points, the requirements for computing power are higher, which will increase the computing power burden and reduce performance. Therefore, the embodiment of the present application first generates candidate special effect material images with different blur levels, and then they can be directly superimposed on the corresponding target pixel point, which can not only present a sense of reality similar to that captured by the shooting equipment, but also has lower requirements for computing power, will not increase the computing power burden, and improve performance.
[0078] In an optional embodiment, when obtaining the material area corresponding to the target pixel in the image to be processed, the material area corresponding to the target pixel can also be determined based on the area of the connected domain corresponding to the target pixel, wherein the number of the material areas corresponding to the target pixel is one or more, which is not limited in this application, and is exemplary:
[0079] First, the shape of each material area includes a target shape (such as a square, rectangle, circle, and other polygons, which are not specifically limited in this application). Based on the area of the connected domain corresponding to the target pixel, the size of the target shape corresponding to the target pixel is determined. When the target shape is a square, the size is the side length of the square. The same is true for other target shapes, which are not explained one by one here. In an embodiment of the present application, there is a preset second mapping relationship between the size of the target shape and the area of the connected domain, and the second mapping relationship indicates that the size of the target shape is positively correlated with the area of the connected domain. Then, the size of the target shape corresponding to the target pixel can be determined based on the area of the connected domain corresponding to the target pixel and the second mapping relationship.
[0080] Then, based on the target pixel point and the size of the target shape corresponding to the target pixel point, the first material area corresponding to the target pixel point is determined, wherein the shape and size of the first material area corresponding to the target pixel point are the target shape corresponding to the target pixel point and the size of the target shape, and the center of the first material area is the target pixel point. For example, when the target shape is a square, the first material area corresponding to the target pixel point is based on the target pixel point as the center of the square, and based on the size of the target shape corresponding to the target pixel point, extends from the target pixel point to all sides to obtain the first material area corresponding to the target pixel point. At this time, the shape of the first material area is a square and the center is the target pixel point.
[0081] Then, the first material area corresponding to the target pixel point can be determined as the material area corresponding to the target pixel point; or, the first material area corresponding to the target pixel point can also be translated to obtain one or more second material areas corresponding to the target pixel point, for example, the first material area corresponding to the target pixel point is translated in a preset direction and at a preset translation distance to obtain one or more second material areas corresponding to the target pixel point, wherein the preset translation distance can be a preset distance, or a preset ratio of the size of the target shape (for example, if the target shape is a square, the target translation distance can be a preset ratio of the side length of the square, such as 1 / 2, which is not limited in this application), and this application does not limit the preset translation distance; the preset direction, taking a two-dimensional coordinate system as an example, can include one or more of horizontal right, horizontal left, horizontal upward, horizontal downward, a direction that forms a preset angle with the horizontal direction or the vertical direction, the direction of the special effect material in the candidate special effect material image, etc. It should be explained that the direction of the special effect material is the direction in which the special effect material forms a preset angle with the horizontal direction and / or the vertical direction in the two-dimensional coordinate system, and this application does not limit the preset angle.
[0082] Finally, based on the first material area corresponding to the target pixel and the one or more second material areas corresponding to the target pixel, the material area corresponding to the target pixel is determined, for example, the first material area corresponding to the target pixel and the one or more second material areas corresponding to the target pixel are both determined as the material area corresponding to the target pixel, that is, at this time, the number of material areas corresponding to the target pixel is multiple; or optionally, the one or more second material areas corresponding to the target pixel can be screened to obtain the third material area corresponding to the target pixel, for example, the grayscale value of each pixel in each second material area corresponding to the target pixel is summed and averaged to obtain the average grayscale value of each second material area corresponding to the target pixel, and then based on the average grayscale value of each second material area corresponding to the target pixel, the one or more second material areas corresponding to the target pixel are screened to obtain the third material area corresponding to the target pixel, wherein the average grayscale value corresponding to the third material area corresponding to the target pixel is in a preset grayscale interval, and then the third material area corresponding to the target pixel and the first material area corresponding to the target pixel can be both determined as the material area corresponding to the target pixel.
[0083] In an optional embodiment, when obtaining the material area corresponding to the target pixel in the image to be processed, the material area corresponding to the target pixel can also be determined based on the area of the connected domain corresponding to the target pixel, wherein the number of the material areas corresponding to the target pixel is one or more, which is not limited in this application, and is exemplary:
[0084] Based on the area of the connected domain corresponding to the target pixel point, all the target pixel points corresponding to one or more connected domains are classified to obtain multiple types of target pixel points, wherein the multiple types correspond one-to-one to multiple preset area intervals; then the fourth material area corresponding to each target pixel point among all the target pixel points corresponding to the one or more connected domains is determined, wherein the principle of determining the fourth material area corresponding to each target pixel point among all the target pixel points corresponding to the one or more connected domains is similar to the principle of determining the first material area corresponding to the target pixel point mentioned above, and will not be repeated here; then the fourth material area corresponding to each target pixel point, based on the type corresponding to each target pixel point, determines the material area corresponding to each target pixel point, for example: the multiple types include the first type, the second type, and the third type, wherein the minimum value of the area interval corresponding to the target pixel point of the second type is greater than the maximum value of the area interval corresponding to the target pixel point of the first type and is less than the minimum value of the area interval corresponding to the target pixel point of the third type, that is, the target pixel points are divided into small (corresponding to the first type), medium (corresponding to the second type), and large (corresponding to the third type) target pixel points; then, for the first type of target pixel points and the third type of target pixel points, the first material area corresponding to the first type of target pixel points and the third type of target pixel points is determined as the material area corresponding to the first type of target pixel points and the third type of target pixel points, that is, at this time, the number of material areas corresponding to the first type of target pixel points and the third type of target pixel points is one; for the second type of target pixel points, the first material area corresponding to the second type of target pixel points is translated to obtain one or more second material areas corresponding to the second type of target pixel points (the principle is similar to the principle of determining one or more second material areas corresponding to each target pixel point in the above embodiment, which will not be repeated here); then, the one or more second material areas corresponding to the second type of target pixel points and the first material area corresponding to the second type of target pixel points are determined as the material area corresponding to the second type of target pixel points, that is, at this time, the number of material areas corresponding to the second type of target pixel points is multiple.
[0085] It should be explained that, in an embodiment of the present application, the material area corresponding to the target pixel point, in addition to the corresponding first material area, may also include a second material area obtained by translating the first material area, that is, by increasing the number of material areas corresponding to the target pixel point, the diversity of special effects display can be improved, and then the quality of special effects images can be improved.
[0086] Finally, based on one or more material areas corresponding to each target pixel and the target special effect material image corresponding to each target pixel, the target special effect material image corresponding to each target pixel in the image to be processed is superimposed on each material area corresponding to each target pixel in the image to be processed to obtain the target special effect image. The principle will not be repeated here.
[0087] See also Figure 8 , Figure 8 A flowchart of another image processing method provided in an embodiment of the present application is provided. The method is applied to the image processing device in the above embodiment. The method includes but is not limited to the following steps S801-S806:
[0088] S801: Obtain an image to be processed.
[0089] S802: Perform thresholding processing on the image to be processed to obtain a first image.
[0090] S803, determining whether the area of the connected domain in the first image is less than a first threshold, if so, executing step S804, if not, executing step S805.
[0091] S804: Determine a target pixel point corresponding to the connected domain based on the aspect ratio of the connected domain.
[0092] S805: Determine target pixel points corresponding to the connected domain based on the contour pixel points of the connected domain.
[0093] S806 , adding corresponding special effects to target pixels in the image to be processed to obtain a target special effect image.
[0094] In the embodiment of the present application, the principles of steps S801-S806 have been explained in the embodiment corresponding to the above steps S301-S304, and will not be repeated here.
[0095] It should be noted that for the embodiments of the present application involving size relationships such as greater than, less than, etc., the relationship of "equal to" can be on the greater than relationship side, that is, greater than or equal to, or on the less than relationship side, that is, less than or equal to, and this application does not make specific limitations.
[0096] See also Fig. 9 , Fig. 9 This is a block diagram of the functional units of an image processing device provided in an embodiment of the present application. The image processing device includes: a first acquisition unit 901 and a first processing unit 902;
[0097] A first acquisition unit 901 is used to acquire an image to be processed;
[0098] A first processing unit 902 is used to perform threshold processing on the image to be processed to obtain a first image;
[0099] The first processing unit 902 is further configured to determine a target pixel point corresponding to the connected domain based on the area of the connected domain in the first image;
[0100] The first processing unit 902 is further configured to add corresponding special effects to target pixels in the image to be processed to obtain a target special effect image.
[0101] In one embodiment of the present application, in determining the target pixel corresponding to the connected domain based on the area of the connected domain, the first processing unit 902 is specifically configured to:
[0102] If the area of the connected domain is less than the first threshold, obtaining the aspect ratio of the connected domain;
[0103] Based on the aspect ratio of the connected domain, determine the target pixel point corresponding to the connected domain;
[0104] If the area of the connected domain is greater than the first threshold, obtaining the contour pixel points of the connected domain;
[0105] Based on the contour pixels of the connected domain, the target pixels corresponding to the connected domain are determined.
[0106] In one embodiment of the present application, in determining the target pixel corresponding to the connected domain based on the aspect ratio of the connected domain, the first processing unit 902 is specifically configured to:
[0107] If the aspect ratio is greater than the first preset value and less than the second preset value, the centroid of the connected domain is determined as the target pixel point corresponding to the connected domain;
[0108] If the aspect ratio is less than the first preset value or greater than the second preset value, a target pixel point corresponding to the connected domain is determined based on the contour pixel points of the connected domain.
[0109] In one embodiment of the present application, in determining the target pixel point corresponding to the connected domain based on the contour pixel point of the connected domain, the first processing unit 902 is specifically configured to:
[0110] Determine a first pixel point based on the contour pixel points of the connected domain;
[0111] The centroid of the connected domain and the first pixel point are determined as the target pixel point corresponding to the connected domain.
[0112] In one embodiment of the present application, in determining the first pixel point based on the contour pixel points of the connected domain, the first processing unit 902 is specifically configured to:
[0113] Obtaining a sampling distance corresponding to the area of the connected domain, wherein the smaller the area of the connected domain is, the larger the corresponding sampling distance is;
[0114] Based on the sampling distance, the contour pixel points are sampled to obtain the first pixel point.
[0115] In one embodiment of the present application, in terms of adding a corresponding special effect to a target pixel in an image to be processed to obtain a target special effect image, the first processing unit 902 is specifically configured to:
[0116] Get the depth value of the target pixel;
[0117] Based on the depth value of the target pixel, a target special effect material image corresponding to the depth value of the target pixel is obtained from a plurality of preset candidate special effect material images;
[0118] Based on the target special effect material image corresponding to the target pixel point, the target special effect material image is superimposed on the target pixel point in the image to be processed to obtain the target special effect image.
[0119] In one embodiment of the present application, multiple candidate special effect material images correspond one-to-one to multiple preset depth value intervals, and the blurriness of the multiple candidate special effect material images is different, and the larger the depth value interval, the greater the blurriness of the candidate special effect material image.
[0120] In one embodiment of the present application, in terms of obtaining a target special effect image by superimposing the target special effect material image on the target pixel in the image to be processed based on the target special effect material image corresponding to the target pixel, the first processing unit 902 is specifically configured to:
[0121] Obtain the material area corresponding to the target pixel point in the image to be processed;
[0122] Obtain the first texture coordinate of the vertex of the material area corresponding to the target pixel point in the image to be processed;
[0123] Determine, based on the first texture coordinates corresponding to the vertices of the material area corresponding to the target pixel point, the second texture coordinates of the vertices of the material area corresponding to the target pixel point in the target special effect material image;
[0124] Determine the second texture coordinates of each pixel in the material area corresponding to the target pixel in the target special effect material image based on the second texture coordinates corresponding to the vertices of the material area corresponding to the target pixel;
[0125] The texture pixels corresponding to the first texture coordinates of each pixel point in the material area corresponding to the target pixel point in the image to be processed and the texture pixels corresponding to the second texture coordinates of each pixel point in the material area corresponding to the target pixel point in the target special effect material image are superimposed to obtain the target special effect image.
[0126] In one embodiment of the present application, before determining the target pixel corresponding to the connected domain based on the area of the connected domain in the first image, the first processing unit 902 is specifically configured to:
[0127] Performing edge detection on the first image to obtain an edge image;
[0128] Expand the pixels in the edge image to obtain an expanded image;
[0129] Connected domains are identified on the dilated image to obtain connected domains.
[0130] In one embodiment of the present application, the number of connected domains is one or more, and the first processing unit 902 is specifically configured to:
[0131] Get the preset distance threshold;
[0132] Based on the distance threshold, all target pixel points corresponding to each connected domain are screened to obtain target pixel points in the image to be processed, wherein the distance between any two target pixel points in the image to be processed is greater than or equal to the distance threshold.
[0133] In a specific implementation, the first acquisition unit 901 and the first processing unit 902 described in the embodiment of the present invention may execute other implementations described in the embodiment of the image processing method provided by the embodiment of the present invention, which will not be described in detail here.
[0134] See also Fig.10 , Fig.10 This is a block diagram of the functional units of another image processing device provided in an embodiment of the present application. The image processing device includes: a second acquisition unit 1001 and a second processing unit 1002;
[0135] The second acquisition unit 1001 is used to acquire an image to be processed;
[0136] The second processing unit 1002 is used to perform threshold processing on the image to be processed to obtain a first image;
[0137] The second processing unit 1002 is further configured to determine a target pixel corresponding to the connected domain based on the aspect ratio of the connected domain if the area of the connected domain in the first image is smaller than the first threshold;
[0138] The second processing unit 1002 is further configured to determine a target pixel point corresponding to the connected domain based on the contour pixel points of the connected domain if the area of the connected domain in the first image is greater than the first threshold value;
[0139] The second processing unit 1002 is further configured to add corresponding special effects to target pixels in the image to be processed to obtain a target special effect image.
[0140] In a specific implementation, the second acquisition unit 1001 and the second processing unit 1002 described in the embodiment of the present invention may execute other implementations described in the embodiment of the image processing method provided by the embodiment of the present invention, which will not be described in detail here.
[0141] See also Fig.11 , Fig.11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig.11 As shown, the electronic device 1100 includes a transceiver 1101, a processor 1102 and a memory 1103. They are connected via a bus 1104. The memory 1103 is used to store computer programs and data, and can transmit the data stored in the memory 1103 to the processor 1102.
[0142] The processor 1102 is used to read the computer program in the memory 1103 and perform the following operations:
[0143] Control the transceiver 1101 to obtain an image to be processed; perform thresholding processing on the image to be processed to obtain a first image; determine a target pixel point corresponding to the connected domain based on the area of the connected domain in the first image; add a corresponding special effect to the target pixel point in the image to be processed to obtain a target special effect image;
[0144] Alternatively, the transceiver 1101 is controlled to obtain an image to be processed; thresholding is performed on the image to be processed to obtain a first image; a connected domain is obtained from the first image; if the area of the connected domain in the first image is less than the first threshold, the target pixel points corresponding to the connected domain are determined based on the aspect ratio of the connected domain; if the area of the connected domain in the first image is greater than the first threshold, the target pixel points corresponding to the connected domain are determined based on the contour pixel points of the connected domain; corresponding special effects are added to the target pixel points in the image to be processed to obtain a target special effect image.
[0145] In one embodiment of the present application, in terms of determining the target pixel corresponding to the connected domain based on the area of the connected domain, the processor 1102 is specifically configured to perform the following steps:
[0146] If the area of the connected domain is less than the first threshold, obtaining the aspect ratio of the connected domain;
[0147] Based on the aspect ratio of the connected domain, determine the target pixel point corresponding to the connected domain;
[0148] If the area of the connected domain is greater than the first threshold, obtaining the contour pixel points of the connected domain;
[0149] Based on the contour pixels of the connected domain, the target pixels corresponding to the connected domain are determined.
[0150] In one embodiment of the present application, in determining the target pixel corresponding to the connected domain based on the aspect ratio of the connected domain, the processor 1102 is specifically configured to perform the following steps:
[0151] If the aspect ratio is greater than the first preset value and less than the second preset value, the centroid of the connected domain is determined as the target pixel point corresponding to the connected domain;
[0152] If the aspect ratio is less than the first preset value or greater than the second preset value, a target pixel point corresponding to the connected domain is determined based on the contour pixel points of the connected domain.
[0153] In one embodiment of the present application, in determining the target pixel points corresponding to the connected domain based on the contour pixel points of the connected domain, the processor 1102 is specifically configured to perform the following steps:
[0154] Determine a first pixel point based on the contour pixel points of the connected domain;
[0155] The centroid of the connected domain and the first pixel point are determined as the target pixel point corresponding to the connected domain.
[0156] In one embodiment of the present application, in determining the first pixel point based on the contour pixel points of the connected domain, the processor 1102 is specifically configured to perform the following steps:
[0157] Obtaining a sampling distance corresponding to the area of the connected domain, wherein the smaller the area of the connected domain is, the larger the corresponding sampling distance is;
[0158] Based on the sampling distance, the contour pixel points are sampled to obtain the first pixel point.
[0159] In one embodiment of the present application, in terms of adding a corresponding special effect to a target pixel in an image to be processed to obtain a target special effect image, the processor 1102 is specifically configured to perform the following steps:
[0160] Get the depth value of the target pixel;
[0161] Based on the depth value of the target pixel, a target special effect material image corresponding to the depth value of the target pixel is obtained from a plurality of preset candidate special effect material images;
[0162] Based on the target special effect material image corresponding to the target pixel point, the target special effect material image is superimposed on the target pixel point in the image to be processed to obtain the target special effect image.
[0163] In one embodiment of the present application, multiple candidate special effect material images correspond one-to-one to multiple preset depth value intervals, and the blurriness of the multiple candidate special effect material images is different, and the larger the depth value interval, the greater the blurriness of the candidate special effect material image.
[0164] In one embodiment of the present application, in terms of obtaining the target special effect image by superimposing the target special effect material image on the target pixel in the image to be processed based on the target special effect material image corresponding to the target pixel, the processor 1102 is specifically configured to perform the following steps:
[0165] Obtain the material area corresponding to the target pixel point in the image to be processed;
[0166] Obtain the first texture coordinate of the vertex of the material area corresponding to the target pixel point in the image to be processed;
[0167] Determine, based on the first texture coordinates corresponding to the vertices of the material area corresponding to the target pixel point, the second texture coordinates of the vertices of the material area corresponding to the target pixel point in the target special effect material image;
[0168] Determine the second texture coordinates of each pixel in the material area corresponding to the target pixel in the target special effect material image based on the second texture coordinates corresponding to the vertices of the material area corresponding to the target pixel;
[0169] The texture pixels corresponding to the first texture coordinates of each pixel point in the material area corresponding to the target pixel point in the image to be processed and the texture pixels corresponding to the second texture coordinates of each pixel point in the material area corresponding to the target pixel point in the target special effect material image are superimposed to obtain the target special effect image.
[0170] In one embodiment of the present application, before determining the target pixel corresponding to the connected domain based on the area of the connected domain in the first image, the processor 1102 is specifically configured to perform the following steps:
[0171] Performing edge detection on the first image to obtain an edge image;
[0172] Expand the pixels in the edge image to obtain an expanded image;
[0173] Connected domains are identified on the dilated image to obtain connected domains.
[0174] In one embodiment of the present application, the number of connected domains is one or more, and the first processing unit 902 is specifically configured to:
[0175] Get the preset distance threshold;
[0176] Based on the distance threshold, the target pixel points corresponding to each connected domain are screened to obtain the target pixel points in the image to be processed, wherein the distance between any two target pixel points in the image to be processed is greater than or equal to the distance threshold.
[0177] Specifically, the transceiver 1101 may be Fig. 9The first acquisition unit 901 of the image processing device of the embodiment, Fig.10 The second acquisition unit 1001 of the image processing device of the embodiment, the processor 1102 may be Fig. 9 The first processing unit 902 of the image processing device of the embodiment, Fig.10 The second processing unit 1002 of the image processing apparatus of the embodiment.
[0178] In a specific implementation, the transceiver 1101 and the processor 1102 described in the embodiment of the present invention may also execute other implementations described in the embodiment of the image processing method provided in the embodiment of the present invention, which will not be described in detail here.
[0179] It should be understood that the electronic device in this application can be an image processing device, and the image processing device can be a server, such as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and basic cloud computing services such as big data and artificial intelligence platforms, which are not specifically limited in this application. The above electronic devices are only examples, not exhaustive, and include but are not limited to the above electronic devices.
[0180] It should be understood that the embodiments of the present application also provide a computer-readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement part or all of the steps of any image processing method recorded in the above method embodiments.
[0181] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute part or all of the steps of any image processing method recorded in the above method embodiments.
[0182] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0183] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0184] In the several embodiments provided in the present application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple 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 or other forms.
[0185] 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 multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0186] 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 integrated unit may be implemented in the form of hardware or in the form of a software program module.
[0187] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, 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, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of each embodiment method of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0188] A person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable memory, and the memory can include: a flash drive, a read-only memory (English: Read-Only Memory, abbreviated as: ROM), a random access memory (English: Random Access Memory, abbreviated as: RAM), a magnetic disk or an optical disk, etc.
[0189] The embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. An image processing method, characterized in that: The method comprises: Get the image to be processed; Performing threshold processing on the image to be processed to obtain a first image; Determining a target pixel point corresponding to the connected domain based on the area of the connected domain in the first image; Adding corresponding special effects to the target pixel points in the image to be processed to obtain a target special effect image.
2. The method according to claim 1, characterized in that The determining, based on the area of the connected domain, a target pixel point corresponding to the connected domain comprises: If the area of the connected domain is smaller than a first threshold, obtaining the aspect ratio of the connected domain; Determining a target pixel point corresponding to the connected domain based on the aspect ratio of the connected domain; If the area of the connected domain is greater than the first threshold, obtaining contour pixel points of the connected domain; Based on the contour pixels of the connected domain, target pixels corresponding to the connected domain are determined.
3. The method according to claim 2, characterized in that The step of determining a target pixel point corresponding to the connected domain based on the aspect ratio of the connected domain comprises: If the aspect ratio is greater than a first preset value and less than a second preset value, determining the centroid of the connected domain as a target pixel point corresponding to the connected domain; If the aspect ratio is less than the first preset value or greater than the second preset value, a target pixel point corresponding to the connected domain is determined based on the contour pixel points of the connected domain.
4. The method according to claim 2 or 3, characterized in that: The determining of the target pixel points corresponding to the connected domain based on the contour pixel points of the connected domain includes: Determine a first pixel point based on the contour pixel points of the connected domain; The centroid of the connected domain and the first pixel point are determined as target pixel points corresponding to the connected domain.
5. The method according to claim 4, characterized in that The determining of the first pixel point based on the contour pixel points of the connected domain includes: Obtaining a sampling distance corresponding to the area of the connected domain, wherein the smaller the area of the connected domain, the larger the sampling distance; Based on the sampling distance, the contour pixel points are sampled to obtain the first pixel points.
6. The method according to any one of claims 1 to 5, characterized in that: The adding a corresponding special effect to the target pixel point in the image to be processed to obtain a target special effect image includes: Obtaining the depth value of the target pixel; Based on the depth value of the target pixel point, acquiring a target special effect material image corresponding to the depth value of the target pixel point from a plurality of preset candidate special effect material images; Based on the target special effect material image corresponding to the target pixel point, the target special effect material image is superimposed on the target pixel point in the image to be processed to obtain the target special effect image.
7. The method according to claim 6, characterized in that The multiple candidate special effect material images correspond one-to-one to multiple preset depth value intervals, the multiple candidate special effect material images have different blurring degrees, and the larger the depth value interval, the larger the blurring degree of the candidate special effect material image.
8. The method according to claim 6 or 7, characterized in that: The step of superimposing the target special effect material image on the target pixel point in the image to be processed based on the target special effect material image corresponding to the target pixel point to obtain the target special effect image includes: Acquire a material area corresponding to the target pixel point in the image to be processed; Obtaining a first texture coordinate of a vertex of a material area corresponding to the target pixel point in the image to be processed; Determining, based on the first texture coordinates corresponding to the vertices of the material area corresponding to the target pixel point, the second texture coordinates of the vertices of the material area corresponding to the target pixel point in the target special effect material image; Determine, based on the second texture coordinates corresponding to the vertices of the material area corresponding to the target pixel point, the second texture coordinates of each pixel point in the material area corresponding to the target pixel point in the target special effect material image; The texture pixels corresponding to the first texture coordinates of each pixel point in the material area corresponding to the target pixel point in the image to be processed and the texture pixels corresponding to the second texture coordinates of each pixel point in the material area corresponding to the target pixel point in the target special effect material image are superimposed to obtain the target special effect image.
9. The method according to any one of claims 1 to 8, characterized in that: Before determining the target pixel corresponding to the connected domain based on the area of the connected domain in the first image, the method further includes: Performing edge detection on the first image to obtain an edge image; Expanding the pixels in the edge image to obtain an expanded image; Connected domain identification is performed on the dilated image to obtain the connected domain.
10. The method according to any one of claims 1 to 9, characterized in that: The number of the connected domains is one or more, and the method further includes: Get the preset distance threshold; Based on the distance threshold, the target pixel points corresponding to each connected domain are screened to obtain the target pixel points in the image to be processed, wherein the distance between any two target pixel points in the image to be processed is greater than or equal to the distance threshold.
11. An image processing method, characterized in that: The method comprises: Get the image to be processed; Performing threshold processing on the image to be processed to obtain a first image; Acquire a connected domain from the first image; If the area of the connected domain in the first image is smaller than a first threshold, determining a target pixel point corresponding to the connected domain based on the aspect ratio of the connected domain; If the area of the connected domain is greater than the first threshold, determining a target pixel point corresponding to the connected domain based on the contour pixel points of the connected domain; A corresponding special effect is added to the target pixel point in the image to be processed to obtain a target special effect image.
12. An image processing device, characterized in that: The device comprises: a first acquisition unit and a first processing unit; The first acquisition unit is used to acquire the image to be processed; The first processing unit is used to perform threshold processing on the image to be processed to obtain a first image; The first processing unit is further configured to determine a target pixel point corresponding to the connected domain based on an area of the connected domain in the first image; The first processing unit is further used to add corresponding special effects to the target pixel points in the image to be processed to obtain a target special effect image.
13. An image processing device, characterized in that: The device comprises: a second acquisition unit and a second processing unit; The second acquisition unit is used to acquire the image to be processed; The second processing unit is used to perform threshold processing on the image to be processed to obtain a first image; The second processing unit is further used to obtain a connected domain from the first image; The second processing unit is further configured to determine a target pixel point corresponding to the connected domain based on an aspect ratio of the connected domain if an area of the connected domain in the first image is smaller than a first threshold; The second processing unit is further configured to determine a target pixel point corresponding to the connected domain based on the contour pixel points of the connected domain if the area of the connected domain is greater than the first threshold; The second processing unit is further used to add corresponding special effects to the target pixel points in the image to be processed to obtain a target special effect image.
14. An electronic device, characterized in that: include: A processor and a memory, the processor being connected to the memory, the memory being used to store a computer program, and the processor being used to execute the computer program stored in the memory so that the electronic device executes the method according to any one of claims 1 to 10 or claim 11.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 10 or claim 11.