Image edge cutting method and device based on boundary detection, equipment and storage medium

By preprocessing the image and performing scene-adaptive edge detection, combined with boundary localization rules, the problem of inaccurate boundary recognition in complex scenes by traditional methods is solved, achieving a more stable and reliable image cropping effect.

CN121033089BActive Publication Date: 2026-02-06CREATOR CHINA TCH CO +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511545789.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-28
Publication Date
2026-02-06
Estimated Expiration
2045-10-28

AI Technical Summary

Technical Problem

Existing automatic image cropping methods based on Canny edge detection and Hough transform are difficult to stably and accurately filter out the real physical boundaries in low-contrast, dark, or colored bordered card images, resulting in poor robustness and insufficient reliability of the cropping results in complex scenes.

Method used

By preprocessing the original image, the scene type is determined, and edge detection is performed based on the edge detection strategy corresponding to the scene type. Adaptive edge detection and boundary localization rules are used to determine the target boundary line segment from the candidate line segments for edge trimming.

Benefits of technology

It effectively improves the accuracy of boundary recognition in challenging scenarios such as low light and complex backgrounds, achieves more stable and reliable image cropping effects, and ensures the efficient operation of the algorithm in a lightweight computing environment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121033089B_ABST
    Figure CN121033089B_ABST
Patent Text Reader

Abstract

The application discloses an image edge cutting method and device based on boundary detection, equipment and a storage medium, relates to the technical field of image boundary detection, and comprises the following steps: preprocessing an original image to obtain a target image; determining the scene type of the target image; performing edge detection on the target image based on an edge detection strategy corresponding to the scene type to obtain an edge image; performing straight line detection on the edge image to obtain a plurality of candidate straight line segments; determining a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule, so as to cut the edges of the original image according to the target boundary line segment. The application can generate a more reliable image edge cutting effect.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image boundary detection, and particularly relates to an image edge cutting method and device based on boundary detection, equipment and a storage medium. BACKGROUND

[0002] The prior art image automatic edge cutting method based on Canny edge detection and Hough transformation often leads to low signal-to-noise ratio of the edge image and a large number of interference candidate straight lines when processing low-contrast, dark-light or color frame card images, and it is difficult to stably and accurately screen out the real physical boundary from the candidate straight lines, resulting in poor robustness and insufficient reliability of the edge cutting result in complex scenes.

[0003] The above content is only used to assist in understanding the technical solutions of the present application and does not represent the acknowledgement of the above content as prior art. SUMMARY

[0004] The main purpose of the present application is to provide an image edge cutting method, which aims to solve the technical problem that the traditional image edge cutting method is difficult to accurately screen out the real physical boundary, resulting in poor edge cutting effect in complex scenes.

[0005] To achieve the above purpose, the present application provides an image edge cutting method based on boundary detection, which comprises:

[0006] Pretreating an original image to obtain a target image;

[0007] Determining the scene type of the target image;

[0008] Based on the edge detection strategy corresponding to the scene type, performing edge detection on the target image to obtain an edge image;

[0009] Performing straight line detection on the edge image to obtain a plurality of candidate straight line segments;

[0010] Based on a boundary positioning rule, determining a target boundary line segment from the plurality of candidate straight line segments to cut the edges of the original image according to the target boundary line segment.

[0011] In an embodiment, the step of determining the scene type of the target image comprises:

[0012] Calculating the median and standard deviation of the gray scale of the target image;

[0013] Judging whether the median of the gray scale is less than a dark field threshold and whether the standard deviation of the gray scale is less than a contrast threshold;

[0014] if the gray median is less than the dark field threshold and the gray standard deviation is less than the contrast threshold, determining that the scene type is a low-contrast dark field scene;

[0015] Otherwise, determining whether a top / bottom strip region of the target image has a dominant color channel;

[0016] if the dominant color channel exists, determining that the scene type is a dark card color edge scene;

[0017] Otherwise, determining that the scene type is a regular scene.

[0018] In an embodiment, the step of performing edge detection on the target image based on the edge detection strategy corresponding to the scene type comprises:

[0019] when the scene type of the target image is a low-contrast dark field scene, performing edge detection on the target image based on global binarization processing, strip projection whitening processing, and adaptive edge detection to obtain an edge image;

[0020] when the scene type of the target image is a dark card color edge scene, determining a dominant color channel according to the pixel mean values of the top strip region and the bottom strip region of the target image, and performing adaptive edge detection on the dominant color channel to obtain an edge image;

[0021] when the scene type of the target image is a regular scene, sequentially performing limited contrast adaptive histogram equalization, Gaussian blur, and adaptive edge detection on the gray image of the target image to obtain an edge image.

[0022] In an embodiment, the step of performing edge detection on the target image based on global binarization processing, strip projection whitening processing, and adaptive edge detection to obtain an edge image comprises:

[0023] performing global binarization processing on the target image to obtain a binary image;

[0024] in the top strip region and the bottom strip region of the binary image, counting the number of white pixels in each row, regarding rows with a number of white pixels lower than a dynamic threshold as noise rows, and setting all noise rows as a background color to obtain a target binary image;

[0025] performing adaptive edge detection on the target binary image to obtain an edge image, wherein the high and low thresholds of the adaptive edge detection are dynamically calculated based on the gray median of the target binary image.

[0026] In an embodiment, the step of determining the target boundary line segment from the plurality of candidate straight line segments based on the boundary positioning rule comprises:

[0027] determining a left / right margin area and an upper / lower margin area of the target image;

[0028] aggregating all candidate straight line segments in the left / right margin area with an angle smaller than a preset angle with a vertical edge into a left / right edge line cluster and aggregating all candidate straight line segments in the upper / lower margin area with an angle smaller than a preset angle with a horizontal edge into an upper / lower edge line cluster;

[0029] taking the longest candidate straight line segment in the left / right edge line cluster as a left / right boundary line segment and taking the longest candidate straight line segment in the upper / lower edge line cluster as an upper / lower boundary line segment;

[0030] determining the target boundary line segment based on the left boundary line segment, the right boundary line segment, the upper boundary line segment and the lower boundary line segment.

[0031] In an embodiment, the step of cropping the original image according to the target boundary line segment comprises:

[0032] determining a scaling ratio between the original image and the target image;

[0033] mapping the coordinates of the target boundary line segment in the target image coordinate system back to the original image coordinate system by the scaling ratio to obtain original image boundary coordinates;

[0034] determining a cropping area in the original image according to the original image boundary coordinates;

[0035] cropping the original image based on the cropping area to obtain a cropped image.

[0036] In an embodiment, the step of determining the target boundary line segment from the plurality of candidate straight line segments based on the boundary positioning rule, and cropping the original image according to the target boundary line segment comprises:

[0037] determining the target boundary line segment from the plurality of candidate straight line segments based on the boundary positioning rule;

[0038] judging whether the target boundary line segment is missing;

[0039] when it is detected that the target boundary line segment is missing, determining a missing boundary straight line segment based on a preset conservative cropping distance, and cropping the original image based on the target boundary line segment and the missing boundary straight line segment.

[0040] In addition, to achieve the above object, the application further provides an image edge cutting device based on boundary detection, which comprises:

[0041] a processing module, configured to pre-process an original image to obtain a target image;

[0042] a determining module, configured to determine a scene type of the target image;

[0043] a detecting module, configured to perform edge detection on the target image based on an edge detection strategy corresponding to the scene type to obtain an edge image;

[0044] the detecting module is further configured to perform straight line detection on the edge image to obtain a plurality of candidate straight line segments;

[0045] the determining module is further configured to determine a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule, so as to cut the edges of the original image according to the target boundary line segment.

[0046] In addition, to achieve the above object, the application further provides an image edge cutting device based on boundary detection, which comprises: a memory, a processor and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the image edge cutting method based on boundary detection as described above.

[0047] In addition, to achieve the above object, the application further provides a storage medium, which is a computer readable storage medium, and a computer program is stored on the storage medium, the computer program being executed by a processor to implement the steps of the image edge cutting method based on boundary detection as described above.

[0048] In addition, to achieve the above object, the application further provides a computer program product, which comprises a computer program, the computer program being executed by a processor to implement the steps of the image edge cutting method based on boundary detection as described above.

[0049] The one or more technical solutions provided by the application have at least the following technical effects:

[0050] The image edge cutting method, device and equipment based on boundary detection and the storage medium provided in the application, through preprocessing of an original image, obtain a target image; determine the scene type of the target image; perform edge detection on the target image based on the edge detection strategy corresponding to the scene type to obtain an edge image; perform straight line detection on the edge image to obtain a plurality of candidate straight line segments; determine a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule, so as to cut the edges of the original image according to the target boundary line segment. The technical problem that the traditional image edge cutting method is difficult to accurately screen out the real physical boundary, resulting in poor edge cutting effect in a complex scene is solved. Compared with the prior art, the scene-adaptive edge detection strategy and the intelligent boundary positioning rule effectively improve the boundary recognition accuracy in challenging scenes such as low light and complex background, realize more stable and reliable image edge cutting effect, and ensure efficient operation of the algorithm in a light computing environment. BRIEF DESCRIPTION OF DRAWINGS

[0051] The accompanying drawings, which are incorporated into and form a part of the specification, illustrate an embodiment consistent with the present application and, together with the description, serve to explain the principles of the application.

[0052] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained based on these drawings without creative labor.

[0053] Figure 1 The flowchart provided for the first embodiment of the image edge cutting method based on boundary detection of the present application;

[0054] Figure 2 The system framework diagram provided for the first embodiment of the image edge cutting method based on boundary detection of the present application;

[0055] Figure 3 The detailed flowchart provided for the first embodiment of the image edge cutting method based on boundary detection of the present application;

[0056] Figure 4 The line cluster winner diagram provided for the first embodiment of the image edge cutting method based on boundary detection of the present application;

[0057] Figure 5 The bottom-up diagram provided for the first embodiment of the image edge cutting method based on boundary detection of the present application;

[0058] Figure 6 The flowchart provided for the second embodiment of the image edge cutting method based on boundary detection of the present application;

[0059] Figure 7 A strip projection white coating schematic diagram provided for the second embodiment of the image cropping method based on boundary detection of the present application;

[0060] Figure 8 A module structure schematic diagram of the image cropping device based on boundary detection of the embodiment of the present application;

[0061] Figure 9 A device structure schematic diagram of the hardware running environment involved in the image cropping method based on boundary detection in the embodiment of the present application.

[0062] The object implementation, functional features and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0063] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application, and are not used to limit the present application.

[0064] In order to better understand the technical solutions of the present application, the specific embodiments will be described in detail below with reference to the drawings and the specific embodiments.

[0065] The main solution of the embodiment of the present application is: preprocessing the original image to obtain a target image; determining the scene type of the target image; performing edge detection on the target image based on the edge detection strategy corresponding to the scene type to obtain an edge image; performing straight line detection on the edge image to obtain a plurality of candidate straight line segments; determining a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule, so as to crop the original image according to the target boundary line segment.

[0066] From the above embodiment, it can be seen that the present application obtains a target image by preprocessing an original image; determines the scene type of the target image; performs edge detection on the target image based on the edge detection strategy corresponding to the scene type to obtain an edge image; performs straight line detection on the edge image to obtain a plurality of candidate straight line segments; determines a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule, so as to crop the original image according to the target boundary line segment. The technical problem that the traditional image cropping method is poor in cropping effect in a complex scene because it is difficult to accurately screen out the real physical boundary is solved. Compared with the prior art, the present application effectively improves the boundary recognition accuracy in challenging scenes such as low light and complex background by using a scene-adaptive edge detection strategy and an intelligent boundary positioning rule, realizes more stable and reliable image cropping effect, and at the same time ensures efficient operation of the algorithm in a light computing environment.

[0067] It should be noted that the execution subject of the embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, an image edge cutting device based on boundary detection, etc. The following will take the image edge cutting device based on boundary detection as an example to describe the embodiment and the following embodiments.

[0068] Based on this, the embodiment of the present application provides an image edge cutting method based on boundary detection, which refers to Figure 1 , Figure 1 The flowchart of the first embodiment of the image edge cutting method based on boundary detection of the present application is shown in the figure.

[0069] In the embodiment, the image edge cutting method based on boundary detection includes steps S10-S50:

[0070] Step S10, pre-processing the original image to obtain a target image;

[0071] It should be noted that the pre-processing of the original image is mainly to resize the original image to the target height H=800 to obtain the target image, and the scaling ratio ratio between the original image and the target image can be calculated.

[0072] It should be noted that the front end (product side): provides single / batch image input, optional visual debugging switch (output edge map and candidate line overlay map). Execution subject: application UI thread scheduling + background worker thread.

[0073] Step S20, determining the scene type of the target image;

[0074] It should be noted that the scene type mainly includes three types of low-contrast dark field scene, dark card color edge scene and regular scene.

[0075] In a possible implementation, the step of determining the scene type of the target image includes: calculating the median gray value and the gray standard deviation of the target image; judging whether the median gray value is less than a dark field threshold and the gray standard deviation is less than a contrast threshold; if the median gray value is less than the dark field threshold and the gray standard deviation is less than the contrast threshold, determining that the scene type is a low-contrast dark field scene; otherwise, judging whether the top / bottom strip area of the target image exists a dominant color channel; if the dominant color channel exists, determining that the scene type is a dark card color edge scene; otherwise, determining that the scene type is a regular scene.

[0076] In a specific implementation, the scene type can be determined in the following way:

[0077] First, the median gray value (med) and the standard deviation of the gray value of the target image are calculated. When the median gray value is less than a dark field threshold (Td) and the standard deviation of the gray value is less than a contrast threshold (Ts), it is determined to be a low-contrast dark field scene;

[0078] When the low-contrast dark field scene condition is not met, the color distribution of the top and bottom band regions of the image is further analyzed, and the pixel mean values of the RGB three channels are calculated. If there is a dominant color channel (i.e., the pixel mean value of a certain channel is significantly higher than that of other channels, such as the ratio of the pixel mean value of the channel to the pixel mean value of the second highest channel is greater than a preset proportion coefficient k, or the pixel mean value of the channel exceeds a certain percentage threshold of the sum of the three channels), it is determined to be a dark card color edge scene.

[0079] When neither the low-contrast dark field scene condition nor the dark card color edge scene condition is met, it is determined to be a regular scene.

[0080] It should be noted that this multi-level scene discrimination mechanism based on image statistical features can select the optimal edge detection strategy for different image characteristics, so that accurate boundary detection results can be obtained under complex shooting conditions.

[0081] Step S30, based on the edge detection strategy corresponding to the scene type, performing edge detection on the target image to obtain an edge image;

[0082] It should be noted that this step discards the traditional single and invariant edge detection process. The core is to dynamically switch to the optimal edge detection strategy according to the determined scene type, so as to solve the main challenges in different scenes and thus improve the signal-to-noise ratio of the edge image at the source. The specific strategy is as follows:

[0083] 1. If the scene type is "low-contrast dark field scene": the main contradiction of this scene is that the signal-to-noise ratio is extremely low and is easily disturbed by systematic band noise. Therefore, the system adopts a "global binarization -> band projection whitening (BPW) -> adaptive Canny detection" enhancement pipeline. First, preliminary segmentation is performed through global binarization; then, the horizontal projection analysis is performed on the band regions at the top and bottom of the image, and the noise rows with a foreground pixel number less than a dynamic threshold are removed (whitened) in whole rows, which can effectively remove the upper and lower band noise and provide "clean" input for the subsequent steps; finally, the Canny operator based on adaptive calculation of the image gray median is used to ensure that effective edges can be extracted even in dark light.

[0084] 2. If the scene type is "dark card color edge scene": the core problem of this scene is that the color edge frame leads to inconsistent signals between color channels. The system strategy is to select the dominant channel. Specifically, by analyzing the average of the pixels in the B, G, R three color channels of the top and bottom strip area of the image, the channel with the highest average is selected as the dominant channel. The subsequent edge detection will only be performed on this dominant channel, which is equivalent to automatically matching the best "filter" for edge detection, which can effectively suppress the noise interference of other color channels and significantly enhance the contrast of the real card edge frame and the background.

[0085] 3. If the scene type is "regular scene": for the case of good image quality, the system adopts a balanced and efficient enhancement process: "grayscale -> CLAHE -> Blur -> adaptive Canny detection". CLAHE is used to enhance the local contrast without amplifying the noise, and Gaussian blur is used to smooth the fine texture, and finally the reliable edge extraction is also completed by adaptive Canny.

[0086] Step S40, straight line detection is performed on the edge image to obtain a plurality of candidate straight line segments;

[0087] In a specific implementation, a probability-based Hough transform algorithm can be used to detect straight line segments from the edge image. The probability-based Hough transform algorithm mentioned in the present application has core parameters that are not fixed but are adaptively adjusted according to the scene type to achieve the best detection balance between complex scenes and simple scenes. Specifically: when the scene type is "low-contrast dark field scene" or "dark card color edge scene", it indicates that the image signal-to-noise ratio is low or the edge structure is complex. At this time, the system will use stricter detection parameters, for example: 1. Increase the accumulator threshold: require more pixel points to vote for a straight line to be detected, so as to suppress the false straight lines generated by noise; 2. Increase the minimum length of the line segment: avoid misjudging a series of accidentally aligned noise short edges as effective boundaries; 3. Reduce the maximum line segment gap allowed for connection: prevent two discontinuous edge segments from being incorrectly connected into a long straight line. Conversely, when the scene type is "regular scene", it indicates that the image quality is high and the edge is clear. At this time, the system will use relatively loose detection parameters, such as appropriately reducing the accumulator threshold and the minimum length, to ensure that all possible real boundary line segments can be recalled and missed detection can be avoided.

[0088] It can be understood that through this parameter adaptive straight line detection mechanism, the present application can effectively filter interference in difficult example scenes and ensure recall rate in regular scenes, providing a higher quality and more reliable candidate straight line segment set for the subsequent boundary screening step.

[0089] Step S50, determining a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule, to crop the original image according to the target boundary line segment.

[0090] In a specific implementation, as shown in the detailed flowchart, the data flow is as follows: BGR original image → preprocessing (resampling H=800) → difficult case shunting → (branch) BPW / leading channel / regular → adaptive Canny → Hough straight line → candidate sorting → line cluster winner → bottom line → coordinate remapping → output cropped image. Figure 2 、 3 In a specific implementation, as shown in the detailed flowchart, the data flow is as follows: BGR original image → preprocessing (resampling H=800) → difficult case shunting → (branch) BPW / leading channel / regular → adaptive Canny → Hough straight line → candidate sorting → line cluster winner → bottom line → coordinate remapping → output cropped image.

[0091] In a specific implementation, as shown in the detailed flowchart, the data flow is as follows: BGR original image → preprocessing (resampling H=800) → difficult case shunting → (branch) BPW / leading channel / regular → adaptive Canny → Hough straight line → candidate sorting → line cluster winner → bottom line → coordinate remapping → output cropped image.

[0092] In a specific implementation, the "multiple solutions" problem of Hough transform output can be solved by a multi-level screening mechanism. The specific execution process includes:

[0093] 1. Spatial region division and preliminary screening:

[0094] In the image edge preset boundary search region (left / right margin region, upper / lower margin region), only the candidate line segments falling into the corresponding region are retained. At the same time, the line segment angle is screened:

[0095] Left / right margin region: screen line segments with nearly vertical angles (angle deviation ≤ vertical angle tolerance threshold);

[0096] Upper / lower margin region: screen line segments with nearly horizontal angles (angle deviation ≤ horizontal angle tolerance threshold);

[0097] 2. Line cluster aggregation and optimal selection:

[0098] Perform spatial clustering on the candidate line segments that pass the preliminary screening:

[0099] In the left / right boundary region, the line segments are clustered according to the horizontal coordinates of the line segment center points, and the line segments with a distance less than a threshold value ε are classified into the same vertical line cluster;

[0100] In the upper / lower margin area, the line segments with vertical coordinates of the center points within a threshold value are clustered into the same horizontal line cluster.

[0101] In each line cluster, the longest line segment is selected as the "winner" of the cluster, representing the candidate boundary of the side.

[0102] 3. Boundary representation verification: further verification of the selected winner line segment:

[0103] (1) Exclude false boundaries (such as reflective strips) that are too close to the image edge;

[0104] (2) In the upper boundary group, select the line segment with the smallest vertical coordinate as the actual upper boundary;

[0105] (3) In the lower boundary group, select the line segment with the largest vertical coordinate as the actual lower boundary.

[0106] It should be noted that through the three-level progressive mechanism of "partition screening-line cluster aggregation-length optimization", the problem of stable positioning of the real boundary from the chaotic candidate straight lines is solved.

[0107] 1. The rationality of partition screening:

[0108] Firstly, this method clearly defines the left / right margin area and the upper / lower margin area. This design is based on a priori knowledge: the physical boundary of the card must be located in the edge area of the image. Through this step, a large number of invalid line segments located in the center of the image (these line segments may be derived from the texture, printed text or background interference inside the card) can be directly filtered out, greatly reducing the candidate set for subsequent processing and improving the efficiency of the algorithm.

[0109] 2. The necessity of line cluster aggregation:

[0110] In a complex scene, due to the concave-convex texture (such as bank card embossed numbers), anti-counterfeiting patterns or noise interference on the surface of the card, the same physical boundary of the card may be broken into multiple short line segments with similar positions and directions in the edge image. The traditional "select the longest one" method will fail here, because a single line segment may not be complete. By line cluster aggregation, line segments with adjacent spatial positions (for example, the X coordinates of the center points of the line segments differ by less than a threshold value ε) are merged into the same "edge line cluster". As shown in Figure 4 This operation cleverly converts the problem of "selecting one line from multiple lines" into the problem of "determining the optimal position from multiple candidate positions (clusters)". Each line cluster represents a potential boundary position candidate.

[0111] 3. Robustness of length optimization:

[0112] Within each cluster of lines formed by the aggregation, the rule of "the longest wins" is applied to select the longest line segment in the cluster as the final representative of the boundary. This strategy is based on a sound engineering intuition that a line segment representing a real, continuous physical boundary usually has the longest continuous pixel representation. Those short lines caused by internal textures or random noise, on the other hand, will be effectively eliminated under this rule. This approach is superior to simply taking the average position or the midpoint line segment, because it ensures that the selected boundary line segment itself has the highest integrity and confidence, thus making the final determined cropping rectangle more accurate and stable.

[0113] In this embodiment, the redundant and cluttered Hough transform output is clearly converged into four optimal boundary line segments through a three-step rule of interlocking. It not only performs well in ideal cases, but also effectively deals with complex situations such as boundary breakage and the existence of parallel ghost images, which is a key step to achieve the high robustness and high precision goals of the present application. It also effectively filters out the fragmented short line interference caused by detail textures or noise through a two-stage method of "clustering first, then selecting the best", achieving convergence from "multiple solutions" to "optimal solution", and thus accurately and stably outputting the left and right boundaries of the card.

[0114] In an embodiment, the step of cropping the original image according to the target boundary line segment includes: determining a scaling ratio between the original image and the target image; mapping the coordinates of the target boundary line segment in the target image coordinate system back to the original image coordinate system through the scaling ratio to obtain original image boundary coordinates; determining a cropping region in the original image according to the original image boundary coordinates; and cropping the original image based on the cropping region to obtain a cropped image.

[0115] It should be noted that the coordinate mapping mechanism in the cropping process is the key to achieving high-precision cropping. Since all image processing operations (including edge detection, line detection, etc.) are performed on the target image with a lower resolution (height H = 800), and the final output is the cropped result of the original high-resolution image, an accurate mapping relationship between the two coordinate systems must be established. Specifically, by multiplying the coordinates of the target boundary line segments determined in the target image by the scaling ratio ratio calculated in the preprocessing stage, the corresponding positions of these boundaries in the original image can be accurately restored. This processing method not only ensures the processing efficiency of the algorithm (complex operations are performed on small-sized images), but also ensures the quality of the final output image (cropping based on the original high-definition image).

[0116] In this embodiment, high-fidelity scale mapping: the entire complex analysis and positioning process is efficiently carried out on the scaled-down image, but in the last step, the algorithm will map the calculated precise cutting coordinates back to the original high-resolution image for cutting through the initial scaling ratio ratio. This ensures the best of both speed and accuracy of the final output, avoiding pixel loss caused by cutting on a small image.

[0117] In an embodiment, the step of determining a target boundary line segment from the plurality of candidate straight line segments based on the boundary positioning rule to crop the original image according to the target boundary line segment comprises: determining a target boundary line segment from the plurality of candidate straight line segments based on the boundary positioning rule; judging whether the target boundary line segment is missing; when it is detected that the target boundary line segment is missing, determining a missing boundary straight line segment based on a preset conservative cutting distance, to crop the original image based on the target boundary line segment and the missing boundary straight line segment.

[0118] It should be noted that, as shown in Figure 5 After the system determines the target boundary line segment from the candidate straight line segments based on the boundary positioning rule, it will first perform integrity judgment to detect whether the four-side boundary of the image is missing; if it is found that an effective target boundary line segment is missing for a certain boundary (such as the left or upper side), a conservative cutting strategy is started, and a virtual boundary straight line segment corresponding to the missing boundary is generated through a preset dynamic calculation rule (usually based on 2%-5% of the short side size of the image); finally, the system will integrate the actual detected target boundary line segment and the compensation boundary line segment generated through the conservative strategy to form a complete cutting boundary box. This design ensures that even in the case of partial boundary detection failure, the system can still output a cutting result that meets the basic requirements, avoiding process interruption caused by single-side detection failure, and ensuring the integrity of the core image content through intelligent calculation of the conservative distance, thereby significantly improving the practicability and stability of the edge cutting method in complex actual scenarios.

[0119] It can be understood that the determinacy fallback is that when any of the above boundary lines fails to be successfully detected due to extreme conditions, the system will not crash or return invalid results. Instead, a fallback strategy based on a fixed inset pixel value (fallback_inset) is enabled. This predictable fallback mechanism ensures the stability of the output, facilitating downstream business processing.

[0120] The embodiment obtains a target image by preprocessing an original image, determines a scene type of the target image, performs edge detection on the target image based on an edge detection strategy corresponding to the scene type to obtain an edge image, performs straight line detection on the edge image to obtain a plurality of candidate straight line segments, and determines a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule to crop the original image based on the target boundary line segment. The technical problem that the traditional image cropping method is poor in cropping effect in a complex scene due to the difficulty in accurately screening a real physical boundary is solved. Compared with the prior art, the scene adaptive edge detection strategy and the intelligent boundary positioning rule effectively improve the boundary recognition accuracy in a challenging scene such as low light and complex background, achieve more stable and reliable image cropping effect, and ensure efficient operation of the algorithm in a lightweight computing environment.

[0121] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as the above first embodiment can be referred to the above introduction, and will not be described in detail. On this basis, please refer to Figure 6 , step S30 further includes steps S301-S303:

[0122] Step S301, when the scene type of the target image is a low-contrast dark-field scene, performing edge detection on the target image based on global binarization processing, band projection whitening processing and adaptive edge detection to obtain an edge image.

[0123] It should be noted that the band projection whitening processing refers to only performing row projection and threshold removal on the upper and lower narrow bands of the image to remove strip noise.

[0124] It should be noted that the horizontal stripes or regional noise after binarization in the "dark light low contrast" scene is not processed on the whole image, but only focuses on the image top and bottom band regions which play a decisive role in final boundary positioning. As Figure 7 shown, by performing horizontal projection analysis on these regions and removing (whitening) the "noise row" with the number of foreground pixels below the dynamic threshold, a very "clean" input can be provided for Hough transform without damaging the vertical edges of the card subject, which reduces the false straight line detection from the root.

[0125] In a specific implementation, adaptive edge detection refers to median adaptive Canny (i.e., adaptive Canny threshold setting mechanism), which does not rely on fixed empirical threshold, but takes the gray median v of the image (or selected channel) as a dynamic reference, and automatically calculates the high and low thresholds through the formula (1±σ) * v, which enables the edge detection algorithm to "self-calibrate" and always maintain an optimal sensitivity interval in different light and dark images, greatly enhancing the universality and stability of the algorithm. The specific calculation formula is as follows:

[0126] Let the median be v and the parameter be σ:

[0127]

[0128]

[0129] Actual use as the Canny threshold.

[0130] In a feasible implementation, the step of performing edge detection on the target image based on global binarization processing, band projection whitening processing, and adaptive edge detection to obtain an edge image includes: performing global binarization processing on the target image to obtain a binary image; in a top band region and a bottom band region of the binary image, counting the number of white pixels in each row row by row, regarding a row with a number of white pixels lower than a dynamic threshold as a noise row, and setting all noise rows as a background color to obtain a target binary image; and performing adaptive edge detection on the target binary image to obtain an edge image, wherein the high and low thresholds of the adaptive edge detection are dynamically calculated based on the gray median of the target binary image.

[0131] It should be noted that for low-contrast dark-field scenes, a dynamic, statistically-based band noise suppression method is needed to enhance the traditional binarization process, and an adaptive edge detection threshold is combined to ensure the robustness and accuracy of edge extraction under extremely poor imaging conditions. Specifically: first, by performing global binarization on the target image (such as using the Otsu method), the weak gray scale contrast is converted into absolute black and white contrast, thereby preliminarily outlining the potential object contour to obtain an initial binary image; Next, the algorithm performs a key band projection whitening process, which is not uniformly applied to the entire image, but intelligently focuses on the top and bottom band regions where noise interference is most significant - in this region, by scanning each row and counting the number of white pixels in each row, and based on this statistic (such as setting a dynamic threshold relative to the region height or global white pixel ratio), those "noise rows" with an abnormally small number of white pixels due to uneven lighting or sensor noise are accurately identified, these noise rows usually correspond to pure black interference bands with no information, and then all the pixels of the determined noise rows are set to the background color (i.e. white), which effectively removes large artifacts at the image boundary, purifies the scene background, and obtains a denoised target binary image; Finally, adaptive edge detection is performed on the purified target binary image, and the adaptability is particularly embodied in the setting strategy of the high and low threshold values of the Canny edge detector - the high and low threshold values are not fixed values, but are dynamically calculated based on the median gray value of the target binary image (for example, the threshold values are set by floating up and down by a certain proportion based on the median gray value), this dynamic calculation mechanism enables the edge detection threshold to adapt to the overall contrast level of the current binary image, thereby ensuring that the true edges are captured completely while minimizing the false detection of sporadic noise points as edges due to binarization, and finally outputting a clear, clean and coherent edge image.

[0132] In a specific implementation, the calculation formula of BPW (white pixel count and whitening) is as follows:

[0133] Let the binary image be B.

[0134]

[0135] In the formula, B represents the binary image, H represents the height of the image, and W represents the width of the image.

[0136] White pixel count in the ith row in the upper / lower band:

[0137]

[0138] In the formula, i represents the row index in the image, and j represents the column index in the image, White pixel count in the ith row.

[0139] Dynamic threshold (relative width ratio p):

[0140]

[0141] wherein, 0 represents the dynamic threshold, p represents the relative width ratio, and W represents the width of the image.

[0142] For the rows satisfying Perform "whitening" (set the entire row to 0) on the rows:

[0143]

[0144] wherein, represents the binary image after whitening.

[0145] In step S302, when the scene type of the target image is the dark card color edge scene, a dominant color channel is determined according to the pixel mean values of the top and bottom strip-shaped regions of the target image, and adaptive edge detection is performed on the dominant color channel to obtain an edge image.

[0146] It should be noted that the dominant channel refers to the channel with the maximum mean value in the B / G / R three channels for the selected region (such as the upper and lower strips), which is used as the edge detection channel.

[0147] It should be noted that the design for the "dark card color edge scene" is to solve the inherent defects of the traditional grayscale method in this type of scene: when the card body color is deep and the edge has distinct color characteristics, direct grayscale conversion will severely weaken the contrast of the color edge, resulting in loss of key contour information. The present scheme innovatively adopts a strategy of color channel decoupling and advantage channel focusing. First, the pixel mean values of the top and / or bottom strip-shaped regions of the target image (which are usually the most representative of the typical colors of the background interference or card edge) are calculated to calculate the average intensity of the R, G, and B color channels in the region. Then, the channel with the maximum deviation from the neutral gray level, i.e., the highest absolute value or the most significant variance, is selected as the "dominant color channel". This selection mechanism can intelligently lock the spectral component that best distinguishes the color edge from the dark body. Then, the algorithm directly performs adaptive edge detection on the two-dimensional data of the dominant color channel, which converts the weak color edge signal in the full color domain into a high-contrast brightness step in a single channel, so that it can be accurately captured by the Canny edge detector. The adaptability of the detection process is reflected in the setting of the high and low thresholds, which can be dynamically calculated based on the gradient amplitude distribution or the gray median of the dominant channel to ensure that the real edge is strengthened while effectively suppressing channel noise.

[0148] Note that for "dark card color edge scene", adaptive Canny edge detection with high sigma is used (i.e. edge detection is not performed on the grayscale image, but on the dominant channel image selected in the previous step), which converts the original image into a single channel image, but this channel is not grayscale, but the R, G, or B channel we selected. This ensures that the input image has the maximum foreground-background contrast. High sigma Gaussian blur: before Canny edge detection, a strong Gaussian blur is performed on this single channel image, and a high sigma value means a larger width of the Gaussian kernel, and the smoothing effect is very significant. Purpose: to greatly suppress noise, especially for dark images, which usually have more noise, and high sigma blur can effectively remove it. Focus on the main edge: high sigma blur filters out all the fine textures and unimportant gradient changes, and only keeps the most significant and macroscopic object contours - which are the edges of the card. This is also crucial for "color edge discrimination", because color difference also mainly occurs on these main edges. Adaptive Canny: adaptive Canny edge detection is performed on the high sigma blurred image, and "adaptive" means that its high and low thresholds are not fixed, but are dynamically calculated according to the local gradient statistics of the image. Advantage in dark card scene: since the card region and the background region differ significantly in the dominant channel, but the overall image may still be dark, adaptive thresholding can ensure that suitable edges can be found in the darker card region, rather than being ignored by a global high threshold.

[0149] It can be understood that for "dark card" scenes with complex backgrounds or color borders, the color distribution of the upper and lower edge regions of the image can be automatically analyzed, and the color channel with the strongest signal (highest mean) can be intelligently selected for subsequent processing. This is equivalent to automatically finding the best "filter" for edge detection, which can effectively suppress noise interference in other color channels and significantly improve edge contrast.

[0150] In step S303, when the scene type of the target image is a regular scene, the grayscale image of the target image is sequentially subjected to limited contrast adaptive histogram equalization, Gaussian blur, and adaptive edge detection to obtain an edge image.

[0151] It should be noted that the processing flow designed for the conventional scene is a classic "enhancement-smoothing-detection" pipeline, the core of which is to achieve the best balance between detail enhancement and noise suppression through multi-stage processing: first, the gray image is subjected to limited contrast adaptive histogram equalization (CLAHE), which divides the image into multiple local regions and independently performs histogram equalization while limiting the height of the histogram to avoid excessive amplification of noise, thereby effectively enhancing the local contrast and making the originally blurred edge details visible; then, Gaussian blur processing is applied to the enhanced image, and convolution operation is performed on the image using a Gaussian kernel to smooth the fine noise and irrelevant texture that may be amplified by CLAHE, and this key step controls the smoothing degree by adjusting the standard deviation parameter of the Gaussian kernel, while preserving the main edge structure and creating a cleaner input for subsequent edge detection; finally, adaptive edge detection is performed on the preprocessed image, usually using the Canny algorithm and dynamically calculating the high and low threshold based on the statistical characteristics of the image gradient amplitude, to ensure that the real edge can be accurately captured while effectively suppressing the false edge, and finally output a single-pixel wide edge image. This carefully designed series processing strategy enables the edges of various intensities and directions in the conventional scene to be extracted completely and accurately, providing a reliable foundation for subsequent image analysis tasks.

[0152] In this embodiment, when the scene type of the target image is a low-contrast dark-field scene, edge detection is performed on the target image based on global binarization processing, band projection whitening processing, and adaptive edge detection to obtain an edge image; when the scene type of the target image is a dark card color edge scene, the dominant color channel is determined according to the pixel mean values of the top and bottom band regions of the target image, and adaptive edge detection is performed on the dominant color channel to obtain an edge image; when the scene type of the target image is a conventional scene, the gray image of the target image is sequentially subjected to limited contrast adaptive histogram equalization (CLAHE), Gaussian blur, and adaptive edge detection to obtain an edge image. Through the above manner, differential edge detection strategies can be configured for low-contrast dark-field, dark card color edge, and conventional scenes respectively, and accurate adaptation to different scene characteristics is achieved. This method improves the signal-to-noise ratio by directional noise suppression in low-contrast scenes, enhances the boundary contrast by selecting the dominant channel in color edge scenes, and maintains edge integrity by image enhancement in conventional scenes, so that high-quality edge images can be obtained under various complex conditions, significantly improving the robustness and accuracy of boundary detection.

[0153] It should be noted that the above examples are only for understanding the present application and do not constitute a limitation on the image edge cutting method based on boundary detection of the present application. Further simple transformations based on this technical concept are within the scope of protection of the present application.

[0154] The application further provides an image edge cutting device based on boundary detection, which refers to Figure 8 The image edge cutting device based on boundary detection comprises:

[0155] A processing module 10 is configured to pre-process an original image to obtain a target image.

[0156] A determination module 20 is configured to determine a scene type of the target image.

[0157] A detection module 30 is configured to perform edge detection on the target image based on an edge detection strategy corresponding to the scene type to obtain an edge image.

[0158] The detection module 30 is further configured to perform straight line detection on the edge image to obtain a plurality of candidate straight line segments.

[0159] The determination module 20 is further configured to determine a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule, so as to cut the original image according to the target boundary line segment.

[0160] The image edge cutting device based on boundary detection provided by the application adopts the image edge cutting method based on boundary detection in the above embodiment, and can solve the technical problem that the traditional image edge cutting method has poor cutting effect in a complex scene due to the difficulty in accurately screening out a real physical boundary. Compared with the prior art, the image edge cutting device based on boundary detection provided by the application has the same beneficial effects as the image edge cutting method based on boundary detection provided by the above embodiment, and other technical features in the image edge cutting device based on boundary detection are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0161] The application provides an image edge cutting device based on boundary detection, which comprises at least one processor and a memory in communication connection with the at least one processor. The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the image edge cutting method based on boundary detection in the above embodiment one.

[0162] Reference will be made to Figure 9This document illustrates a structural schematic diagram of an image cropping device based on boundary detection suitable for implementing embodiments of this application. The image cropping device based on boundary detection in these embodiments may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 9 The image cropping device based on boundary detection shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.

[0163] like Figure 9 As shown, the boundary detection-based image cropping device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory 1002 or a program loaded from a storage device 1003 into a random access memory 1004. The random access memory 1004 also stores various programs and data required for the operation of the boundary detection-based image cropping device. The processing unit 1001, the read-only memory 1002, and the random access memory 1004 are interconnected via a bus 1005. An input / output interface 1006 is also connected to the bus. Typically, the following systems can be connected to the input / output interface 1006: input devices 1007 including, for example, a touchscreen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1003 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. The communication device 1009 allows the boundary detection-based image cropping device to communicate wirelessly or wiredly with other devices to exchange data. While the figures show boundary detection-based image cropping devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.

[0164] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing program code for executing the method shown in the flowchart. In such embodiments, the computer program can be downloaded and installed from a network through a communication device, or installed from the storage device 1003, or installed from the read-only memory 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiments disclosed in the present application are executed.

[0165] The image edge cutting device based on boundary detection provided by the present application adopts the image edge cutting method based on boundary detection in the above-mentioned embodiments, which can solve the technical problem that the traditional image edge cutting method has poor edge cutting effect in complex scenes due to the difficulty in accurately screening out the real physical boundary. Compared with the prior art, the beneficial effects of the image edge cutting device based on boundary detection provided by the present application are the same as those of the image edge cutting method based on boundary detection provided by the above-mentioned embodiments, and other technical features in the image edge cutting device based on boundary detection are the same as those disclosed in the previous embodiment method, which will not be repeated here.

[0166] It should be understood that various parts of the present application can be realized by hardware, software, firmware or a combination thereof. In the description of the above-mentioned embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0167] The above is merely specific implementation of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

[0168] The present application provides a computer readable storage medium having stored thereon computer readable program instructions (i.e. computer program) for executing the image edge cutting method based on boundary detection in the above-mentioned embodiments.

[0169] The computer readable storage medium provided in the present application may, for example, be a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system or device, or any combination of the above. More specific examples of the computer readable storage medium may include, but are not limited to, an electric connection with one or more conductive wires, a portable computer disk, a hard disk, a random access memory (RAM), a read only memory (ROM), an erasable programmable read only memory (EPROM or flash memory), an optical fiber, a portable compact disk read only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system or device. The program code contained on the computer readable storage medium can be transmitted by any suitable medium, including but not limited to an electric wire, an optical cable, an RF (Radio Frequency), and the like, or any suitable combination of the above.

[0170] The computer readable storage medium described above can be contained in the image edge cutting device based on boundary detection, or can exist separately without being assembled into the image edge cutting device based on boundary detection.

[0171] The computer readable storage medium described above carries one or more programs, which, when executed by the image edge cutting device based on boundary detection, cause the image edge cutting device based on boundary detection to: pre-process an original image to obtain a target image; determine a scene type of the target image; perform edge detection on the target image based on an edge detection strategy corresponding to the scene type to obtain an edge image; perform straight line detection on the edge image to obtain a plurality of candidate straight line segments; determine a target boundary line segment from the plurality of candidate straight line segments based on a boundary positioning rule to cut the edges of the original image according to the target boundary line segment.

[0172] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).

[0173] The flow diagrams and the block diagrams in the drawings are illustrations of architectures, functionalities, and operations of possible implementations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flow diagrams or block diagrams can represent a module, a segment, or a portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently or the blocks may

[0174] The modules involved in the embodiments of the present application can be implemented in the form of software or in the form of hardware. In some cases, the name of the module does not constitute a limitation on the module itself.

[0175] The readable storage medium provided by the present application is a computer readable storage medium, which stores computer readable program instructions (i.e. computer programs) for executing the above-mentioned image edge cutting method based on boundary detection, and can solve the technical problem that the traditional image edge cutting method has poor edge cutting effect in a complex scene due to the difficulty in accurately screening out the real physical boundary. Compared with the prior art, the computer readable storage medium provided by the present application has the same beneficial effects as the image edge cutting method based on boundary detection provided by the above-mentioned embodiments, and will not be described here.

[0176] The application also provides a computer program product comprising a computer program which, when executed by a processor, implements the steps of the image edge cutting method based on boundary detection as described above.

[0177] The computer program product provided by the application can solve the technical problem that the traditional image edge cutting method has poor edge cutting effect in a complex scene because it is difficult to accurately screen out the real physical boundary. Compared with the prior art, the beneficial effects of the computer program product provided by the application are the same as those of the image edge cutting method based on boundary detection provided by the above-mentioned embodiments, and are not described here.

[0178] The above only describes some embodiments of the application, and does not limit the patent scope of the application. Any equivalent structural transformation made by using the content of the specification and drawings, or direct / indirect application in other related technical fields within the technical concept of the application is included in the patent protection scope of the application.

Claims

1. An image cropping method based on boundary detection, characterized in that, The image cropping method based on boundary detection includes: The original image is preprocessed to obtain the target image; Determine the scene type of the target image; The step of determining the scene type of the target image includes: Calculate the median and standard deviation of the gray levels of the target image; Determine whether the median grayscale value is less than the dark field threshold and whether the standard deviation of grayscale value is less than the contrast threshold; If the median gray level is less than the dark field threshold and the standard deviation of gray level is less than the contrast threshold, then the scene type is determined to be a low-contrast dark field scene. Otherwise, determine whether a dominant color channel exists in the top / bottom strip region of the target image; If a dominant color channel exists, the scene type is determined to be a dark card with colored borders scene; Otherwise, the scenario type is determined to be a regular scenario; Based on the edge detection strategy corresponding to the scene type, edge detection is performed on the target image to obtain an edge image; The step of performing edge detection on the target image based on the edge detection strategy corresponding to the scene type to obtain an edge image includes: If the scene type of the target image is a low-contrast dark scene, then based on global binarization processing, strip projection whitening processing and adaptive edge detection, edge detection is performed on the target image to obtain an edge image; If the scene type of the target image is a dark card with colored edges, then the dominant color channel is determined based on the pixel average of the top and bottom strip regions of the target image, and adaptive edge detection is performed on the dominant color channel to obtain the edge image; If the scene type of the target image is a regular scene, then the grayscale image of the target image is sequentially subjected to contrast-limited adaptive histogram equalization, Gaussian blur and adaptive edge detection to obtain an edge image; Line detection is performed on the edge image to obtain multiple candidate line segments; Based on the boundary positioning rules, a target boundary line segment is determined from the plurality of candidate line segments, so as to crop the original image according to the target boundary line segment; Specifically, the global binarization process involves performing global binarization on the target image to obtain a binary image. The strip projection whitening process specifically involves counting the number of white pixels in each row within the top and bottom strip regions of the binary image, identifying rows with a white pixel count lower than a dynamic threshold as noise rows, and then setting all noise rows to the background color to obtain the target binary image.

2. The image cropping method based on boundary detection as described in claim 1, characterized in that, The adaptive edge detection specifically involves performing adaptive edge detection on the target binary image to obtain an edge image, wherein the high and low thresholds of the adaptive edge detection are dynamically calculated based on the median gray level of the target binary image.

3. The image cropping method based on boundary detection as described in claim 1, characterized in that, The step of determining the target boundary line segment from the plurality of candidate line segments based on boundary positioning rules includes: Determine the left / right margin region and the top / bottom margin region of the target image; Aggregate all candidate line segments in the left / right margin region whose angle with the vertical edge is less than a preset angle into a left / right edge line cluster, and aggregate all candidate line segments in the top / bottom margin region whose angle with the horizontal edge is less than a preset angle into a top / bottom edge line cluster; The longest candidate straight line segment in the left / right edge line cluster is taken as the left / right boundary line segment, and the longest candidate straight line segment in the upper / lower edge line cluster is taken as the upper / lower boundary line segment. The target boundary segment is determined based on the left boundary segment, the right boundary segment, the upper boundary segment, and the lower boundary segment.

4. The image cropping method based on boundary detection as described in claim 1, characterized in that, The step of cropping the original image based on the target boundary line segment includes: Determine the scaling ratio between the original image and the target image; The coordinates of the target boundary line segment in the target image coordinate system are mapped back to the original image coordinate system using the scaling ratio to obtain the original image boundary coordinates; The cropping region is determined in the original image based on the original image boundary coordinates; The original image is cropped based on the cropping region to obtain a cropped image.

5. The image cropping method based on boundary detection as described in claim 1, characterized in that, The step of determining a target boundary line segment from the plurality of candidate line segments based on boundary positioning rules, and then cropping the original image according to the target boundary line segment, includes: Based on the boundary positioning rules, the target boundary line segment is determined from the plurality of candidate line segments; Determine whether the target boundary line segment is missing; When a missing target boundary line segment is detected, the missing boundary line segment is determined based on a preset conservative cropping distance, and the original image is cropped based on the target boundary line segment and the missing boundary line segment.

6. An image cropping device based on boundary detection, characterized in that, The image cropping device based on boundary detection includes: The processing module is used to preprocess the original image to obtain the target image; A determination module is used to determine the scene type of the target image; The determining module is also used to calculate the median gray level and the standard deviation gray level of the target image; Determine whether the median grayscale value is less than the dark field threshold and whether the standard deviation of grayscale value is less than the contrast threshold; If the median gray level is less than the dark field threshold and the standard deviation of gray level is less than the contrast threshold, then the scene type is determined to be a low-contrast dark field scene. Otherwise, determine whether a dominant color channel exists in the top / bottom strip region of the target image; If a dominant color channel exists, the scene type is determined to be a dark card with colored borders scene; Otherwise, the scenario type is determined to be a regular scenario; The detection module is used to perform edge detection on the target image based on the edge detection strategy corresponding to the scene type, and obtain an edge image; The detection module is further configured to perform edge detection on the target image based on global binarization, strip projection whitening, and adaptive edge detection if the scene type of the target image is a low-contrast dark scene, thereby obtaining an edge image. If the scene type of the target image is a dark card with colored edges, then the dominant color channel is determined based on the pixel mean of the top and bottom strip regions of the target image, and adaptive edge detection is performed on the dominant color channel to obtain the edge image; If the scene type of the target image is a regular scene, then the grayscale image of the target image is sequentially subjected to contrast-limited adaptive histogram equalization, Gaussian blur and adaptive edge detection to obtain an edge image; The detection module is also used to perform line detection on the edge image to obtain multiple candidate line segments; The determining module is further configured to determine a target boundary line segment from the plurality of candidate line segments based on boundary positioning rules, so as to crop the original image according to the target boundary line segment; Specifically, the global binarization process involves performing global binarization on the target image to obtain a binary image. The strip projection whitening process specifically involves counting the number of white pixels in each row within the top and bottom strip regions of the binary image, identifying rows with a white pixel count lower than a dynamic threshold as noise rows, and then setting all noise rows to the background color to obtain the target binary image.

7. An image cropping device based on boundary detection, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the image cropping method based on boundary detection as described in any one of claims 1 to 5.

8. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the image cropping method based on boundary detection as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Picture trimming system and method thereof

    CN102254302A

  • Image-based stripe cloth detection locating cutting method and system, and storage medium

    CN108335309A