Image processing methods, apparatuses, electronic devices, and computer-readable storage media
Patent Information
- Application Number
- CN202311221557.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-20
- Publication Date
- 2026-09-18
- Estimated Expiration
- 2043-09-20
AI Technical Summary
[0003]现有的描边效果的实现,一般仅仅是沿着图像的边缘生成一层描边效果,致使图像的描边效果的表现形式较差
[0009] In this embodiment, an image to be processed is obtained, which includes a target image that needs to be processed with an outline effect. Multiple outer contour points of the target image are obtained, and based on the positions of two adjacent outer contour points, at least one interpolation point is inserted between them. Based on the position of each interpolation point on the target image, each interpolation point is shifted outwards to obtain a shifted interpolation point. The outer contour points and the shifted interpolation points form a polyline segment. The multiple outer contour points and the shifted interpolation points are shifted at least once along the normal direction to obtain at least one shift result. Based on the at least one shift result, an outline effect with a polyline feel is generated for the target image in the image to be processed, thereby improving the appearance of the outline effect.
Smart Images

Figure CN117611439B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and more specifically to an image processing method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] With the rise of the internet, people are increasingly demanding personalized display of images and videos when sharing them on social media platforms. Sometimes, to meet these demands, people control the display of certain special effects, such as outline effects.
[0003] Existing methods for achieving outline effects typically only generate an outline layer along the edge of the image, resulting in poor outline quality. Summary of the Invention
[0004] This application provides an image processing method, apparatus, electronic device, and computer-readable storage medium that can improve the appearance of image outlines.
[0005] In a first aspect, embodiments of this application provide an image processing method, the method comprising: Obtain the image to be processed, which contains the target image that needs to be processed with an outline effect; Multiple outer contour points of the target image are obtained, and at least one interpolation point is inserted between two adjacent outer contour points based on the positions of two adjacent outer contour points. Based on the position of each of the above interpolation points on the above target image, each of the above interpolation points is offset outward to obtain the offset interpolation points. The above outer contour points and the offset interpolation points form a polyline segment. The above-mentioned external contour points and the above-mentioned offset interpolation points are offset along the normal direction at least once to obtain at least one offset result; Based on at least one offset result, a polygonal outline effect is generated for the target image in the above-mentioned image to be processed.
[0006] Secondly, embodiments of this application also provide an image processing apparatus, the apparatus comprising: The image acquisition module is used to acquire images to be processed, which include target images that need to be processed with outline effects. An interpolation point insertion module is used to acquire multiple external contour points of the target image and, based on the positions of two adjacent external contour points, insert at least one interpolation point between two adjacent external contour points. The first offset module is used to offset each of the above interpolation points outward based on the position of each of the above interpolation points on the above target image, so as to obtain the offset interpolation points. The above outer contour points and the offset interpolation points form a polyline segment. The second offset module is used to offset the multiple external contour points and the offset interpolation points along the normal direction at least once to obtain at least one offset result. The effect generation module is used to generate a polygonal outline effect for the target image in the image to be processed, based on at least one offset result.
[0007] Thirdly, embodiments of this application also provide an electronic device, including a memory storing multiple instructions; the processor loads instructions from the memory to execute steps in any of the image processing methods provided in embodiments of this application.
[0008] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute steps in any of the image processing methods provided in embodiments of this application.
[0009] In this embodiment, an image to be processed is obtained, which includes a target image that needs to be processed with an outline effect. Multiple outer contour points of the target image are obtained, and based on the positions of two adjacent outer contour points, at least one interpolation point is inserted between them. Based on the position of each interpolation point on the target image, each interpolation point is shifted outwards to obtain a shifted interpolation point. The outer contour points and the shifted interpolation points form a polyline segment. The multiple outer contour points and the shifted interpolation points are shifted at least once along the normal direction to obtain at least one shift result. Based on the at least one shift result, an outline effect with a polyline feel is generated for the target image in the image to be processed, thereby improving the appearance of the outline effect. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a schematic flowchart of one embodiment of the image processing method provided in this application; Figure 2This is a schematic diagram of the image to be processed provided in the embodiments of this application; Figure 3 This is a schematic diagram of the target image provided in the embodiments of this application; Figure 4 This is a schematic diagram of the first target area provided in the embodiments of this application; Figure 5 This is a schematic diagram of the second target area provided in the embodiments of this application; Figure 6 This is a schematic diagram of the outline effect provided in the embodiments of this application; Figure 7 This is a schematic diagram of the structure of the image processing apparatus provided in the embodiments of this application; Figure 8 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0012] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0013] Before providing a detailed explanation of the embodiments of this application, some terms involved in the embodiments of this application will be explained.
[0014] In the description of the embodiments of this application, the terms "first," "second," etc., may be used herein to describe various concepts, but unless specifically stated otherwise, these concepts are not limited by these terms. These terms are used only to distinguish one concept from another. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.
[0015] This application provides an image processing method, apparatus, electronic device, and computer-readable storage medium. Specifically, the image processing method of this application can be executed by an electronic device, which can be a terminal or a server. The terminal can be a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. The terminal can also include a client, which can be a game application client, a browser client carrying a game program, or an instant messaging client. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0016] For example, taking a terminal as an example, the electronic device can acquire an image to be processed, which contains a target image that needs to be processed with an outline effect; acquire multiple outer contour points of the target image, and insert at least one interpolation point between two adjacent outer contour points based on the positions of two adjacent outer contour points; based on the position of each interpolation point on the target image, offset each interpolation point outward to obtain an offset interpolation point, and the outer contour points and the offset interpolation points form a polyline segment; offset the multiple outer contour points and the offset interpolation points at least once along the normal direction to obtain at least one offset result; based on the at least one offset result, generate an outline effect with a polyline feel for the target image in the image to be processed.
[0017] To address the aforementioned issues, embodiments of this application provide an image processing method, apparatus, electronic device, and computer-readable storage medium that can improve the representation of image outline effects.
[0018] The following is a detailed description in conjunction with the accompanying drawings. It should be noted that the order of description of the following embodiments is not intended to limit the preferred order of the embodiments. Although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be performed in a different order than that shown in the drawings.
[0019] In this embodiment, a terminal is used as an example for illustration. This embodiment provides an image processing method, such as... Figure 1 As shown, the specific process of this image processing method can be as follows: 101. Obtain the image to be processed, which contains the target image that needs to be processed with an outline effect.
[0020] The above-mentioned image to be processed is the image that needs to be processed with an outline effect. The target image in the image to be processed is the object to which the outline effect is applied. There is at least one target image in the image to be processed. For example, the target image can be two people in the image to be processed, or the target image can be a tree in the image to be processed, etc. The specific settings can be set according to the requirements and are not limited here.
[0021] In some embodiments, the terminal can directly detect and process the target image in the image to be processed to generate a corresponding outline effect. Alternatively, the terminal can segment and extract the target image from the image to be processed to detect and process the target image to generate a corresponding outline effect.
[0022] For example, if the above target profile is a person, such as Figure 2 As shown, based on the ability to segment human faces, an AI algorithm model can be used to process the image to obtain the segmented target image (denoted as the mask image). Furthermore, to better process the target image, grayscale processing or solid color filling can be applied to the segmented target image, such as... Figure 3 As shown.
[0023] 102. Obtain multiple external contour points of the target image, and based on the positions of two adjacent external contour points, insert at least one interpolation point between the two adjacent external contour points.
[0024] The aforementioned external contour points form the external contour of the target image. These multiple external contour points can be sparse or dense, and can be set according to requirements, without limitation here.
[0025] Since it is necessary to generate a stroke effect for the target image, and in order to improve the display effect of the stroke effect, it is necessary to form a stroke effect with a sense of polygonal lines. However, the outer contour points of the target image are only points generated based on the outer contour of the target image. Therefore, it is not possible to generate a stroke effect with a sense of polygonal lines based solely on the outer contour points. Thus, in this embodiment, in order to make the stroke effect have a sense of polygonal lines, the terminal introduces interpolation points to generate the stroke effect by improving the interpolation points.
[0026] Specifically, the terminal can obtain multiple external contour points by performing contour point detection on the target image.
[0027] In some embodiments, since the outer contour points can be dense, in order to reduce the amount of computation and improve the corresponding display effect, the terminal can perform sparsification processing on the outer contour points to obtain sparse outer contour points.
[0028] Specifically, before inserting at least one interpolation point between two adjacent external contour points based on their positions, the method may further include: performing sparsification processing on a plurality of external contour points of the target image based on a preset sparsity indicator parameter to obtain sparsified external contour points.
[0029] The aforementioned sparsity indicator parameters can be set according to requirements. For example, the target points with a preset number of points interval can be used as the outer contour points after sparsification. Alternatively, a point can be randomly selected from a preset number of consecutive points or selected according to a preset selection rule. The preset selection rule can be to retain a point in a certain rank among the preset number of consecutive points, such as retaining the first point among the preset number of consecutive points.
[0030] The preset quantity can be set according to needs and is not limited here, such as 50.
[0031] For example, if multiple external contour points are sorted starting from 1, then if the above-mentioned preset number is 50, that is, one point is retained out of 50 points, then points with serial numbers 1, 51, 101, 151, 201, and 251 can be obtained.
[0032] In some embodiments, when interpolating between two adjacent external contour points, since there is at least one interpolation point inserted between two adjacent external contour points, in order to better display the outline effect of the target image, a certain number of interpolation points can be randomly inserted between two adjacent external contour points, or a certain number of interpolation points can be inserted between two adjacent external contour points according to a preset interpolation rule.
[0033] Among them, the above-mentioned preset rules can be to set the interpolation step size. For example, if the step size is 0-1 and the interpolation step size is set to 0.4, then an interpolation point can be inserted at the positions of 0.4 and 0.8 respectively.
[0034] The aforementioned preset rule can also be set based on the distance between two adjacent external contour points. If the distance between two adjacent external contour points is large, the interpolation step size can be set smaller to insert more interpolation points between the two adjacent external contour points. If the distance between two adjacent external contour points is small, the interpolation step size can be set larger to insert fewer interpolation points between the two adjacent external contour points.
[0035] 103. Based on the position of each of the above interpolation points on the above target image, each of the above interpolation points is offset outward to obtain the offset interpolation points. The above outer contour points and the offset interpolation points form a polyline segment.
[0036] In this embodiment, to achieve a polygonal line effect in the outline, the terminal needs to process the interpolation points so that they can form polygonal line segments, thus creating an outline composed of multiple polygonal line segments. Specifically, the terminal can offset the interpolation points outwards from the target image. These interpolation points also function as contour points of the target image. This offset makes the contour points of the target image less smooth, allowing the offset interpolation points to form polygonal line segments with the outer contour points. Since a polygonal line segment requires at least three points, it can be formed by at least one interpolation point and at least two outer contour points, or by at least two interpolation points and at least one outer contour point.
[0037] Specifically, the terminal can obtain the offset direction and offset distance corresponding to each interpolation point for offset. For example, the offset direction can be the direction corresponding to the preset angle of the normal of the interpolation point, or the direction between the interpolation point and the center point of the target image. The specific settings can be set according to the requirements and are not limited here. It should be noted that the interpolation point is offset in a direction away from the target image.
[0038] For example, the terminal can compare the coordinates of the current interpolation point and the center point on the horizontal axis. That is, if the interpolation point is to the left of the center point, it means that the interpolation point needs to be shifted to the left; if the interpolation point is to the right of the center point, it means that the interpolation point needs to be shifted to the right.
[0039] The offset distance of the interpolation point can be set randomly or based on the distance between the interpolation point and the center point. For example, the offset distance can be set to a preset multiple of the distance between the interpolation point and the center point, such as 0.1 times. The specific setting can be determined according to the requirements and is not limited here.
[0040] In some embodiments, the above-mentioned method of offsetting each interpolation point outward based on its position on the target image to obtain an offset interpolation point may include: obtaining the center point of the target image; determining the offset direction of the interpolation point based on the position of the interpolation point and the position of the center point; offsetting the interpolation point outward in the offset direction to obtain an offset interpolation point, thereby obtaining a set of non-smooth polyline points by offsetting the interpolated points in a direction away from the center point of the target image, i.e., a set of points that saves the outer contour points and the offset interpolation points.
[0041] In some embodiments, before offsetting the plurality of external contour points and the offset interpolation points at least once along the normal direction, the method may further include: among the plurality of external contour points and the offset interpolation points, sequentially comparing the point distance between adjacent current points and previous points with a preset distance threshold; if the point distance is greater than the preset distance threshold, offsetting the current point along the normal direction; if the point distance is less than or equal to the preset distance threshold, deleting the current point.
[0042] In this embodiment, the polyline effect is optimized by removing points that do not meet the distance condition and shifting points that meet the distance condition, i.e., deleting relatively close points.
[0043] The current point and the previous point mentioned above can be external contour points or the interpolated points after offset. The calculations are performed sequentially according to the order of the points.
[0044] The distance by which the current point is offset along the normal direction can be set randomly or based on the distance between the current point and the previous point. For example, the distance can be set as a preset multiple of the distance between the interpolation point and the center point, such as 0.001 times. The specific setting can be determined according to the requirements and is not limited here.
[0045] In some embodiments, before comparing the point distance between adjacent current points and previous points with a preset distance threshold in a plurality of the aforementioned external contour points and offset interpolation points, it is also necessary to determine the aforementioned distance threshold for comparison.
[0046] Specifically, the distance threshold can be determined by the terminal determining the distance between two adjacent points among multiple external contour points and offset interpolation points, and calculating an average distance value based on the distance between adjacent points. Then, the distance threshold is determined based on the average distance value and a preset distance comparison coefficient. The distance comparison coefficient can be set according to requirements and is not limited here, such as 1 / 2.
[0047] 104. Offset the above-mentioned external contour points and the offset interpolation points along the normal direction at least once to obtain at least one offset result.
[0048] 105. Based on at least one offset result, generate a stroke effect with a polygonal line feel for the target image in the above-mentioned image to be processed.
[0049] In this embodiment, since the outer contour points are set along the outer contour of the target image, in order to better display the stroke effect and prevent the stroke effect from occluding the edge position of the target image, the multiple outer contour points and the offset interpolation points that make up the stroke effect need to be offset respectively. In order to prevent the shape of the stroke effect from being changed, the multiple outer contour points and the offset interpolation points need to be offset outward along the normal direction according to a uniform offset amount. Based on the offset result, a stroke effect with a polygonal line feel can be generated for the target image in the image to be processed.
[0050] The offset direction can be set according to requirements, such as an offset of 20 pixels.
[0051] It is understandable that the number of times the above-mentioned external contour points and the offset interpolation points are offset can be set according to the requirements. Different offset numbers correspond to different stroke effects. For example, if there is only one offset, the stroke effect is generated based on the polyline segment formed by the above-mentioned external contour points and the offset interpolation points.
[0052] If there are two offsets, the stroke effect is generated by forming two polyline segments based on the two sets of outer contour points obtained from the two offsets and the interpolation points after the offset, thus producing a stroke effect with width and a polyline feel.
[0053] If there are three offsets, the stroke effect is generated by forming three polyline segments based on the three sets of outer contour points obtained from the three offsets and the interpolation points after the offsets. This results in a polyline channel with two widths, which can generate different effect styles in different polyline channels.
[0054] Specifically, when there are two offsets, the above-mentioned offsetting of the multiple external contour points and the offset interpolation points along the normal direction at least once to obtain at least one offset result may include: based on the first offset indication parameter, offsetting the multiple external contour points and the offset interpolation points along the normal direction for the first time, and obtaining the first target region based on the points after the first offset, such as... Figure 4 As shown; based on the second offset indicator parameter, the aforementioned external contour points and the offset interpolation points are respectively offset a second time along the normal direction, and based on the points after the second offset, the second target region is obtained, as shown. Figure 5 As shown.
[0055] Among them, from Figure 4 and Figure 5 It can be seen from this that Figure 4 A larger mask can be obtained from this. Figure 5 A smaller, expanded mask can be obtained from this.
[0056] Specifically, the points after the first offset and the points after the second offset can be connected in a closed loop to form the first target region and the second target region respectively. For ease of processing, the first target region and the second target region can be filled with a solid color.
[0057] Accordingly, when there are two offsets, the above-mentioned generation of a polygonal outline effect for the target image in the image to be processed based on at least one offset result may include: comparing the first target region and the second target region to determine the non-overlapping region between the first target region and the second target region; and generating a polygonal outline effect for the target image in the image to be processed based on the non-overlapping region.
[0058] For example, based on Figure 4 and Figure 5 The example shown will Figure 4 and Figure 5 By overlapping the regions in the diagram, a non-overlapping region can be obtained, such as... Figure 6 As shown, Figure 6 The above target image is then used to generate a stroke effect with a polygonal line feel.
[0059] Specifically, after obtaining the first target region (denoted as mask1) and the second target region (denoted as mask2), the interpolation between mask1 and mask2 can be calculated to obtain... Figure 6 The image shows a stroke with a width and a zigzag shape. This stroke is then processed to obtain a stroke effect. By blending and overlaying the stroke effect with the original image, a zigzag-like stroke effect can be generated for the target image in the image to be processed.
[0060] The stroke effect processing described above can be customized as needed. For example, a processing panel for stroke effect processing can be set up, which includes at least one effect configuration control for the stroke, such as color sliders corresponding to different colors. By adjusting the color sliders, the stroke color can be set. Figure 6 The white in the middle.
[0061] As can be seen from the above, by acquiring the image to be processed, which contains a target image that needs to be processed with an outline effect; acquiring multiple outer contour points of the target image, and inserting at least one interpolation point between two adjacent outer contour points based on their positions; shifting each interpolation point outward based on its position on the target image to obtain a shifted interpolation point, and forming a polyline segment with the outer contour points and the shifted interpolation points; shifting the multiple outer contour points and the shifted interpolation points at least once along the normal direction to obtain at least one shift result; and generating an outline effect with a polyline feel for the target image in the image to be processed, thereby improving the appearance of the outline effect of the image.
[0062] To better implement the above methods, this application also provides an image processing device, which can be integrated into an electronic device, such as a computer device, which can be a terminal, server, or other device.
[0063] The terminal can be a mobile phone, tablet computer, smart Bluetooth device, laptop computer, personal computer, etc.; the server can be a single server or a server cluster composed of multiple servers.
[0064] For example, in this embodiment, the method of this application embodiment will be described in detail by taking the image processing device specifically integrated into the terminal as an example. This embodiment provides an image processing device, such as... Figure 7 As shown, the image processing apparatus may include: Image acquisition module 701 is used to acquire an image to be processed, which contains a target image that needs to be processed with an outline effect. The interpolation point insertion module 702 is used to acquire multiple external contour points of the target image and, based on the position of two adjacent external contour points, insert at least one interpolation point between two adjacent external contour points. The first offset module 703 is used to offset each of the above interpolation points outward based on the position of each of the above interpolation points on the above target image, so as to obtain the offset interpolation points. The above outer contour points and the offset interpolation points form a polyline segment. The second offset module 704 is used to offset the multiple external contour points and the offset interpolation points along the normal direction at least once to obtain at least one offset result. Effect generation module 705 is used to generate a polygonal outline effect for the target image in the image to be processed based on at least one offset result.
[0065] In some embodiments, the image processing apparatus further includes a processing module, which is specifically used for: Based on the preset sparsity indicator parameters, the aforementioned external contour points of the target image are subjected to sparsification processing to obtain the sparsified external contour points.
[0066] In some embodiments, the first offset module 703 is specifically used for: Obtain the center point of the target image mentioned above; Based on the positions of the interpolation points and the center point, the offset direction of the interpolation points is determined. The interpolation point is shifted outward in the aforementioned offset direction to obtain the offset interpolation point.
[0067] In some embodiments, the image processing apparatus further includes a comparison module, which is specifically used for: Among the multiple external contour points and the offset interpolation points mentioned above, the point distance between the adjacent current point and the previous point is compared with a preset distance threshold in turn; If the distance between the above points is greater than the preset distance threshold, the current point will be offset along the normal direction; If the distance to the above point is less than or equal to the preset distance threshold, then the above current point will be deleted.
[0068] In some embodiments, the image processing apparatus further includes a computing module, which is specifically used for: Determine the distance between any two adjacent points among the aforementioned external contour points and the offset interpolation points, and calculate the average distance value based on the distance between any two adjacent points; Based on the above average distance value and the preset distance comparison coefficient, the distance threshold is determined.
[0069] In some embodiments, the second offset module 704 is specifically used for: Based on the first offset indicator parameter, the multiple external contour points and the offset interpolation points are offset along the normal direction for the first time, and the first target area is obtained based on the points after the first offset. Based on the second offset indicator parameter, the multiple external contour points and the offset interpolation points are offset a second time along the normal direction, and the second target region is obtained based on the points after the second offset.
[0070] In some embodiments, the effect generation module 705 is specifically used for: By comparing the first target region and the second target region, the non-overlapping region between the first target region and the second target region is determined. Based on the aforementioned non-overlapping regions, a polygonal outline effect is generated for the target image in the aforementioned image to be processed.
[0071] As described above, the image acquisition module 701 acquires the image to be processed, which contains the target image that needs to be processed with an outline effect; the interpolation point insertion module 702 acquires multiple outer contour points of the target image, and inserts at least one interpolation point between two adjacent outer contour points based on their positions; the first offset module 703 offsets each interpolation point outward based on its position on the target image to obtain an offset interpolation point, and the outer contour points and the offset interpolation points form a polyline segment; the second offset module 704 offsets the multiple outer contour points and the offset interpolation points at least once along the normal direction to obtain at least one offset result; the effect generation module 705 generates an outline effect with a polyline feel for the target image in the image to be processed based on the at least one offset result, thereby improving the appearance of the outline effect of the image.
[0072] Accordingly, this application also provides an electronic device, which can be a terminal, such as a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. Figure 8 As shown, Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device 800 includes a processor 801 with one or more processing cores, a memory 802 with one or more computer-readable storage media, and a computer program stored on the memory 802 and executable on the processor. The processor 801 and the memory 802 are electrically connected. Those skilled in the art will understand that the electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0073] The processor 801 is the control center of the electronic device 800. It connects various parts of the electronic device 800 through various interfaces and lines. By running or loading software programs and / or modules stored in the memory 802, and calling data stored in the memory 802, it executes various functions of the electronic device 800 and processes data, thereby performing overall monitoring of the electronic device 800.
[0074] In this embodiment, the processor 801 in the electronic device 800 loads the instructions corresponding to the processes of one or more applications into the memory 802 according to the following steps, and the processor 801 runs the applications stored in the memory 802 to realize various functions: Obtain the image to be processed, which contains the target image that needs to be processed with an outline effect; Multiple outer contour points of the target image are obtained, and at least one interpolation point is inserted between two adjacent outer contour points based on the positions of two adjacent outer contour points. Based on the position of each of the above interpolation points on the above target image, each of the above interpolation points is offset outward to obtain the offset interpolation points. The above outer contour points and the offset interpolation points form a polyline segment. The above-mentioned external contour points and the above-mentioned offset interpolation points are offset along the normal direction at least once to obtain at least one offset result; Based on at least one offset result, a polygonal outline effect is generated for the target image in the above-mentioned image to be processed.
[0075] In some embodiments, before inserting at least one interpolation point between two adjacent outer contour points based on their positions, the method further includes: Based on the preset sparsity indicator parameters, the aforementioned external contour points of the target image are subjected to sparsification processing to obtain the sparsified external contour points.
[0076] In some embodiments, the above-mentioned method of shifting each interpolation point outward based on its position on the target image to obtain the shifted interpolation point includes: Obtain the center point of the target image mentioned above; Based on the positions of the interpolation points and the center point, the offset direction of the interpolation points is determined. The interpolation point is shifted outward in the aforementioned offset direction to obtain the offset interpolation point.
[0077] In some embodiments, before offsetting the plurality of external contour points and the offset interpolation points at least once along the normal direction, the method further includes: Among the multiple external contour points and the offset interpolation points mentioned above, the point distance between the adjacent current point and the previous point is compared with a preset distance threshold in turn; If the distance between the above points is greater than the preset distance threshold, the current point will be offset along the normal direction; If the distance to the above point is less than or equal to the preset distance threshold, then the above current point will be deleted.
[0078] In some embodiments, before comparing the point distance between adjacent current points and previous points with a preset distance threshold in a plurality of the aforementioned external contour points and offset interpolation points, the method further includes: Determine the distance between any two adjacent points among the aforementioned external contour points and the offset interpolation points, and calculate the average distance value based on the distance between any two adjacent points; Based on the above average distance value and the preset distance comparison coefficient, the distance threshold is determined.
[0079] In some embodiments, the above-mentioned offsetting of the plurality of external contour points and the offset interpolation points along the normal direction at least once to obtain at least one offset result includes: Based on the first offset indicator parameter, the multiple external contour points and the offset interpolation points are offset along the normal direction for the first time, and the first target area is obtained based on the points after the first offset. Based on the second offset indicator parameter, the multiple external contour points and the offset interpolation points are offset a second time along the normal direction, and the second target region is obtained based on the points after the second offset.
[0080] In some embodiments, generating a polygonal outline effect for the target image in the image to be processed based on at least one offset result includes: By comparing the first target region and the second target region, the non-overlapping region between the first target region and the second target region is determined. Based on the aforementioned non-overlapping regions, a polygonal outline effect is generated for the target image in the aforementioned image to be processed.
[0081] Therefore, the electronic device 800 provided in this embodiment can bring about the following technical effects: improve the expression of the outline effect of the image.
[0082] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0083] Optional, such as Figure 8 As shown, the electronic device 800 also includes: a touch display screen 803, a radio frequency circuit 804, an audio circuit 805, an input unit 806, and a power supply 807. The processor 801 is electrically connected to the touch display screen 803, the radio frequency circuit 804, the audio circuit 805, the input unit 806, and the power supply 807. Those skilled in the art will understand that... Figure 8 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0084] The touch display screen 803 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 803 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the electronic device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 801. It can also receive and execute commands from the processor 801. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 801 to determine the type of touch event. Subsequently, the processor 801 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 803 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 803 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 803 can also be used as part of the input unit 806 to achieve input functions.
[0085] The radio frequency circuit 804 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other electronic devices, and to transmit and receive signals with network devices or other electronic devices.
[0086] Audio circuit 805 can be used to provide an audio interface between a user and an electronic device via a speaker and a microphone. Audio circuit 805 can convert received audio data into electrical signals and transmit them to the speaker, where the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuit 805, converted back into audio data, and then processed by processor 801 before being transmitted via radio frequency circuit 804 to, for example, another electronic device, or output to memory 802 for further processing. Audio circuit 805 may also include an earphone jack to provide communication between peripheral headphones and electronic devices.
[0087] The input unit 806 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.
[0088] Power supply 807 is used to supply power to various components of electronic device 800. Optionally, power supply 807 can be logically connected to processor 801 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 807 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0089] although Figure 8 As not shown in the diagram, the electronic device 800 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.
[0090] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0091] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0092] Therefore, embodiments of this application provide a computer-readable storage medium storing a plurality of computer programs that can be loaded by a processor to execute the steps of any of the image processing methods provided in embodiments of this application. For example, the computer program can execute the following steps: Obtain the image to be processed, which contains the target image that needs to be processed with an outline effect; Multiple outer contour points of the target image are obtained, and at least one interpolation point is inserted between two adjacent outer contour points based on the positions of two adjacent outer contour points. Based on the position of each of the above interpolation points on the above target image, each of the above interpolation points is offset outward to obtain the offset interpolation points. The above outer contour points and the offset interpolation points form a polyline segment. The above-mentioned external contour points and the above-mentioned offset interpolation points are offset along the normal direction at least once to obtain at least one offset result; Based on at least one offset result, a polygonal outline effect is generated for the target image in the above-mentioned image to be processed.
[0093] In some embodiments, before inserting at least one interpolation point between two adjacent outer contour points based on their positions, the method further includes: Based on the preset sparsity indicator parameters, the aforementioned external contour points of the target image are subjected to sparsification processing to obtain the sparsified external contour points.
[0094] In some embodiments, the above-mentioned method of shifting each interpolation point outward based on its position on the target image to obtain the shifted interpolation point includes: Obtain the center point of the target image mentioned above; Based on the positions of the interpolation points and the center point, the offset direction of the interpolation points is determined. The interpolation point is shifted outward in the aforementioned offset direction to obtain the offset interpolation point.
[0095] In some embodiments, before offsetting the plurality of external contour points and the offset interpolation points at least once along the normal direction, the method further includes: Among the multiple external contour points and the offset interpolation points mentioned above, the point distance between the adjacent current point and the previous point is compared with a preset distance threshold in turn; If the distance between the above points is greater than the preset distance threshold, the current point will be offset along the normal direction; If the distance to the above point is less than or equal to the preset distance threshold, then the above current point will be deleted.
[0096] In some embodiments, before comparing the point distance between adjacent current points and previous points with a preset distance threshold in a plurality of the aforementioned external contour points and offset interpolation points, the method further includes: Determine the distance between any two adjacent points among the aforementioned external contour points and the offset interpolation points, and calculate the average distance value based on the distance between any two adjacent points; Based on the above average distance value and the preset distance comparison coefficient, the distance threshold is determined.
[0097] In some embodiments, the above-mentioned offsetting of the plurality of external contour points and the offset interpolation points along the normal direction at least once to obtain at least one offset result includes: Based on the first offset indicator parameter, the multiple external contour points and the offset interpolation points are offset along the normal direction for the first time, and the first target area is obtained based on the points after the first offset. Based on the second offset indicator parameter, the multiple external contour points and the offset interpolation points are offset a second time along the normal direction, and the second target region is obtained based on the points after the second offset.
[0098] In some embodiments, generating a polygonal outline effect for the target image in the image to be processed based on at least one offset result includes: By comparing the first target region and the second target region, the non-overlapping region between the first target region and the second target region is determined. Based on the aforementioned non-overlapping regions, a polygonal outline effect is generated for the target image in the aforementioned image to be processed.
[0099] As can be seen, a computer program can be loaded by a processor to execute the steps in any of the image processing methods provided in the embodiments of this application, thereby bringing about the following technical effects: improving the appearance of the outline effect of the image.
[0100] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0101] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0102] Since the computer program stored in the computer-readable storage medium can execute the steps of any of the image processing methods provided in the embodiments of this application, the beneficial effects that any of the image processing methods provided in the embodiments of this application can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.
[0103] The foregoing has provided a detailed description of an image processing method, apparatus, electronic device, and computer-readable storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. An image processing method, characterized by, The method includes: Obtain an image to be processed, wherein the image to be processed contains a target image that needs to be processed with an outline effect; Multiple outer contour points of the target image are obtained, and at least one interpolation point is inserted between two adjacent outer contour points based on their positions. Based on the position of each interpolation point on the target image, each interpolation point is offset outward to obtain an offset interpolation point. The outer contour point and the offset interpolation point form a polyline segment. The multiple external contour points and the offset interpolation points are offset along the normal direction at least once to obtain at least one offset result; Based on at least one offset result, a polygonal outline effect is generated for the target image in the image to be processed.
2. The image processing method as described in claim 1, characterized in that, Before inserting at least one interpolation point between two adjacent outer contour points based on their positions, the method further includes: Based on preset sparsity indicator parameters, multiple external contour points of the target image are subjected to sparsification processing to obtain the sparsified external contour points.
3. The image processing method as described in claim 1, characterized in that, The step of shifting each interpolation point outward based on its position on the target image to obtain the shifted interpolation point includes: Obtain the center point of the target image; Based on the position of the interpolation point and the position of the center point, the offset direction of the interpolation point is determined; The interpolation point is offset outward in the offset direction to obtain the offset interpolation point.
4. The image processing method as described in claim 1, characterized in that, Before offsetting the plurality of external contour points and the offset interpolation points at least once along the normal direction, the method further includes: Among the multiple external contour points and the offset interpolation points, the point distance between the adjacent current point and the previous point is compared with a preset distance threshold in turn; If the distance to the point is greater than a preset distance threshold, the current point will be offset along the normal direction. If the distance to the point is less than or equal to a preset distance threshold, then the current point is deleted.
5. The image processing method as described in claim 4, characterized in that, Before comparing the point distances between adjacent current points and previous points with a preset distance threshold among the multiple external contour points and the offset interpolation points, the method further includes: Determine the distance between any two adjacent points among the multiple external contour points and the offset interpolation points, and calculate the average distance value based on the distance between any two adjacent points; The distance threshold is determined based on the average distance value and the preset distance comparison coefficient.
6. The image processing method according to any one of claims 1 to 5, characterized in that, The step of offsetting the plurality of external contour points and the offset interpolation points at least once along the normal direction to obtain at least one offset result includes: Based on the first offset indicator parameter, the multiple external contour points and the offset interpolation points are offset along the normal direction for the first time, and the first target region is obtained based on the points after the first offset. Based on the second offset indicator parameter, the multiple external contour points and the offset interpolation points are offset a second time along the normal direction, and the second target region is obtained based on the points after the second offset.
7. The image processing method as described in claim 6, characterized in that, The step of generating a polygonal outline effect for the target image in the image to be processed based on at least one offset result includes: Compare the first target region and the second target region to determine the non-overlapping region between the first target region and the second target region; Based on the non-overlapping region, a polygonal outline effect is generated for the target image in the image to be processed.
8. An image processing apparatus, characterized in that, The device includes: The image acquisition module is used to acquire an image to be processed, wherein the image to be processed contains a target image that needs to be processed with an outline effect. An interpolation point insertion module is used to acquire multiple external contour points of the target image and, based on the positions of two adjacent external contour points, insert at least one interpolation point between two adjacent external contour points. The first offset module is used to offset each interpolation point outward based on the position of each interpolation point on the target image to obtain the offset interpolation point. The outer contour point and the offset interpolation point form a polyline segment. The second offset module is used to offset the multiple external contour points and the offset interpolation points along the normal direction at least once to obtain at least one offset result. An effect generation module is used to generate a polygonal outline effect for the target image in the image to be processed based on at least one offset result.
9. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing multiple instructions; the processor loads instructions from the memory to perform the steps of the image processing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted for loading by a processor to perform the steps of the image processing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image stroking special effect generation method and device, equipment and readable storage medium
CN117274432A