Gray code binarization method, system and electronic device
The method stabilizes image brightness and enhances accuracy in Gray code binarization by using a brightness adjustment model and targeted reasoning, addressing low accuracy and long inference times in traditional methods, enabling efficient deployment on edge devices.
Patent Information
- Application Number
- CN202411010656.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-07-26
AI Technical Summary
Existing three-dimensional imaging technologies using Gray code fringe projection suffer from low accuracy of binarization results and long inference times, particularly in reflective scenes and under varying lighting conditions, with traditional methods being unstable and deep learning approaches being too time-consuming for edge devices.
A method involving a brightness adjustment model to stabilize image brightness within a preset range, followed by connected domain analysis and targeted reasoning using a binarization model, which includes a brightness adjustment module, preliminary binarization module, and result integration to enhance accuracy and reduce computational load.
Stabilizes binarization results across varying lighting conditions, reduces computational requirements, and enables deployment on edge devices by improving accuracy and reducing inference time in reflective scenarios.
Smart Images

Figure CN118570241B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing, and in particular to a Gray code binarization method, system and electronic equipment. Background Art
[0002] The three-dimensional imaging technology based on structured light illumination usually projects the structured light field onto the surface of the object to be measured at a certain angle, and shoots the deformation light field of the surface of the object to be measured at another angle, and restores the three-dimensional information of the object to be measured by decoding the photographed deformation light field. In the method based on structured light illumination, the use of binary-coded Gray code is a coding method that minimizes errors. Therefore, the three-dimensional imaging technology based on Gray code fringe projection is widely used in industry. The three-dimensional imaging process usually projects the binary black and white fringe patterns of Gray code of different frequencies onto the surface to be measured, and then performs 0 / 1 binarization and decoding on each Gray code image after the image is acquired.
[0003] The existing technology generally includes the traditional Gray code binarization method and the Gray code binarization method based on deep learning. The traditional Gray code binarization method usually takes the average of a fully black projection image and a fully white projection image as the threshold, and sets the pixels above the threshold to 1, and vice versa, to achieve the purpose of dynamic binarization. The traditional Gray code binarization method is greatly affected by lighting conditions, and the binarization results are unstable. In reflective scenes, due to unclear textures, the accuracy of the binarization results is not high. The Gray code binarization method based on deep learning takes a long time to infer and cannot be deployed on edge devices.
[0004] The existing technology has the problems of low accuracy of binarization results and long inference time. Summary of the invention
[0005] The embodiments of the present application provide a Gray code binarization method, system and electronic device to at least solve the problems of low accuracy of binarization results and long reasoning time in the related art.
[0006] In a first aspect, an embodiment of the present application provides a Gray code binarization method, comprising:
[0007] Acquire a first projection image, and process the first projection image using a brightness adjustment model to obtain a second projection image;
[0008] determining a preliminary binarization result based on the second projection image, performing a connected domain analysis on the preliminary binarization result to obtain at least one connected domain, and determining a problem area from the connected domain according to a width of the connected domain in a horizontal direction;
[0009] Determine a target area according to the problem area and the second projection image, and perform reasoning on the target area through a binary model to obtain a reasoning result;
[0010] A final binarization result is determined according to the preliminary binarization result, the inference result and the problem area.
[0011] In one embodiment, the second projection image includes a full white projection image, a full black projection image, and a stripe projection image, and determining the target area according to the problem area and the second projection image includes:
[0012] splicing the all-black projection image, the all-white projection image and the fringe projection image into a three-channel image in the channel dimension;
[0013] A target area is cropped out from the three-channel image according to the problem area.
[0014] In one embodiment, determining the final binarization result according to the preliminary binarization result, the inference result and the problem area includes:
[0015]
[0016] Among them, R B is the final binarization result, L p is the problem area, R B0 is the preliminary binarization result, R B1 is the inference result.
[0017] In one embodiment, determining a preliminary binarization result based on the second projection image includes:
[0018] Calculating the mean of the all-white projection image and the all-black projection image;
[0019] A preliminary binarization result is determined according to the pixel value of each pixel point in the fringe projection image.
[0020] In one embodiment, the brightness adjustment model is used to automatically adjust the brightness value of the first projection image to a preset brightness range, and the brightness adjustment model is configured to be obtained in the following manner:
[0021] Acquire a first image within a preset brightness range, and randomly increase and decrease the brightness value of the first image to obtain a low-brightness image and a high-brightness image;
[0022] Constructing data pairs according to the first image and the corresponding low-brightness image and high-brightness image, taking all the data pairs as first training set images, and the data label is the first image;
[0023] Construct the first loss function through L1 loss and gradient loss;
[0024] The brightness adjustment model is obtained by training a neural network model using the first loss function, the first training set image and the data label.
[0025] In one embodiment, constructing the first loss function by using L1 loss and gradient loss includes:
[0026] Calculate the L1 loss. The specific calculation formula is as follows:
[0027]
[0028] Among them, i represents the i-th image, is the neural network parameter of the brightness adjustment model, S i represents the i-th image in the first training set, G i represents the i-th image in the data tag;
[0029] Calculate the gradient loss. The specific calculation formula is as follows:
[0030]
[0031] Among them, x represents the horizontal direction, y represents the vertical direction, and L Grad_x represents the gradient loss in the x direction, L Grad_y Represents the gradient loss in the y direction, sobel x ( ) indicates that the gradient in the x direction is calculated by the Sobel function. y ( ) indicates that the gradient in the y direction is calculated by the Sobel function, L Grad represents the gradient loss;
[0032] Construct the first loss function. The specific formula is as follows:
[0033]
[0034] Among them, La is the first loss function.
[0035] In one embodiment, the binarization model is used to predict the binarization result of the target area, and the binarization model is configured to be obtained in the following manner:
[0036] A projection image set and a corresponding true value set are obtained by data simulation, and a fully black projection image, a fully white projection image, and a stripe projection image in the projection image set are spliced into a three-channel image set in the channel dimension;
[0037] The three-channel image set is cropped to form a second training set image, and the true value set is cropped according to the second training set image to obtain a label image;
[0038] Construct the second loss function through cross entropy loss, gradient loss and L2 loss;
[0039] The neural network model is trained using the second training set images, the label images and the second loss function to obtain a binarized model.
[0040] In one embodiment, constructing the second loss function by using cross entropy loss, gradient loss and L2 loss includes:
[0041] Calculate the cross entropy loss. The specific calculation formula is as follows:
[0042]
[0043] Among them, L ce is the cross entropy loss, h is the height of the cropped area, w is the width of the cropped area, hw is the number of pixels in the cropped area, i represents the i-th image, j represents the j-th pixel in the image, S crop_ij represents the jth pixel of the i-th image in the second training set, G crop_ij represents the jth pixel in the i-th label in the corresponding label image, are the neural network parameters of the binarization model;
[0044] Calculate the L2 loss. The specific calculation formula is as follows:
[0045]
[0046] Among them, G crop_i represents the i-th label in the label image, S crop_i represents the i-th image in the second training set;
[0047] Construct the second loss function, the specific formula is as follows:
[0048]
[0049] Among them, L b is the second loss function, L Grad represents the gradient loss.
[0050] In a second aspect, an embodiment of the present application provides a Gray code binarization system, comprising:
[0051] Brightness adjustment module: used for acquiring a first projection image, and processing the first projection image through a brightness adjustment model to obtain a second projection image;
[0052] A preliminary binarization module: used for determining a preliminary binarization result based on the second projection image, performing a connected domain analysis on the preliminary binarization result to obtain at least one connected domain, and determining a problem area from the connected domain according to a width of the connected domain in a horizontal direction;
[0053] Model reasoning module: used for determining a target area according to the problem area and the second projection image, and obtaining a reasoning result by reasoning the target area through a binary model;
[0054] Result integration module: used to determine the final binarization result according to the preliminary binarization result, the inference result and the problem area.
[0055] In a third aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the Gray code binarization method described in the first aspect above is implemented.
[0056] The embodiments of the present application provide a Gray code binarization method, system, and electronic device that have at least the following technical effects.
[0057] This application uses a brightness adjustment model to stabilize the image brightness within a preset range, and can cope with various lighting change scenes and output a stable binarization effect. The binarization model is based on the traditional method to solve the problem of difficult binarization and low accuracy of binarization results in reflective conditions. By cutting out the problem area for reasoning, compared with directly reasoning on the entire image, the amount of calculation and time consumed by model reasoning are reduced, the deployment problem of edge devices is solved, and usability is achieved on edge devices.
[0058] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0060] Figure 1 is a flow chart of a Gray code binarization method provided according to an embodiment of the present application;
[0061] Figure 2 is a schematic diagram showing a preliminary binarization result according to an exemplary embodiment;
[0062] Figure 3is a schematic diagram showing a final binarization result according to an exemplary embodiment;
[0063] Figure 4 It is a structural block diagram of a Gray code binarization system provided according to an embodiment of the present application;
[0064] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0065] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0066] Obviously, the drawings described below are only some examples or embodiments of the present application. For ordinary technicians in this field, the present application can also be applied to other similar scenarios based on these drawings without creative work. In addition, it can also be understood that although the efforts made in this development process may be complicated and lengthy, for ordinary technicians in this field related to the content disclosed in this application, some changes in design, manufacturing or production based on the technical content disclosed in this application are just conventional technical means, and should not be understood as insufficient content disclosed in this application.
[0067] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0068] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantity limitation, and may indicate the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects before and after are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0069] In a first aspect, an embodiment of the present application provides a Gray code binarization method. Figure 1 is a flow chart of a Gray code binarization method provided according to an embodiment of the present application, such as Figure 1 As shown, the method includes:
[0070] Step S101, acquiring a first projection image, and processing the first projection image using a brightness adjustment model to obtain a second projection image.
[0071] Optionally, the first projection image includes a full white projection image, a full black projection image, and a stripe projection image. The brightness learning model uses a deep learning model. When the first projection image is too bright or too dark, the brightness of the image is adjusted to a preset brightness range through the brightness adjustment model to obtain the second projection image. In this way, the brightness of the image is adjusted through the brightness adjustment model so that it is always in a constant brightness range, solving the problem that the traditional Gray code binarization method is greatly affected by illumination and the binarization result is unstable.
[0072] In one example, the brightness adjustment model is used to automatically adjust the brightness value of the first projection image to a preset brightness range, and the brightness adjustment model is configured to be obtained in the following manner:
[0073] Step S1011, obtaining a first image within a preset brightness range, and randomly increasing and decreasing the brightness value of the first image to obtain a low-brightness image and a high-brightness image.
[0074] Optionally, a set of images is collected under an ideal lighting environment as the first image S normal , randomly reduce the overall brightness value of the first image, iterate N times, and obtain a set of low-brightness images S low The overall brightness value of the first image is randomly increased, and the cycle is iterated N times to obtain a set of high-brightness images S high .
[0075] Step S1012, constructing data pairs according to the first image and the corresponding low-brightness image and high-brightness image, taking all data pairs as first training set images, and the data label is the first image.
[0076] Optionally, the first image and the corresponding low-brightness image and high-brightness image are taken as a data pair, the first training set image is the set of all data pairs, and the first training set image S=S low ∪S normal ∪S high , data label G=S normal .
[0077] Step S1013, constructing a first loss function through L1 loss and gradient loss.
[0078] In one example, step S1013 specifically includes:
[0079] (1) Calculate the L1 loss. The specific calculation formula is as follows:
[0080]
[0081] Among them, i represents the i-th image, is the neural network parameter of the brightness adjustment model, S i represents the i-th image in the first training set, G i Represents the i-th image in the data label.
[0082] (2) Calculate the gradient loss. The specific calculation formula is as follows:
[0083]
[0084] Among them, x represents the horizontal direction, y represents the vertical direction, and L Grad_x represents the gradient loss in the x direction, L Grad_y Represents the gradient loss in the y direction, sobel x( ) indicates that the gradient in the x direction is calculated by the Sobel function. y ( ) indicates that the gradient in the y direction is calculated by the Sobel function, L Grad represents the gradient loss.
[0085] (3) Construct the first loss function. The specific formula is as follows:
[0086]
[0087] Among them, La is the first loss function.
[0088] Step S1014, training a neural network model using a first loss function, a first training set image, and data labels to obtain a brightness adjustment model.
[0089] Optionally, the neural network model includes but is not limited to any one of Autoencoder, GANs and U-Net models. The deep learning model used in this application is a U-Net model, and the deep learning model is trained by gradient descent until the model converges. During training, images with normal illumination are used to supervise images with the same image content but too low or too high illumination, so that when various illumination images are input, the brightness adjustment model can adjust the brightness value of the image to a preset range.
[0090] Continue to refer to Figure 1 , after step S101, step S102 is performed, as follows.
[0091] Step S102 : determining a preliminary binarization result based on the second projection image, performing connected domain analysis on the preliminary binarization result to obtain at least one connected domain, and determining a problem area from the connected domain according to the width of the connected domain in the horizontal direction.
[0092] Optionally, the binarization result is preliminarily determined by a conventional Gray code binarization method. Figure 2 is a schematic diagram showing a preliminary binarization result according to an exemplary embodiment. The width of each connected domain is determined after the connected domain analysis. Specifically, the pixel width in the horizontal direction of the black and white stripes is scanned by a horizontal line. Figure 2 , the inclination angle of the stripes is relatively stable and will not exceed a certain angle, so the number of pixels in the stripes in the horizontal direction will also be within a certain threshold. Therefore, when the width of the connected domain in the horizontal direction is greater than the threshold, the connected domain is determined to be a problem area. In this way, the binarization result is preliminarily determined, and the problem area is analyzed based on the binarization result, which is convenient for subsequent direct reasoning on the problem area.
[0093] In one example, determining a preliminary binarization result based on the second projection image in step S102 includes:
[0094] Calculate the mean of the all-white projection image and the all-black projection image, and determine the preliminary binarization result according to the pixel value of each pixel in the fringe projection image. Optionally, the mean calculation formula is as follows:
[0095]
[0096] Among them, I average is the mean, I light For a full white projection image, I dark For each pixel in the fringe projection image I, if its pixel value is higher than I average If the pixel value of the pixel at the same position in the image is 1, then it is set to 1, otherwise, it is set to 0, and the preliminary binarization result R is obtained. B0 .
[0097] Continue to refer to Figure 1 , after step S102, step S103 is performed, as follows.
[0098] Step S103, determining a target area according to the problem area and the second projection image, and performing inference on the target area through a binary model to obtain an inference result.
[0099] Optionally, the second projection image is merged, and the target area is determined from the merged image through the problem area. The binarization model is a deep learning model, and the target area is inferred in parallel through the binarization model based on deep learning. In this way, the problem area predicted by the traditional method is inferred through the binarization model based on deep learning. Compared with directly reasoning the entire image, the amount of calculation and time consumption of model reasoning are reduced, and the deployment problem of edge devices is solved. At the same time, the Gray code binarization method based on the deep model solves the problem of difficult binarization and low accuracy of binarization results in the case of reflection in the traditional method.
[0100] In one example, the second projection image includes an all-white projection image, an all-black projection image, and a stripe projection image. In step S103, the target area is determined according to the problem area and the second projection image, including: splicing the all-black projection image, the all-white projection image, and the stripe projection image into a three-channel image in the channel dimension, and cropping the target area from the three-channel image according to the problem area.
[0101] In one example, a binarization model is used to predict a binarization result of a target area, and the binarization model is configured to be obtained in the following manner:
[0102] Step S1031, obtain a projection image set and a corresponding true value set through data simulation, and splice the all-black projection image, the all-white projection image, and the stripe projection image in the projection image set into a three-channel image set in the channel dimension. Optionally, data simulation is performed through NVIDIA simulation platform Omniverse.
[0103] Step S1032, cropping the three-channel image set to form a second training set image, and cropping the true value set according to the second training set image to obtain a label image.
[0104] Optionally, a target area is obtained by cutting out a corresponding position on the three-channel image according to the problem area, and the target area is used as the second training set image. The target area can be expressed as:
[0105]
[0106] Among them, the concat operation represents the splicing of the channel dimension, the crop operation represents the cropping operation, and all I crop Construct the second training set image S crop . Cut out the position corresponding to the binary image and the projection image in the true value set G to obtain the label image G crop .
[0107] Step S1033, constructing a second loss function through cross entropy loss, gradient loss and L2 loss.
[0108] In one example, step S1033 includes:
[0109] (1) Calculate the cross entropy loss. The specific calculation formula is as follows:
[0110]
[0111] Among them, L ce is the cross entropy loss, h is the height of the cropped area, w is the width of the cropped area, hw is the number of pixels in the cropped area, i represents the i-th image, j represents the j-th pixel in the image, S crop_ij represents the jth pixel of the i-th image in the second training set, G crop_ij represents the jth pixel in the i-th label in the corresponding label image, are the neural network parameters of the binarization model.
[0112] (2) Calculate the L2 loss. The specific calculation formula is as follows:
[0113]
[0114] Among them, G crop_i represents the i-th label in the label image, Scrop_i Represents the i-th image in the second training set.
[0115] (3) Construct the second loss function. The specific formula is as follows:
[0116]
[0117] Among them, L b is the second loss function, L Grad Represents the gradient loss. Optionally, the gradient loss is calculated in the same way as the gradient loss of the brightness adjustment model, and the specific calculation formula is as follows:
[0118]
[0119] Among them, x represents the horizontal direction, y represents the vertical direction, and L Grad_x represents the gradient loss in the x direction, L Grad_y Represents the gradient loss in the y direction, sobel x ( ) indicates that the gradient in the x direction is calculated by the Sobel function. y ( ) indicates that the gradient in the y direction is calculated using the Sobel function.
[0120] Step S1034, training the neural network model using the second training set images, the label images and the second loss function to obtain a binarized model.
[0121] Optionally, the neural network model includes but is not limited to any one of Autoencoder, GANs and U-Net models. The deep learning model used in this application is a U-Net model, and the deep learning model is trained by gradient descent method until the model converges.
[0122] In this example, the problem area predicted by the traditional method is inferred by the binarization model based on deep learning, which reduces the amount of calculation and time consumption of model inference compared with directly inferring the entire image. At the same time, the Gray code binarization method based on the deep model solves the problem of difficult binarization and low accuracy of binarization results in the case of reflection in the traditional method.
[0123] Step S104, determining a final binarization result according to the preliminary binarization result, the inference result and the problem area.
[0124] Optionally, the traditional Gray code binarization method and the binarization result based on model reasoning are integrated to obtain the final binarization result. Figure 3 is a schematic diagram of a final binarization result according to an exemplary embodiment. Figure 3As shown, the Gray code binarization method provided in the present application has significantly improved the binarization effect in both the black background area and the reflective area.
[0125] In one example, step S104 specifically includes:
[0126]
[0127] Among them, R B is the final binarization result, L p is the problem area, R B0 is the preliminary binarization result, R B1 For the inference result.
[0128] In summary, this application uses a brightness adjustment model to stabilize the image brightness within a preset range, can cope with various lighting change scenes, and output a stable binarization effect. The Gray code binarization method based on the deep model solves the problem of difficult binarization and low accuracy of binarization results in reflective conditions in traditional methods. By cutting out the problem area for reasoning, compared with directly reasoning on the entire image, the amount of calculation and time consumed for model reasoning are reduced, the deployment problem of edge devices is solved, and usability is achieved on edge devices.
[0129] In a second aspect, the embodiment of the present application provides a Gray code binarization system. Figure 4 : is a structural block diagram of a Gray code binarization system provided according to an embodiment of the present application, the system comprising:
[0130] The brightness adjustment module 100 is used to obtain a first projection image, and process the first projection image using a brightness adjustment model to obtain a second projection image.
[0131] The preliminary binarization module 200 is used to determine a preliminary binarization result based on the second projection image, perform connected domain analysis on the preliminary binarization result to obtain at least one connected domain, and determine the problem area from the connected domain according to the width of the connected domain in the horizontal direction.
[0132] Model inference module 300: used to determine the target area according to the problem area and the second projection image, and to obtain an inference result by inferring the target area through a binary model.
[0133] Result integration module 400: used to determine the final binarization result according to the preliminary binarization result, the inference result and the problem area.
[0134] In one example, the second projection image includes a full white projection image, a full black projection image, and a stripe projection image, and the model reasoning module 300 includes:
[0135] It is used to stitch the all-black projection image, the all-white projection image and the stripe projection image into a three-channel image in the channel dimension; and to crop the target area from the three-channel image according to the problem area.
[0136] In one example, the result integration module 400 includes:
[0137]
[0138] Among them, R B is the final binarization result, L p is the problem area, R B0 is the preliminary binarization result, R B1 For the inference result.
[0139] In one example, the preliminary binarization module 200 includes:
[0140] It is used to calculate the mean of the all-white projection image and the all-black projection image, and determine the preliminary binarization result according to the pixel value of each pixel in the fringe projection image.
[0141] In one example, the brightness adjustment model is used to automatically adjust the brightness value of the first projection image to a preset brightness range, and the brightness adjustment model in the brightness adjustment module 100 is configured to be obtained in the following manner:
[0142] An acquisition unit is used to acquire a first image within a preset brightness range, and to randomly increase and decrease the brightness value of the first image to obtain a low-brightness image and a high-brightness image.
[0143] Data and label unit: used to construct data pairs according to the first image and the corresponding low-brightness image and high-brightness image, and take all data pairs as the first training set images, and the data label is the first image.
[0144] Loss unit: used to construct the first loss function through L1 loss and gradient loss.
[0145] Training unit: used to train the neural network model through the first loss function, the first training set image and the data label to obtain the brightness adjustment model.
[0146] In one example, the loss unit includes:
[0147] Calculate the L1 loss. The specific calculation formula is as follows:
[0148]
[0149] Among them, i represents the i-th image, is the neural network parameter of the brightness adjustment model, S i represents the i-th image in the first training set, G iRepresents the i-th image in the data tag.
[0150] Calculate the gradient loss. The specific calculation formula is as follows:
[0151]
[0152] Among them, x represents the horizontal direction, y represents the vertical direction, and L Grad_x represents the gradient loss in the x direction, L Grad_y Represents the gradient loss in the y direction, sobel x ( ) indicates that the gradient in the x direction is calculated by the Sobel function. y ( ) indicates that the gradient in the y direction is calculated by the Sobel function, L Grad represents the gradient loss.
[0153] Construct the first loss function. The specific formula is as follows:
[0154]
[0155] Among them, La is the first loss function.
[0156] In one example, the binarization model is used to predict the binarization result of the target area, and the binarization model in the model reasoning module 300 is configured to be obtained in the following manner:
[0157] Acquisition unit: used to obtain a projection image set and a corresponding true value set through data simulation, and to splice the all-black projection image, all-white projection image and stripe projection image in the projection image set into a three-channel image set in the channel dimension.
[0158] Data and label unit: used to crop the three-channel image set to form a second training set image, and to crop the true value set according to the second training set image to obtain a label image.
[0159] Loss unit: used to construct the second loss function through cross entropy loss, gradient loss and L2 loss.
[0160] Training unit: used to train the neural network model through the second training set image, the label image and the second loss function to obtain a binarized model.
[0161] In one example, the loss unit in the model inference module 300 includes:
[0162] Calculate the cross entropy loss. The specific calculation formula is as follows:
[0163]
[0164] Among them, L ceis the cross entropy loss, h is the height of the cropped area, w is the width of the cropped area, hw is the number of pixels in the cropped area, i represents the i-th image, j represents the j-th pixel in the image, S crop_ij represents the jth pixel of the i-th image in the second training set, G crop_ij represents the jth pixel in the i-th label in the corresponding label image, are the neural network parameters of the binarization model.
[0165] Calculate the L2 loss. The specific calculation formula is as follows:
[0166]
[0167] Among them, G crop_i represents the i-th label in the label image, S crop_i Represents the i-th image in the second training set.
[0168] Construct the second loss function, the specific formula is as follows:
[0169]
[0170] Among them, L b is the second loss function, L Grad represents the gradient loss.
[0171] In summary, the present application uses the brightness adjustment module 100 to stabilize the image brightness within a preset range, can cope with various lighting change scenes, and output a stable binarization effect. The Gray code binarization method based on the deep model in the model reasoning module 300 solves the problem of difficult binarization and low accuracy of binarization results in reflective conditions in traditional methods. By cutting out the problem area for reasoning, compared with directly reasoning the entire image, the amount of calculation and time consumption of model reasoning are reduced, the deployment problem of edge devices is solved, and usability is achieved on edge devices.
[0172] In a third aspect, an embodiment of the present application provides an electronic device, Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the Gray code binarization method provided in the first aspect is implemented. Figure 5 The electronic device 60 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0173] The electronic device 60 may be in the form of a general-purpose computing device, for example, it may be a server device. The components of the electronic device 60 may include but are not limited to: at least one processor 61, at least one memory 62, and a bus 63 connecting different system components (including the memory 62 and the processor 61).
[0174] The bus 63 includes a data bus, an address bus, and a control bus.
[0175] The memory 62 may include a volatile memory, such as a random access memory (RAM) 621 and / or a cache memory 622 , and may further include a read-only memory (ROM) 623 .
[0176] The memory 62 may also include a program / utility 625 having a set (at least one) of program modules 624, such program modules 624 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0177] The processor 61 executes various functional applications and data processing by running the computer program stored in the memory 62, such as the Gray code binarization method provided in the first aspect of the present application.
[0178] The electronic device 60 may also communicate with one or more external devices 64 (e.g., keyboards, pointing devices, etc.). Such communication may be performed via an input / output (I / O) interface 65. Furthermore, the model-generated device 60 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 66. As shown, the network adapter 66 communicates with other modules of the model-generated device 60 via a bus 63. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the model-generated device 60, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.
[0179] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.
[0180] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described 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.
[0181] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A Gray code binarization method, characterized in that: include: Acquire a first projection image, and process the first projection image through a brightness adjustment model to obtain a second projection image, wherein the second projection image includes a full white projection image, a full black projection image, and a stripe projection image; determining a preliminary binarization result based on the second projection image, performing a connected domain analysis on the preliminary binarization result to obtain at least one connected domain, determining a problem area from the connected domain according to a width of the connected domain in a horizontal direction, and determining that the connected domain is a problem area when the width of the connected domain in the horizontal direction is greater than a threshold; Determining a target area according to the problem area and the second projection image, and performing reasoning on the target area through a binarization model to obtain a reasoning result, wherein determining the target area according to the problem area and the second projection image includes: splicing the all-black projection image, the all-white projection image, and the stripe projection image into a three-channel image in a channel dimension, and cutting out the target area from the three-channel image according to the problem area; A final binarization result is determined according to the preliminary binarization result, the inference result and the problem area.
2. The Gray code binarization method according to claim 1, characterized in that: The determining of the final binarization result according to the preliminary binarization result, the inference result and the problem area comprises: Among them, R B is the final binarization result, L p is the problem area, R B0 is the preliminary binarization result, R B1 is the inference result.
3. The Gray code binarization method according to claim 1, characterized in that: The step of determining a preliminary binarization result based on the second projection image comprises: Calculating the mean of the all-white projection image and the all-black projection image; A preliminary binarization result is determined according to the pixel value of each pixel point in the fringe projection image.
4. The Gray code binarization method according to claim 1, characterized in that: The brightness adjustment model is used to automatically adjust the brightness value of the first projection image to a preset brightness range, and the brightness adjustment model is configured to be obtained in the following manner: Acquire a first image within a preset brightness range, and randomly increase and decrease the brightness value of the first image to obtain a low-brightness image and a high-brightness image; Constructing data pairs according to the first image and the corresponding low-brightness image and high-brightness image, taking all the data pairs as first training set images, and the data label is the first image; Construct the first loss function through L1 loss and gradient loss; The brightness adjustment model is obtained by training a neural network model using the first loss function, the first training set image and the data label.
5. The Gray code binarization method according to claim 4, characterized in that: The first loss function is constructed by L1 loss and gradient loss, including: Calculate the L1 loss. The specific calculation formula is as follows: Among them, i represents the i-th image, is the neural network parameter of the brightness adjustment model, S i represents the i-th image in the first training set, G i represents the i-th image in the data tag; Calculate the gradient loss. The specific calculation formula is as follows: Among them, x represents the horizontal direction, y represents the vertical direction, and L Grad_x represents the gradient loss in the x direction, L Grad_y Represents the gradient loss in the y direction, sobel x ( ) indicates that the gradient in the x direction is calculated by the Sobel function. y ( ) indicates that the gradient in the y direction is calculated by the Sobel function, L Grad represents the gradient loss; Construct the first loss function. The specific formula is as follows: Among them, La is the first loss function.
6. The Gray code binarization method according to claim 5, characterized in that: The binarization model is used to predict the binarization result of the target area, and the binarization model is configured to be obtained in the following manner: A projection image set and a corresponding true value set are obtained by data simulation, and a fully black projection image, a fully white projection image, and a stripe projection image in the projection image set are spliced into a three-channel image set in the channel dimension; The three-channel image set is cropped to form a second training set image, and the true value set is cropped according to the second training set image to obtain a label image; Construct the second loss function through cross entropy loss, gradient loss and L2 loss; The neural network model is trained using the second training set images, the label images and the second loss function to obtain a binarized model.
7. The Gray code binarization method according to claim 6, characterized in that: The second loss function is constructed by cross entropy loss, gradient loss and L2 loss, including: Calculate the cross entropy loss. The specific calculation formula is as follows: Among them, L ce is the cross entropy loss, h is the height of the cropped area, w is the width of the cropped area, hw is the number of pixels in the cropped area, i represents the i-th image, j represents the j-th pixel in the image, S crop_ij represents the jth pixel of the i-th image in the second training set, G crop_ij represents the jth pixel in the i-th label in the corresponding label image, are the neural network parameters of the binarization model; Calculate the L2 loss. The specific calculation formula is as follows: Among them, G crop_i represents the i-th label in the label image, S crop_i represents the i-th image in the second training set; Construct the second loss function. The specific formula is as follows: Among them, L b is the second loss function, L Grad represents the gradient loss.
8. A Gray code binarization system, characterized in that: include: Brightness adjustment module: used for acquiring a first projection image, and processing the first projection image through a brightness adjustment model to obtain a second projection image, wherein the second projection image includes a full white projection image, a full black projection image, and a stripe projection image; A preliminary binarization module: used to determine a preliminary binarization result based on the second projection image, perform a connected domain analysis on the preliminary binarization result to obtain at least one connected domain, determine a problem area from the connected domain according to the width of the connected domain in the horizontal direction, and when the width of the connected domain in the horizontal direction is greater than a threshold, determine that the connected domain is a problem area; Model inference module: used for determining the target area according to the problem area and the second projection image, and obtaining an inference result by inferring the target area through a binary model, wherein the determining the target area according to the problem area and the second projection image comprises: splicing the all-black projection image, the all-white projection image, and the stripe projection image into a three-channel image in the channel dimension, and cutting out the target area from the three-channel image according to the problem area; Result integration module: used to determine the final binarization result according to the preliminary binarization result, the inference result and the problem area.
9. An electronic device, characterized in that: include Memory, processor, and A computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the Gray code binarization method according to any one of claims 1 to 7 is implemented.
