Image generation method and device, rotation detection method and device and readable storage medium

By employing data augmentation and model optimization techniques, the problem of insufficient data in rotation detection under complex backgrounds has been solved, achieving efficient and accurate rotation target detection, which is suitable for resource-constrained industrial applications.

CN121660903APending Publication Date: 2026-03-13GUANGLIWEI (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-11
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Existing rotation detection technologies are inconvenient in industrial environments where data acquisition costs are high and annotation work is cumbersome. Furthermore, they are difficult to learn rotation invariant features in small sample data environments, resulting in insufficient detection accuracy and robustness, especially in complex backgrounds.

Method used

By introducing advanced data augmentation techniques to generate training samples, optimizing the model loss function, and combining local OTSU threshold adjustment and edge detection with background template generation, the YOLOv5 model structure is improved, and the KLD loss function is used for training.

Benefits of technology

It improves the model's generalization ability and robustness, reduces false detections and false negatives, is suitable for real-time detection in resource-constrained environments, and maintains high detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121660903A_ABST
    Figure CN121660903A_ABST
Patent Text Reader

Abstract

The invention relates to an image generation method and device, a rotation detection method and device and a readable storage medium, and the method comprises the steps: dividing a to-be-processed image into a plurality of regions, and determining a binary threshold value of each region; generating a copy of the to-be-processed picture, performing binarization processing on the copy according to the binarization threshold, and obtaining a foreground picture and a background picture lacking a foreground part from the to-be-processed picture in combination with edge detection; acquiring background texture features from the background picture, dividing the background picture into a plurality of image blocks, and processing the image blocks lacking foreground parts according to the similarity of the background texture features in each image block to generate a background template; rotating the foreground picture by a random angle and combining the foreground picture with the background template to form an enhanced picture; the small sample learning technology is adopted, and the training efficiency and the detection performance of the model under the small sample condition are remarkably improved through model loss function optimization and a data enhancement strategy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of image processing, and particularly relates to an image generation method, a rotation detection method, an apparatus, and a readable storage medium. Background Technology

[0002] Rotation detection is an important research area in computer vision; however, existing rotation detection techniques face numerous challenges in practical applications. First, traditional rotation detection methods typically rely on large amounts of labeled data for training, which is particularly inconvenient in industrial environments where data acquisition is costly and labeling is tedious. Second, these methods perform poorly when dealing with small sample sizes; the models struggle to learn sufficient rotation-invariant features from limited data, resulting in insufficient adaptability and robustness to rotational changes during detection. Furthermore, interference from complex backgrounds increases the difficulty of detection, further limiting the model's ability to extract target features and significantly reducing detection accuracy.

[0003] In traditional rotation detection techniques, models typically rely on large amounts of labeled data to learn the rotation-invariant features of the target. However, in environments with small sample sizes, the scarcity of data makes it difficult for the model to generalize effectively and fully capture the feature changes of the target at various rotation angles. This deficiency leads to unstable performance when handling rotational changes, making the model susceptible to the complexity of the background and the diversity of target shapes.

[0004] Traditional methods typically include techniques based on template matching, feature extraction, and machine learning. Template matching methods require a predefined rotation template for the target, but this approach lacks adaptability to unseen rotation angles. Feature extraction techniques, such as SIFT and HOG, perform rotation detection by extracting local features, but these features may be insufficient to cover all rotation transformations in small sample sizes. Machine learning methods, such as Support Vector Machines (SVM) and decision trees, rely on a large number of feature inputs for classification, and struggle to perform well with limited data.

[0005] Furthermore, deep learning methods have been widely used in rotation detection in recent years, automatically learning image features through architectures such as convolutional neural networks (CNNs). However, these methods typically require large-scale datasets for training to ensure the model can effectively recognize rotational changes. Without data augmentation, the model struggles to simulate the target's behavior at different rotation angles, leading to a decrease in detection accuracy and robustness. Summary of the Invention

[0006] To address all or part of the problems in the prior art, this invention provides an image generation method, a rotation detection method, an apparatus, and a readable storage medium. By introducing advanced data augmentation techniques, more training samples can be generated in complex backgrounds, thereby improving the generalization ability of the model. At the same time, the model loss function is optimized to give it stronger generalization ability and reduce false detections and false negatives.

[0007] Firstly, this embodiment provides an image generation method, including: The image to be processed is divided into multiple regions, and the binarization threshold for each region is determined. A copy of the image to be processed is generated, and the copy is binarized according to the binarization threshold. The foreground image and the background image with the missing foreground part are obtained from the image to be processed by combining edge detection. The background texture features are extracted from the background image, the background image is divided into multiple image blocks, and the image blocks lacking foreground parts are processed according to the similarity of the background texture features in each image block to generate a background template. The foreground image is rotated at a random angle and combined with the background template to form an enhanced image.

[0008] Optionally, determining the binarization threshold for each region includes: Obtain the local threshold and texture complexity of each region, determine the threshold adjustment strategy based on the texture complexity to dynamically adjust the local threshold, and generate the binarized threshold for each region.

[0009] Optionally, the step of obtaining the local threshold and texture complexity of each region, and determining a threshold adjustment strategy based on the texture complexity to dynamically adjust the local threshold, includes: OTSU calculations are performed separately for each region to obtain the local threshold; Calculate the discrete pixel values ​​within each region to represent texture complexity, and calculate the average threshold between adjacent regions corresponding to each region. A threshold adjustment strategy is selected based on the discrete pixel values ​​of each region. The threshold adjustment strategy adjusts the local threshold based on the average threshold value or a preset value.

[0010] Optionally, the step of selecting a threshold adjustment strategy based on the discrete pixel values ​​of each region, wherein the threshold adjustment strategy adjusts the local threshold based on the average threshold value or a preset value, includes... When discrete pixel values ​​represent low texture, the local threshold and the average threshold of the current region are averaged to obtain the binarized threshold. When pixel discrete values ​​represent high texture, the local threshold of the current region is subtracted from the preset value to obtain the binarized threshold.

[0011] Optionally, obtaining background texture features from the background image includes: Perform a two-dimensional Fourier transform on the background image to obtain its spectrum. Low-frequency components in the image are filtered out based on the spectrogram to obtain background texture features.

[0012] Optionally, image patches lacking foreground portions are processed based on the similarity of background texture features in each image patch, including: For image blocks lacking foreground parts, similarity matching is performed, and the matched image blocks replace the image blocks lacking foreground parts. Alternatively, the missing foreground parts are repaired based on the matched image blocks, and bilinear interpolation is performed on the boundary pixels.

[0013] Optionally, the similarity of background texture features in each image patch is calculated using a K-nearest neighbor search.

[0014] Optionally, after combining the foreground image with the background template by rotating it at a random angle, the method further includes: The average value of the edge pixels of the foreground image and the pixels in the background module that are located relative to the edge pixels is used to blur the boundary.

[0015] Secondly, this embodiment provides a rotation detection method, including: Obtain the source image dataset, and perform data augmentation on the source image dataset based on the image generation method described above to obtain training data; The original YOLOv5 model is improved by replacing the backbone network of the original YOLOv5 with a residual block structure; The improved YOLOv5 model is trained based on the training data, and the model parameters are updated using the loss function. The target image is detected using the trained YOLOv5 model.

[0016] Optionally, the loss function includes center point coordinate loss, width and height loss, and rotation angle loss.

[0017] Thirdly, this embodiment provides an image generation apparatus, including: The threshold update module divides the image to be processed into multiple regions and determines the binarization threshold for each region. The image processing module generates a copy of the image to be processed, performs binarization processing on the copy according to the binarization threshold, and obtains the foreground image and the background image lacking the foreground part from the image to be processed by combining edge detection. The background template generation module extracts background texture features from the background image, divides the background image into multiple image blocks, and processes image blocks lacking foreground parts based on the similarity of background texture features in each image block to generate a background template. The image enhancement generation module combines the foreground image with the background template by rotating it at a random angle to form an enhanced image.

[0018] Fourthly, this embodiment provides a readable storage medium storing a program that, when executed, can perform the image generation method provided in the first aspect of this disclosure, or the rotation detection method provided in the second aspect of this disclosure.

[0019] Compared with the prior art, the embodiments disclosed herein have at least one of the following beneficial effects: By employing the aforementioned technical solutions and introducing advanced data augmentation techniques, more training samples can be generated in complex backgrounds, thereby improving the model's generalization ability. Simultaneously, the model's loss function is optimized to enhance its generalization capability, reducing false positives and false negatives. Furthermore, this technique enhances the model's robustness to environmental changes, maintaining high detection accuracy even under conditions of varying lighting and complex backgrounds.

[0020] This solution effectively trains a high-performance rotation detection model even with limited data resources, reducing the cost of data collection and annotation. Secondly, the optimized model and training strategy ensure high computational efficiency while maintaining high performance, making it suitable for deployment in resource-constrained environments. Finally, this solution supports real-time detection, enabling rapid response to changes in rotating targets, making it suitable for industrial applications requiring fast reaction times. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the conventional technology, the drawings used in the description of the embodiments or the conventional technology will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 Here is a flowchart of an image generation method in one embodiment; Figure 2 Here is a flowchart of data augmentation in one embodiment; Figure 3 This is a structural diagram of a rotation detection algorithm in one embodiment. Detailed Implementation

[0023] To facilitate understanding of this application, a more complete description will be provided below with reference to the accompanying drawings, which illustrate embodiments of the present application. However, the present application can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that the disclosure of this application will be thorough and complete.

[0024] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.

[0025] It should also be understood that the terms "comprising / including" or "having," etc., specify the presence of the stated features, wholes, steps, operations, components, parts, or combinations thereof, but do not preclude the possibility of the presence or addition of one or more other features, wholes, steps, operations, components, parts, or combinations thereof. Meanwhile, in this specification, the term "and / or" includes any and all combinations of the associated listed items.

[0026] Figure 1 This is a flowchart illustrating an image generation method according to an exemplary embodiment.

[0027] like Figure 1 As shown, this application provides an image generation method, including: The image to be processed is divided into multiple regions, and the binarization threshold for each region is determined. A copy of the image to be processed is generated, and the copy is binarized according to the binarization threshold. The foreground image and the background image with the missing foreground part are obtained from the image to be processed by combining edge detection. The background texture features are extracted from the background image, the background image is divided into multiple image blocks, and the image blocks lacking foreground parts are processed according to the similarity of the background texture features in each image block to generate a background template. The foreground image is rotated at a random angle and combined with the background template to form an enhanced image.

[0028] The above scheme divides the image to be processed into multiple regions, determines the binarization threshold for each region, and performs binarization processing separately. This can separate more accurate and detailed foreground / background information to meet the target detection needs in complex backgrounds. Then, for regions lacking foreground, similarity matching is performed by extracting features that represent most of the texture to obtain background templates with high overall background similarity. The obtained foreground images and background templates can be arbitrarily combined to form the required images for model training, thereby meeting the rotation detection needs of small sample data.

[0029] In addition, the region can be divided using a grid of a specific size, and the division strategy can be selected based on the position, shape, and size of the foreground. The division strategy includes the area of ​​the foreground and the proportion of the area occupied by the background.

[0030] In one possible embodiment, determining the binarization threshold for each region includes: Obtain the local threshold and texture complexity of each region, determine the threshold adjustment strategy based on the texture complexity to dynamically adjust the local threshold, and generate the binarized threshold for each region.

[0031] By calculating the local threshold for each region individually, a preliminary binarization threshold is obtained. Then, based on the complexity of the background, a corresponding adjustment strategy is selected to dynamically adjust the preliminary binarization threshold. For example, if a region has high texture, it means that it is more likely to be a foreground, so the threshold can be appropriately reduced to obtain more texture information.

[0032] In one possible embodiment, obtaining the local threshold and texture complexity of each region, and determining a threshold adjustment strategy based on the texture complexity to dynamically adjust the local threshold, includes: OTSU calculations are performed separately for each region to obtain the local threshold; Calculate the discrete pixel values ​​within each region to represent texture complexity, and calculate the average threshold between adjacent regions corresponding to each region. A threshold adjustment strategy is selected based on the discrete pixel values ​​of each region. The threshold adjustment strategy adjusts the local threshold based on the average threshold value or a preset value.

[0033] Conventional OTSU calculation involves binarizing the entire image and calculating a threshold, but this is only suitable for images with high background-foreground contrast and uniform lighting, and cannot handle images with complex backgrounds. This application innovatively divides the image into multiple regions, applies OTSU calculation to the threshold calculation of a single region, and then adjusts the local threshold based on the texture of each region. For example: When discrete pixel values ​​represent low texture, the local threshold and the average threshold of the current region are averaged to obtain the binarized threshold. When pixel discrete values ​​represent high texture, the local threshold of the current region is subtracted from the preset value to obtain the binarized threshold.

[0034] In one possible embodiment, obtaining background texture features from the background image includes: Perform a two-dimensional Fourier transform on the background image to obtain its spectrum. Low-frequency components in the image are filtered out based on the spectrogram to obtain background texture features.

[0035] In one possible embodiment, image patches lacking foreground portions are processed based on the similarity of background texture features in each image patch, including: For image blocks lacking foreground parts, similarity matching is performed, and the matched image blocks replace the image blocks lacking foreground parts. Alternatively, the missing foreground parts are repaired based on the matched image blocks, and bilinear interpolation is performed on the boundary pixels.

[0036] In one possible embodiment, the similarity of background texture features in each image patch is calculated using a K-nearest neighbor search.

[0037] In one possible embodiment, after combining the foreground image with the background template by rotating it at a random angle, the method further includes: The average value of the edge pixels of the foreground image and the pixels in the background module that are located relative to the edge pixels is used to blur the boundary.

[0038] Figure 2 This is a data augmentation flowchart illustrating an image generation method according to an exemplary embodiment, mainly involving data augmentation, specifically including: Step 1: Input an image of a certain size (width * height); Step 2: For the input image, use the improved OTSU mechanism to separate the foreground. 2.1 First, perform Gaussian smoothing on the image to remove noise; 2.2 Divide the Gaussian-smoothed image into N*N regions, and perform OTSU calculation on each region separately to determine the local threshold; 2.3 Calculate the standard deviation of pixels within each region to measure the complexity of the texture; 2.4 Calculate the mean of the threshold between adjacent regions; specifically, adjacent refers to adjacent regions that are in contact or adjacent regions within a certain distance. Then calculate the mean of the threshold of all surrounding adjacent regions under the current region, such as calculating the mean with four or eight surrounding regions. 2.5, Adjust the binarization threshold Case 1: If the standard deviation is small, it indicates that the region has low texture. In this case, the threshold is adjusted by using the average of the local threshold calculated in step 2.2 and the threshold of the neighboring region calculated in step 2.4. For example: the adaptively adjusted threshold = (the local threshold of the region + the mean of the average threshold of the neighboring regions) / 2. Case 2: If the standard deviation is large, it means that this area has high texture and the threshold needs to be lowered to capture more detailed features. The adaptively adjusted threshold should be based on step 2.2 minus a certain preset value, for example, the preset value is set to 15 pixels. 2.6 Before binarizing the image, the image is copied to form a copy. Each region of the copy is binarized according to the adjusted binarization threshold to obtain a binarized image. 2.7. Edge detection is performed on the binarized image to obtain a series of foreground coordinates. The foreground is then extracted from the original image based on the foreground coordinates. 2.8. Perform a closing operation on the extracted foreground to fill in the holes in the foreground region and refine the foreground boundary. Step 3: Using the improved restoration method, restore the background of the input image (the image after subtracting the foreground from the original image in Step 2.7). 3.1. Extract the texture features of the background, using vector form. Perform a two-dimensional Fourier transform on the image to obtain the spectrum. The high-frequency and low-frequency components in the image are obtained from the spectrogram. The desired low-frequency components are filtered out by high and low thresholds, which correspond to the overall structure and large-area texture, or simply the background style, to obtain the background texture features. Texture features are derived from low-frequency and high-frequency information obtained from the spectrogram. The image is divided into multiple image blocks (regions). Each image block has a corresponding texture feature vector. These texture blocks are equivalent to a database. 3.2. Use K-nearest neighbor search to find similar samples for the image patch from step 3.1; 3.3. Fill the part after removing the foreground with the matched image blocks, and perform bilinear interpolation on the boundary pixels to avoid the boundary blending being too harsh; you can also directly replace the texture blocks after removing the foreground with the matched texture blocks. 4. After rotating the foreground obtained in step 2 by a random angle, paste it onto the restored background obtained in step 3; 5. Take the average value of the edge pixels of the foreground and the background pixels in step 4, and blur the pasted boundary to improve the quality of the resulting image.

[0039] This embodiment also provides a rotation detection method, including: Obtain the source image dataset, and perform data augmentation on the source image dataset based on the image generation method described above to obtain training data; The original YOLOv5 model is improved by replacing the backbone network of the original YOLOv5 with a residual block structure; The improved YOLOv5 model is trained based on the training data, and the model parameters are updated using the loss function. The target image is detected using the trained YOLOv5 model.

[0040] The original YOLOv5 model can only detect horizontal bounding boxes and cannot adapt to rotating bounding boxes. This application improves the existing YOLOv5 to enable it to detect rotating targets. The main improvements are: the backbone structure of the rotation detection model, the data representation method, and the loss function.

[0041] 1. Backbone structure of the rotation detection model: The rotation detection algorithm structure of this scheme is as follows: Figure 3 As shown, the backbone uses ResNet18 (residual block structure) instead of the original DarkNet53 structure (convolutional structure). ResNet18, through its deep structure and residual connections, can lose fewer features compared to the convolutional structure and performs better when dealing with rotated targets. This is because deep networks can learn more abstract features, which have better invariance to geometric transformations such as rotation.

[0042] 2. Data Representation Methods During training, it is necessary to change the data format, converting HBB format data to OBB format, that is, converting from a horizontal bounding box to a rotated bounding box. The conversion steps are as follows: HBB (Horizontal Bounding Box): Defined as (x, y, w, h), where (x, y) are the coordinates of the top-left corner of the bounding box, and w and h are the width and height of the bounding box, respectively. OBB (Rotated Bounding Box): Defined as (xc, yc, w, h, θ), where (xc, yc) are the coordinates of the center of the bounding box, w and h are the width and height of the bounding box, and θ is the rotation angle of the bounding box (counterclockwise rotation relative to the horizontal line). Calculate the center point: xc = x + 2w, yc = y + 2h, where (xc, yc) is the center point of OBB; Determine the rotation angle: If the bounding box is horizontal or vertical, the rotation angle θ can be 0 or 90 degrees. For any rotated bounding box, the angle between it and the horizontal line needs to be calculated. θ is calculated using the angle between the diagonal of the bounding box and the horizontal line: θ = arctan(x2−x1,y2−y1), where (x1,y1) and (x2,y2) are the two diagonal vertices of the bounding box.

[0043] 3. Loss Function Section KLD loss is used to measure the difference between the predicted rotated box and the ground truth box. KLD loss consists of three parts: KLD loss for the center point coordinates, KLD loss for the width and height, and KLD loss for the rotation angle.

[0044] 3.1 KLD loss for center point coordinates: Assume the predicted OBB parameters are The actual OBB parameters are For the coordinates of the center point The KLD loss between the predicted OBB and the actual OBB parameters can be calculated. The calculation process is as follows: Where σ and These are the standard deviations of the actual and predicted coordinates, respectively.

[0045] 3.2 KLD Loss in Width and Height: For width w and height h, a log-normal distribution is used to approximate the actual size distribution, calculated as follows: in, and These are the log-standard deviations of the actual and predicted sizes, respectively.

[0046] 3.3 KLD loss due to rotation angle: The periodic difference in angles is converted into a non-periodic difference using the sine or cosine value of the angle difference. The calculation formula is as follows: In summary, the formula for calculating the total KLD loss is: In summary, this application provides the following key technologies: 1. Improved foreground extraction and complex background restoration techniques Traditional foreground extraction using OTSU only performs global threshold calculations. This proposed solution combines local OTSU with threshold adjustment, edge detection, and morphological operations, resulting in a more complete foreground extraction. It also boasts greater universality, avoiding incomplete extraction due to differences in foreground color or shape. The improved background restoration technique, unlike backgrounds generated through adversarial learning, uses Fourier transform for pixel value completion to generate near-realistic background images. This technique achieves high-quality background extraction and restoration even in complex environments, with the enhanced data showing a high degree of morphological fit to the real data, and increases the sample size. Traditional background extraction methods may not achieve such high-quality restoration results.

[0047] 2. Rotational data augmentation techniques in complex backgrounds To address the challenges of limited industrial defect data and the risk of overfitting during training, a highly efficient data augmentation technique was designed. This technique enables high-quality foreground extraction and excellent background restoration in complex contexts. The augmented data exhibits a high degree of morphological fit with the real data, significantly increasing the sample size. By introducing random rotation transformations during the data augmentation stage, this technique simulates various rotation angles that targets may encounter in real-world scenarios. This rotational data augmentation method allows the model to learn rotation-invariant features, thereby improving its ability to detect rotating targets and greatly enriching the diversity of rotation angles in the training data, resulting in stronger model robustness. Traditional data augmentation methods, such as random cropping and color jittering, cannot effectively simulate the diversity of rotation angles.

[0048] 3. Design of Rotational Detection Loss Function In calculating the loss for rotating target detection, in addition to the loss from position regression, additional consideration needs to be given to the angle loss. This paper employs a composite loss mechanism, KLD loss, which calculates the KLD loss for center point coordinates, width and height, and rotation angle. The KLD loss for center point coordinates measures the difference between the predicted and true center point. By calculating this KLD loss, the model can be effectively guided to learn a more accurate center point position. The KLD loss for width and height measures the difference between the predicted and true bounding box sizes. By calculating this KLD loss, the model's estimation accuracy for the size of the rotating target can be improved. The KLD loss for rotation angle measures the difference between the predicted and true rotation angles. Since angles are periodic, directly using traditional loss functions may lead to optimization problems. This technique addresses the periodicity of angles by calculating the KLD loss between the predicted and true angles, thereby improving the model's estimation accuracy for rotation angles. Explanation of the periodicity of the rotation angle: The rotation angle is a periodic variable; for example, angles of 0° and 360° actually represent the same direction. If a common loss function (such as Mean Squared Error, MSE) is used to calculate the difference between the predicted and actual angles, unreasonable situations may occur. For instance, from a practical perspective, the difference between 0° and 350° is only 10°, but MSE might calculate a very large value ((350-0)). 2 =122500), which is inconsistent with reality. Using KLD loss will transform the angle information into a probability distribution form, representing the angle as a probability distribution on the circumference, taking into account the periodicity of the angle, and automatically treating 0∘ and 360∘ as the same value, which is more in line with reality.

[0049] This embodiment provides an image generation apparatus, including: The threshold update module divides the image to be processed into multiple regions and determines the binarization threshold for each region. The image processing module generates a copy of the image to be processed, performs binarization processing on the copy according to the binarization threshold, and obtains the foreground image and the background image lacking the foreground part from the image to be processed by combining edge detection. The background template generation module extracts background texture features from the background image, divides the background image into multiple image blocks, and processes image blocks lacking foreground parts based on the similarity of background texture features in each image block to generate a background template. The image enhancement generation module combines the foreground image with the background template by rotating it at a random angle to form an enhanced image.

[0050] This embodiment provides a readable storage medium storing a program, which, when executed, can perform the image generation method or the rotation detection method provided above.

[0051] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0052] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0053] In the description of this specification, the references to terms such as "some embodiments," "other embodiments," "ideal embodiments," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example that are included in at least one embodiment or example of this application. In this specification, the illustrative descriptions of the above terms do not necessarily refer to the same embodiments or examples.

[0054] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0055] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. An image generation method, characterized in that, include: The image to be processed is divided into multiple regions, and the binarization threshold for each region is determined. A copy of the image to be processed is generated, and the copy is binarized according to the binarization threshold. The foreground image and the background image with the missing foreground part are obtained from the image to be processed by combining edge detection. The background texture features are extracted from the background image, the background image is divided into multiple image blocks, and the image blocks lacking foreground parts are processed according to the similarity of the background texture features in each image block to generate a background template. The foreground image is rotated at a random angle and combined with the background template to form an enhanced image.

2. The image generation method according to claim 1, characterized in that, Determining the binarization threshold for each region includes: Obtain the local threshold and texture complexity of each region, determine the threshold adjustment strategy based on the texture complexity to dynamically adjust the local threshold, and generate the binarized threshold for each region.

3. The image generation method according to claim 2, characterized in that, The process of obtaining the local threshold and texture complexity of each region, and determining a threshold adjustment strategy based on the texture complexity to dynamically adjust the local threshold, includes: OTSU calculations are performed separately for each region to obtain the local threshold; Calculate the discrete pixel values ​​within each region to represent texture complexity, and calculate the average threshold between adjacent regions corresponding to each region. A threshold adjustment strategy is selected based on the discrete pixel values ​​of each region. The threshold adjustment strategy adjusts the local threshold based on the average threshold value or a preset value.

4. The image generation method according to claim 3, characterized in that, The threshold adjustment strategy is selected based on the discrete pixel values ​​of each region. This threshold adjustment strategy adjusts the local threshold based on the average threshold value or a preset value, including... When discrete pixel values ​​represent low texture, the local threshold and the average threshold of the current region are averaged to obtain the binarized threshold. When pixel discrete values ​​represent high texture, the local threshold of the current region is subtracted from the preset value to obtain the binarized threshold.

5. The image generation method according to claim 1, characterized in that, The step of obtaining background texture features from the background image includes: Perform a two-dimensional Fourier transform on the background image to obtain its spectrum. Low-frequency components in the image are filtered out based on the spectrogram to obtain background texture features.

6. The image generation method according to claim 1, characterized in that, Based on the similarity of background texture features in each image patch, image patches lacking foreground components are processed, including: For image blocks lacking foreground parts, similarity matching is performed, and the matched image blocks replace the image blocks lacking foreground parts. Alternatively, the missing foreground parts are repaired based on the matched image blocks, and bilinear interpolation is performed on the boundary pixels.

7. The image generation method according to claim 1, characterized in that, The similarity of background texture features in each image patch is calculated using K-nearest neighbor search.

8. The image generation method according to claim 1, characterized in that, After combining the foreground image with the background template by rotating it at a random angle, the method further includes: The average value of the edge pixels of the foreground image and the pixels in the background module that are located relative to the edge pixels is used to blur the boundary.

9. A rotation detection method, characterized in that, include: Obtain the source image dataset, and perform data augmentation on the source image dataset based on the image generation method according to any one of claims 1-7 to obtain training data; The original YOLOv5 model is improved by replacing the backbone network of the original YOLOv5 with a residual block structure; The improved YOLOv5 model is trained based on the training data, and the model parameters are updated using the loss function. The target image is detected using the trained YOLOv5 model.

10. The rotation detection method according to claim 9, characterized in that, The loss function includes center point coordinate loss, width and height loss, and rotation angle loss.

11. An image generation apparatus, characterized in that, include: The threshold update module divides the image to be processed into multiple regions and determines the binarization threshold for each region. The image processing module generates a copy of the image to be processed, performs binarization processing on the copy according to the binarization threshold, and obtains the foreground image and the background image lacking the foreground part from the image to be processed by combining edge detection. The background template generation module extracts background texture features from the background image, divides the background image into multiple image blocks, and processes image blocks lacking foreground parts based on the similarity of background texture features in each image block to generate a background template. The image enhancement generation module combines the foreground image with the background template by rotating it at a random angle to form an enhanced image.

12. A readable storage medium storing a program, characterized in that, When the program is executed, it implements the image generation method according to any one of claims 1 to 8.