Automatic image cutting contour identification method and related device
By automatically identifying and processing layer outlines and effects, it solves the problem that existing design software cannot correctly handle layers outside the container and special effects during the drawing process, achieving a more efficient and accurate drawing process and reducing the designer's time. workload.
Patent Information
- Application Number
- CN202410775139.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2024-09-10
AI Technical Summary
Existing design software cannot correctly handle the situation when the layer exceeds the container during the cutting process, and cannot accurately identify and process special effects on the layer, such as strokes and shadows, resulting in poor design results.
By automatically identifying the layer outline, it determines whether the layer exceeds the container and matches the layer part inside the container; at the same time, it identifies and matches the outer edge of the layer effect and generates the special effect cutting outline, using the Sobel operator, Prewitt operator and The non-maximum suppression algorithm is used for edge detection, and the contour is adjusted by combining the B-spline curve and the LSM level set method.
It improves the accuracy and consistency of cutting pictures, lowers the technical threshold of designers, avoids content overflow and layout confusion, and ensures consistent effects on different platforms and devices.
Smart Images

Figure CN118626085A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software design, and in particular to a method for automatically identifying a cut image contour and a related device. Background Art
[0002] With the rapid development of Internet technology and the popularity of mobile devices, graphical user interface (GUI) design has become crucial. It is not only about the appearance and user experience of software, applications, websites and games, but also about how to maintain the consistency and usability of the design under different screen sizes and resolutions. In the traditional design process, after the designer completes the design, the design file needs to be converted into an image resource that the developer can use. It usually involves manually selecting and cutting various elements in the design file, including text, shapes, pictures, etc., and then saving them as different image files. Therefore, designers are required to have high image processing skills, and the image cutting process is not only time-consuming but also prone to errors. In order to improve the conversion efficiency from design to development, reduce the error rate, and reduce the workload of designers, an automatic image cutting function is urgently needed, that is, automatically identifying different elements in the design file and automatically exporting them into image files of multiple formats and sizes according to preset rules and parameters.
[0003] Although some existing design software or plug-ins provide image cutting functions, they still have the following image cutting defects: first, when a layer exceeds its container, the exceeding part cannot be processed correctly; second, when a layer has special effects (such as strokes, shadows, etc.), the outer edges of the special effects cannot be accurately identified and cut. Taking Photoshop as an example, when a layer exceeds its container, its image cutting function will not automatically crop the exceeding part. For the special effects on the layer, the outer edges of these special effects cannot be accurately identified, resulting in the special effects being truncated or deformed when exporting the cut image, affecting the final design effect. Similar to Photoshop, Sketch cannot accurately identify and crop the part that exceeds the container, nor can it accurately identify and process the special effects on the layer, resulting in the special effects not being correctly presented when exporting the cut image.
[0004] In order to solve the above problems, the present invention proposes an automatic recognition method for cutting contours, which can not only automatically recognize various types of layer contours, but also determine whether the layer exceeds the container and only match the layer part located inside the container. At the same time, it can also automatically recognize layer effects and match their outer edges to obtain special effect cutting contours, which not only improves the accuracy and consistency of cutting, but also further reduces the technical threshold, so that more designers can benefit from it. Summary of the invention
[0005] In view of the above problems, a method and related device for automatically identifying a cut-out contour are proposed to overcome the above problems of low accuracy and efficiency of cut-out contour recognition.
[0006] According to one aspect of the present invention, a method for automatically identifying a cut image contour is provided, comprising:
[0007] When the mouse clicks on a layer in a suspended state, the layer outline of the layer is automatically identified; wherein the types of the layer include but are not limited to: text, shape, picture, instance and path type;
[0008] Determine whether the layer exceeds the container in which it is located. If it exceeds, only match the layer portion located inside the container to obtain the overlay cut outline of the layer; and
[0009] Determine whether the layer has a layer effect, and if so, match the outer edge of the layer effect to obtain a special effect cut image outline of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects;
[0010] A dotted-line frame of the superimposed cut image outline and / or the special effect cut image outline is created and displayed, so as to generate a corresponding cut image file according to the layer in the dotted-line frame of the cut image.
[0011] In an optional manner, the automatically identifying the layer outline of the layer further comprises:
[0012] Use the Sobel operator to detect the edge of the layer, obtain the horizontal and vertical gradient components, and calculate the gradient intensity and gradient direction of each pixel;
[0013] For edges with high gradient intensity, the directional Prewitt operator is used for detection;
[0014] For the edge after combining the Sobel operator and the directional Prewitt operator, the non-maximum suppression algorithm is used to compare the gradient strength of each pixel with that of the adjacent pixels along the gradient direction, and only the local maximum value in the gradient direction is retained;
[0015] The broken edges are connected to generate a layer outline of the layer.
[0016] In an optional manner, the connecting the disconnected edges to generate the layer outline of the layer further comprises:
[0017] For each edge segment, searching for other segments within a preset range around it, if the distance between any two segments is less than a preset threshold, connecting the two segments by a B-spline curve method to generate a layer contour of the layer;
[0018] The shape of the layer contour is adjusted by the LSM level set method.
[0019] In an optional manner, the determining whether the layer exceeds the container in which it is located further includes:
[0020] Get the boundary of the layer, including the first upper left corner coordinate and the first lower right corner coordinate; get the boundary of the container, including the second upper left corner coordinate and the second lower right corner coordinate;
[0021] If the horizontal coordinate of the first upper left corner coordinate is smaller than the horizontal coordinate of the second upper left corner coordinate, or the horizontal coordinate of the first lower right corner coordinate is larger than the horizontal coordinate of the second lower right corner coordinate, then the layer exceeds the boundary of the container in the horizontal direction, and the layer exceeds the container in which it is located;
[0022] If the ordinate of the first lower-right corner coordinate is smaller than the ordinate of the second lower-right corner coordinate, or the ordinate of the first lower-right corner coordinate is larger than the ordinate of the second lower-right corner coordinate, the layer exceeds the boundary of the container in the vertical direction, and the layer exceeds the container in which it is located.
[0023] In an optional manner, the determining whether the layer has a layer effect further includes:
[0024] Parsing the style attribute information of the layer, determining whether the style attribute information includes a layer effect attribute, and if so, determining that the layer has a layer effect;
[0025] The layer effect properties include but are not limited to: color adjustment, sharpening, stroke color, stroke width, shadow color, shadow size, shadow position and shadow blur.
[0026] In an optional manner, matching the outer edge of the layer effect to obtain the special effect cut outline of the layer further includes:
[0027] For a layer with a stroke effect, the edge of the layer outline is extended according to the stroke width of the layer to obtain a special effect cut image outline;
[0028] For layers with shadow effects, create a shadow area that matches the shadow size and position below or to the side of the original layer outline; soften the shadow edge of the shadow area based on the shadow blur; merge the shadow area with the original layer outline to obtain the special effect cut outline.
[0029] In an optional manner, generating a corresponding image cutting file according to the layer in the image cutting dashed box further comprises:
[0030] A CSS style cutting file of the layer is generated according to the layer effect properties of the layer and the position, width and height of the cutting dotted line frame.
[0031] According to another aspect of the present invention, there is provided a device for automatically identifying a cut image contour, comprising:
[0032] A layer outline recognition module, used to automatically recognize the layer outline of the layer when the mouse clicks on the layer in the suspended state; wherein the types of the layer include but are not limited to: text, shape, picture, instance and path type;
[0033] A container boundary matching module is used to determine whether the layer exceeds the container in which it is located. If it exceeds, only the layer portion located inside the container is matched to obtain the overlay cut outline of the layer; and
[0034] A layer effect contour matching module is used to determine whether the layer has a layer effect, and if so, to match the outer edge of the layer effect to obtain the special effect cut image contour of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects;
[0035] The image cutting outline display module is used to create and display the image cutting dotted line frame of the superimposed image cutting outline and / or the special effect image cutting outline, so as to generate a corresponding image cutting file according to the layer in the image cutting dotted line frame.
[0036] According to another aspect of the present application, there is provided a computing device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0037] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute operations corresponding to the above-mentioned method for automatically identifying the contour of a cut image.
[0038] According to another aspect of the present application, a computer program product is provided, comprising at least one executable instruction, wherein the executable instruction enables a processor to perform operations corresponding to the above-mentioned method for automatically identifying a cut image contour.
[0039] The solution provided by the above embodiment of the present invention is that when the mouse clicks on a layer in a suspended state, the layer outline of the layer is automatically identified; wherein the type of the layer includes but is not limited to: text, shape, picture, instance and path type; it is determined whether the layer exceeds the container in which it is located, and if it exceeds, only the layer part located inside the container is matched to obtain the superimposed cutting outline of the layer; and it is determined whether the layer has a layer effect, and if it does, the outer edge of the layer effect is matched to obtain the special effect cutting outline of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects; a cutting dotted line frame of the superimposed cutting outline and / or the special effect cutting outline is created and displayed to generate a corresponding cutting file according to the layer in the cutting dotted line frame. The present invention reduces the time for designers to manually perform tedious operations such as cutting and adjusting outlines by automatically identifying layer outlines, judging layer boundaries and layer effects, and greatly improves work efficiency. With the help of edge detection algorithms and non-maximum suppression, the edges of layers are accurately identified, providing cutting accuracy. For layers that exceed the boundaries of the container, only the layer part inside the container is cut. Designers can control which parts of the content are finally displayed to users, thus avoiding content overflow or chaotic layout problems. When matching the outer edge of the layer effect, a special effect cutting outline is generated according to the properties of the layer effect (such as stroke width, shadow size, etc.) to ensure the accuracy of the cutting effect. A CSS style cutting file is generated according to the style properties of the layer and the layer outline to ensure consistent effects on different platforms and devices. Edge detection and boundary matching algorithms are used to avoid errors that occur during manual cutting, further improving the accuracy of cutting and reducing the requirements for the designer's technical level, allowing designers to easily complete the cutting work.
[0040] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above description and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0042] Figure 1 A schematic diagram showing a flow chart of a method for automatically identifying a cut image contour according to an embodiment of the present invention;
[0043] FIG. 2A to FIG. 2B A schematic diagram of overlapping cut image contour matching according to an embodiment of the present invention is shown;
[0044] FIG. 3A to FIG. 3B A schematic diagram of special effect cut image contour matching according to an embodiment of the present invention is shown;
[0045] Figure 4 A schematic diagram showing the functional structure of a device for automatically identifying a cut image contour according to an embodiment of the present invention is shown;
[0046] Figure 5 A schematic diagram of the structure of a computing device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0047] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present invention and to enable the scope of the present invention to be fully communicated to those skilled in the art.
[0048] Embodiment 1:
[0049] Figure 1 FIG. 1 is a flow chart of a method for automatically identifying a cut image contour according to an embodiment of the present invention. Specifically, Figure 1 As shown, the following steps are included:
[0050] Step S101, when the mouse clicks on a layer in a suspended state, the layer outline of the layer is automatically identified; wherein the type of the layer includes but is not limited to: text, shape, picture, instance and path type.
[0051] In this embodiment, the mouse click event is detected by the listening thread of the design tool. When the mouse clicks the side layer tree (layer panel) or the canvas, it is determined whether the mouse clicks the layer by analyzing the mouse coordinates and the edge of the current visible layer. Layer types include text, shape, image, instance, and path. Figure 2A , Figure 3A As shown, assuming that the shortcut key for cutting is "S", the S key invokes cutting to support automatic recognition of the cutting outline. When the mouse clicks on a suspended layer (whether in the side layer tree or in the canvas), a "cutting dotted box" that completely matches the size of the layer will be automatically created.
[0052] In an optional manner, the automatically identifying the layer outline of the layer further comprises:
[0053] Use the Sobel operator to detect the edge of the layer, obtain the horizontal and vertical gradient components, and calculate the gradient intensity and gradient direction of each pixel;
[0054] For edges with high gradient intensity, the directional Prewitt operator is used for detection;
[0055] For the edge after combining the Sobel operator and the directional Prewitt operator, the non-maximum suppression algorithm is used to compare the gradient strength of each pixel with that of the adjacent pixels along the gradient direction, and only the local maximum value in the gradient direction is retained;
[0056] The broken edges are connected to generate a layer outline of the layer.
[0057] In this embodiment, the Sobel operator includes two 3x3 convolution kernels, one for detecting horizontal edges and the other for detecting vertical edges. The horizontal edge detection kernel is: The vertical edge detection kernel is: Applying the above two edge detection kernels to the layer for convolution operation can obtain the horizontal (G x ) and longitudinal (G y ) edge strength. According to G x and G y Calculate the gradient strength and gradient direction of each pixel (i, j) in the layer. The calculation formula of the gradient strength G(i, j) is: The calculation formula of the gradient direction θ(i,j) is: θ(i,j) = arctan(G y (i,j) / G x (i,j)).
[0058] For edges with high gradient intensity, the directional Prewitt operator is used for detection. The directional Prewitt operator contains not only templates in the horizontal and vertical directions, but also templates in the diagonal direction. According to the gradient direction θ obtained by the Sobel operator, the directional Prewitt operator template closest to θ is selected for convolution. For example, if θ(i,j) points to a specific diagonal direction, the corresponding diagonal directional Prewitt operator template is used to convolve the pixel (i,j) and its neighborhood.
[0059] The edge detection result after combining the Sobel operator and the directional Prewitt operator is used as input, and the non-maximum suppression algorithm is applied to compare the gradient strength of each pixel with its neighboring pixels along the gradient direction θ(i,j). If the gradient strength of the current pixel is not the local maximum, it will be suppressed (that is, set as non-edge), and only the significant edges in the gradient direction will be retained.
[0060] After non-maximum suppression, some disconnected edge fragments are obtained. In order to generate a complete layer outline, these disconnected edges need to be connected.
[0061] This embodiment combines the Sobel operator and the directional Prewitt operator to more accurately detect edges in the image, especially when the edge direction is strong. The non-maximum suppression algorithm is used to eliminate non-edge points while retaining significant edges in the gradient direction, making the detected edges clearer and more continuous.
[0062] In an optional manner, the connecting the disconnected edges to generate the layer outline of the layer further comprises:
[0063] For each edge segment, searching for other segments within a preset range around it, if the distance between any two segments is less than a preset threshold, connecting the two segments by a B-spline curve method to generate a layer contour of the layer;
[0064] The shape of the layer contour is adjusted by the LSM level set method.
[0065] In this embodiment, a search area (e.g., a circle or rectangular area with a fixed length as radius and a center point of the segment as the center) is defined for each edge segment. Other edge segments are searched in the search area. If two segments are found and the distance between the two segments (e.g., the distance between the segment endpoints) is less than a preset threshold (e.g., less than a certain ratio or fixed value of the segment length), the two segments can be connected.
[0066] Then use B-spline curve to fit the two segments and generate a smooth connection. Among them, B-spline curve is a linear combination of B-spline basis curves, which is a generalization and extension of Bezier curve (also known as Bezier curve). It retains many advantages of Bezier curve, such as defining the shape of the curve by control points, while adding more flexibility and local control. B-spline curve introduces more control points and node vectors, so that the curve can approximate complex shapes more smoothly and has higher efficiency when processing large amounts of data. For example, there are two disconnected edge segments, each of which is defined by two endpoints: the endpoints of segment 1: P1(0,0) and P2(1,2); the endpoints of segment 2: P3(2,1) and P4(3,0). To connect the two segments using B-spline curve, a cubic B-spline curve (i.e., k=3) is used, and it is assumed that there are 4 control points (the same number as the endpoints of the segment) and 5 node vectors (one more than the number of control points). The endpoints of the segment are selected as control points, i.e., P1, P2, P3, and P4. The knot vectors define the parameter space of the B-spline curve. You can simply choose a uniform knot vector, such as T = {0,0,0,1,2,3,3,3}. The points on the curve are calculated using the formula of the B-spline curve (using specialized mathematical software or libraries for calculation). The smooth curve through P1, P2, P3, P4 has a smooth transition between P2 and P3, rather than a sharp angle, which is the process of connecting two segments of the B-spline curve.
[0067] All edge fragments are connected into an initial contour, which may not be completely accurate (there may be some small defects). The shape of the contour is adjusted using the LSM (Level Set Method). LSM is a numerical technique for image segmentation and shape modeling. The basic idea is to represent the contour as the zero level set of a level set function, and then change the shape of the contour by iteratively updating the level set function. For example, the initial contour is used as the input of LSM, and an energy function (such as an energy function based on image gradient) is defined, which describes the degree of match between the contour and the image features. Then, a better contour shape is found by optimizing the energy function. When the energy function reaches the minimum value or meets a certain stop condition, a more accurate and smooth layer contour adjusted by LSM is obtained.
[0068] Step S102, determining whether the layer exceeds the container in which it is located, if so, only matching the layer portion located inside the container to obtain the overlapping cut image outline of the layer.
[0069] The bounds of a container are usually a rectangular area defined by the coordinates of the upper left corner, width, and height of the container. If any part of the layer exceeds the bounds of the container (that is, the bounds of the layer are less than the minimum coordinates of the container or greater than the maximum coordinates of the container), the layer exceeds the container. If the layer exceeds the container, only the part of the layer that is inside the container is retained, which can be achieved by cropping or masking. After the layer is cropped or masked, calculate and get the overlay cut outline of the part of the layer that is inside the container. FIG. 2A to FIG. 2B As shown, only the visible content part is matched, and the part clipped by the container is not matched. When the layer exceeds the part in the container (the exceeding part is clipped and not displayed), the clipped part will be displayed together when it is hovered, but the size of the created "cutting box" only includes the visible part.
[0070] In an optional manner, the determining whether the layer exceeds the container in which it is located further includes:
[0071] Get the boundary of the layer, including the first upper left corner coordinate and the first lower right corner coordinate; get the boundary of the container, including the second upper left corner coordinate and the second lower right corner coordinate;
[0072] If the horizontal coordinate of the first upper left corner coordinate is smaller than the horizontal coordinate of the second upper left corner coordinate, or the horizontal coordinate of the first lower right corner coordinate is larger than the horizontal coordinate of the second lower right corner coordinate, then the layer exceeds the boundary of the container in the horizontal direction, and the layer exceeds the container in which it is located;
[0073] If the ordinate of the first lower-right corner coordinate is smaller than the ordinate of the second lower-right corner coordinate, or the ordinate of the first lower-right corner coordinate is larger than the ordinate of the second lower-right corner coordinate, the layer exceeds the boundary of the container in the vertical direction, and the layer exceeds the container in which it is located.
[0074] Step S103, determining whether the layer has a layer effect, and if so, matching the outer edge of the layer effect to obtain a special effect cut-out outline of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects.
[0075] You can determine whether a layer has special effects such as strokes and shadows by checking the layer's properties or style information. If the layer has special effects such as strokes or shadows, analyze the outer edges of these special effects. For stroke special effects, the special effect cut-out outline is usually the outermost boundary of the stroke line. For shadow special effects, you need to find the outermost edge of the shadow based on the diffusion range and blur level of the shadow as the special effect cut-out outline.
[0076] In an optional manner, the determining whether the layer has a layer effect further includes:
[0077] Parsing the style attribute information of the layer, determining whether the style attribute information includes a layer effect attribute, and if so, determining that the layer has a layer effect;
[0078] The layer effect properties include but are not limited to: color adjustment, sharpening, stroke color, stroke width, shadow color, shadow size, shadow position and shadow blur.
[0079] For example, the style attribute information list of the layer is traversed to check whether each attribute belongs to a layer effect attribute. The layer effect attribute attributes include color adjustment (such as brightness, contrast, saturation, etc.), sharpening, stroke color, stroke width, shadow color, shadow size (such as horizontal offset and vertical offset), shadow position (such as inside, outside, center), and shadow blur, etc. If at least one layer effect attribute is found during the traversal process, it is determined that the layer has a layer effect.
[0080] In an optional manner, matching the outer edge of the layer effect to obtain the special effect cut outline of the layer further includes:
[0081] For a layer with a stroke effect, the edge of the layer outline is extended according to the stroke width of the layer to obtain a special effect cut image outline;
[0082] For layers with shadow effects, create a shadow area that matches the shadow size and position below or to the side of the original layer outline; soften the shadow edge of the shadow area based on the shadow blur; merge the shadow area with the original layer outline to obtain the special effect cut outline.
[0083] Stroke and shadow effects are treated differently when matching the outer edges of layer effects to get the layer's special effect cutout outline.
[0084] For layers with stroke effects, the stroke-related parameters are extracted from the layer style properties, including stroke color, stroke width, and stroke style (such as inner stroke, outer stroke, or center stroke). For outer strokes, an equal-width border is drawn outside the original outline of the layer according to the stroke width. For center strokes, the layer outline is extended by half the stroke width on both sides, and the extended outline is used as the special effect cutting outline.
[0085] For layers with shadow effects, extract shadow-related parameters from the layer style properties, including shadow color, shadow size (including horizontal and vertical offsets), shadow position (such as external, internal or blurred edges), and shadow blur. According to the shadow size and position, determine the starting position of the shadow area below or to the side of the original layer outline. The size and shape of the shadow area are similar to the original layer outline, but there will be a certain offset and extension (depending on the blurriness of the shadow). Merge the shadow area with the original layer outline, and the merged area is the special effect cut outline containing the shadow effect. The edge processing of the shadow area can also be performed according to the blur function in the obtained design draft.
[0086] Step S104, creating and displaying a dotted-line frame of the superimposed cut image outline and / or the special effect cut image outline, so as to generate a corresponding cut image file according to the layer in the dotted-line frame.
[0087] A dotted frame that overlays the original layer outline and / or special effect cutout outline in the design software interface. You can enhance visibility by adjusting the color, line width, and transparency of the dotted frame. For the original layer outline, you can use the coordinates of a rectangular area to determine the export area. For the special effect cutout outline, you can use the coordinates of a rectangular area to determine the export area or use a polygonal clipping algorithm to determine an irregularly shaped export area. Save the image of the export area as a cutout file.
[0088] In this embodiment, a CSS style cutting file (such as an HTML format file or other types of cutting files) of the layer is generated according to the layer effect properties of the layer and the position, width and height of the cutting dashed line frame.
[0089] For example, the layer's cutout outline properties are converted to the corresponding CSS styles: the background color is converted to the background-color property; the stroke effect is converted to the border-width, border-color, and border-style properties; the shadow effect is converted to the box-shadow property.
[0090] Embed the above CSS style in the HTML file, and use the CSS position, top, left, width, and height attributes to set the position and size of the HTML element to match the position, width, and height of the dotted box of the cut image.
[0091] As shown below, save the generated HTML file as a cut-image file.
[0092]
[0093] }
[0094]
[0095]
[0096]
[0097] <div class="cutout-layer"> <!--Corresponding HTML element-->
[0098]
[0099]
[0100] The solution provided by the above embodiment of the present invention is that when the mouse clicks on a layer in a suspended state, the layer outline of the layer is automatically identified; wherein the type of the layer includes but is not limited to: text, shape, picture, instance and path type; it is determined whether the layer exceeds the container in which it is located, and if it exceeds, only the layer part located inside the container is matched to obtain the superimposed cutting outline of the layer; and it is determined whether the layer has a layer effect, and if it does, the outer edge of the layer effect is matched to obtain the special effect cutting outline of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects; a cutting dotted line frame of the superimposed cutting outline and / or the special effect cutting outline is created and displayed to generate a corresponding cutting file according to the layer in the cutting dotted line frame. The present invention reduces the time for designers to manually perform tedious operations such as cutting and adjusting outlines by automatically identifying layer outlines, judging layer boundaries and layer effects, and greatly improves work efficiency. With the help of edge detection algorithms and non-maximum suppression, the edges of layers are accurately identified, providing cutting accuracy. For layers that exceed the boundaries of the container, only the layer part inside the container is cut. Designers can control which parts of the content are finally displayed to users, thus avoiding content overflow or chaotic layout problems. When matching the outer edge of the layer effect, a special effect cutting outline is generated according to the properties of the layer effect (such as stroke width, shadow size, etc.) to ensure the accuracy of the cutting effect. A CSS style cutting file is generated according to the style properties of the layer and the layer outline to ensure consistent effects on different platforms and devices. Edge detection and boundary matching algorithms are used to avoid errors that occur during manual cutting, further improving the accuracy of cutting and reducing the requirements for the designer's technical level, allowing designers to easily complete the cutting work.
[0101] Embodiment 2:
[0102] Figure 4 The functional structure diagram of the automatic recognition device for image cut contours of an embodiment of the present invention is shown. The automatic recognition device for image cut contours 400 comprises: a layer contour recognition module 401, a container boundary matching module 402, a layer effect contour matching module 403 and an image cut contour display module 404.
[0103] The layer outline recognition module 401 is used to automatically recognize the layer outline of the layer when the mouse clicks on the layer in the suspended state; wherein the type of the layer includes but is not limited to: text, shape, picture, instance and path type;
[0104] The container boundary matching module 402 is used to determine whether the layer exceeds the container in which it is located. If it exceeds, only the layer portion located inside the container is matched to obtain the overlapping cut image outline of the layer; and
[0105] The layer effect contour matching module 403 is used to determine whether the layer has a layer effect, and if so, to match the outer edge of the layer effect to obtain the special effect cut image contour of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects;
[0106] The image cutting outline display module 404 is used to create and display the image cutting dotted line frame of the superimposed image cutting outline and / or the special effect image cutting outline, so as to generate a corresponding image cutting file according to the layer in the image cutting dotted line frame.
[0107] In an optional manner, the automatically identifying the layer outline of the layer further comprises:
[0108] Use the Sobel operator to detect the edge of the layer, obtain the horizontal and vertical gradient components, and calculate the gradient intensity and gradient direction of each pixel;
[0109] For edges with high gradient intensity, the directional Prewitt operator is used for detection;
[0110] For the edge after combining the Sobel operator and the directional Prewitt operator, the non-maximum suppression algorithm is used to compare the gradient strength of each pixel with that of the adjacent pixels along the gradient direction, and only the local maximum value in the gradient direction is retained;
[0111] The broken edges are connected to generate a layer outline of the layer.
[0112] In an optional manner, the connecting the disconnected edges to generate the layer outline of the layer further comprises:
[0113] For each edge segment, searching for other segments within a preset range around it, if the distance between any two segments is less than a preset threshold, connecting the two segments by a B-spline curve method to generate a layer contour of the layer;
[0114] The shape of the layer contour is adjusted by the LSM level set method.
[0115] In an optional manner, the determining whether the layer exceeds the container in which it is located further includes:
[0116] Get the boundary of the layer, including the first upper left corner coordinate and the first lower right corner coordinate; get the boundary of the container, including the second upper left corner coordinate and the second lower right corner coordinate;
[0117] If the horizontal coordinate of the first upper left corner coordinate is smaller than the horizontal coordinate of the second upper left corner coordinate, or the horizontal coordinate of the first lower right corner coordinate is larger than the horizontal coordinate of the second lower right corner coordinate, then the layer exceeds the boundary of the container in the horizontal direction, and the layer exceeds the container in which it is located;
[0118] If the ordinate of the first lower-right corner coordinate is smaller than the ordinate of the second lower-right corner coordinate, or the ordinate of the first lower-right corner coordinate is larger than the ordinate of the second lower-right corner coordinate, the layer exceeds the boundary of the container in the vertical direction, and the layer exceeds the container in which it is located.
[0119] In an optional manner, the determining whether the layer has a layer effect further includes:
[0120] Parsing the style attribute information of the layer, determining whether the style attribute information includes a layer effect attribute, and if so, determining that the layer has a layer effect;
[0121] The layer effect properties include but are not limited to: color adjustment, sharpening, stroke color, stroke width, shadow color, shadow size, shadow position and shadow blur.
[0122] In an optional manner, matching the outer edge of the layer effect to obtain the special effect cut outline of the layer further includes:
[0123] For a layer with a stroke effect, the edge of the layer outline is extended according to the stroke width of the layer to obtain a special effect cut image outline;
[0124] For layers with shadow effects, create a shadow area that matches the shadow size and position below or to the side of the original layer outline; soften the shadow edge of the shadow area based on the shadow blur; merge the shadow area with the original layer outline to obtain the special effect cut outline.
[0125] In an optional manner, generating a corresponding image cutting file according to the layer in the image cutting dashed box further comprises:
[0126] A CSS style cutting file of the layer is generated according to the layer effect properties of the layer and the position, width and height of the cutting dotted line frame.
[0127] The solution provided by the above embodiment of the present invention is that when the mouse clicks on a layer in a suspended state, the layer outline of the layer is automatically identified; wherein the type of the layer includes but is not limited to: text, shape, picture, instance and path type; it is determined whether the layer exceeds the container in which it is located, and if it exceeds, only the layer part located inside the container is matched to obtain the superimposed cutting outline of the layer; and it is determined whether the layer has a layer effect, and if it does, the outer edge of the layer effect is matched to obtain the special effect cutting outline of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects; a cutting dotted line frame of the superimposed cutting outline and / or the special effect cutting outline is created and displayed to generate a corresponding cutting file according to the layer in the cutting dotted line frame. The present invention reduces the time for designers to manually perform tedious operations such as cutting and adjusting outlines by automatically identifying layer outlines, judging layer boundaries and layer effects, and greatly improves work efficiency. With the help of edge detection algorithms and non-maximum suppression, the edges of layers are accurately identified, providing cutting accuracy. For layers that exceed the boundaries of the container, only the layer part inside the container is cut. Designers can control which parts of the content are finally displayed to users, thus avoiding content overflow or chaotic layout problems. When matching the outer edge of the layer effect, a special effect cutting outline is generated according to the properties of the layer effect (such as stroke width, shadow size, etc.) to ensure the accuracy of the cutting effect. A CSS style cutting file is generated according to the style properties of the layer and the layer outline to ensure consistent effects on different platforms and devices. Edge detection and boundary matching algorithms are used to avoid errors that occur during manual cutting, further improving the accuracy of cutting and reducing the requirements for the designer's technical level, allowing designers to easily complete the cutting work.
[0128] Figure 5 The schematic diagram of the structure of the computing device embodiment of the present invention is shown. The specific embodiment of the present invention does not limit the specific implementation of the computing device.
[0129] like Figure 5 As shown, the computing device may include: a processor (processor) 502 , a communications interface (Communications Interface) 504 , a memory (memory) 506 , and a communication bus 508 .
[0130] The processor 502, the communication interface 504, and the memory 506 communicate with each other via the communication bus 508. The communication interface 504 is used to communicate with other devices such as a client or other server network elements. The processor 502 is used to execute the program 510, which can specifically execute the relevant steps in the above-mentioned embodiment of the automatic recognition method of the cut contour.
[0131] Specifically, the program 510 may include program codes, which include computer operation instructions.
[0132] The processor 502 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the computing device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0133] The memory 506 is used to store the program 510. The memory 506 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0134] The algorithm or display provided herein is not inherently related to any particular computer, virtual system or other equipment. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the embodiment of the present invention is not directed to any specific programming language yet. It should be understood that various programming languages can be utilized to realize the content of the present invention described herein, and the description made to specific languages above is for disclosing the best mode of the present invention.
[0135] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0136] Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, the various features of the embodiments of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0137] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0138] In addition, those skilled in the art will appreciate that, although some embodiments herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0139] The various component embodiments of the present invention can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components according to embodiments of the present invention. The present invention can also be implemented as a device or apparatus program (e.g., computer program and computer program product) for executing part or all of the methods described herein. Such a program implementing the present invention can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0140] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be understood as limitations on the order of execution.
Claims
1. A method for automatically identifying a cut image contour, characterized in that: include: When the mouse clicks on a layer in a suspended state, the layer outline of the layer is automatically identified; wherein the types of the layer include but are not limited to: text, shape, picture, instance and path type; Determine whether the layer exceeds the container in which it is located. If it exceeds, only match the layer portion located inside the container to obtain the overlay cut outline of the layer; and Determine whether the layer has a layer effect, and if so, match the outer edge of the layer effect to obtain a special effect cut image outline of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects; A dotted-line frame of the superimposed cut image outline and / or the special effect cut image outline is created and displayed, so as to generate a corresponding cut image file according to the layer in the dotted-line frame of the cut image.
2. The method according to claim 1, characterized in that The automatically identifying the layer outline of the layer further comprises: Use the Sobel operator to detect the edge of the layer, obtain the horizontal and vertical gradient components, and calculate the gradient intensity and gradient direction of each pixel; For edges with high gradient intensity, the directional Prewitt operator is used for detection; For the edge after combining the Sobel operator and the directional Prewitt operator, the non-maximum suppression algorithm is used to compare the gradient strength of each pixel with that of the adjacent pixels along the gradient direction, and only the local maximum value in the gradient direction is retained; The broken edges are connected to generate a layer outline of the layer.
3. The method according to claim 2, characterized in that The step of connecting the disconnected edges to generate the layer outline of the layer further comprises: For each edge segment, searching for other segments within a preset range around it, if the distance between any two segments is less than a preset threshold, connecting the two segments by a B-spline curve method to generate a layer contour of the layer; The shape of the layer contour is adjusted by the LSM level set method.
4. The method according to claim 1, characterized in that: The step of determining whether the layer exceeds the container in which it is located further includes: Get the boundary of the layer, including the first upper left corner coordinate and the first lower right corner coordinate; get the boundary of the container, including the second upper left corner coordinate and the second lower right corner coordinate; If the horizontal coordinate of the first upper left corner coordinate is smaller than the horizontal coordinate of the second upper left corner coordinate, or the horizontal coordinate of the first lower right corner coordinate is larger than the horizontal coordinate of the second lower right corner coordinate, then the layer exceeds the boundary of the container in the horizontal direction, and the layer exceeds the container in which it is located; If the ordinate of the first lower-right corner coordinate is smaller than the ordinate of the second lower-right corner coordinate, or the ordinate of the first lower-right corner coordinate is larger than the ordinate of the second lower-right corner coordinate, the layer exceeds the boundary of the container in the vertical direction, and the layer exceeds the container in which it is located.
5. The method according to claim 1, characterized in that The determining whether the layer has a layer effect further includes: Parsing the style attribute information of the layer, determining whether the style attribute information includes a layer effect attribute, and if so, determining that the layer has a layer effect; The layer effect properties include but are not limited to: color adjustment, sharpening, stroke color, stroke width, shadow color, shadow size, shadow position and shadow blur.
6. The method according to claim 5, characterized in that The step of matching the outer edge of the layer effect to obtain the special effect cut image outline of the layer further includes: For a layer with a stroke effect, the edge of the layer outline is extended according to the stroke width of the layer to obtain a special effect cut image outline; For layers with shadow effects, create a shadow area that matches the shadow size and position below or to the side of the original layer outline; soften the shadow edge of the shadow area based on the shadow blur; merge the shadow area with the original layer outline to obtain the special effect cut outline.
7. The method according to claim 1, characterized in that The generating of the corresponding image cutting file according to the layer in the image cutting dotted frame further comprises: A CSS style cutting file of the layer is generated according to the layer effect properties of the layer and the position, width and height of the cutting dotted line frame.
8. A device for automatically identifying the contour of a cut image, characterized in that: include: A layer outline recognition module, used to automatically recognize the layer outline of the layer when the mouse clicks on the layer in the suspended state; wherein the types of the layer include but are not limited to: text, shape, picture, instance and path type; A container boundary matching module is used to determine whether the layer exceeds the container in which it is located. If it exceeds, only the layer portion located inside the container is matched to obtain the overlay cut outline of the layer; and A layer effect contour matching module is used to determine whether the layer has a layer effect, and if so, to match the outer edge of the layer effect to obtain the special effect cut image contour of the layer; wherein the layer effect includes but is not limited to stroke and shadow special effects; The image cutting outline display module is used to create and display the image cutting dotted line frame of the superimposed image cutting outline and / or the special effect image cutting outline, so as to generate a corresponding image cutting file according to the layer in the image cutting dotted line frame.
9. A computing device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform operations corresponding to the method for automatically identifying the contour of a cut image as described in any one of claims 1-7.
10. A computer program product, comprising at least one executable instruction, wherein the executable instruction enables a processor to execute operations corresponding to the method for automatically identifying a cut image contour according to any one of claims 1 to 7.
