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.
Patent Information
- Application Number
- CN202511545789.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-28
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2045-10-28
AI Technical Summary
Existing automatic image cropping methods based on Canny edge detection and Hough transform struggle to accurately identify true physical boundaries when processing low-contrast, dark, or colored bordered card images, resulting in poor robustness and reliability of cropping results in complex scenarios.
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.
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.
Smart Images

Figure CN121033089A_ABST
Abstract
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 card certificate images with color frames, and it is difficult to stably and accurately screen out the real physical boundary from the candidate straight lines, which finally causes the problem of 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 of poor edge cutting effect in complex scenes caused by the difficulty of accurately screening out the real physical boundary in the traditional image edge cutting method.
[0005] To achieve the above purpose, the present application provides an image edge cutting method based on boundary detection, which comprises: preprocessing an original image to obtain a target image; determining a 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, and cutting the original image according to the target boundary line segment.
[0006] In an embodiment, the step of determining the scene type of the target image comprises: calculating a median gray value and a 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 a dominant color channel exists in a top / bottom strip area 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.
[0007] In one embodiment, 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: When the scene type of the target image is a low-contrast dark scene, edge detection is performed on the target image based on global binarization processing, strip projection whitening processing, and adaptive edge detection to obtain an edge image; When the scene type of the target image is a dark card with colored edges, 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; When the scene type of the target image is a regular scene, 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.
[0008] In one embodiment, the step of performing edge detection on the target image based on global binarization, strip projection whitening, and adaptive edge detection to obtain an edge image includes: The target image is subjected to global binarization to obtain a binary image; In the top and bottom strip regions of the binary image, the number of white pixels in each row is counted row by row. Rows with a number of white pixels lower than the dynamic threshold are identified as noise rows. After setting all noise rows as the background color, the target binary image is obtained. Adaptive edge detection is performed 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.
[0009] In one embodiment, 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.
[0010] In one embodiment, 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.
[0011] In one embodiment, 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.
[0012] Furthermore, to achieve the above objectives, this application also proposes an image cropping device based on boundary detection, the image cropping device based on boundary detection comprising: 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 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 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.
[0013] In addition, to achieve the above objectives, this application also proposes an image cropping device based on boundary detection, the device comprising: 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 above.
[0014] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the image cropping method based on boundary detection as described above.
[0015] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the image cropping method based on boundary detection as described above.
[0016] One or more technical solutions proposed in this application have at least the following technical effects: This application proposes an image cropping method, apparatus, device, and storage medium based on boundary detection. The method involves 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 line detection on the edge image to obtain multiple candidate line segments; and determining the target boundary line segment from the multiple candidate line segments based on boundary localization rules, thereby cropping the original image according to the target boundary line segment. This solves the technical problem of poor cropping performance in complex scenes due to the difficulty in accurately identifying real physical boundaries in traditional image cropping methods. Compared to existing technologies, this application effectively improves the boundary recognition accuracy in challenging scenes such as low light and complex backgrounds through a scene-adaptive edge detection strategy and intelligent boundary localization rules, achieving a more stable and reliable image cropping effect while ensuring efficient operation of the algorithm in a lightweight computing environment. Attached Figure Description
[0017] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a flowchart illustrating an embodiment of the image cropping method based on boundary detection in this application. Figure 2 This is a system framework diagram provided for Embodiment 1 of the image cropping method based on boundary detection in this application; Figure 3 This is a detailed flowchart illustrating an embodiment of the image cropping method based on boundary detection in this application. Figure 4 This is a schematic diagram of the line cluster winner provided in Embodiment 1 of the image cropping method based on boundary detection in this application; Figure 5 This is a catch-all diagram provided for Embodiment 1 of the image cropping method based on boundary detection in this application; Figure 6 This is a flowchart illustrating Embodiment 2 of the image cropping method based on boundary detection in this application; Figure 7 This is a schematic diagram of the strip projection whitening provided in Embodiment 2 of the image cropping method based on boundary detection in this application; Figure 8 This is a schematic diagram of the module structure of the image cropping device based on boundary detection according to an embodiment of this application; Figure 9 This is a schematic diagram of the device structure of the hardware operating environment involved in the image cropping method based on boundary detection in the embodiments of this application.
[0020] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0021] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0022] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0023] The main solution of this application embodiment 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 line detection on the edge image to obtain multiple candidate line segments; and determining a target boundary line segment from the multiple candidate line segments based on boundary positioning rules, so as to crop the original image according to the target boundary line segment.
[0024] As can be seen from the above embodiments, this application obtains a target image by preprocessing the 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 line detection on the edge image to obtain multiple candidate line segments; and determines the target boundary line segment from the multiple candidate line segments based on boundary localization rules, so as to crop the original image according to the target boundary line segment. This solves the technical problem that traditional image cropping methods suffer from poor cropping effects in complex scenes due to the difficulty in accurately filtering out real physical boundaries. Compared with existing technologies, this application effectively improves the boundary recognition accuracy in challenging scenes such as low light and complex backgrounds through a scene-adaptive edge detection strategy and intelligent boundary localization rules, achieving a more stable and reliable image cropping effect while ensuring efficient operation of the algorithm in a lightweight computing environment.
[0025] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device capable of performing the above functions, such as an image cropping device based on boundary detection. The following description uses an image cropping device based on boundary detection as an example to illustrate this embodiment and the subsequent embodiments.
[0026] Based on this, embodiments of this application provide an image cropping method based on boundary detection, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the image cropping method based on boundary detection in this application.
[0027] In this embodiment, the image cropping method based on boundary detection includes steps S10 to S50: Step S10: Preprocess the original image to obtain the target image; It should be noted that the preprocessing of the original image mainly involves resizing the original image to the target height H=800 to obtain the target image, and the scaling ratio between the original image and the target image can be calculated. It should be noted that the front-end (product side) provides single / batch image input and an optional visual debugging switch (outputs edge maps and candidate line coverage maps). The execution entity consists of the application UI thread scheduler and background worker threads. Step S20: Determine the scene type of the target image; It should be noted that the scene types mainly include three types: low-contrast dark scene, dark card with colored border scene, and regular scene.
[0028] In one feasible implementation, the step of determining the scene type of the target image includes: calculating the median gray level and the standard deviation gray level of the target image; determining whether the median gray level is less than a dark field threshold and whether the standard deviation gray level is less than a contrast threshold; if the median gray level is less than the dark field threshold and the standard deviation gray level is less than the contrast threshold, then the scene type is determined to be a low-contrast dark field scene; otherwise, determining whether a dominant color channel exists in the top / bottom strip region of the target image; if a dominant color channel exists, then the scene type is determined to be a dark card with colored edges scene; otherwise, the scene type is determined to be a normal scene.
[0029] In practical implementation, the scenario type can be determined in the following ways: First, calculate the median gray level (med) and standard deviation gray level of the target image. When the median gray level is less than the dark field threshold (Td) and the standard deviation gray level is less than the contrast threshold (Ts), it is determined to be a low contrast dark field scene. When the low-contrast dark scene conditions are not met, further analyze the color distribution of the top and bottom strip regions of the image, calculate the pixel mean of the RGB three channels, and if there is a significant dominant color channel (i.e., the pixel mean of a certain channel is significantly higher than that of other channels, for example, the ratio of the pixel mean of this channel to the pixel mean of the second highest channel is greater than the preset ratio coefficient k, or the pixel mean of this channel exceeds a specific percentage threshold of the sum of the three channels), then it is determined to be a dark card edge scene; If the scene conditions for both low-contrast dark scene and dark card with colored edges are not met, it is judged as a normal scene.
[0030] 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, thereby obtaining accurate boundary detection results even under complex shooting conditions.
[0031] Step S30: Based on the edge detection strategy corresponding to the scene type, perform edge detection on the target image to obtain an edge image; It should be noted that this step abandons the traditional, unchanging edge detection process. The core lies in dynamically switching to the optimal edge detection strategy based on the determined scene type, thereby addressing the main challenges in different scenarios and improving the signal-to-noise ratio of the edge image at the source. The specific strategy is as follows: 1. If the scene type is "low-contrast dark scene": The main problem in this scene is the extremely low signal-to-noise ratio and susceptibility to systematic strip noise. Therefore, the system adopts an enhanced pipeline of "global binarization -> strip projection whitening (BPW) -> adaptive Canny detection". First, preliminary segmentation is performed through global binarization; then, horizontal projection analysis is performed on the strip regions at the top and bottom of the image, and noise lines with a foreground pixel count below the dynamic threshold are completely removed (whitened). This effectively removes the upper and lower strip noise, providing "clean" input for subsequent steps; finally, the Canny operator, which adaptively calculates the threshold based on the median gray level of the image, is used to ensure that effective edges can be extracted even in low light.
[0032] 2. If the scenario type is "Dark Card with Colored Edges": The core issue in this scenario is that the colored borders cause signal inconsistencies between color channels. The system strategy is to select a dominant channel. Specifically, by analyzing the average pixel values of the top and bottom stripes of the image across the B, G, and R color channels, the channel with the highest average value is selected as the dominant channel. Subsequent edge detection will only be performed on this dominant channel. This is equivalent to automatically matching the best "filter" for edge detection, effectively suppressing noise interference from other color channels and significantly enhancing the contrast between the true card border and the background.
[0033] 3. If the scene type is "normal scene": For images with good quality, the system employs a balanced and efficient enhancement process: "Grayscale conversion -> Contrast-limited adaptive histogram equalization (CLAHE) -> Gaussian blur (Blur) -> Adaptive Canny detection". CLAHE is used to enhance local contrast without amplifying noise, Gaussian blur is used to smooth fine textures, and finally, adaptive Canny detection is used to reliably extract edges.
[0034] Step S40: Perform line detection on the edge image to obtain multiple candidate line segments; In practical implementation, a probability-based Hough transform algorithm can be used to detect straight line segments from the edge image. The core parameters of this probability-based Hough transform algorithm are not fixed but adaptively adjusted according to the scene type, thus achieving the best detection balance between complex and simple scenes. Specifically: when the scene type is a "low-contrast dark scene" or a "dark card with colored edges scene," it indicates that the image signal-to-noise ratio is low or the edge structure is complex. In this case, the system will use stricter detection parameters, such as: 1. Increasing the accumulator threshold: requiring more pixels to vote for a straight line before it can be detected, thereby suppressing false straight lines generated by noise; 2. Increasing the minimum length of line segments: avoiding misjudging a series of accidentally aligned short noisy edges as valid boundaries; 3. Reducing the maximum allowed gap between line segments: preventing two discontinuous edges from being incorrectly connected into a long straight line. Conversely, when the scene type is a "normal scene," it indicates that the image quality is high and the edges are clear. At this point, the system will use relatively lenient detection parameters, such as appropriately reducing the accumulator threshold and minimum length, to ensure that all possible real boundary segments can be fully recalled and to avoid missed detections.
[0035] Understandably, through this parameter-adaptive line detection mechanism, the present invention can effectively filter interference in difficult scenarios and ensure recall in normal scenarios, providing a higher quality and more reliable set of candidate line segments for subsequent boundary screening steps.
[0036] Step S50: Based on the boundary positioning rules, determine the target boundary line segment from the plurality of candidate line segments, so as to crop the original image according to the target boundary line segment.
[0037] In specific implementations, such as Figure 2 , 3 The detailed flowchart shown shows the data flow steps as follows: BGR original image → preprocessing (resampling H=800) → difficult case splitting → (branch) BPW / dominant channel / regular → adaptive Canny → Hough line → candidate sorting → line cluster winner → fallback → coordinate backmapping → output cropped image.
[0038] In one feasible implementation, the step of determining the target boundary line segment from the plurality of candidate line segments based on boundary positioning rules includes: determining the left / right margin region and the top / bottom margin region of the target image; aggregating 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 aggregating 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; taking the longest candidate line segment in the left / right edge line cluster as the left / right boundary line segment and the longest candidate line segment in the top / bottom edge line cluster as the top / bottom boundary line segment; and determining the target boundary line segment based on the left boundary line segment, the right boundary line segment, the top boundary line segment, and the bottom boundary line segment.
[0039] In practical implementation, the "multiple solutions" problem of the Hough transform output can be solved through a multi-level filtering mechanism. The specific execution flow includes: 1. Spatial region division and initial screening: Within a predefined boundary search area at the image edge (left / right margin area, top / bottom margin area), only candidate line segments falling within the corresponding area are retained. Simultaneously, filtering is performed based on the line segment angle. Left / Right Margin Area: Filter line segments with near-vertical angles (angle deviation ≤ vertical angle tolerance threshold). Top / bottom margin area: Filter line segments with near-horizontal angles (angle deviation ≤ horizontal angle tolerance threshold); 2. Cable Clustering and Best Choice: Perform spatial clustering on the candidate line segments that passed the initial screening: In the left / right boundary region, clustering is performed according to the horizontal coordinate of the center point of the line segment, and line segments with a distance less than the threshold ε are grouped into the same vertical line cluster. In the upper / lower margin area, clustering is performed according to the vertical coordinates of the center point of the line segment, and line segments with a distance less than the threshold ε are grouped into the same horizontal line cluster. Within each line cluster, the longest line segment is selected as the "winner" of that cluster, representing the candidate boundary on that side.
[0040] 3. Boundary representativeness verification: Further verification is performed on the selected winning line segments: (1) Eliminate false boundaries (such as reflective stripes) that are too close to the image edge; (2) Select the line segment with the smallest ordinate in the upper boundary group as the actual boundary; (3) Select the line segment with the largest ordinate in the lower boundary group as the actual lower boundary.
[0041] It should be noted that the three-level progressive mechanism of "partition filtering - line cluster aggregation - length selection" solves the problem of stably locating the true boundary from a chaotic pool of candidate lines.
[0042] 1. The rationality of the partitioned filtering: First, this method explicitly defines the left / right margin regions and the top / bottom margin regions. This design is based on the prior knowledge that the physical boundaries of the card must be located in the edge region of the image. Through this step, a large number of invalid line segments located in the center of the image (these line segments may originate from the texture inside the card, printed text, or background interference) can be directly filtered out, greatly reducing the candidate set for subsequent processing and improving the efficiency of the algorithm.
[0043] 2. The necessity of line cluster aggregation: In complex scenarios, due to the texture of the card surface (such as embossed serial numbers on bank cards), anti-counterfeiting patterns, or noise interference, the same physical boundary of the card may be brokenly detected in the edge image as multiple parallel short line segments that are close in location and similar in direction. The traditional "select the longest one" method will fail here because a single line segment may not be complete. By using line clustering, line segments that are spatially adjacent (e.g., in the left and right regions, the X coordinates of the center points of the line segments differ by less than a threshold ε) are grouped into the same "edge line cluster." Figure 4 As shown, this operation cleverly transforms the problem of "choosing one line from multiple lines" into the problem of "determining an optimal position from multiple candidate positions (clusters)". Each line cluster represents a potential candidate boundary position.
[0044] 3. Robustness of length selection: Within each cluster of lines formed by aggregation, the longest line segment in the cluster is selected as the final representative of the boundary, following the "longest wins" rule. This strategy is based on a reliable engineering intuition: line segments representing real, continuous physical boundaries typically have the longest consecutive pixel representation. Shorter lines generated by internal textures or random noise are effectively eliminated under this rule. This method is superior to simply taking the average position or midpoint of the line segment because it ensures that the selected boundary line segment itself has the highest integrity and confidence, resulting in a more accurate and stable final clipping rectangle.
[0045] In this embodiment, through a series of interconnected three-step rules, the redundant and chaotic Hough transform output is clearly converged into four optimal boundary line segments. This not only performs well under ideal conditions but also effectively handles complex situations such as boundary breaks and parallel ghosting, making it a key step in achieving the high robustness and high precision goals of this invention. Furthermore, the two-stage method of "clustering first, then selecting the best" effectively filters out fragmented short-line interference caused by detailed textures or noise, achieving convergence from "multiple solutions" to "optimal solution," thereby accurately and stably producing the left and right boundaries of the card.
[0046] In one feasible implementation, the step of cropping the original image based on the target boundary line segment includes: determining the 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 the original image boundary coordinates; determining the cropping region in the original image based on the original image boundary coordinates; and cropping the original image based on the cropping region to obtain a cropped image.
[0047] It's important to note that the coordinate mapping mechanism during the cropping process is crucial for achieving high-precision cropping. Since all image processing operations (including edge detection and line detection) are performed on a low-resolution target image (height H=800), and the final output needs to be 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 determined target boundary line segments in the target image by the scaling ratio calculated in the preprocessing stage, the corresponding positions of these boundaries in the original image can be accurately reconstructed. This approach ensures both the algorithm's processing efficiency (performing complex calculations on small images) and the quality of the final output image (based on cropping from the original high-resolution image).
[0048] In this embodiment, high-fidelity scaling is employed: the entire complex analysis and localization process is performed efficiently on a proportionally scaled-down image. However, in the final step, the algorithm maps the calculated precise cropping coordinates back to the original high-resolution image without loss using the initial scaling ratio for cropping. This ensures both processing speed and final output accuracy, avoiding pixel loss caused by cropping on a small image.
[0049] In one feasible implementation, 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 based on the target boundary line segment, includes: determining a target boundary line segment from the plurality of candidate line segments based on boundary positioning rules; determining whether the target boundary line segment is missing; and when a missing target boundary line segment is detected, determining the missing boundary line segment based on a preset conservative cropping distance, and then cropping the original image based on the target boundary line segment and the missing boundary line segment.
[0050] It should be noted that, as Figure 5As shown, after determining the target boundary line segment from candidate line segments based on boundary localization rules, the system first performs an integrity check to detect whether there are any missing boundaries on the four sides of the image. If a boundary (such as the left or top side) lacks a valid target boundary line segment, a conservative cropping strategy is activated. This strategy generates a virtual boundary line segment corresponding to the missing boundary using preset dynamic calculation rules (usually based on 2%-5% of the image's shorter side size). Finally, the system combines the actually detected target boundary line segments with the compensated boundary line segments generated by the conservative strategy to form a complete cropping bounding box. This design ensures that even in the unfavorable situation of partial boundary detection failure, the system can still output cropping results that meet basic requirements. This avoids process interruptions caused by single-sided detection failures and ensures the integrity of the core image content through intelligent calculation of conservative distances, thus significantly improving the practicality and stability of the cropping method in complex real-world scenarios.
[0051] Understandably, deterministic fallback means that if any of the aforementioned boundary lines fails to be detected due to extreme circumstances, the system will not crash or return an invalid result. Instead, it will employ a fallback strategy based on a fixed inset pixel value (fallback_inset). This predictable fallback mechanism ensures stable output and facilitates downstream business processing.
[0052] This embodiment preprocesses the original image to obtain a target 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 line detection on the edge image to obtain multiple candidate line segments; and determines the target boundary line segment from the multiple candidate line segments based on boundary localization rules, so as to crop the original image according to the target boundary line segment. This solves the technical problem of poor cropping effect in complex scenes caused by the difficulty in accurately filtering out the real physical boundary in traditional image cropping methods. Compared with the prior art, this application effectively improves the boundary recognition accuracy in challenging scenes such as low light and complex backgrounds through scene-adaptive edge detection strategies and intelligent boundary localization rules, achieving a more stable and reliable image cropping effect while ensuring efficient operation of the algorithm in a lightweight computing environment.
[0053] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 6 Step S30 also includes steps S301 to S303: Step S301: When the scene type of the target image is a low-contrast dark scene, the target image is subjected to edge detection based on global binarization processing, strip projection whitening processing and adaptive edge detection to obtain an edge image; It should be noted that strip projection whitening refers to performing line projection and threshold clearing only on the narrow upper and lower bands of the image to remove strip noise.
[0054] It should be noted that, for the horizontal stripes or regional noise commonly found after binarization in "low-light, low-contrast" scenes, it does not process the entire image, but only focuses on the top and bottom striped areas of the image that play a decisive role in the final boundary localization. For example... Figure 7 As shown, by performing horizontal projection analysis on these regions and clearing (whitening) the entire "noise lines" with fewer foreground pixels than the dynamic threshold, an extremely "clean" input can be provided for the Hough transform without damaging the vertical edge of the card body, thereby reducing subsequent false line detection from the root.
[0055] In its implementation, adaptive edge detection refers to median adaptive Canny (i.e., an adaptive Canny thresholding mechanism). It does not rely on fixed empirical thresholds but instead uses the median grayscale value *v* of the image (or selected channel) as a dynamic benchmark. The high and low thresholds are automatically calculated using the formula (1±σ) * v. This allows the edge detection algorithm to "self-calibrate," maintaining an optimal sensitivity range across images of varying brightness, greatly enhancing the algorithm's versatility and stability. The specific calculation formula is as follows: Let the median be v, and the parameter be σ:
[0056]
[0057] Practical use As the Canny threshold.
[0058] In one feasible implementation, the step of performing edge detection on the target image based on global binarization, strip projection whitening, and adaptive edge detection to obtain an edge image includes: performing global binarization on the target image to obtain a binary image; counting the number of white pixels in each row in 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 setting all noise rows as the background color to obtain the target binary image; and performing adaptive edge detection on the target binary image to obtain the edge image, wherein the high and low thresholds of the adaptive edge detection are dynamically calculated based on the median grayscale value of the target binary image.
[0059] It should be noted that for low-contrast dark scenes, a dynamic, statistically based banded noise suppression method is needed to enhance the traditional binarization process. Combined with an adaptive edge detection threshold, this ensures the robustness and accuracy of edge extraction under extremely harsh imaging conditions. Specifically: First, global binarization of the target image (e.g., using Otsu's method) transforms weak grayscale contrast into absolute black-and-white contrast, thus initially outlining the potential object contours and obtaining an initial binary image. Next, the algorithm performs a crucial banded projection whitening process. This process is not applied uniformly to the entire image but intelligently focuses on the top and bottom banded regions where noise interference is most significant. Within these regions, the number of white pixels in each row is scanned and counted. Based on this statistic (e.g., setting a dynamic threshold relative to the region height or the global white pixel ratio), "noise rows" with abnormally low white pixel counts due to uneven lighting or sensor noise are accurately identified. These noise rows typically correspond to pure black interference bands with no information. Subsequently, all identified noise row pixels are... First, the background color is set to white. This effectively removes large artifacts at the image boundaries, purifies the scene background, and yields a denoised target binary image. Finally, adaptive edge detection is performed on this purified target binary image. Its adaptability is particularly reflected in the setting strategy of the high and low thresholds of the Canny edge detector. The high and low thresholds are not fixed values, but are dynamically calculated based on the median gray level of the target binary image itself (for example, the threshold is set by floating up and down a certain proportion based on the median gray level). This dynamic calculation mechanism allows the edge detection threshold to adapt to the overall contrast level of the current binary image, thereby ensuring that the real edges are captured completely while minimizing the possibility of sporadic noise points being misdetected as edges due to binarization, and finally outputting a clear, clean, and coherent edge image.
[0060] In the specific implementation, the calculation formula for BPW (line white pixel count and whitening) is as follows: Let's define a binary graph:
[0061] In the formula, B represents the binary image, H represents the height of the image, and W represents the width of the image.
[0062] The white pixel count in the i-th row within the top / bottom band:
[0063] In the formula, i represents the row index in the image, and j represents the column index in the image. The count of white pixels in the i-th row.
[0064] Dynamic threshold (relative width ratio ρ):
[0065] In the formula, θ represents the dynamic threshold, ρ represents the relative width ratio, and W represents the width of the image.
[0066] To satisfy The line is executed with "whitewash" (set the entire line to 0):
[0067] In the formula, This represents a binary image after it has been whitened out.
[0068] Step S302: When the scene type of the target image is a dark card with colored edges, 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 an edge image. It should be noted that the dominant channel refers to the channel with the largest average value in the selected area (such as the upper and lower bands) among the B / G / R three channels, and is used as the edge detection channel.
[0069] It should be noted that the design for the "dark card with colored edges" is designed to address the inherent shortcomings of traditional grayscale methods in such scenarios: when the main color of the card is dark and the edges have distinct colored features, direct grayscale conversion will severely weaken the contrast of the colored edges, resulting in the loss of key outline information. This innovative solution employs a strategy of color channel decoupling and dominant channel focusing. First, it performs mean statistics on the pixels in the top and / or bottom strip regions of the target image (these regions typically best represent the background interference or the typical colors of card edges), calculating the average intensity of the R, G, and B color channels in these regions. Then, it selects the channel with the largest mean deviation from neutral gray, i.e., the highest absolute value or the most significant variance, as the "dominant color channel." This selection mechanism intelligently locks onto the spectral component that most clearly distinguishes the colored edges from the dark subject. Subsequently, the algorithm directly performs adaptive edge detection on the two-dimensional data of this dominant color channel. This transforms the weak colored edge signals in the full color gamut into high-contrast brightness steps in a single channel, allowing edge detectors such as Canny to accurately capture them. The adaptability of the detection process is reflected in the setting of high and low thresholds, which can be dynamically calculated based on the gradient amplitude distribution or gray median of the dominant channel to ensure effective suppression of channel noise while enhancing true edges.
[0070] It's important to note that for the "dark card with colored edges" scenario, a high-σ adaptive Canny edge detection is employed (i.e., edge detection is not performed on the grayscale image, but on the dominant channel image selected in the previous step). This converts the original image into a single-channel image, but this channel is not grayscale; instead, it's the R, G, or B channel we selected. This ensures the input image has the maximum foreground-background contrast. High-σ (standard deviation) Gaussian blur: Before performing Canny edge detection, a strong Gaussian blur is applied to this single-channel image. A higher σ value means a wider Gaussian kernel, resulting in a very significant smoothing effect. Purpose: To greatly suppress noise, especially since noise is often more pronounced in dark images, and high-σ blur effectively removes it. Focusing on major edges: High-σ blur filters out all subtle textures and unimportant gradient changes, retaining only the most significant and macroscopic object contours—which are precisely the edges of the cards. This is also crucial for "colored edge discrimination," as color differences mainly occur at these major edges. Adaptive Canny: On images with high σ blur, adaptive Canny edge detection is performed. The "adaptive" aspect refers to the fact that its high and low thresholds are not fixed, but dynamically calculated based on the local gradient statistics of the image. Advantages in dark card scenes: Because the card area and background area differ significantly in the dominant channel, but the overall image may still be dark, the adaptive threshold ensures that suitable edges are found even in darker card areas, rather than being ignored by a globally high threshold.
[0071] Understandably, for "dark-colored ID card" scenarios with complex backgrounds or colored borders, the system can automatically analyze the color distribution in the upper and lower edge areas of the image and intelligently select the color channel with the strongest signal (highest mean) for subsequent processing. This is equivalent to automatically finding the best "filter" for edge detection, effectively suppressing noise interference from other color channels and significantly improving edge contrast.
[0072] 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 contrast-limited adaptive histogram equalization, Gaussian blur and adaptive edge detection to obtain an edge image.
[0073] It's important to note that the processing flow designed for typical scenarios is a classic "enhancement-smoothing-detection" pipeline. Its core lies in achieving the optimal balance between detail enhancement and noise suppression through multi-stage processing: First, the grayscale image undergoes Limit Contrast Adaptive Histogram Equalization (CLAHE). This method segments the image into multiple local regions and performs histogram equalization independently, while limiting the histogram height to avoid excessive noise amplification, effectively enhancing local contrast and revealing previously blurred edge details. Next, Gaussian blur is applied to the enhanced image. A Gaussian kernel is used to convolve the image to smooth out subtle noise and irrelevant textures that might have been amplified by CLAHE. This crucial step controls the smoothing degree by adjusting the standard deviation parameter of the Gaussian kernel, preserving the main edge structure while creating a cleaner input for subsequent edge detection. Finally, adaptive edge detection is performed on the preprocessed image, typically using the Canny algorithm and dynamically calculating high and low thresholds based on the statistical characteristics of the image gradient magnitude. This ensures accurate capture of real edges while effectively suppressing false edges, ultimately outputting a coherent and clear single-pixel wide-edge image. This carefully designed concatenated processing strategy enables edges of various intensities and directions in normal scenes to be extracted completely and accurately, providing a reliable foundation for subsequent image analysis tasks.
[0074] This embodiment performs edge detection on the target image when the scene type is a low-contrast dark scene, based on global binarization, strip projection whitening, and adaptive edge detection, to obtain an edge image. When the scene type is a dark card with colored edges, 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 an edge image. When the scene type is a normal scene, 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. Through the above methods, differentiated edge detection strategies can be configured for low-contrast dark scenes, dark card with colored edges, and normal scenes, achieving accurate adaptation to different scene characteristics. This method improves the signal-to-noise ratio through directional noise suppression in low-contrast scenes, enhances boundary contrast through dominant channel selection in colored edge scenes, and maintains edge integrity through image enhancement in normal scenes, thus obtaining high-quality edge images under various complex conditions, significantly improving the robustness and accuracy of boundary detection.
[0075] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the image cropping method based on boundary detection in this application. Any simple transformations based on this technical concept are within the protection scope of this application.
[0076] This application also provides an image cropping device based on boundary detection; please refer to [reference needed]. Figure 8 The image cropping device based on boundary detection includes: Processing module 10 is used to preprocess the original image to obtain the target image; The determining module 20 is used to determine the scene type of the target image; Detection module 30 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 30 is also used to perform line detection on the edge image to obtain multiple candidate line segments; The determining module 20 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.
[0077] The image cropping device based on boundary detection provided in this application employs the image cropping method based on boundary detection in the above embodiments, which can solve the technical problem that traditional image cropping methods have poor cropping effects in complex scenes due to the difficulty in accurately screening out the real physical boundaries. Compared with the prior art, the beneficial effects of the image cropping device based on boundary detection provided in this application are the same as those of the image cropping method based on boundary detection provided in the above embodiments, and other technical features in the image cropping device based on boundary detection are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0078] This application provides an image cropping device based on boundary detection. The image cropping device based on boundary detection includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein 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 cropping method based on boundary detection in the first embodiment described above.
[0079] The following is for reference. Figure 9 This 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.
[0080] 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.
[0081] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0082] The image cropping device based on boundary detection provided in this application employs the image cropping method based on boundary detection in the above embodiments, which can solve the technical problem that traditional image cropping methods have poor cropping effects in complex scenes due to the difficulty in accurately screening out the real physical boundaries. Compared with the prior art, the beneficial effects of the image cropping device based on boundary detection provided in this application are the same as those of the image cropping method based on boundary detection provided in the above embodiments, and other technical features in this image cropping device based on boundary detection are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0083] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0084] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0085] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the image cropping method based on boundary detection in the above embodiments.
[0086] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this 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 may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0087] The aforementioned computer-readable storage medium may be included in a boundary detection-based image cropping device; or it may exist independently and not assembled into a boundary detection-based image cropping device.
[0088] The aforementioned computer-readable storage medium carries one or more programs that, when executed by an image cropping device based on boundary detection, cause the image cropping device based on boundary detection to: preprocess the original image to obtain a target image; determine the 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 line detection on the edge image to obtain multiple candidate line segments; and determine a target boundary line segment from the multiple candidate line segments based on a boundary localization rule, so as to crop the original image according to the target boundary line segment.
[0089] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0091] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0092] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described image cropping method based on boundary detection. This solves the technical problem that traditional image cropping methods suffer from poor cropping results in complex scenes due to the difficulty in accurately identifying real physical boundaries. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the image cropping method based on boundary detection provided in the above embodiments, and will not be repeated here.
[0093] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the image cropping method based on boundary detection as described above.
[0094] The computer program product provided in this application can solve the technical problem that traditional image cropping methods suffer from poor cropping results in complex scenes due to the difficulty in accurately identifying the true physical boundaries. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the image cropping method based on boundary detection provided in the above embodiments, and will not be repeated here.
[0095] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this 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; Based on the edge detection strategy corresponding to the scene type, edge detection is performed on the target image to obtain an edge image; Line detection is performed on the edge image to obtain multiple candidate line segments; Based on boundary positioning rules, target boundary line segments are determined from the plurality of candidate line segments, so as to crop the edges of the original image according to the target boundary line segments.
2. The image cropping method based on boundary detection as described in claim 1, characterized in that, 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.
3. The image cropping method based on boundary detection as described in claim 1, characterized in that, 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: When the scene type of the target image is a low-contrast dark scene, edge detection is performed on the target image based on global binarization processing, strip projection whitening processing, and adaptive edge detection to obtain an edge image; When the scene type of the target image is a dark card with colored edges, 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; When the scene type of the target image is a regular scene, 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.
4. The image cropping method based on boundary detection as described in claim 3, characterized in that, The step of performing edge detection on the target image based on global binarization, strip projection whitening, and adaptive edge detection to obtain an edge image includes: The target image is subjected to global binarization to obtain a binary image; In the top and bottom strip regions of the binary image, the number of white pixels in each row is counted row by row. Rows with a number of white pixels lower than the dynamic threshold are identified as noise rows. After setting all noise rows as the background color, the target binary image is obtained. Adaptive edge detection is performed 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.
5. 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.
6. 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.
7. 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.
8. 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 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 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.
9. 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 7.
10. 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 7.
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
Image cutting method, electronic equipment and storage medium
CN114723768A
Image processing method and device, electronic equipment and storage medium
CN115018704A
Up-sampling method, up-sampling device, electronic equipment and storage medium
CN116309654A
Cited By
Interface identification method and system based on minimum dynamic mean error
CN121661514A
Vehicle-mounted highway tunnel brightness real-time monitoring and early warning system
CN121963496A
An image automatic cropping method and system based on trajectory coordinates, and a storage medium
CN122695039A