Sample generation method and sample generation apparatus in industrial detection
By randomly shifting rows and columns in industrial site images, new samples are generated, which solves the image distortion problem caused by camera shake in the existing technology, and improves the diversity of samples and the training effect of the deep learning model.
Patent Information
- Application Number
- PCT/CN2023/123673
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-02-27
- Filing Date
- 2023-10-10
- Publication Date
- 2024-09-06
AI Technical Summary
The existing image translation method causes inconsistent translation amplitudes of pixels in different rows and rows in the image due to camera shake at industrial sites, which limits the training effect of the deep learning model and cannot effectively improve the diversity of samples.
By obtaining the industrial site image and disassembling it into rows and columns, obtain random offset values for each row and column, offset them along the X and Y directions, and generate new image samples to ensure that the offset image will not Change the original pixel values, thus increasing the diversity of the samples.
This method avoids the image distortion problem caused by camera shake, improves the diversity of samples, is simple, efficient, and easy to program.
Smart Images

Figure CN2023123673_06092024_PF_FP
Abstract
Description
Sample generation method and sample generation device in industrial detection Technical Field
[0001] The present invention relates to the technical field of industrial detection, and in particular to a sample generation method and a sample generation device in industrial detection. Background Art
[0002] In the field of intelligent industrial inspection, due to the small number of samples, data enhancement can be performed on a small number of samples to increase sample diversity and improve the generalization ability of deep learning models. Therefore, creating new data enhancement methods through different methods has great engineering value.
[0003] Related technologies typically use image translation for data augmentation, but this method shifts the entire image, making it less effective for image enhancement in some industrial sites. This is because high-frequency jitter in cameras or equipment can cause the captured image to not necessarily be a fully translated image, potentially resulting in inconsistent pixel shifts across different rows and columns within the image. Consequently, using existing image augmentation methods in these situations has limited effectiveness in training deep learning models and fails to achieve the goal of increasing sample diversity.
[0004] Summary of the Invention
[0005] In order to solve the above technical problems, the first object of the present invention is to provide a sample generation method for industrial detection.
[0006] The second objective of the present invention is to provide a sample generating device for industrial testing.
[0007] The technical solution adopted in the present invention is as follows:
[0008] An embodiment of the first aspect of the present invention proposes a sample generation method for industrial inspection, including the following steps: step S1, obtaining an industrial site image and converting it into a grayscale image; step S2, obtaining pixel points of the grayscale image; step S3, traversing each row and / or column of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each row of the grayscale image along the X direction and / or the pixel points of each column along the Y direction according to the random offset value, wherein the random offset value is re-obtained for each row and column, and the random offset value is within a preset range; step S4, after the traversal is completed, generating a sample for industrial inspection based on the offset image.
[0009] The sample generation method for industrial testing proposed in the present invention may also have the following additional technical features:
[0010] According to one embodiment of the present invention, traversing each row of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each row of the grayscale image along the X direction according to the random offset value specifically includes: generating a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; generating a second matrix with a width of (W+px) and a height of H, setting the values of all elements in the second matrix to 0, wherein px is the maximum offset value of the random offset value along the X direction; traversing each row of the first matrix, randomly generating a random offset value ni for the i-th row of the first matrix, and copying the pixel points of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinates, where the value range of ni is [0, px], and i is a positive integer; after the traversal is completed, storing the second matrix.
[0011] According to one embodiment of the present invention, each column of the grayscale image is traversed to obtain a random offset value, and the pixel points of each column of the grayscale image are offset along the Y direction according to the random offset value, specifically comprising: generating a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; generating a third matrix with a width of W and a height of (H+py), wherein the values of all elements in the third matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; traversing each column of the first matrix, randomly generating a random offset value mj for the j-th column of the first matrix, and copying the pixel points of the j-th column of the first matrix to the third matrix with (mj, j) as the starting coordinates, wherein the value range of mj is [0, py], and j is a positive integer; after the traversal is completed, storing the third matrix.
[0012] According to one embodiment of the present invention, traversing each row and column of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each row of the grayscale image along the X direction and the pixel points of each column along the Y direction according to the random offset value, specifically includes: generating a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; generating a second matrix with a width of (W+px) and a height of H, and setting the values of all elements in the second matrix to 0, wherein px is the maximum offset value of the random offset value along the X direction; traversing each row of the first matrix, randomly generating a random offset value ni for the i-th row of the first matrix, and offsetting the pixel points of the first matrix along the Y direction. The pixel points in the i-th row are copied to the second matrix with (i, ni) as the starting coordinates, where ni is in the range of [0, px] and i is a positive integer; after the traversal is completed, the second matrix is stored; a fourth matrix with a width of (W+px) and a height of (H+py) is generated, and the values of all elements in the fourth matrix are set to 0, where py is the maximum offset value of the random offset value along the Y direction; each column of the second matrix is traversed, and a random offset value mj is randomly generated for the j-th column of the second matrix, and the pixel points in the j-th column of the second matrix are copied to the fourth matrix with (mj, j) as the starting coordinates; after the traversal is completed, the fourth matrix is stored.
[0013] According to an embodiment of the present invention, the sample generation method further includes: cropping the shifted image from a central area according to the size of the industrial scene image.
[0014] An embodiment of the second aspect of the present invention proposes a sample generation device for industrial inspection, including: a conversion module, the conversion module is used to acquire an industrial site image and convert it into a grayscale image; an acquisition module, the acquisition module is used to acquire pixel points of the grayscale image; a traversal module, the traversal module is used to traverse each row and / or column of the grayscale image, acquire a random offset value, and offset the pixel points of each row of the grayscale image along the X direction and / or the pixel points of each column along the Y direction according to the random offset value, wherein the random offset value is re-acquired for each row and column, and the random offset value is within a preset range; and a generation module, the generation module is used to generate industrial inspection samples based on the offset image after the traversal is completed.
[0015] The sample generation device for industrial testing proposed in the present invention may also have the following additional technical features:
[0016] According to one embodiment of the present invention, the traversal module is specifically used to: generate a first matrix based on the grayscale image, wherein the width of the first matrix is W and the height is H; generate a second matrix with a width of (W+px) and a height of H, and the values of all elements in the second matrix are set to 0, wherein px is the maximum offset value of the random offset value along the X direction; traverse each row of the first matrix, randomly generate a random offset value ni for the i-th row of the first matrix, and copy the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate, where the value range of ni is [0, px], and i is a positive integer; after the traversal is completed, store the second matrix.
[0017] According to one embodiment of the present invention, the traversal module is specifically used to: generate a first matrix based on the grayscale image, wherein the width of the first matrix is W and the height is H; generate a third matrix with a width of W and a height of (H+py), and the values of all elements in the third matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; traverse each column of the first matrix, randomly generate a random offset value mj for the j-th column of the first matrix, and copy the pixel points of the j-th column of the first matrix to the third matrix with (mj, j) as the starting coordinates, where the value range of mj is [0, py], and j is a positive integer; after the traversal is completed, store the third matrix.
[0018] According to one embodiment of the present invention, the traversal module is specifically used to: generate a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; generate a second matrix with a width of (W+px) and a height of H, and the values of all elements in the second matrix are set to 0, wherein px is the maximum offset value of the random offset value along the X direction; traverse each row of the first matrix, randomly generate a random offset value ni for the i-th row of the first matrix, and copy the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate, where the value range of ni is [0, px], and i is a positive integer; after the traversal is completed, store the second matrix; generate a fourth matrix with a width of (W+px) and a height of (H+py), and the values of all elements in the fourth matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; traverse each column of the second matrix, randomly generate a random offset value mj for the j-th column of the second matrix, and copy the pixel point of the j-th column of the second matrix to the fourth matrix with (mj, j) as the starting coordinate; after the traversal is completed, store the fourth matrix.
[0019] According to an embodiment of the present invention, the sample generation device further includes: a cropping module, configured to crop the shifted image from a central area according to the size of the industrial scene image.
[0020] Beneficial effects of the present invention:
[0021] The present invention decomposes industrial site images into rows and columns, and performs different random offset operations on each row and column to perform image enhancement. The enhanced image does not change the pixel values in the original image, thereby increasing the diversity of samples. The entire method not only avoids image distortion problems caused by camera shake, but is also simple, efficient, and easy to program and implement. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] FIG1 is a flow chart of a method for generating samples in industrial inspection according to an embodiment of the present invention;
[0023] FIG2 is a block diagram of a sample generating apparatus for industrial inspection according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0025] FIG1 is a flow chart of a method for generating a sample in industrial inspection according to an embodiment of the present invention. As shown in FIG1 , the method includes the following steps:
[0026] Step S1: Acquire an industrial site image and convert it into a grayscale image.
[0027] Step S2: Obtain pixel points of the grayscale image.
[0028] Step S3: traverse each row and / or column of the grayscale image, obtain a random offset value, and offset the pixel points of each row of the grayscale image along the X direction and / or offset the pixel points of each column along the Y direction according to the random offset value, wherein the random offset value is re-obtained for each row and column, and the random offset value is within a preset range.
[0029] Step S4: After the traversal is completed, industrial inspection samples are generated based on the offset images.
[0030] Specifically, an industrial site image is acquired and converted into a grayscale image, and the pixels of the grayscale image are obtained. Each row / column of the grayscale image is traversed, a random offset value n is obtained, and the row / column is offset by n pixels in the X / Y direction to finally generate a new image. The random offset can be performed only on the rows, only on the columns, or on both the rows and the columns. When performing random offsets row by row and column by column, the random offset value is re-acquired or generated for each row and column. That is, the random offset value of each row / column is generated in real time and randomly within a preset range.
[0031] In order to control the distortion of the image, the range of the random offset value n cannot be too large. The maximum value of the random offset value n is based on the fact that the human eye can still recognize defects after enhancement, and is obtained in advance through relevant experiments based on actual conditions.
[0032] Therefore, the industrial site images are decomposed into rows and columns, and different random offset operations are performed on each row and column for image enhancement. The enhanced image does not change the pixel values in the original image, thereby increasing the diversity of samples. The entire method not only avoids the image distortion problem caused by camera shake, but is also simple, efficient, and easy to program.
[0033] According to one embodiment of the present invention, the aforementioned sample generation method for industrial inspection may further include: cropping the offset image according to the size of the industrial scene image, and generating the industrial inspection sample based on the cropped image. This ensures that the size of the enhanced image is consistent with the original image.
[0034] The following describes how to perform row and column offsets in conjunction with specific embodiments.
[0035] According to one embodiment of the present invention, traversing each row of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each row of the grayscale image along the X direction according to the random offset value specifically includes the following steps S301:
[0036] S301 : Generate a first matrix according to a grayscale image, where the width of the first matrix is W and the height is H.
[0037] S302 generates a second matrix with a width of (W+px) and a height of H, and sets the values of all elements in the second matrix to 0, where px is the maximum offset value of the random offset value along the X direction.
[0038] S303, traverse each row of the first matrix, randomly generate a random offset value ni for the i-th row of the first matrix, and copy the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate. The value range of ni is [0, px], and i is a positive integer.
[0039] S304: After the traversal is completed, the second matrix is stored.
[0040] Specifically, each row in the first matrix is shifted rightward by a random offset value to form a second matrix, or each row is shifted leftward to form a corresponding image according to the second matrix to generate a corresponding industrial detection sample.
[0041] According to one embodiment of the present invention, traversing each column of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each column of the grayscale image along the Y direction according to the random offset value specifically includes the following steps S310-S313:
[0042] S310 , generating a first matrix according to the grayscale image, wherein the first matrix has a width of W and a height of H.
[0043] S311 , generating a third matrix with a width of W and a height of (H+py), wherein the values of all elements in the third matrix are set to 0, where py is the maximum offset value of the random offset value along the Y direction.
[0044] S312: traverse each column of the first matrix, randomly generate a random offset value mj for the j-th column of the first matrix, and copy the pixel point in the j-th column of the first matrix to the third matrix with (mj, j) as the starting coordinate. The value of mj is in the range [0, py], and j is a positive integer.
[0045] S313: After the traversal is completed, the third matrix is stored.
[0046] Specifically, each column in the first matrix is shifted downward by a random offset value to form a third matrix, or it can be shifted upward, and a corresponding image is formed according to the third matrix to generate a corresponding industrial detection sample.
[0047] According to one embodiment of the present invention, each row and column of the grayscale image is traversed to obtain a random offset value, and the pixels of each row of the grayscale image are offset along the X direction and the pixels of each column of the grayscale image are offset along the Y direction according to the random offset value. Specifically, the following steps S320-S are included:
[0048] Step S320: Generate a first matrix according to the grayscale image, where the width of the first matrix is W and the height is H.
[0049] Step S321 : Generate a second matrix with a width of (W+px) and a height of H. Set the values of all elements in the second matrix to 0, where px is the maximum offset value of the random offset value along the X direction.
[0050] Step S322, traverse each row of the first matrix, randomly generate a random offset value ni for the i-th row of the first matrix, and copy the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate. The value range of ni is [0, px], and i is a positive integer.
[0051] Step S323: After the traversal is completed, the second matrix is stored.
[0052] Step S324: Generate a fourth matrix with a width of (W+px) and a height of (H+py), and set the values of all elements in the fourth matrix to 0, where py is the maximum offset value of the random offset value along the Y direction.
[0053] Step S325 , traverse each column of the second matrix, randomly generate a random offset value mj for the j-th column of the second matrix, and copy the pixel point of the j-th column of the second matrix to the fourth matrix with (mj, j) as the starting coordinate.
[0054] Step S326: After the traversal is completed, the fourth matrix is stored.
[0055] Specifically, each row in the first matrix is shifted to the right by a random offset value to form a second matrix, or it can be shifted to the left. Then, each column in the second matrix is shifted downward by a random offset value to form a fourth matrix, or it can be shifted upward. A corresponding image is formed according to the fourth matrix to generate corresponding industrial inspection samples.
[0056] In summary, according to the sample generation method in industrial inspection according to an embodiment of the present invention, the industrial site image is decomposed into rows and columns, and different random offset operations are performed on each row and each column to perform image enhancement. The enhanced image does not change the pixel values in the original image, thereby increasing the diversity of samples. The entire method can not only avoid the image distortion problem caused by camera shake, but also is simple, efficient, and easy to program and implement.
[0057] Corresponding to the above-mentioned sample generation method in industrial detection, the present invention also proposes a sample generation device in industrial detection.
[0058] FIG2 is a block diagram of a sample generation device in industrial inspection according to an embodiment of the present invention. As shown in FIG2 , the device includes: a conversion module 1 , an acquisition module 2 , a traversal module 3 and a generation module 4 .
[0059] Among them, the conversion module 1 is used to acquire the industrial site image and convert it into a grayscale image; the acquisition module 2 is used to acquire the pixel points of the grayscale image; the traversal module 3 is used to traverse each row and / or column of the grayscale image, obtain a random offset value, and offset the pixel points of each row of the grayscale image along the X direction and / or the pixel points of each column along the Y direction according to the random offset value, wherein the random offset value is re-acquired for each row and column, and the random offset value is within a preset range; the generation module 4 is used to generate industrial inspection samples based on the offset image after the traversal is completed.
[0060] According to one embodiment of the present invention, the traversal module 3 is specifically used to: generate a first matrix based on the grayscale image, where the width of the first matrix is W and the height is H; generate a second matrix with a width of (W+px) and a height of H, and the values of all elements in the second matrix are set to 0, where px is the maximum offset value of the random offset value along the X direction; traverse each row of the first matrix, randomly generate a random offset value ni for the i-th row of the first matrix, and copy the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate, where the value range of ni is [0, px], and i is a positive integer; after the traversal is completed, store the second matrix.
[0061] According to one embodiment of the present invention, the traversal module 3 is specifically used to: generate a first matrix based on the grayscale image, wherein the width of the first matrix is W and the height is H; generate a third matrix with a width of W and a height of (H+py), and the values of all elements in the third matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; traverse each column of the first matrix, randomly generate a random offset value mj for the j-th column of the first matrix, and copy the pixel points of the j-th column of the first matrix to the third matrix with (mj, j) as the starting coordinates, where the value range of mj is [0, py], and j is a positive integer; after the traversal is completed, store the third matrix.
[0062] According to one embodiment of the present invention, the traversal module 3 is specifically used to: generate a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; generate a second matrix with a width of (W+px) and a height of H, and the values of all elements in the second matrix are set to 0, wherein px is the maximum offset value of the random offset value along the X direction; traverse each row of the first matrix, randomly generate a random offset value ni for the i-th row of the first matrix, and copy the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate, where the value range of ni is [0, px], and i is a positive integer; after the traversal is completed, store the second matrix; generate a fourth matrix with a width of (W+px) and a height of (H+py), and the values of all elements in the fourth matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; traverse each column of the second matrix, randomly generate a random offset value mj for the j-th column of the second matrix, and copy the pixel point of the j-th column of the second matrix to the fourth matrix with (mj, j) as the starting coordinate; after the traversal is completed, store the fourth matrix.
[0063] According to an embodiment of the present invention, the sample generation device further includes: a cropping module, configured to crop the shifted image from a central area according to the size of the industrial scene image.
[0064] In summary, according to the sample generation device in industrial inspection according to the embodiment of the present invention, the industrial site image is decomposed into rows and columns, and different random offset operations are performed on each row and each column to perform image enhancement. The enhanced image does not change the pixel values in the original image, thereby increasing the diversity of samples. The entire method can not only avoid the image distortion problem caused by camera shake, but also is simple, efficient, and easy to program and implement.
[0065] In the description of the present invention, the terms "first" and "second" are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the number of the technical features indicated. Therefore, a feature specified as "first" or "second" may explicitly or implicitly include one or more of such features. "Multiple" means two or more, unless otherwise specifically defined.
[0066] Throughout this specification, reference to terms such as "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of the present invention. Throughout this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate different embodiments or examples described in this specification, as well as features from different embodiments or examples, without conflicting interpretations. Throughout this specification, reference to terms such as "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of the present invention. Throughout this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and combine different embodiments or examples and features of different embodiments or examples described in this specification without mutual contradiction.
[0067] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may be performed out of the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention pertain.
[0068] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing the logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (e.g., a computer-based system, a system including a processor, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device). For purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic devices), a portable computer disk cartridge (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and programmable read-only memory (EPROM or flash memory), fiber optic devices, and a portable compact disc read-only memory (CDROM). Furthermore, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing it in another suitable manner if necessary, and then storing it in a computer memory.
[0069] It should be understood that various parts of the present invention can be implemented using hardware, software, firmware, or a combination thereof. In the above-described embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application-specific integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0070] Those skilled in the art will understand that all or part of the steps in the method of the above embodiment can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.
[0071] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing module, or each unit may exist physically separately, or two or more units may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or in the form of software functional modules. If the integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may also be stored in a computer-readable storage medium.
[0072] The storage medium mentioned above may be a read-only memory, a magnetic disk, or an optical disk, etc. Although the embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and are not to be construed as limiting the present invention. Persons skilled in the art may make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present invention.
[0073] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A sample generation method in industrial detection, characterized in that: The following steps are involved: Step S1, acquiring an industrial site image and converting it into a grayscale image; Step S2, obtaining pixel points of the grayscale image; Step S3, traversing each row and / or column of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each row of the grayscale image along the X direction and / or the pixel points of each column along the Y direction according to the random offset value, wherein the random offset value is re-obtained for each row and column, and the random offset value is within a preset range; Step S4, after the traversal is completed, generate according to the offset image.
2. The sample generation method in industrial detection according to claim 1, characterized in that: Traversing each row of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each row of the grayscale image along the X direction according to the random offset value specifically includes: Generate a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; Generate a second matrix with a width of (W+px) and a height of H, wherein the values of all elements in the second matrix are set to 0, wherein px is the maximum offset value of the random offset value along the X direction; Traversing each row of the first matrix, randomly generating a random offset value ni for the i-th row of the first matrix, and copying the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate, where the value range of ni is [0, px], and i is a positive integer; After the traversal is completed, the second matrix is stored.
3. The sample generation method in industrial detection according to claim 1, characterized in that: Traversing each column of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each column of the grayscale image along the Y direction according to the random offset value, specifically comprising: Generate a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; Generate a third matrix with a width of W and a height of (H+py), wherein the values of all elements in the third matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; Traverse each column of the first matrix, randomly generate a random offset value mj for the j-th column of the first matrix, and copy the pixel point of the j-th column of the first matrix to the third matrix with (mj, j) as the starting coordinate, where the value range of mj is [0, py], and j is a positive integer; After the traversal is completed, the third matrix is stored.
4. The sample generation method in industrial detection according to claim 1, characterized in that: Traversing each row and column of the grayscale image, obtaining a random offset value, and offsetting the pixel points of each row of the grayscale image along the X direction and the pixel points of each column along the Y direction according to the random offset value, specifically comprising: Generate a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; Generate a second matrix with a width of (W+px) and a height of H, wherein the values of all elements in the second matrix are set to 0, wherein px is the maximum offset value of the random offset value along the X direction; Traversing each row of the first matrix, randomly generating a random offset value ni for the i-th row of the first matrix, and copying the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate, where the value range of ni is [0, px], and i is a positive integer; After the traversal is completed, the second matrix is stored; Generate a fourth matrix with a width of (W+px) and a height of (H+py), wherein the values of all elements in the fourth matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; Traverse each column of the second matrix, randomly generate a random offset value mj for the j-th column of the second matrix, and copy the pixel point of the j-th column of the second matrix to the fourth matrix with (mj, j) as the starting coordinate; After the traversal is completed, the fourth matrix is stored.
5. The sample generation method in industrial detection according to claim 1, characterized in that: Also includes: The shifted image is cropped from a central area according to the size of the industrial scene image.
6. A sample generation device for industrial detection, characterized in that: include: A conversion module, the conversion module is used to acquire the industrial scene image and convert it into a grayscale image; An acquisition module, the acquisition module is used to acquire pixel points of the grayscale image; A traversal module, the traversal module is used to traverse each row and / or column of the grayscale image, obtain a random offset value, and offset the pixel points of each row of the grayscale image along the X direction and / or offset the pixel points of each column along the Y direction according to the random offset value, wherein the random offset value is re-obtained for each row and column, and the random offset value is within a preset range; A generation module is used to generate industrial inspection samples based on the offset images after the traversal is completed.
7. The sample generating device in industrial detection according to claim 6, characterized in that: The traversal module is specifically used for: Generate a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; Generate a second matrix with a width of (W+px) and a height of H, wherein the values of all elements in the second matrix are set to 0, wherein px is the maximum offset value of the random offset value along the X direction; Traverse each row of the first matrix, randomly generate a random offset value ni for the i-th row of the first matrix, copy the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate, and the value range of ni is is [0, px], i is a positive integer; After the traversal is completed, the second matrix is stored.
8. The sample generating device in industrial detection according to claim 6, characterized in that: The traversal module is specifically used for: Generate a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; Generate a third matrix with a width of W and a height of (H+py), wherein the values of all elements in the third matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; Traverse each column of the first matrix, randomly generate a random offset value mj for the j-th column of the first matrix, and copy the pixel point of the j-th column of the first matrix to the third matrix with (mj, j) as the starting coordinate, where the value range of mj is [0, py], and j is a positive integer; After the traversal is completed, the third matrix is stored.
9. The sample generation device in industrial detection according to claim 6, characterized in that: The traversal module is specifically used for: Generate a first matrix according to the grayscale image, wherein the width of the first matrix is W and the height is H; Generate a second matrix with a width of (W+px) and a height of H, wherein the values of all elements in the second matrix are set to 0, wherein px is the maximum offset value of the random offset value along the X direction; Traversing each row of the first matrix, randomly generating a random offset value ni for the i-th row of the first matrix, and copying the pixel point of the i-th row of the first matrix to the second matrix with (i, ni) as the starting coordinate, where the value range of ni is [0, px], and i is a positive integer; After the traversal is completed, the second matrix is stored; Generate a fourth matrix with a width of (W+px) and a height of (H+py), wherein the values of all elements in the fourth matrix are set to 0, wherein py is the maximum offset value of the random offset value along the Y direction; Traverse each column of the second matrix, randomly generate a random offset value mj for the j-th column of the second matrix, and copy the pixel point of the j-th column of the second matrix to the fourth matrix with (mj, j) as the starting coordinate; After the traversal is completed, the fourth matrix is stored.
10. The sample generating device in industrial detection according to claim 6, characterized in that: Also includes: A cropping module is used to crop the offset image from a central area according to the size of the industrial scene image.
Citation Information
Patent Citations
Fine-grained image recognition method based on multi-grained adversarial loss
CN112733912A
Image generation method, image generation device, detection equipment and readable storage medium
CN113469969A
Network construction method, device and equipment for image recognition
CN113642554A
Sample generation method and sample generation device in industrial detection
CN115861740A
Image processing method
JP2000224405A
