Background difference method, system and storage medium with strong environmental interference resistance
Through the feature extraction model and feature distance calculation trained by the fully convolutional network, combined with the new loss function and data enhancement method, the problem of insufficient anti-environmental interference ability of the traditional background difference method is solved, and more accurate foreground and background segmentation is achieved, which is suitable for for various application scenarios.
Patent Information
- Application Number
- CN202211647846.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-21
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-12-21
AI Technical Summary
The traditional background difference method has weak resistance to environmental interference and is easily affected by lighting changes, jitter, shadows and other factors, resulting in false detections and missed detections. Especially when the color of a new intruding object is similar to the background, the segmentation effect is poor.
A fully convolutional network is used to train the underlying feature extraction model, and the foreground and background targets are obtained through feature distance calculation and threshold segmentation of the feature vector map. New loss functions and data enhancement methods are designed to enhance the model's robustness and anti-interference ability.
It significantly improves the robustness and anti-environmental interference capabilities of the background difference method, can more accurately segment foreground and background targets, reduces false detection and missed detection rates, and is suitable for traffic monitoring, anomaly detection and other fields.
Smart Images

Figure CN115810111B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of image algorithms and deep learning technology, and specifically relates to a background difference method, system and storage medium with strong anti-environmental interference capability. Background Art
[0002] Road spill detection, because there are actually an infinite number of categories of spilled objects, if supervised learning methods (such as target detection) are used, the work of data acquisition and data labeling is huge, and it still cannot cover all categories. Therefore, the background difference method is often used in such scenarios. Based on a camera installed at a fixed position, a certain area is continuously monitored, and new intruders can be located. Then, through secondary category analysis, it is further identified whether the object is a spilled object.
[0003] Background extraction is to extract the background from the video image sequence. The background is the static scenery in the scene. Because the camera is not moving, each pixel in the image has a corresponding background value. This background value is relatively fixed over a period of time. The goal of background extraction is to find the background value of each point in the image based on the video image sequence. There are many algorithms for background extraction, such as the background difference method for static cameras, the inter-frame difference method, the Gaussian mixture model background difference method, the ViBe background extraction algorithm and its improved algorithm ViBe+, and the optical flow method for moving cameras. The underlying logic of the above methods is to directly differentiate pixels. For example, after simple pre-processing of the two images, directly subtract pixels to obtain the difference image, and then perform threshold segmentation on the difference image to obtain the foreground target. However, directly differentiating pixels has the disadvantages of poor robustness, and environmental interference such as illumination change, camera shake, and shadow intrusion has a greater impact on the final foreground segmentation result.
[0004] The traditional background difference method is used to detect moving targets in video images. Its basic principle is to subtract the current frame in the image sequence from the background reference model (background image) that has been determined or acquired in real time. The area where the pixel difference with the background image exceeds a certain threshold is calculated as the moving area, so as to determine the position, outline, size and other characteristics of the moving object. The traditional background difference process: First, the original image is filtered / denoised and other traditional processes are performed; then, the two images are subtracted to obtain a difference image; finally, the "difference image" is threshold segmented to calculate the image area where the new object has entered.
[0005] However, the traditional background difference method has limitations and its ability to resist environmental interference is weak. For example, illumination change, jitter, shadow change, etc. will cause pixel values to change, and camera jitter will cause the pixel coordinates of road objects to be slightly misaligned. When dealing with the above problems, the traditional "pixel-level" background difference method is prone to false detection. In addition, when the color and brightness of the new intruder are similar to the background surface, the threshold configuration of the traditional pixel-level difference is more difficult: if the pixel segmentation threshold is set too high, such new intruders are not easy to be completely distinguished; if the pixel segmentation threshold is set too low, it is easy to segment too much noise as the foreground. In short, the traditional background difference method has a weak ability to resist environmental interference, which affects the use of the background difference method. Summary of the invention
[0006] The purpose of the present invention is to overcome the defects of the prior art. The present invention provides a background difference method, system and storage medium with strong anti-environmental interference ability. The feature vector map of the sample image is extracted by the underlying feature extraction model, and the feature distance calculation is performed on the sample feature vector map to obtain the feature distance map. The feature distance map is then threshold segmented and calculated to obtain the image area where the new object breaks in. Compared with the traditional background difference method, the present invention has better robustness, is not easily affected by changes in the external environment, has strong anti-environmental interference ability, and can better obtain foreground targets and background targets. The present invention can be widely used in traffic monitoring, anomaly detection, smart communities, industrial detection and other fields.
[0007] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0008] A background difference method with strong anti-environmental interference ability, comprising:
[0009] S1) obtaining sample image data and performing preprocessing, wherein the preprocessing includes generating labels and label maps;
[0010] S2) training the underlying feature extraction model based on the fully convolutional network according to the sample image data;
[0011] S3) extracting a background feature vector map and a foreground feature vector map of the sample image based on the underlying feature extraction model and performing feature distance calculation to obtain a feature distance map;
[0012] S4) designing a loss function according to the feature distance map and the label map, calculating the loss of each cell in the feature distance map and the label map one by one, and repeatedly iterating all weight parameters of the underlying feature extraction model based on the back propagation algorithm to generate an optimized underlying feature extraction model;
[0013] S5) obtaining sample image data and inputting it into the optimized underlying feature extraction model for feature extraction to obtain a background feature vector map and a foreground feature vector map, then performing feature distance calculation on the background feature vector map and the foreground feature vector map to obtain a feature distance map, and performing threshold segmentation on the feature distance map to obtain a foreground target and a background target.
[0014] Furthermore, the acquired sample image data is a two-tuple data set, and the two-tuple data set is [first sample, second sample], and the first sample and the second sample in the two-tuple data set are preprocessed.
[0015] Furthermore, the label specifically includes: 0, 1, -1, wherein the label of different pixel cells of the first sample and the second sample is 0, the label of the same pixel cell of the first sample and the second sample is 1, and the label of the pixel cell in the first sample and the second sample that does not participate in back propagation training is -1.
[0016] Furthermore, when all pixel cells of the two sample images are different, the label of each cell is 0; when all pixel cells of the two sample images are exactly the same, the first sample image is kept unchanged, and the second sample image is synthesized.
[0017] Furthermore, the image synthesis specifically includes: pasting pixels of other images into the second sample, wherein the label of the cell in the second sample that is not disturbed by the pasted pixels is 1; the label of the cell whose total pixel of the pasted pixel / cell is > 0.5 is 0; and the label of the remaining cells is -1.
[0018] Furthermore, the preprocessing also includes data enhancement, specifically including:
[0019] When all pixel cells of the two sample images are different, the enhancement method used does not include filling the same relative area of the two sample images with the same gray value and mapping based on the same foreground image. Other methods are feasible;
[0020] When all pixel cells of two sample images are exactly the same, the enhancement methods used include a certain degree of lighting change, a small amount of color distortion, jitter changes of several pixels, mild mixup, simulated shadows, and simulated water marks.
[0021] Furthermore, the depth and width of the underlying feature extraction model and the length of a single vector of the output layer feature vector map are selected based on the complexity of the scene and the performance requirements for model reasoning.
[0022] Furthermore, the loss function is:
[0023]
[0024] Among them, dis represents the feature distance value; loss1 is the loss function of similar blocks; loss2 is the loss function of dissimilar blocks; y represents the label value, and e represents the natural constant.
[0025] The present invention also discloses a background difference system with strong anti-environmental interference capability, comprising:
[0026] A preprocessing module, used to obtain sample image data and perform preprocessing, wherein the preprocessing includes generating labels and label maps;
[0027] The model training module trains the underlying feature extraction model based on the fully convolutional network according to the sample image data; based on the underlying feature extraction model, extracts the background feature vector map and the foreground feature vector map of the sample image and performs feature distance calculation to obtain a feature distance map; designs a loss function according to the feature distance map and the label map, calculates the loss for each cell in the feature distance map and the label map one by one, and repeatedly iterates all weight parameters of the underlying feature extraction model based on the back propagation algorithm to generate an optimized underlying feature extraction model;
[0028] The model application module obtains sample image data and inputs it into the optimized underlying feature extraction model for feature extraction to obtain a background feature vector map and a foreground feature vector map. Feature distance calculation is then performed on the background feature vector map and the foreground feature vector map to obtain a feature distance map. Threshold segmentation is performed on the feature distance map to obtain foreground targets and background targets.
[0029] The present invention also discloses a computer storage medium for storing a computer program for implementing any of the above method steps.
[0030] The working idea of the present invention is as follows: the present invention provides a background difference method with strong anti-environmental interference ability, firstly, sample image data is obtained and preprocessed, and the preprocessing includes generating labels and label maps; secondly, a model is trained, specifically including: according to the sample image data, an underlying feature extraction model is trained based on a full convolutional network; based on the underlying feature extraction model, a background feature vector map and a foreground feature vector map of the sample image are extracted and feature distance calculation is performed to obtain a feature distance map; a loss function is designed according to the feature distance map and the label map, and loss calculation is performed for each cell in the feature distance map and the label map one by one, and based on the back propagation algorithm, all weight parameters of the underlying feature extraction model are repeatedly iterated to generate an optimized underlying feature extraction model; finally, the model is applied, the sample image data is obtained and input into the optimized underlying feature extraction model for feature extraction, a background feature vector map and a foreground feature vector map are obtained, feature distance calculation is performed on the background feature vector map and the foreground feature vector map to obtain a feature distance map, and threshold segmentation is performed on the feature distance map to obtain a foreground target and a background target.
[0031] Compared with the prior art, the beneficial effects of the present invention are as follows: the method of the present invention is a method for background difference based on a full convolutional network, and a full convolutional network model of background difference and a corresponding loss function are designed; the model in this method can be trained based on any data set, and can be used in any scene, such as being widely used in traffic monitoring, anomaly detection, smart communities, industrial detection and other fields; and the data does not need to be manually labeled, and the designed label generation method is directly used, saving labor costs; a data enhancement method is also designed to improve the effect of model training; the present invention can also introduce an inter-frame difference method based on a convolutional network to transform a single Gaussian algorithm, a mixed Gaussian algorithm, an optical flow method, etc.; the present invention can also use the inter-frame difference method based on a convolutional network in combination with a traditional pixel-level frame difference method. Compared with the traditional background difference method, the present invention has better robustness, is not easily affected by changes in the external environment, has strong resistance to environmental interference, and can better obtain foreground targets and background targets. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0033] Figure 1 It is a flow chart of a background difference method with strong anti-environmental interference capability provided by an embodiment of the present invention.
[0034] Figure 2 It is a schematic diagram of model training supervision of a background difference method with strong anti-environmental interference capability provided by an embodiment of the present invention.
[0035] Figure 3 It is a schematic diagram of label generation for two sample images with different foregrounds and backgrounds according to a background difference method with strong anti-environmental interference capability provided by an embodiment of the present invention.
[0036] Figure 4 It is a schematic diagram of label generation for two sample images with different foregrounds and the same background according to a background difference method with strong anti-environmental interference capability provided by an embodiment of the present invention.
[0037] Figure 5 It is a schematic diagram of a loss function with label 1 of a background difference method with strong anti-environmental interference capability provided by an embodiment of the present invention.
[0038] Figure 6It is a schematic diagram of a loss function with a label of 0 of a background difference method with strong anti-environmental interference capability provided by an embodiment of the present invention.
[0039] Figure 7 The present invention provides a background difference method with strong anti-environmental interference capability, and includes two sample images with different foregrounds and the same background;
[0040] Figure 8 It is extracted by the underlying feature extraction model of a background difference method with strong anti-environmental interference capability provided by the embodiment of the present invention. Figure 7 Eigenvector graph of the two sample graphs in .
[0041] Fig. 9 The background difference method with strong anti-environmental interference capability provided by the embodiment of the present invention is used to calculate Figure 8 The feature distance map obtained from the feature vector map in .
[0042] Fig.10 yes Fig. 9 A partial enlarged view of .
[0043] Fig.11 yes Fig. 9 The final threshold segmentation effect diagram. DETAILED DESCRIPTION
[0044] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0045] Example 1
[0046] See also Figures 1 to 10 The present invention discloses a background difference method with strong anti-environmental interference capability, comprising:
[0047] S1) Obtain sample image data and perform preprocessing, the preprocessing includes generating labels and label maps; the sample image data obtained is a binary data set, the binary data set is [first sample, second sample], and the first sample and the second sample in the binary data set are preprocessed; the labels specifically include: 0, 1, -1, where the labels of different pixel cells of the first sample and the second sample are 0, the labels of the same pixel cells of the first sample and the second sample are 1, and the labels of the pixel cells in the first sample and the second sample that do not participate in back propagation training are -1. Figure 2As shown. The meaning of pixel cells is: an image can be divided into multiple square pixel cells, and the size of each cell can be 2X2, 4X4, 8X8, etc., which is determined by the downsampling ratio of the designed underlying feature extraction model.
[0048] When all pixel cells of two sample images are different, the label of each cell is 0, such as Figure 3 As shown; when all pixel cells of two sample images are exactly the same, that is, the two sample images can be copied twice using one image, the first sample image is kept unchanged, and the second sample image is synthesized. This operation can make the two sample images have both the same pixel area and different pixel areas, such as Figure 4 As shown. The image synthesis specifically includes: pasting pixels of other images into the second sample, that is, taking the second sample image as the background, using other images for mapping, and then changing the pixel information of certain areas on the second sample, wherein the label of the cell in the second sample that is not disturbed by the pasted pixel is 1; the label of the cell with the total pixel of the pasted pixel / cell>0.5 is 0; the label of the remaining cells is -1. When the foreground pixel cells of the two sample images are different and the background pixel cells are the same, or the foreground pixel cells are the same and the background pixel cells are different, the labels of the different pixel cells are 0, the labels of the same pixel cells are 1, and the labels of the pixel cells that do not participate in the back-propagation training are -1. Among them, the cell label in the edge area is -1, because there will be a translation change of several pixels, and the edge pixels may have been removed from the image, so they do not participate in the loss feedback.
[0049] The preprocessing also includes data enhancement, specifically including:
[0050] When all pixel cells of two sample images are different, the enhancement method used does not include filling the same relative area of the two sample images with the same grayscale value and mapping based on the same foreground image, and other methods are feasible; because the enhancement method of filling the same relative area of the two sample images with the same grayscale value and mapping based on the same foreground image may cause pixel cells that were originally different in the two samples to become the same pixel cells, which will cause a situation that does not correspond to the label.
[0051] When all pixel cells of two sample images are exactly the same, or the foreground pixel cells of the two sample images are different and the background pixel cells are the same, or the foreground pixel cells are the same and the background pixel cells are different, the enhancement methods used include a certain degree of illumination change, a small amount of color distortion, jitter changes of several pixels (selected according to anti-jitter requirements), mild mixup, simulated shadows, simulated water marks, etc.
[0052] The present invention can train the model in this method based on any data set. For example, the imagenet data set, the coco data set, and the voc data set can all be used to train the underlying feature extraction model in this method, and only the original images need to be used without using labels. The labels required by the model in this method are automatically generated by the code, which saves the manual annotation process, is conducive to improving work efficiency, and reducing labor costs.
[0053] S2) Based on the sample images, the underlying feature extraction model is trained based on the convolutional network; specifically, it includes: input scale (batch, h, w, c), output scale (batch, h / d, w / d, feature_len); where batch represents the number of images; h represents the height of the original image, w represents the width of the original image, and c represents the number of image channels (c for color images is 3 / c for grayscale images is 1); d represents the scale of the output layer relative to the input layer, and d also represents the downsampling ratio of the model, or d represents the side length of the pixel block corresponding to each feature vector, d can be customized, and the value is usually 2, 4, 8, 16... etc.; feature_len represents the length of each feature vector, which can be 32, 64, 128, 256... etc. In addition, the depth and width of the underlying feature extraction model and the single vector length of the output layer feature vector map are selected based on the complexity of the scene and the performance requirements for model reasoning.
[0054] The main function of this model is to extract the feature vector graph of the sample image. Each feature vector in the feature vector graph mainly expresses the underlying features of each cell in the original image. For example, when training, input [image 1, image 2, label graph], each cell in the label graph records whether the pixel areas corresponding to images 1 and 2 are similar pixel blocks. Images 1 and 2 are extracted through the underlying feature model to obtain feature vectors. Figure 1 and the eigenvector Figure 2 ; For the feature vector Figure 1 and the eigenvector Figure 2 The feature distance is calculated cell by cell (such as using the normalized Euclidean distance) to obtain a distance map. In the distance map, the value of each cell is used to represent Figure 1 and Figure 2 The width and height of the distance map are equal to the width and height of the label map, and its cells correspond one to one.
[0055] The underlying feature extraction model in the present invention only needs to be trained once and can be applied to any scenario, without the need for special training for each specific scenario. For example, it can be used to assist in detecting abnormal intrusions on traffic roads; it can be used to assist in detecting objects thrown from high places in smart parks; it can be used to detect foreground objects on conveyor belts in the industrial field. This method is particularly important when the conveyor belt has poor lighting and traditional image algorithms cannot segment the foreground.
[0056] When training the underlying feature extraction model, the effects of environmental changes such as illumination changes and slight camera shake (i.e., slight shift) are taken into consideration, so that the features extracted by the underlying feature extraction model are not affected by the above environmental problems.
[0057] S3) Based on the underlying feature extraction model, extract the background feature vector map and the foreground feature vector map of the sample image and perform feature distance calculation to obtain a feature distance map; specifically comprising: using the underlying feature extraction model to perform forward reasoning on the background pixels and the foreground pixels respectively to obtain the background feature vector map and the foreground feature vector map. Based on the background feature vector map and the foreground feature vector map, feature distance calculation is performed to obtain a feature distance map. Currently, the normalized Euclidean distance is used, and the cosine distance can also be used for feature distance calculation.
[0058] S4) Design a loss function based on the feature distance graph and the label graph, calculate the loss of each cell in the feature distance graph and the label graph one by one, and iterate all weight parameters of the underlying feature extraction model based on the back propagation algorithm to generate an optimized underlying feature extraction model. The present invention also proposes a new loss function. Since the underlying feature extraction model proposed in the present invention is a new model, the existing loss function cannot be used directly, so it is necessary to design a new loss function for supporting use. The function of the new loss function is:
[0059] a) A cell in the distance graph corresponds to Figure 1 and Figure 2 The pixel blocks at the corresponding positions in are similar pixel blocks, and the supervision method of the loss function is to make the distance value as small as possible;
[0060] b) A cell in the distance graph corresponds to Figure 1 and Figure 2 The pixel blocks at the corresponding positions in are dissimilar pixel blocks, and the supervision method of the loss function is to make the distance value as large as possible;
[0061] c) In order to prevent overfitting, the design of this loss function introduces the idea of label smoothing. When the distance between similar pixel blocks is less than or equal to 0.15, the loss function is equal to 0, which means no supervision; when the distance between dissimilar pixel blocks is greater than or equal to 0.85, the loss function is equal to 0, which means no supervision. The distance between similar pixel blocks is 0.15 and the distance between dissimilar pixel blocks is 0.85. These two parameters can also be modified as needed.
[0062] The loss function is:
[0063]
[0064] Among them, dis represents the feature distance value; loss1 is the loss function of similar blocks, such as Figure 5 The loss function diagram with label 1 is shown in the figure. Similar blocks represent two similar pixel blocks in the corresponding two input images. Loss2 is the loss function of dissimilar blocks, such as Figure 6 The loss function graph with label 0 shown; y represents the label value and e represents a natural constant.
[0065] S5) Obtain sample image data and input it into the optimized underlying feature extraction model for feature extraction to obtain a background feature vector map and a foreground feature vector map, then perform feature distance calculation on the background feature vector map and the foreground feature vector map to obtain a feature distance map, and perform threshold segmentation on the feature distance map to obtain a foreground target and a background target. Figures 7 to 10 FIG. 1 is a model application workflow of a background difference method with strong anti-environmental interference capability provided by an embodiment of the present invention. First, two sample images with different foregrounds and the same background are input, such as Figure 7 As shown; Secondly, based on the underlying feature extraction model Figure 7 The characteristic vector graphs of the two sample graphs in are as follows: Figure 8 As shown; again through the feature distance calculation to get Figure 8 The characteristic distance graph of the characteristic vector graph in is Fig. 9 As shown, in order to more clearly illustrate this solution, the feature distance map is combined with the original map for display. The actual feature distance is a floating point number between 0.0 and 1.5. For the convenience of drawing, the distance is mapped to an integer representation of 0-9; Fig.10 yes Fig. 9 The local enlarged picture, and finally Fig. 9 The feature distance map in is threshold segmented to obtain the final threshold segmentation effect map, as shown in Fig.11 As shown, Fig. 9 The feature distance map in the image is thresholded and segmented to obtain the binary image of the foreground and background. In order to display it more clearly, the segmented binary image is combined with the original image for display.
[0066] The present invention proposes a solution for background difference based on a convolutional network, which is mainly used to extract the underlying features of the input sample image, and the extracted feature vector map can be used for background difference. The background difference process proposed by the present invention is: first, the feature vector map of the input sample image is extracted by the underlying feature extraction model; then, the feature distance is calculated for the feature vector map (the present invention uses the Euclidean distance) to obtain the feature distance map; finally, the feature distance map is threshold segmented to calculate the foreground target. The feature vector extracted based on the convolutional network model can filter out the influence of external environments such as illumination changes, shadows, and slight jitters, making the separation of foreground targets more stable and reducing the false detection rate and missed detection rate.
[0067] A new background difference method proposed in the present invention can effectively deal with external environmental interference such as jitter, shadow intrusion, and illumination change. Different from the traditional method of directly calculating the distance between the pixel values of two images, the present invention designs an underlying feature extraction model for extracting a feature vector map of a sample image. Each cell in the feature vector map is a feature vector, which is used to express the features of the corresponding pixel block in the sample image. The scale of the pixel block can be designed by itself, the block is a square, and the side length of the pixel block is represented by d, which can be 2, 4, 8, 16... etc. For example, assuming that the scale of the original image is (w, h, c), w represents the image width, h represents the image height, and c represents the number of image channels (c for color images is 3 / c for grayscale images is 1); after extraction by the underlying feature extraction model, the scale of the feature vector map obtained is (w / d, h / d, feature_len), and feature_len represents the length of each feature vector.
[0068] In current background modeling methods such as single Gaussian model and mixed Gaussian model, the performance can be improved by replacing the pixel-level background difference used in the underlying difference method with the background difference based on the underlying feature extraction model proposed in the present invention.
[0069] Example 2
[0070] The present invention also discloses a background difference system with strong anti-environmental interference capability, comprising:
[0071] The preprocessing module is used to obtain sample image data and perform preprocessing, wherein the preprocessing includes generating labels and label maps; the sample image data obtained is a binary data set, wherein the binary data set is [first sample, second sample], and the first sample and the second sample in the binary data set are preprocessed; the labels specifically include: 0, 1, -1, wherein the different pixel cells of the first sample and the second sample are 0, the same pixel cells of the first sample and the second sample are 1, and the pixel cells of the first sample and the second sample that do not participate in the back propagation training are -1. Figure 2 As shown. The meaning of pixel cells is: an image can be divided into multiple square pixel cells, and the size of each cell can be 2X2, 4X4, 8X8, etc., which is determined by the downsampling ratio of the designed underlying feature extraction model.
[0072] When all pixel cells of two sample images are different, the label of each cell is 0, such as Figure 3 As shown; when all pixel cells of two sample images are exactly the same, that is, the two sample images can be copied twice using one image, the first sample image is kept unchanged, and the second sample image is synthesized. This operation can make the two sample images have both the same pixel area and different pixel areas, such as Figure 4 As shown. The image synthesis specifically includes: pasting pixels of other images into the second sample, that is, taking the second sample image as the background, using other images for mapping, and then changing the pixel information of certain areas on the second sample, wherein the label of the cell in the second sample that is not disturbed by the pasted pixel is 1; the label of the cell with the total pixel of the pasted pixel / cell>0.5 is 0; the label of the remaining cells is -1. When the foreground pixel cells of the two sample images are different and the background pixel cells are the same, or the foreground pixel cells are the same and the background pixel cells are different, the labels of the different pixel cells are 0, the labels of the same pixel cells are 1, and the labels of the pixel cells that do not participate in the back-propagation training are -1. Among them, the cell label in the edge area is -1, because there will be a translation change of several pixels, and the edge pixels may have been removed from the image, so they do not participate in the loss feedback.
[0073] The preprocessing also includes data enhancement, specifically including:
[0074] When all pixel cells of two sample images are different, the enhancement method used does not include filling the same relative area of the two sample images with the same grayscale value and mapping based on the same foreground image, and other methods are feasible; because the enhancement method of filling the same relative area of the two sample images with the same grayscale value and mapping based on the same foreground image may cause pixel cells that were originally different in the two samples to become the same pixel cells, which will cause a situation that does not correspond to the label.
[0075] When all pixel cells of two sample images are exactly the same, or the foreground pixel cells of the two sample images are different and the background pixel cells are the same, or the foreground pixel cells are the same and the background pixel cells are different, the enhancement methods used include a certain degree of illumination change, a small amount of color distortion, jitter changes of several pixels (selected according to anti-jitter requirements), mild mixup, simulated shadows, simulated water marks, etc.
[0076] The present invention can train the model in this method based on any data set. For example, the imagenet data set, the coco data set, and the voc data set can all be used to train the underlying feature extraction model in this method, and only the original images need to be used without using labels. The labels required by the model in this method are automatically generated by the code, which saves the manual annotation process, is conducive to improving work efficiency, and reducing labor costs.
[0077] The model training module trains the underlying feature extraction model based on the fully convolutional network according to the sample image data; specifically includes: input scale (batch, h, w, c), output scale (batch, h / d, w / d, feature_len); batch represents the number of images; h represents the height of the original image, w represents the width of the original image, and c represents the number of image channels (c for color images is 3 / c for grayscale images is 1); d represents the scale of the output layer relative to the input layer, and d also represents the downsampling ratio of the model, or d represents the side length of the pixel block corresponding to each feature vector, d can be customized, and the value is usually 2, 4, 8, 16... etc.; feature_len represents the length of each feature vector, which can be 32, 64, 128, 256... etc. In addition, the depth and width of the underlying feature extraction model and the single vector length of the output layer feature vector map are selected based on the complexity of the scene and the performance requirements for model reasoning.
[0078] The main function of this model is to extract the feature vector graph of the sample image. Each feature vector in the feature vector graph mainly expresses the underlying features of each cell in the original image. For example, when training, input [image 1, image 2, label graph], each cell in the label graph records whether the pixel areas corresponding to images 1 and 2 are similar pixel blocks. Images 1 and 2 are extracted through the underlying feature model to obtain feature vectors. Figure 1 and the eigenvector Figure 2 ; For the feature vector Figure 1 and the eigenvector Figure 2 The feature distance is calculated cell by cell (such as using the normalized Euclidean distance) to obtain a distance map. In the distance map, the value of each cell is used to represent Figure 1 and Figure 2 The width and height of the distance map are equal to the width and height of the label map, and its cells correspond one to one.
[0079] The underlying feature extraction model in the present invention only needs to be trained once and can be applied to any scenario, without the need for special training for each specific scenario. For example, it can be used to assist in detecting abnormal intrusions on traffic roads; it can be used to assist in detecting objects thrown from high places in smart parks; it can be used to detect foreground objects on conveyor belts in the industrial field. This method is particularly important when the conveyor belt has poor lighting and traditional image algorithms cannot segment the foreground.
[0080] When training the underlying feature extraction model, the effects of environmental changes such as illumination changes and slight camera shake (i.e., slight shift) are taken into consideration, so that the features extracted by the underlying feature extraction model are not affected by the above environmental problems.
[0081] Based on the underlying feature extraction model, the background feature vector map and foreground feature vector map of the sample image are extracted and feature distance calculation is performed to obtain a feature distance map; specifically, the method includes: using the underlying feature extraction model to perform forward reasoning on the background pixels and foreground pixels respectively to obtain the background feature vector map and foreground feature vector map. Based on the background feature vector map and the foreground feature vector map, feature distance calculation is performed to obtain a feature distance map. Currently, the normalized Euclidean distance is used, and the cosine distance can also be used for feature distance calculation.
[0082] A loss function is designed based on the feature distance graph and the label graph, and the loss is calculated for each cell in the feature distance graph and the label graph one by one. Based on the back propagation algorithm, all weight parameters of the underlying feature extraction model are repeatedly iterated to generate an optimized underlying feature extraction model. The present invention also proposes a new loss function. Since the underlying feature extraction model proposed in the present invention is a new model, the existing loss function cannot be used directly, so a new loss function needs to be designed for supporting use. The functions of the new loss function are:
[0083] a) A cell in the distance graph corresponds to Figure 1 and Figure 2 The pixel blocks at the corresponding positions in are similar pixel blocks, and the supervision method of the loss function is to make the distance value as small as possible;
[0084] b) A cell in the distance graph corresponds to Figure 1 and Figure 2 The pixel blocks at the corresponding positions in are dissimilar pixel blocks, and the supervision method of the loss function is to make the distance value as large as possible;
[0085] c) In order to prevent overfitting, the design of this loss function introduces the idea of label smoothing. When the distance between similar pixel blocks is less than or equal to 0.15, the loss function is equal to 0, which means no supervision; when the distance between dissimilar pixel blocks is greater than or equal to 0.85, the loss function is equal to 0, which means no supervision. The distance between similar pixel blocks is 0.15 and the distance between dissimilar pixel blocks is 0.85. These two parameters can also be modified as needed.
[0086] The loss function is:
[0087]
[0088] Among them, dis represents the feature distance value; loss1 is the loss function of similar blocks, such as Figure 5 The loss function diagram with label 1 is shown in the figure. Similar blocks represent two similar pixel blocks in the corresponding two input images. Loss2 is the loss function of dissimilar blocks, such as Figure 6 The loss function graph with label 0 shown; y represents the label value and e represents a natural constant.
[0089] The model application module obtains sample image data and inputs it into the optimized underlying feature extraction model for feature extraction to obtain background feature vector graph and foreground feature vector graph, then performs feature distance calculation on the background feature vector graph and foreground feature vector graph to obtain feature distance graph, and performs threshold segmentation on the feature distance graph to obtain foreground targets and background targets. Figures 7 to 10 FIG. 1 is a model application workflow of a background difference method with strong anti-environmental interference capability provided by an embodiment of the present invention. First, two sample images with different foregrounds and the same background are input, such as Figure 7 As shown; Secondly, based on the underlying feature extraction model Figure 7 The characteristic vector graphs of the two sample graphs in are as follows: Figure 8 As shown; again through the feature distance calculation to get Figure 8 The characteristic distance graph of the characteristic vector graph in is Fig. 9 As shown, in order to more clearly illustrate this solution, the feature distance map is combined with the original map for display. The actual feature distance is a floating point number between 0.0 and 1.5. For the convenience of drawing, the distance is mapped to an integer representation of 0-9; Fig.10 yes Fig. 9 The local enlarged picture, and finally Fig. 9 The feature distance map in is threshold segmented to obtain the final threshold segmentation effect map, as shown in Fig.11 As shown, Fig. 9 The feature distance map in the image is thresholded and segmented to obtain the binary image of the foreground and background. In order to display it more clearly, the segmented binary image is combined with the original image for display.
[0090] Example 3
[0091] The present invention also discloses a computer storage medium for storing a computer program for implementing any of the above method steps.
[0092] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A background difference method with strong anti-environmental interference ability, characterized in that: include: S1) obtaining sample image data and performing preprocessing, wherein the preprocessing includes generating labels and label maps; The acquired sample image data is a two-tuple data set, wherein the two-tuple data set is [first sample image, second sample image], and preprocessing is performed on the first sample image and the second sample image in the two-tuple data set; The labels specifically include: 0, 1, -1, wherein the labels of different pixel cells of the first sample image and the second sample image are 0, the labels of the same pixel cells of the first sample image and the second sample image are 1, and the labels of the pixel cells in the first sample image and the second sample image that do not participate in the back propagation training are -1; S2) training the underlying feature extraction model based on the fully convolutional network according to the sample image data; S3) extracting a background feature vector map and a foreground feature vector map of the sample image based on the underlying feature extraction model and performing feature distance calculation to obtain a feature distance map; S4) designing a loss function according to the feature distance map and the label map, calculating the loss of each cell in the feature distance map and the label map one by one, and repeatedly iterating all weight parameters of the underlying feature extraction model based on the back propagation algorithm to generate an optimized underlying feature extraction model; S5) obtaining sample image data and inputting it into the optimized underlying feature extraction model for feature extraction to obtain a background feature vector map and a foreground feature vector map, then performing feature distance calculation on the background feature vector map and the foreground feature vector map to obtain a feature distance map, and performing threshold segmentation on the feature distance map to obtain a foreground target and a background target.
2. A background difference method with strong anti-environmental interference ability as claimed in claim 1, characterized in that: When all pixel cells of two sample images are different, the label of each cell is 0; when all pixel cells of two sample images are exactly the same, the first sample image is kept unchanged and the second sample image is synthesized.
3. A background difference method with strong anti-environmental interference ability as claimed in claim 2, characterized in that: The image synthesis specifically includes: pasting pixels of other images into the second sample image, wherein the labels of cells in the second sample image that are not disturbed by the pasted pixels are 1; the labels of cells whose total pixels of pasted pixels / cell>0.5 are 0; and the labels of the remaining cells are -1.
4. A background difference method with strong anti-environmental interference ability as claimed in claim 1, characterized in that: The preprocessing also includes data enhancement, specifically including: When all pixel cells of the two sample images are different, the enhancement method used does not include filling the same relative area of the two sample images with the same gray value and mapping based on the same foreground image. Other methods are feasible; When all pixel cells of two sample images are exactly the same, the enhancement methods used include a certain degree of lighting change, a small amount of color distortion, pixel jitter change, mild mixup, simulated shadows, and simulated water marks.
5. A background difference method with strong anti-environmental interference capability as claimed in claim 1, characterized in that: The depth and width of the underlying feature extraction model and the length of a single vector of the output layer feature vector map are selected based on the complexity of the scene and the performance requirements for model inference.
6. A background difference method with strong anti-environmental interference capability as claimed in claim 1, characterized in that: The loss function is: Among them, dis represents the feature distance value; loss1 is the loss function of similar pixel cells; loss2 is the loss function of dissimilar pixel cells; y represents the label value, and e represents a natural constant.
7. A background difference system with strong anti-environmental interference capability, characterized in that: include: A preprocessing module, used to obtain sample image data and perform preprocessing, wherein the preprocessing includes generating labels and label maps; The acquired sample image data is a two-tuple data set, wherein the two-tuple data set is [first sample image, second sample image], and preprocessing is performed on the first sample image and the second sample image in the two-tuple data set; The labels specifically include: 0, 1, -1, wherein the labels of different pixel cells of the first sample image and the second sample image are 0, the labels of the same pixel cells of the first sample image and the second sample image are 1, and the labels of the pixel cells in the first sample image and the second sample image that do not participate in the back propagation training are -1; The model training module trains the underlying feature extraction model based on the fully convolutional network according to the sample image data; based on the underlying feature extraction model, extracts the background feature vector map and the foreground feature vector map of the sample image and performs feature distance calculation to obtain a feature distance map; designs a loss function according to the feature distance map and the label map, calculates the loss for each cell in the feature distance map and the label map one by one, and repeatedly iterates all weight parameters of the underlying feature extraction model based on the back propagation algorithm to generate an optimized underlying feature extraction model; The model application module obtains sample image data and inputs it into the optimized underlying feature extraction model for feature extraction to obtain a background feature vector map and a foreground feature vector map. Feature distance calculation is then performed on the background feature vector map and the foreground feature vector map to obtain a feature distance map. Threshold segmentation is performed on the feature distance map to obtain foreground targets and background targets.
8. A computer storage medium, characterized in that: A computer program for storing a computer program for implementing the method steps according to any one of claims 1 to 6.
