Intelligent image cutting method, device and equipment based on SAM segmentation model
The SAM segmentation model combines RDP and DBSCAN algorithm to optimize the image contour, which solves the problems of insufficient cutting accuracy and low automation in the existing technology, and realizes high-precision and intelligent image cutting, which is suitable for efficient processing of complex patterns.
Patent Information
- Application Number
- CN202510502354.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-22
- Publication Date
- 2025-07-18
AI Technical Summary
The existing image segmentation technology has low edge contour fineness in high-precision cutting scenarios, and the adjacent areas do not fit closely, and the generated contour files have redundant points and noise, resulting in insufficient cutting accuracy and low automation level.
Image segmentation is performed using SAM segmentation model, combined with RDP algorithm and DBSCAN clustering, contour points are optimized through morphological operations, closed contour curves are generated and converted into DXF documents, which is suitable for processing of CNC equipment.
It significantly improves the cutting accuracy and automation level, reduces the time of manual contour drawing, improves the fineness and splicing quality of the contour after segmentation, and promotes the intelligent development of the cutting process.
Smart Images

Figure CN120339309A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image cutting, and more particularly, to an intelligent image cutting method, device, and equipment based on the SAM segmentation model. Background Art
[0002] In the fields of modern industrial manufacturing and decorative arts, the application of image segmentation and automated cutting technology is becoming increasingly widespread. By segmenting the target image and generating a machinable contour file, efficient cutting and splicing of materials can be achieved, thereby meeting decorative, artistic, and functional requirements.
[0003] Traditional cutting processes usually rely on manual tracing to obtain the contour of the target area. This method not only consumes a large amount of human resources but also has low efficiency and is difficult to meet the needs of large-scale production.
[0004] In recent years, with the development of computer vision technology, deep learning-based image segmentation models, such as SAM (Segment Anything Model), have gradually been applied to the industrial field. Such models can quickly and accurately segment different labeled regions in the image, providing a basis for subsequent automated processing. However, existing image segmentation technologies still have many deficiencies in practical applications. For example, the fineness of the edge contours generated after segmentation is relatively low. Especially in high-precision cutting scenarios, the segmentation results often cannot directly meet the requirements of the numerical control equipment for the contour. In addition, due to the limitations of the segmentation algorithm itself, the contours of adjacent regions may not fit tightly after segmentation, resulting in gaps or misalignments when the processed parts are spliced, affecting the final product quality. At the same time, in the process from the segmentation result to generating a DXF document that can be used by numerical control equipment, there is a lack of systematic optimization methods, resulting in problems such as redundant points, noise points, and non-machinable tiny contours in the generated contour file. These problems not only limit the automation level of the cutting process but also increase the workload of post-processing.
[0005] In view of this, the present application is proposed. Summary of the Invention
[0006] The present invention aims to provide an intelligent image cutting method, device, and equipment based on the SAM segmentation model to solve the disadvantages of low efficiency and insufficient automation in manual contour tracing in existing methods, and aims to provide a more accurate, stable, and adaptable solution for complex pattern segmentation requirements, so as to significantly improve the automation level and accuracy of the cutting process.
[0007] To solve the above technical problems, the present invention is realized through the following technical solutions: An intelligent image cutting method based on the SAM segmentation model, comprising: S1, obtaining a target image to be segmented; S2. Region-label and segment the target image with a preset SAM segmentation model to obtain an initial mask image of the labeled region; S3. Perform binarization format conversion processing on the initial mask image to generate a target mask image; S4. Extract the contour information of the labeled region in the target mask image and convert it into a set of contour points; S5. On the premise that the overall contour of the target image remains unchanged, use the RDP algorithm combined with a preset threshold to selectively remove and add contour points to the set of contour points to obtain a simplified set of contour points; S6. Perform clustering operations on the contour points of adjacent image labeled regions according to the simplified set of contour points to ensure that the adjacent regions of the image can still fit closely and achieve smooth transition; S7. Fit the clustered set of contour points into a closed contour curve through spline curve fitting, and cut the material according to the closed contour curve to complete intelligent image cutting.
[0008] Preferably, the binarization format conversion processing operation is specifically: Convert the initial mask image into a binary image through channel expansion technology; Perform morphological operations on the binary image with preset morphological parameters to fill the internal holes of the image contour and smooth the external contour at the same time, and generate a target mask image.
[0009] Preferably, when extracting contour information, use the boundary tracking algorithm to determine the boundary points of the labeled region by scanning the pixel distribution of the labeled region in the target mask image; Remove noise or tiny contours that cannot be processed in the labeled region through a preset point quantity threshold.
[0010] Preferably, using the RDP algorithm combined with a preset threshold to selectively remove and add contour points to the set of contour points is specifically: Use the RDP algorithm to simplify the set of contour points with a preset simplification threshold, retain the key points that support the contour shape, and obtain a set of key points; Traverse and calculate the inter-point distance between any two points in the set of key points , the expression is: ; where represents any two points in the set of key points 、 's Euclidean distance, that is, the inter-point distance; If the inter-point distance If it is greater than the preset distance threshold D, then according to the ratio of the distance between the points and the preset distance threshold, points are evenly added between the two points, so as to obtain a simplified contour point set.
[0011] Preferably, it further includes: when evenly adding points between two points, the number of added points is an integer obtained by rounding up the ratio of the distance between the points and the preset distance threshold.
[0012] Preferably, when clustering the contour points of adjacent image marking regions according to the simplified contour point set, a dual clustering operation based on DBSCAN is adopted. Specifically: First, the contour point sets of two adjacent regions are respectively defined as the first contour point set and the second contour point set ; Next, the points in the first contour point set are defined as core points, and each point in the second contour point set is marked with a preset neighborhood . The points within the marked range are defined as the first boundary points , and the first clustering operation is completed. The expression is: ; Among them, , respectively represent the points of the first contour point set and the second contour point set ; is an indicator function, which is 1 when the condition is satisfied, otherwise 0; represents the minimum number of objects in the DBSCAN neighborhood; is a preset neighborhood, represents the neighborhood radius of; The first boundary points are defined as the core points of the second round, and the first contour point set is marked with a neighborhood . The points within the marked range are defined as the second boundary points , and the second clustering operation is completed; ; Among them, represents the points in the first boundary points ; represents existence, that is, there exists such that ; Calculate the second boundary points The center point C between it and the corresponding core point is used to replace the second boundary point with the coordinates of the center point C and the positions of its corresponding core points are de-duplicated to achieve point set contraction, and the set of contour points after clustering is obtained , and the expression is: ; ; Among them, 、 respectively represent 、 the points in; represents belonging to but not belonging to the elements of, represents the difference set operation; represents the union operation.
[0013] Preferably, when the set of contour points after clustering is fitted into a closed contour curve by a spline curve, each set of contour points after clustering of the marked area is traversed, and a point with the same coordinates as the starting point in the set of contour points is inserted at the end of the set of contour points to ensure the closure of the spline curve.
[0014] Preferably, it further includes: based on the ezdxf library, a blank DXF document is set, and the control points of the closed contour curve are added to the DXF document to facilitate batch cutting processing according to the DXF document.
[0015] The present invention also provides an intelligent image cutting device based on the SAM segmentation model, including: An acquisition unit for acquiring a target image to be segmented; A SAM segmentation unit for performing region annotation and segmentation on the target image through a preset SAM segmentation model to obtain an initial mask image of the marked area; A binarization unit for performing binarization format conversion processing on the initial mask image to generate a target mask image; A contour point extraction unit for extracting the contour information of the marked area in the target mask image and converting it into a set of contour points; An RDP simplification unit for selectively removing and adding contour points to the set of contour points by using the RDP algorithm in combination with a preset threshold on the premise that the overall contour of the target image remains unchanged, and obtaining a simplified set of contour points; A clustering unit for performing clustering operations on the contour points of adjacent image marked areas according to the simplified set of contour points to ensure that the adjacent areas of the image can still be closely fitted and achieve smooth transition; A curve fitting unit is used to form a closed contour curve by spline curve fitting of the clustered set of contour points, and cut the material according to the closed contour curve to complete intelligent image cutting.
[0016] The present invention also provides an intelligent image cutting device based on the SAM segmentation model, including a processor and a memory. A computer program is stored in the memory, and the computer program can be executed by the processor to implement an intelligent image cutting method based on the SAM segmentation model as described above.
[0017] The present invention also provides a computer-readable storage medium. Computer-readable instructions are stored on the computer-readable storage medium, and when the computer-readable instructions are executed by the processor of the device where the computer-readable storage medium is located, an intelligent image cutting method based on the SAM segmentation model as described above is implemented.
[0018] In summary, compared with the prior art, the present invention has the following beneficial effects: The present invention uses the SAM segmentation model to automatically segment the target image, reducing the time for manual contour drawing while retaining the space for personalized cutting. Secondly, through the optimization processing of contour points and the clustering operation of adjacent regions, the fineness and splicing quality of the segmented contour are significantly improved. In addition, the DXF document generated by the control points of the spline curve is directly used for the processing of numerical control equipment, promoting the automation process of the cutting process. The method of the present invention is applicable to cutting scenarios of various materials and patterns, especially suitable for the high-precision processing requirements of complex patterns.
[0019] The present invention ensures flexibility and adaptability in different application scenarios by dynamically adjusting morphological parameters, point quantity thresholds, simplification thresholds, distance thresholds, and neighborhood parameters, and realizes the efficient conversion from the target image to the processable DXF document.
[0020] The present invention can maintain high precision in complex pattern cutting and reduce the scale of redundant point sets in simple pattern cutting, thereby improving the overall cutting efficiency.
[0021] By combining image segmentation technology, contour optimization algorithms, and automated file generation processes, the present invention solves the problems of high labor costs, insufficient cutting accuracy, and low automation level in the traditional cutting field, providing strong technical support for the intelligent development of the cutting field. Description of the Drawings
[0022] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for the embodiments. It should be understood that the following drawings only show some embodiments of the present invention, and therefore should not be regarded as a limitation of the scope. For those of ordinary skill in the art, without creative efforts, other relevant drawings can also be obtained based on these drawings.
[0023] Figure 1 Flow schematic diagram of an intelligent image cutting method based on the SAM segmentation model provided for Embodiment 1.
[0024] Figure 2 Example diagram of the target image provided for Embodiment 1.
[0025] Figure 3 Example diagram of the target mask image provided for Embodiment 1.
[0026] Figure 4 Example diagram of the contour mixing point set of adjacent image marking regions provided for Embodiment 1.
[0027] Figure 5 Example diagram of the point set after contour clustering of adjacent image marking regions provided for Embodiment 1.
[0028] Figure 6 Example diagram of the machinable contour of the image marking region provided for Embodiment 1.
[0029] Figure 7 Schematic diagram of an intelligent image cutting device based on the SAM segmentation model provided for Embodiment 2.
[0030] The following further details the present invention in conjunction with the drawings and specific embodiments. Specific Embodiments
[0031] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present invention. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present invention.
[0032] Embodiment 1 Embodiment 1 of the present invention provides an intelligent image cutting method based on the SAM segmentation model, which can be implemented by an intelligent image cutting device based on the SAM segmentation model (hereinafter referred to as the image cutting device). In particular, it is executed by one or more processors in the image cutting device.
[0033] In this embodiment, the image cutting device can be an electronic device equipped with a processor, and the processor has a computer program of the intelligent image cutting method based on the SAM segmentation model and the computer program can be executed, such as a computer, a smart phone, a smart tablet, a workstation, etc., which is not limited here.
[0034] As Figure 1 shown, an intelligent image cutting method based on the SAM segmentation model includes steps S1 to S7.
[0035] S1. Obtain the target image to be segmented.
[0036] As Figure 2 shown in the example of the target image, after obtaining the target image, preprocessing such as image enhancement and cropping can be performed on the target image to facilitate subsequent segmentation operations.
[0037] S2. Perform region annotation and segmentation on the target image through a preset SAM segmentation model to obtain an initial mask image of the marked region.
[0038] Segment the target image through a preset SAM segmentation model, and after segmentation, obtain the initial mask image of the marked region in the image.
[0039] In this embodiment, the SAM (Segment Anything Model) segmentation model is an image segmentation model based on deep learning, which adopts an encoder-decoder structure. The encoder extracts image features, and the decoder generates segmentation results to identify objects in the image and generate high-quality segmentation masks.
[0040] In this process, a pre-trained SAM segmentation model is used for segmentation. The user inputs the original image and prompts (such as points, boxes, texts), and different regions in the target image are marked through interactive selection. The SAM segmentation model automatically generates corresponding segmentation results according to the selection and input. The core of the segmentation model lies in its ability to quickly learn and adapt to diverse image features, thereby providing accurate basic data for subsequent processing. In practical applications, for example, in the decorative sheet cutting scenario, the user can mark different parts of the complex pattern separately to ensure that the segmentation result meets the processing requirements.
[0041] S3. Perform binary format conversion processing on the initial mask image to generate a target mask image.
[0042] In this step, the initial mask image is subjected to format conversion to obtain a target mask image example as shown in the appendix. Figure 3 as shown.
[0043] This process includes two main aspects: channel expansion technology and image binarization. The initial mask image usually contains multi-channel information, which is converted into a single-channel image through channel expansion technology, and further converted into a binary image using image binarization. The binarization operation sets the pixel values in the image to 0 or 255, representing the background and foreground regions respectively. However, due to the semi-automatic annotation mode, internal holes or edge serrations may be introduced, so morphological operations are required to optimize the binary image. The selection of morphological parameters needs to be dynamically adjusted according to the characteristics of the target image. For example, for patterns with more complex edges, a larger structural element can be selected for dilation operation to fill the holes, and erosion operation can be used to smooth the external contour. For example, a 5×5 rectangular structural element is used, and 3 dilation operations are performed first and then 2 erosion operations. The target mask image after the above processing not only retains the accuracy of the original segmentation result but also has higher edge fineness, laying a foundation for subsequent contour extraction.
[0044] S4. Extract the contour information of the marked area in the target mask image and convert it into a set of contour points.
[0045] Extract the contour information of each marked area in the target mask image and convert it into a set of contour points, as shown in the appendix. Figure 4 as shown.
[0046] When performing contour extraction, a boundary tracking algorithm can be used. By scanning the pixel distribution in the target mask image, the boundary points of the marked area are determined. These boundary points form a set of contour points, and the coordinates of each point represent the boundary position of the marked area. To ensure that the number of contour points meets the processing requirements of the numerical control equipment, noise points or tiny contours that cannot be processed are removed through a preset point number threshold. For example, in practical applications, if the number of contour points of a certain marked area is lower than the preset threshold, it is determined that the area is an unprocessable area and is excluded. This operation effectively avoids the interference of small invalid contours caused by noise or segmentation errors to the subsequent processing process.
[0047] S5. On the premise that the overall contour of the target image remains unchanged, the RDP algorithm is combined with a preset threshold to selectively remove and add contour points to the set of contour points to obtain a simplified set of contour points.
[0048] On the premise of ensuring that the overall contour remains unchanged, selectively remove and add to the set of contour points to generate a simplified set of contour points.
[0049] This process uses the RDP (Ramer-Douglas-Peucker) algorithm to simplify the set of contour points with a preset simplification threshold (such as set to 0.5 pixels), retaining the key points that support the contour shape to obtain a set of key points.
[0050] The RDP algorithm is an algorithm used to reduce the number of points in a set of points connected by lines, simplifying curves or polygons by retaining the basic shape of the data. The algorithm starts from the starting point and the ending point of a set of points, and finds a point that is farthest from the straight line segment connecting the starting point and the ending point. If the distance of this point to the straight line is less than a given threshold (such as 2.5 mm), then all intermediate points will be removed; if the distance is greater than the threshold, this point will be retained, and then the algorithm will be recursively applied to the two subsets from the starting point to this point and from this point to the ending point.
[0051] The core idea of the RDP algorithm is to recursively calculate the distance from points to the straight line, remove redundant points with a distance less than the simplification threshold, thereby greatly reducing the number of contour points. However, there may be a situation where the distance between two points in the simplified set of contour points is too large, which will cause the straight line part to not be correctly recognized during spline curve fitting. Therefore, traverse and calculate the distance between any two points in the set of key points , and the expression is: ; where represents any two points in the set of key points , 's Euclidean distance, that is, the distance between points; If the distance between points is greater than the preset distance threshold (for example, set to 3 mm), then according to the ratio of the distance between points and the preset distance threshold, points are evenly added between the two points, thereby obtaining a simplified set of contour points.
[0052] Specifically, when evenly adding points between two points, the number of added points can be the integer obtained by rounding up the ratio of the distance between points and the preset distance threshold.
[0053] For example, if the distance between two points is 10 units and the preset distance threshold is 3 units, then 4 points need to be evenly added between the two points to assist the spline curve in correctly recognizing the straight line. Through the above operations, both the number of redundant points is reduced and the geometric accuracy of the contour is ensured.
[0054] S6. Perform a clustering operation on the contour points of adjacent image marking regions according to the simplified set of contour points to ensure that the adjacent regions of the image can still fit closely and achieve a smooth transition.
[0055] To further solve the problem that adjacent regions cannot fit tightly after segmentation, it is necessary to perform a clustering operation on the contour points of adjacent image marking regions to generate a point set of the clustered contours of adjacent regions, as shown in the appendix Figure 5 as follows.
[0056] This process is based on the DBSCAN clustering method. In this embodiment, DBSCAN (Density-Based Spatial Clustering of Applications with Noise) is a density-based clustering algorithm, and its core idea is to divide clusters based on the tightness of sample distribution. The algorithm expands clusters through density reachability: starting from core points, recursively find all density-connected points to form clusters of arbitrary shapes, and automatically exclude noise.
[0057] First, the contour point sets of two adjacent regions are respectively defined as the first contour point set and the second contour point set , and the minimum number of objects in the DBSCAN neighborhood is set.
[0058] Next, the points in the first contour point set are defined as core points, and the points in the second contour point set (such as set as the radius ) are marked with a preset neighborhood . The points within the marked range are defined as the first boundary points (that is, the points in the second contour point set are the first boundary points if they are within the preset neighborhood range ), and the first clustering operation is completed. The expression is: ; where , respectively represent the points of the first contour point set and the second contour point set ; is an indicator function, which is 1 when the condition is satisfied and 0 otherwise; represents the minimum number of objects in the DBSCAN neighborhood; is the preset neighborhood, represents the neighborhood radius of.
[0059] The first boundary points are defined as the core points of the second round, and the first contour point set is marked with a neighborhood . The points within the marked range are defined as the second boundary points (i.e., the first set of contour points If a point in the is within the neighborhood range, it is a second boundary point ), complete the second clustering operation, and the expression is: Among them, represents the points in the first boundary point ; represents existence, that is, there exists such that .
[0060] Calculate the center point C between the second boundary point and its corresponding core point, and replace the coordinates of the second boundary point and the corresponding core point (i.e., the first boundary point ) in the position of the simplified contour point set and remove duplicates to achieve point set contraction, and obtain the clustered contour point set , and the expression is: ; ; Among them, , respectively represent , ; represents belonging to but not belonging to elements, represents the difference set operation; represents the union operation.
[0061] For example, in practical applications, if the coordinates of a certain core point in the first set of contour points are (10, 20) and the coordinates of the second boundary point are (12, 22), then the coordinates of the center point are (11, 21). Through the above double clustering operation, the contour points in adjacent regions can be closely fitted, significantly improving the splicing quality.
[0062] S7. Fit the clustered contour point set into a closed contour curve through spline curve fitting, and cut the material according to the closed contour curve to complete the intelligent image cutting.
[0063] In this step, traverse the clustered contour point sets of each marked area, and insert a point with the same coordinates as the starting point in the contour point set at the end to ensure that the contour point set forms a closed area.
[0064] Based on the ezdxf library, after declaring a blank DXF document, the points of the clustered contour point set are added to the DXF document as the control points of the spline curve to form a closed contour curve and save the DXF document.
[0065] Spline curve fitting ensures that the generated contour curve meets the processing requirements of numerical control equipment through smooth transitions between control points. For example, if the contour point set of a certain marked area contains 100 points, a point with the same coordinates as the first point is added at the 101st position to make the entire contour point set form a closed area. Subsequently, these points are used as the control points of the spline curve and added to the DXF document in sequence, finally generating a machinable contour as shown in the appendix. Figure 6 shown.
[0066] In practical applications, this method is applicable to cutting scenarios of various materials and patterns. For example, in the field of metal sheet cutting, users can quickly generate DXF files of complex patterns through this method and directly use them for processing by laser cutting machines or water jet cutting machines. In addition, this method can also be applied to scenarios such as wood carving and glass cutting. By dynamically adjusting morphological parameters, point quantity thresholds, simplification thresholds, distance thresholds, and neighborhood parameters, the flexibility and adaptability in different application scenarios are ensured. For example, when dealing with simple patterns, the scale of redundant point sets can be reduced by lowering the point quantity threshold and simplification threshold, thereby improving the overall efficiency; while when dealing with complex patterns, the contour accuracy is enhanced by increasing the distance threshold and neighborhood parameters to meet the high-precision processing requirements.
[0067] In summary, compared with the prior art, the present invention has the following beneficial effects: The present invention realizes the efficient conversion from the target image to the machinable DXF document by combining image segmentation technology, contour optimization algorithms, and automated file generation processes. It not only significantly reduces the time for manual contour drawing, improves the fineness and splicing quality of the segmented contours, but also promotes the automation process of the cutting process, providing strong technical support for the intelligent development of the cutting field.
[0068] Embodiment 2 As Figure 7 shown, the second embodiment of the present invention also provides an intelligent image cutting device based on the SAM segmentation model, including: An acquisition unit for acquiring the target image to be segmented; A SAM segmentation unit for performing region annotation and segmentation on the target image through a preset SAM segmentation model to obtain an initial mask image of the marked area; A binarization unit for performing binarization format conversion processing on the initial mask image to generate a target mask image; An outline point extraction unit is used to extract the outline information of the marked area in the target mask image and convert it into a set of outline points; An RDP simplification unit is used to selectively remove and add outline points to the set of outline points by using the RDP algorithm in combination with a preset threshold on the premise that the overall outline of the target image remains unchanged, so as to obtain a simplified set of outline points; A clustering unit is used to perform a clustering operation on the outline points of adjacent image marked areas according to the simplified set of outline points, so as to ensure that the adjacent areas of the image can still fit closely and achieve a smooth transition; A curve fitting unit is used to fit the clustered set of outline points into a closed outline curve through spline curve fitting, and cut the material according to the closed outline curve to complete intelligent image cutting.
[0069] Embodiment III The third embodiment of the present invention also provides an intelligent image cutting device based on the SAM segmentation model, which includes a memory and a processor. A computer program is stored in the memory, and the computer program can be executed by the processor to implement the intelligent image cutting method based on the SAM segmentation model as described above.
[0070] Embodiment IV The fourth embodiment of the present invention also provides a computer-readable storage medium. Computer-readable instructions are stored on the computer-readable storage medium. When the computer-readable instructions are executed by the processor of the device where the computer-readable storage medium is located, the intelligent image cutting method based on the SAM segmentation model as described above is implemented.
[0071] In several embodiments provided by the embodiments of the present invention, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device and method embodiments described above are only illustrative. For example, the flowcharts in the drawings show the possible architectures, functions, and operations of devices, methods, and computer program products according to multiple embodiments of the present invention. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, as well as the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0072] In addition, in each embodiment of the present invention, each functional module may be integrated together to form an independent part, or each module may exist alone, or two or more modules may be integrated to form an independent part.
[0073] If the above-mentioned functions are implemented in the form of software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, an electronic device, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs. It should be noted that in this article, the term "comprising", "including" or any other variant thereof is intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitations, an element defined by the statement "including an..." does not exclude the existence of additional identical elements in the process, method, article or device including the said element.
[0074] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "the" and "said" used in the embodiments of the present invention and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise.
[0075] It should be understood that the term " / and" used in this article is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in this article generally represents an "or" relationship between the associated objects before and after.
[0076] Depending on the context, as used herein, the word "if" can be interpreted as "when" or "while" or "in response to determining" or "in response to detecting". Similarly, depending on the context, the phrase "if determined" or "if detecting (stated condition or event)" can be interpreted as "when determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)".
[0077] The "first / second" mentioned in the embodiments is only to distinguish similar objects and does not represent a specific order for the objects. It can be understood that the "first / second" can be interchanged in a specific order or sequence when permitted. It should be understood that the objects distinguished by the "first / second" can be interchanged under appropriate circumstances so that the embodiments described herein can be implemented in an order other than those illustrated or described herein.
[0078] The foregoing is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. An intelligent image cutting method based on the SAM segmentation model, characterized in that, Including: S1. Obtain a target image to be segmented; S2. Perform region annotation and segmentation on the target image through a preset SAM segmentation model to obtain an initial mask image of the marked region; S3. Perform binary format conversion processing on the initial mask image to generate a target mask image; S4. Extract the contour information of the marked region in the target mask image and convert it into a set of contour points; S5. On the premise that the overall contour of the target image remains unchanged, use the RDP algorithm combined with a preset threshold to selectively remove and add contour points to the set of contour points to obtain a simplified set of contour points; S6. Perform clustering operations on the contour points of adjacent image marked regions according to the simplified set of contour points to ensure that the adjacent regions of the image can still fit closely and achieve smooth transition; S7. Fit the clustered set of contour points into a closed contour curve through spline curve fitting, and cut the material according to the closed contour curve to complete intelligent image cutting.
2. The intelligent image cutting method based on the SAM segmentation model according to claim 1, characterized in that , The binary format conversion processing operation specifically is: Convert the initial mask image into a binary image through channel expansion technology; Perform morphological operations on the binary image with preset morphological parameters to fill the internal holes of the image contour and smooth the external contour at the same time, and generate a target mask image.
3. The intelligent image cutting method based on the SAM segmentation model according to claim 1, wherein , When extracting contour information, use the boundary tracking algorithm to determine the boundary points of the marked region by scanning the pixel distribution of the marked region in the target mask image; Remove noise points or inprocessable tiny contours in the marked region through a preset point quantity threshold.
4. An intelligent image cutting method based on the SAM segmentation model according to claim 1, characterized in that , Using the RDP algorithm combined with a preset threshold to selectively remove and add contour points to the set of contour points specifically is: Use the RDP algorithm to simplify the set of contour points with a preset simplification threshold, and retain the key points supporting the contour shape to obtain a set of key points; Traverse and calculate the distance between any two points in the key point set , and the expression is: ; Among them, represents the Euclidean distance between any two points in the set of key points , that is, the distance between points; If the distance between the points is greater than the preset distance threshold, add points evenly between the two points according to the ratio of the distance between the points and the preset distance threshold, so as to obtain a simplified set of contour points.
5. The intelligent image cutting method based on the SAM segmentation model according to claim 4, characterized in that , It also includes: when adding points evenly between two points, the number of added points is the integer obtained by rounding up the ratio of the distance between the points and the preset distance threshold.
6. The intelligent image cutting method based on the SAM segmentation model according to claim 1, wherein , When performing clustering operations on the contour points of adjacent image marked regions according to the simplified set of contour points, use double clustering operations based on DBSCAN, specifically: First, the contour point sets of two adjacent regions are respectively defined as the first contour point set and the second contour point set ; Next, define the points in the first contour point set as core points, and mark each point in the second contour point set with a preset neighborhood. The points within the marked range are defined as the first boundary points , completing the first clustering operation. The expression is as follows: , completing the first clustering operation, the expression is: ; Among them, , respectively represent the points of the first contour point set and the second contour point set ; is an indicator function, which is 1 when the condition is satisfied and 0 otherwise; represents the minimum number of objects in the DBSCAN neighborhood; is a preset neighborhood, represents the neighborhood radius of; Define the first boundary point as the core point of the second round, and use the neighborhood to mark the first contour point set . The points within the marked range are defined as the second boundary points , completing the second clustering operation. The expression is as follows: ; Among them, represents the points in the first boundary point ; represents existence, that is, there exists such that ; Calculate the second boundary point The center point C between it and the corresponding core point, and replace the second boundary point with the coordinates of the center point C And the positions of its corresponding core points are de-duplicated to achieve point set contraction, and the set of contour points after clustering is obtained , the expression is: ; ; Among them, , respectively represent , the points in; means belonging to but not belonging to the elements of, represents the difference set operation; represents the union operation.
7. The intelligent image cutting method based on the SAM segmentation model according to claim 1, wherein , When fitting the clustered set of contour points into a closed contour curve through spline curve fitting, traverse the clustered set of contour points of each marked region, and insert a point with the same coordinates as the starting point in the set of contour points at the end of the set of contour points to ensure the closure of the generated spline curve.
8. An intelligent image cutting method based on the SAM segmentation model according to claim 1, characterized in that , It also includes: Based on the ezdxf library, set a blank DXF document, and add the control points of the closed contour curve to the DXF document for batch cutting processing according to the DXF document.
9. An intelligent image cutting device based on the SAM segmentation model, characterized in that Including: An acquisition unit for acquiring a target image to be segmented; A SAM segmentation unit for performing region annotation and segmentation on the target image through a preset SAM segmentation model to obtain an initial mask image of the marked region; A binarization unit, configured to perform binarization format conversion processing on the initial mask image to generate a target mask image; A contour point extraction unit, configured to extract the contour information of the marked area in the target mask image and convert it into a contour point set; An RDP simplification unit, configured to selectively remove and add contour points to the contour point set by using the RDP algorithm in combination with a preset threshold on the premise that the overall contour of the target image remains unchanged, so as to obtain a simplified contour point set; A clustering unit, configured to perform clustering operations on the contour points of adjacent image marked areas according to the simplified contour point set, so as to ensure that the adjacent areas of the image can still be closely attached to achieve smooth transition; A curve fitting unit, configured to form a closed contour curve by spline curve fitting of the clustered contour point set, and cut the material according to the closed contour curve to complete intelligent image cutting.
10. An intelligent image cutting device based on the SAM segmentation model, characterized in that, It includes a processor and a memory, and a computer program is stored in the memory. The computer program can be executed by the processor to implement an intelligent image cutting method based on the SAM segmentation model according to any one of claims 1-8.
Citation Information
Cited By
Mask layout correction method and system based on combination of membrane calculation and DBSCAN algorithm, medium, program product and terminal
CN122085587A