An Adaptive Image Segmentation Method and System Based on a Visual Template Engine
By using an adaptive image segmentation method based on a visual template engine, the problems of low efficiency, poor degree of freedom, and uneditable output in existing technologies are solved. This method achieves efficient and flexible artistic image segmentation and independent layer generation, supports user-defined templates, and is suitable for large-scale image processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-19
- Publication Date
- 2026-03-13
AI Technical Summary
Existing image segmentation techniques are inefficient, lack freedom, have insufficient scalability, and their output results are difficult to use for secondary creation in artistic applications. They lack a bridge to combine the flexibility of vector graphics with raster image segmentation processing.
An adaptive image segmentation method based on a visual template engine is provided. The method loads images through user interface interaction, selects or creates segmentation templates, adjusts parameters, generates segmentation masks and identifies segmentation regions, and outputs independent layered results. It supports preset template libraries and user-defined templates, and adopts supersampling anti-aliasing and region quadtree block strategy to optimize the processing.
It achieves efficient and flexible artistic image segmentation, generates independently editable layers, improves creative freedom and efficiency, supports user-defined templates, and solves the problems of low creative efficiency, poor freedom and uneditable output in existing technologies. It is suitable for large-scale image processing.
Smart Images

Figure CN121392289B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to an image segmentation method and system, and more particularly to an adaptive image segmentation method and system based on a visual template engine. Background Technology
[0002] In the field of digital image processing, image segmentation is a fundamental and crucial technique. Its purpose is to divide a digital image into multiple regions (or segments, objects) with unique properties. Existing image segmentation techniques can be mainly categorized as follows:
[0003] Manual segmentation tools: Mainstream image editing software, such as Adobe Photoshop, offers tools like the lasso tool, pen tool, and magic wand tool. Users can select areas manually or based on color or brightness similarity. While these tools offer high precision, they are extremely tedious and time-consuming when creating complex, repetitive patterns with specific artistic styles (such as cracks or fragments), and it is difficult to guarantee the consistency and aesthetics of the segmentation lines.
[0004] Traditional segmentation algorithms include threshold-based segmentation, edge detection-based segmentation (such as Canny and Sobel operators), region growing, watershed algorithms, and clustering-based segmentation (such as K-Means). These methods primarily rely on the low-level pixel features of an image (such as grayscale, color, and texture) for segmentation. Their goal is usually to identify and separate specific objects in an image (such as people, vehicles, and buildings), rather than to achieve a pre-defined, aesthetically pleasing, structured segmentation. Therefore, their segmentation results often do not meet the requirements of formal beauty and structural aesthetics in artistic creation.
[0005] Deep learning-based segmentation: In recent years, deep learning models such as U-Net and Mask R-CNN have achieved great success in semantic segmentation and instance segmentation. These models can accurately identify and segment specific categories of objects in images. However, their training requires large amounts of labeled datasets, and their application scenarios are geared towards "recognition" rather than "creation." They cannot segment arbitrary images according to an abstract, stylized vector pattern based on the user's artistic intent.
[0006] Filters and Effects: Some image processing software or applications offer special effects filters such as "mosaic," "crack," or "glass shards." These filters are usually pixel-based, fixed algorithms with limited adjustable parameters (such as the size of the fragments) and no ability to customize the segmentation path and shape. More importantly, their output is usually a destructively edited, flattened image, rather than a set of independently editable layers, which greatly limits subsequent creative possibilities.
[0007] As can be seen above, existing image segmentation methods often emphasize regular division but lack a unified mathematical model to describe the constraints of "artistic stylized segmentation." This results in current implementations remaining at the empirical level, making it difficult to optimize the balance between visual consistency and creative expression at the algorithmic level. Specific drawbacks are as follows:
[0008] Low creative efficiency: Manual tools are time-consuming and labor-intensive to complete complex artistic and stylized divisions, and are difficult to reuse.
[0009] Low creative freedom: Traditional algorithms and deep learning methods serve the purpose of "recognition" and cannot meet users' customized needs for segmenting "form" and "style". Filters and effects, on the other hand, have fixed patterns and lack flexibility and scalability.
[0010] Lack of editability: Most existing special effects filters are destructive, outputting a single-layer image. The segmented areas cannot be used as independent layers for subsequent filling, color adjustment, transformation, and other secondary creations, limiting the possibility of image reconstruction.
[0011] The disconnect between technology and art: Current technology lacks an effective bridge to combine the flexibility, precision, and procedural generation capabilities of vector graphics with the segmentation processing of raster images to serve the purpose of artistic creation. Summary of the Invention
[0012] The technical problem to be solved by the present invention is to provide an adaptive image segmentation method and system based on a visual template engine, which can solve the problems of low efficiency, poor degree of freedom, insufficient scalability and difficulty in secondary creation of output results in the artistic application of existing image segmentation technology.
[0013] To address the aforementioned technical problems, this invention provides an adaptive image segmentation method based on a visual template engine, comprising the following steps: S1, loading a raster image from local storage or the cloud as the target image to be processed through user interface interaction; S2, selecting a segmentation template from a preset template library, or creating a user-defined template as the segmentation template; S3, adjusting the parameters of the selected template; S4, applying the adjusted template to generate a segmentation mask, and performing segmentation operations based on the mask recognition; S5, generating a layered result after segmentation based on the segmentation result.
[0014] Furthermore, the preset template library in step S2 is a built-in vectorized template library, including: a mirror-crack template: simulating the effect of broken glass or a mirror, consisting of multiple randomly or regularly distributed straight lines or broken lines; a plot template: simulating land, fields, or cell structures, consisting of irregular closed curves; and a monitoring screen template: simulating a monitoring wall composed of multiple rectangular screens, consisting of regular grid lines.
[0015] Further, step S2 creates a user-defined template in the following manner: upload an existing vector graphics file, parse the file, and extract the path information as a segmentation template; or provide a simple vector drawing tool that allows users to draw paths directly on the canvas using straight lines, curves, or Bézier curves, and the drawn paths are instantly generated as segmentation templates.
[0016] Furthermore, step S3 includes: adjusting the thickness of the dividing lines; adjusting the number of dividing units; controlling the angle, position, and curvature of the lines; and scaling, rotating, and translating the template.
[0017] Further, step S4 includes: S41, template vector data processing: receiving the target image, template and parameters, and obtaining the final vector path data; S42, mask generation: rasterizing the vector path data to generate a binary or grayscale mask with the same size as the target image; S43, region recognition: applying a connected component analysis algorithm to the generated mask to identify all closed regions surrounded by segmentation lines, and extracting each segmentation region.
[0018] Further, step S41 represents the set of vector paths from the template as follows:
[0019] ;
[0020] in:
[0021] ;
[0022] Represents the i-th vector path in the set. Let t be the path curve coordinates, t be the parameters on the path, normalized to the interval [0, 1], representing the progress from the starting point to the ending point of the path, and N be the total number of vector paths that constitute this template;
[0023] Scaling, rotating, and translating the template are equivalent to applying a uniform affine transformation to this set of path functions, resulting in a new path. Represented as:
[0024] ;
[0025] in:
[0026] ;
[0027] This is a transformation matrix used to implement scaling and rotation. The angle is the rotation angle.
[0028] Further, in step S42, the segmentation lines are represented as black or white on the mask. During rasterization, the resolution is temporarily increased by a factor of K, then reduced back, and a smooth boundary is obtained using a majority voting method. Specifically, this includes: a. Creating an oversampling canvas: generating a temporary canvas of size (W·K, H·K), where W and H are the width and height of the target image, respectively, and K is the oversampling factor, where K is an integer greater than or equal to 1, and the value range of K is [2, 8]; b. High-precision rasterization: rasterizing the parameter-adjusted vector path data onto the oversampling canvas; c. Downsampling and filtering: downsampling the (W·K, H·K) oversampling canvas and reducing it back to (W, H) using a majority voting method. The original mask size; for each K×K pixel block on the oversampled canvas, count the number of pixels that belong to lines; if the counted number exceeds a threshold (K·K) / 2, the corresponding 1×1 pixel in the final mask is marked as a line; otherwise, it is marked as background.
[0029] Furthermore, step S43 adds an area constraint when labeling connected components:
[0030] ;
[0031] in It is a connected region that has been identified. It is its pixel area. It is a dynamically calculated minimum area threshold:
[0032] ;
[0033] and These are the width and height of the target image. It is an area ratio coefficient. The value range is [0.000005, 0.0001];
[0034] For regions with an area smaller than T, a merging strategy is adopted, merging them with the adjacent connected region with the largest area.
[0035] Furthermore, when the target image is an image larger than 8K, step S4 employs a region quadtree segmentation strategy for segmentation, specifically including: a. Recursive partitioning: The entire image region is used as the root node of the quadtree; for any region within the image, it is checked whether it intersects with the template vector path; if the region does not intersect with any path, then all pixels within the region belong to the same connected component, requiring no further partitioning, and the corresponding node becomes a leaf node; if the region intersects with a path, and its size is greater than the preset minimum block size... If the region size is less than or equal to the specified size, then the region is divided into four sub-regions, which are the children of the current node, and this division process is recursively performed on each child node; if the region size is less than or equal to the specified size, then the division process is repeated. If the segmentation stops, the node becomes a leaf node; b. Local processing and merging: Through the above segmentation, the original image is decomposed into a series of sub-blocks represented by leaf nodes; for the sub-blocks corresponding to leaf nodes that intersect with the path, mask generation and region recognition operations are performed; sub-blocks that do not intersect with the path are directly marked as a whole region; c. Result merging: After all sub-blocks have been processed, by analyzing the connectivity at the boundaries of adjacent sub-blocks, the same region IDs that cross the boundaries of sub-blocks are merged to finally obtain a globally consistent region recognition result.
[0036] Furthermore, step S4 assigns a unique ID to each independent closed region, and step S5 includes: traversing all region IDs identified in step S4; creating a new layer for each region ID; copying the pixel data corresponding to the location of the region ID in the target image into the new layer, and setting all pixels outside the region to transparent; thereby generating an independent transparent layer for each region.
[0037] This invention also provides an adaptive image segmentation system based on a visual template engine, comprising: a user interface module for loading raster images from local storage or the cloud as target images to be processed through user interface interaction; a template management module for providing a preset template library and user-defined templates for selection as segmentation templates; a parameter adjustment module for adjusting the parameters of the selected template; a segmentation template engine for generating a segmentation mask by applying the adjusted template, and performing segmentation operations based on the mask recognition; and a layer generation module for generating layered results after segmentation based on the segmentation results.
[0038] Compared with the prior art, the present invention has the following beneficial effects: The adaptive image segmentation method and system based on the visual template engine provided by the present invention can apply user-defined arbitrary vectorized structure templates to the target image to achieve adaptive stylized segmentation and generate layered results that can be independently edited, thereby greatly improving the creative freedom and efficiency of artistic image processing, and has the characteristics of high efficiency, flexibility and scalability. Attached Figure Description
[0039] Figure 1 This is a schematic diagram of the adaptive image segmentation system architecture based on a visual template engine according to the present invention;
[0040] Figure 2 This is a flowchart illustrating the implementation of the adaptive image segmentation method based on a visual template engine according to the present invention.
[0041] Figure 3 This is a schematic diagram illustrating the principle of applying the template of the present invention to an image. Detailed Implementation
[0042] The present invention will now be further described with reference to the accompanying drawings and embodiments.
[0043] This invention provides an adaptive image segmentation method based on a visual template engine, which is implemented through a core "segmentation template engine". This method can be implemented by software programs in computer devices (such as personal computers, servers, and mobile devices), and its system typically includes a user interface module, a template management module, a parameter adjustment module, a segmentation template engine, and a layer generation module.
[0044] Please see Figure 1 Users interact with the system through the user interface module to load the target image. The template management module manages the preset template library and user-defined templates. Users can modify the selected template through the parameter adjustment module. The core segmentation template engine receives the target image, template, and parameters, and performs the segmentation operation. The layer generation module generates layered results based on the segmentation results and finally presents them to the user.
[0045] The innovative aspects of this invention are as follows:
[0046] 1. The concept of a template engine;
[0047] This invention is the first to propose and implement a "template engine" specifically for artistic image segmentation. It seamlessly integrates vector template design and parametric adjustment with image rasterization, creating a completely new image segmentation paradigm geared towards creative work. This is the most fundamental difference between it and traditional segmentation techniques aimed at "recognition".
[0048] 2. High scalability and user customization capabilities;
[0049] This invention breaks through the fixed mode of traditional filters, giving users almost unlimited creative freedom by supporting users to upload custom vector files (such as SVG) or draw paths directly in the software as templates. Any shape, any symbol, and any text can become a "mold" for segmenting images.
[0050] 3. Non-destructive layered output;
[0051] The most significant workflow innovation of this invention lies in its output being a set of independently editable layers, rather than a flattened image. This aligns with the professional workflow of modern digital art creation, allowing each segmented fragment to be independently modified (e.g., color correction, application of effects, movement, scaling), greatly enriching the creative possibilities of image reconstruction.
[0052] This invention not only provides templated segmentation, but also solves the following problems in practical applications:
[0053] (1) Conflicts between the template path and the raster pixel grid may cause burrs and jagged edges to appear at the segmentation edges;
[0054] (2) When the randomization parameters are not controlled enough, it is easy to cause the layer to be invisible due to "fragment area being too small" or the "fragment clustering being too dense" to cause local visual confusion.
[0055] (3) When processing large images (>8K resolution), the time complexity of mask generation is too high, and a time / memory optimization mechanism is required.
[0056] Please continue reading Figure 2 The specific implementation steps of this invention are as follows:
[0057] Step 1: Load the target image;
[0058] Users can load a raster image (such as JPEG or PNG format) from their local machine or the cloud as the target image to be processed through the user interface module.
[0059] Step 2: Select or create a segmentation template;
[0060] Option A (Select Pre-built Template): The system has a built-in vectorized template library containing various templates with different visual styles and symbolic meanings, such as:
[0061] Mirror-crack template: simulates the effect of broken glass or mirror, consisting of multiple random or regularly distributed straight lines and broken lines.
[0062] Plot-type template: simulates land, fields, or cell structures, consisting of irregular closed curves.
[0063] Monitoring screen template: simulates a monitoring wall composed of multiple rectangular screens, formed by regular grid lines.
[0064] Option B (Creating a Custom Template): This method provides two ways for users to create entirely new templates:
[0065] Upload a custom vector path: Users can upload an existing vector graphics file, ideally in SVG (Scalable Vector Graphics) format. The system parses the file and extracts the path information as a segmentation template.
[0066] Real-time path drawing: The system provides a simple vector drawing tool that allows users to draw paths directly on the canvas using tools such as straight lines, curves, and Bézier curves. The drawn paths are instantly generated as segmentation templates.
[0067] Step 3: Adjust template parameters;
[0068] For pre-built templates or partially programmatically generated custom templates, users can modify them through the parameter adjustment module to achieve a more personalized effect. Adjustable parameters include, but are not limited to:
[0069] The thickness of the dividing line (stroke-width).
[0070] The number of segmented units (e.g., the number of cracks, the number of plots).
[0071] The degree of randomization (controlling the randomness of the angle, position, and curvature of the lines).
[0072] Template scaling, rotation, and translation.
[0073] Step 4: Apply templates and segmentation;
[0074] This is the core computational step performed by the segmentation template engine.
[0075] Template vector data processing: The engine obtains the final vector path data (whether from presets, uploads, or drawing).
[0076] Mask generation: The engine rasterizes the vector path data to generate a binary or grayscale mask with the same size as the target image. The dividing lines are represented by specific values (such as black or white) on the mask.
[0077] Region identification: The system applies a connected-component labeling algorithm to the generated mask to identify all closed regions surrounded by dividing lines. Each independent closed region is assigned a unique ID.
[0078] (1) Template parameterization;
[0079] To achieve programmed adjustments, mathematical modeling of the template is required. A segmentation template consists of a set of vector paths. This is a set of paths, where each path can be represented as a parameterized function. The set of paths can be represented as:
[0080] ;
[0081] in:
[0082] ;
[0083] Let represent the i-th vector path in the set, which is itself a two-dimensional coordinate function. These are the coordinates of the path curve.
[0084] t is a parameter on the path, usually normalized to the interval [0, 1], representing the process from the start point to the end point of the path.
[0085] N is the total number of vector paths that make up the template, and is a positive integer.
[0086] User adjustments to template parameters (such as scaling, rotation, and translation) are equivalent to applying a uniform affine transformation to this set of path functions. For example, for any path P_i(t), the transformed path... It can be represented as:
[0087] ;
[0088] in:
[0089] ;
[0090] This is the transformation matrix used to implement scaling and rotation.
[0091] It is a translation vector used to achieve position movement.
[0092] In this way, user interactions (such as dragging and rotating sliders) are precisely linked to the coefficient adjustments of the underlying mathematical model.
[0093] (2) Rasterization error problem;
[0094] In practice, it has been found that in areas with insufficient resolution or high curvature of curves, vector-to-raster conversion can cause "jagged edges" or "broken lines." By introducing super-sampling anti-aliasing (SSAA) technology, the resolution is temporarily increased during rasterization. Then, shrink back and use a majority vote to obtain a smoother boundary. The specific steps are as follows:
[0095] a. Create an oversampling canvas: Generate a temporary canvas of size (W·K, H·K), where W and H are the width and height of the target image, respectively, and K is the oversampling factor, where K is an integer greater than 1.
[0096] Preferably, the value of K is in the range of [2, 8]. When K=2, an acceptable anti-aliasing effect can be obtained with a lower computational cost; when K=4, a good balance can be achieved between effect and performance, which is a preferred embodiment of the present invention; when K is greater than 4 (e.g., K=8), higher quality edges can be obtained, but the computational cost will increase significantly.
[0097] b. High-precision rasterization: The vector path data after parameter adjustment is rasterized onto the supersampled canvas.
[0098] c. Downsampling and Filtering: The oversampled canvas of (W·K, H·K) is downsampled (shrunk) to the original mask size of (W, H). This process is accomplished through majority voting.
[0099] For each K×K pixel block on the oversampled canvas, count the number of pixels that belong to "lines". If this number exceeds a threshold (K·K) / 2, the corresponding 1×1 pixel in the final mask is marked as a "line"; otherwise, it is marked as "background".
[0100] The SSAA technique described above can effectively eliminate the jagged edges introduced by rasterization, making the segmentation boundaries smoother and more natural.
[0101] (3) Problem of excessively small connected components;
[0102] When random parameters generate extremely small regions, the resulting layers are almost invisible, incurring significant computational overhead. This invention addresses the problem of chaotic layer arrangement by adding area constraints during connected component labeling.
[0103] ;
[0104] in It is a connected region that has been identified. It is its pixel area. It is a dynamically calculated minimum area threshold. To achieve adaptation to images of different resolutions, the threshold... Defined as:
[0105] ;
[0106] in:
[0107] and These are the width and height of the target image.
[0108] It is an area ratio coefficient. Preferably, The value range is [0.000005, 0.0001]. For example, for a 4K image (approximately 8 million pixels), if α = 0.00001, the minimum area threshold T is approximately 80 pixels. This threshold can effectively filter out tiny fragments that are difficult to distinguish with the naked eye.
[0109] For regions R_j with an area smaller than T, the system can employ a merging strategy, merging them with the adjacent connected regions with the largest area. The threshold value is... It can be adaptively selected according to the image resolution.
[0110] (4) Memory issues with large-size images;
[0111] For images above 8K, the mask matrix size is approximately A single channel requires >64MB; multi-layer stacking may cause memory overflow. A region quadtree block strategy is adopted to divide the image... Represented as hierarchical block division:
[0112] ;
[0113] The splitting operation is performed locally within the sub-blocks, and then the results are merged. Memory usage can be reduced from... Down to .
[0114] When processing ultra-high resolution images (such as 8K and above), generating a complete, high-magnification oversampled mask for the entire image would incur huge memory overhead (for example, a 4x oversampled mask for an 8K image requires (7680×4)×(4320×4)×1 byte ≈ 500MB of memory), potentially leading to memory overflow or a sharp drop in processing speed. To address this issue, this invention employs a region quadtree block partitioning strategy.
[0115] a. Recursive partitioning: Treat the entire image region as the root node of the quadtree. For any node (region), check if it intersects with any template vector path.
[0116] If a region does not intersect with any path, then all pixels within the region belong to the same connected component, requiring no further partitioning, and the node becomes a leaf node.
[0117] If the region intersects with the path and its size is larger than the preset minimum block size. (For example, 512×512 pixels) then the region is divided into four sub-regions (quadrants), which are the child nodes of the current node, and this division process is recursively performed on each child node.
[0118] If the area size is less than or equal to If the partitioning stops, the node becomes a leaf node.
[0119] b. Local Processing and Merging: Through the above division, the original image is decomposed into a series of rectangular sub-blocks represented by leaf nodes. The system only needs to perform the aforementioned "mask generation" and "region recognition" operations on those leaf node sub-blocks that intersect the path. Since the size of each sub-block is controllable, the peak memory usage for processing a single sub-block is reduced from... Reduce to Sub-blocks that do not intersect with the path can be directly marked as a whole region.
[0120] c. Result merging: After all sub-blocks have been processed, the connectivity at the boundaries of adjacent sub-blocks is analyzed, and the same region IDs that cross the boundaries of sub-blocks are merged to finally obtain a globally consistent region identification result.
[0121] This strategy not only significantly reduces the peak memory requirements when processing large images, but also enables parallel computing (multiple sub-blocks can be processed in parallel by multi-core CPUs or GPUs), greatly improving overall performance.
[0122] Step 5: Generate a separate layer;
[0123] The layer generation module iterates through all the region IDs identified in the previous step.
[0124] For each region ID, the system creates a new layer.
[0125] In this new layer, the pixel data corresponding to the location of the region ID in the target image is copied over, while all pixels outside the region are set to transparent.
[0126] Ultimately, the system outputs a set of layers, each containing a fragment of the original image. When these layers are overlaid, the visual effect of the segmented image can be completely reconstructed.
[0127] The core logic of the entire process is as follows: The original image and segmentation template are taken as input, processed by a segmentation template engine, and finally output as a set of independent layers containing image fragments, such as... Figure 3 As shown.
[0128] In summary, the technical solution of the present invention has the following beneficial effects:
[0129] 1. Significantly improves creative efficiency: Compared to manually drawing complex dividing lines using tools such as the pen tool, this method can reduce operation time from hours to seconds. Users only need to select or create a template to complete complex dividing tasks with a single click.
[0130] 2. Greatly Enhances Artistic Expression: Users can use vector graphics such as company logos, personal signatures, and specific cultural symbols as templates to create artworks with strong personal style and profound meaning, which is difficult to achieve with current technology. The various pre-built templates also provide users with a wealth of creative starting points.
[0131] 3. Enables a non-destructive and reversible creative workflow: The layered output retains maximum flexibility for post-editing. Artists can refine each fragment, experimenting with different combinations and effects without worrying about damaging the original image data. For example, blurring can be applied to some fragments while sharpening others, creating rich depth of field and visual focus.
[0132] 4. Lowering the technical barrier: Even ordinary users without advanced image editing skills can easily create professional-level stylized segmentation images through simple template selection and parameter adjustment, promoting the popularization of visual creativity.
[0133] 5. Simple structure and powerful function: The core engine of this invention has a clear logic and is easy to implement in software, but its function is very powerful and can produce ever-changing visual effects, which has high practical and commercial value.
[0134] 6. Mathematical template adaptation mechanism: This invention abstracts the "artistic segmentation" problem into an intersection optimization problem of vector path function and raster image, which can quantify the smoothness of segmentation boundary and the distribution of region size, and automatically correct "too small region" or "jaw ridge" through optimization function.
[0135] Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications and improvements without departing from the spirit and scope of the present invention. Therefore, the scope of protection of the present invention shall be defined by the claims.
Claims
1. A method for adaptive image segmentation based on visual template engine, characterized in that, The method comprises the following steps: S1, loading a raster image as a target image to be processed through user interface interaction from a local or cloud; S2, selecting a segmentation template from a preset template library or creating a user-defined template as a segmentation template; S3, adjusting parameters of the selected template; S4, generating a segmentation mask by applying the adjusted template, identifying and performing a segmentation operation based on the mask; S5, generating a segmented layer result according to the segmentation result; The step S4 comprises: S41, template vector data processing: receiving a target image, a template and parameters, and obtaining final vector path data; S42, mask generation: rasterizing the vector path data to generate a binary or grayscale mask with the same size as the target image; S43, region identification: applying a connected component analysis algorithm to the generated mask to identify all closed regions surrounded by segmentation lines and extract each segmentation region.
2. The visual template engine based adaptive image segmentation method of claim 1, wherein, The preset template library in the step S2 is an internal vectorized template library, comprising: mirror crack type template: simulating the effect of glass or mirror breakage, composed of multiple random or regularly distributed straight lines and curved lines; land block type template: simulating land, field or cell structure, composed of irregular closed curves; monitor screen type template: simulating a monitoring wall composed of multiple rectangular screens, composed of regular grid lines.
3. The visual template engine based adaptive image segmentation method of claim 1, wherein, The step S2 creates a user-defined template in the following manner: uploading an existing vector graphics file, parsing the file and extracting path information therein as a segmentation template; or providing a vector drawing tool to accept user drawing paths on a canvas using straight lines, curves or Bezier curves, and the drawn paths are instantly generated as a segmentation template.
4. The visual template engine based adaptive image segmentation method of claim 1, wherein, The step S3 comprises: adjusting the thickness of the segmentation lines; adjusting the number of segmentation units; controlling the angle, position and curvature of the lines; and scaling, rotating and translating the template.
5. The visual template engine based adaptive image segmentation method of claim 1, wherein, The step S41 represents the vector path set from the template as: ; wherein: ; the i-th vector path in the representative set, is the path curve coordinate, t is a parameter on the path, normalized to the interval [0, 1], representing the progress from the start to the end of the path, and N is the total number of vector paths that make up the template; Scaling, rotating, translating, and other adjustments to the template are equivalent to applying a uniform affine transformation to the set of path functions, the new paths is represented as: ; wherein: ; is a transformation matrix for implementing scaling and rotation, is a rotation angle; is a translation vector for implementing position movement.
6. The visual template engine based adaptive image segmentation method of claim 1, wherein, The segmentation lines in the step S42 are represented as black or white on the mask, and the resolution is temporarily increased by K times during rasterization, and then reduced, and a majority voting method is used to obtain a smooth boundary; specifically comprising: a. creating an oversampling canvas: generating a temporary canvas with a size of (W·K, H·K), where W and H are the width and height of the target image respectively, K is the oversampling factor, K is an integer greater than or equal to 1, and the value range of K is [2, 8]; b. high-precision rasterization: rasterizing the vector path data after parameter adjustment to the oversampling canvas; c. downsampling and filtering: downsampling the (W·K, H·K) oversampling canvas to the original mask size (W, H) by majority voting; for each K×K pixel block on the oversampling canvas, count the number of pixels belonging to the line; if the number exceeds a threshold (K·K) / 2, the corresponding 1×1 pixel in the final mask is marked as a line; otherwise, it is marked as background.
7. The visual template engine based adaptive image segmentation method of claim 1, wherein, The step S43 adds an area constraint when labeling connected domains: ; wherein is an identified connected region, is the pixel area thereof, is a dynamically computed minimum area threshold: ; and is the width and height of the target image, is an area proportion coefficient, the value range of is [0.000005, 0.0001]; For the area less than T, the merging strategy is adopted to merge it with the largest adjacent connected area.
8. The visual template engine based adaptive image segmentation method of claim 1, wherein, When the target image is an 8K or above image, the step S4 adopts a region quadtree block strategy for segmentation processing, specifically including: a. Recursive division: the entire image area is taken as the root node of the quadtree; for any region in the image, check whether it intersects with the template vector path; if the region does not intersect with any path, all pixels in the region belong to the same connected domain, and no further division is needed, and the corresponding node becomes a leaf node; if the region intersects the path and its size is greater than a preset minimum bin size then the region is evenly divided into four sub-regions as child nodes of the current node, and this division process is recursively performed for each sub-region; If the region size has been smaller than or equal to then stop dividing, and the node becomes a leaf node as well. b. Local processing and merging: through the above division, the original image is decomposed into a series of sub-blocks represented by leaf nodes; for the sub-blocks corresponding to the leaf nodes intersecting with the path, mask generation and region identification operations are performed; the sub-blocks not intersecting with the path are directly marked as a whole region; c. Result merging: after all sub-blocks are processed, the same region IDs across the sub-block boundaries are merged by analyzing the connectivity at the boundaries of adjacent sub-blocks, and finally a globally consistent region identification result is obtained.
9. The visual template engine based adaptive image segmentation method of claim 1, wherein, The step S4 assigns a unique ID to each independent closed region, and the step S5 includes: traversing all region IDs identified in step S4; creating a new layer for each region ID; In the new layer, the pixel data corresponding to the position of the region ID in the target image is copied, and all pixels outside the region are set to transparent; thus, an independent transparent layer is generated for each region.
Citation Information
Patent Citations
Rapid cutting method for mass images through template self-adaption
CN109961439A
Method, system and device of image segmentation
US20230289969A1