Disclosure of Invention
In view of the above drawbacks and needs of the prior art, the present invention provides a method and an apparatus for measuring the particle size distribution of gravel, which aims to improve the accuracy of measuring the particle size distribution of gravel, thereby solving the technical problem of inaccurate measurement of the particle size distribution of gravel.
To achieve the above object, according to one aspect of the present invention, there is provided a method for measuring a particle size distribution of gravel, comprising:
inputting a first image to be detected into a preset neural network model to obtain a first threshold value and a second threshold value corresponding to the first image output by the neural network model; wherein the first image comprises a plurality of gravel and background objects;
removing background objects in the first image based on an automatic particle size distribution algorithm and the first threshold value to obtain a second image;
filling each gravel in the second image by adopting an area filling technology to obtain a third image;
taking the second threshold value as an H value in H-minima transformation, and segmenting each gravel in the third image based on a watershed algorithm of the H-minima transformation to obtain a fourth image;
and measuring the short axis of each gravel in the fourth image by adopting a Hotelling transformation to classify each gravel in the fourth image, and drawing a particle size distribution diagram of each type of gravel.
Preferably, the neural network model is a back propagation based fuzzy neural network.
Preferably, the first image to be measured is input to a preset neural network model, and the method further includes:
acquiring an original color image to be detected; wherein the original color image comprises a plurality of gravel and background objects;
and performing downsampling on the original color image by adopting discrete wavelet transform to obtain a first image to be detected.
Preferably, the neural network model is obtained as follows:
obtaining a plurality of sample original color images; wherein the sample original color image comprises a plurality of gravel and background objects;
adopting discrete wavelet transform to carry out downsampling on each sample original image to obtain a first sample image corresponding to each sample original image;
acquiring a first sample threshold value and a second sample threshold value corresponding to each first sample image, and combining each sample original image and the corresponding first sample threshold value and second sample threshold value to form a sample;
combining a plurality of the samples to form a training set, training the neural network model based on the training set to adjust parameters of the neural network model.
Preferably, training the neural network model based on the training set to adjust parameters of the neural network model comprises:
for any one sample, inputting the first sample image in the sample into the neural network model, and outputting a first prediction threshold value and a second prediction threshold value corresponding to the first sample image;
calculating a loss value according to the first prediction threshold value and the first sample threshold value in the sample, and the second prediction threshold value and the second sample threshold value in the sample by adopting a preset loss function;
and if the loss value is smaller than a preset threshold value, finishing the training of the neural network model.
Preferably, acquiring a first sample threshold and a second sample threshold corresponding to each of the first sample images includes:
and acquiring a first sample threshold and a second sample threshold corresponding to each first sample image based on an automatic particle size distribution algorithm.
According to another aspect of the present invention, there is provided a gravel particle size distribution measuring apparatus comprising:
the device comprises an input module, a first image acquisition module and a second image acquisition module, wherein the input module is used for inputting a first image to be detected to a preset neural network model to obtain a first threshold value and a second threshold value corresponding to the first image output by the neural network model; wherein the first image comprises a plurality of gravel and background objects;
the background removing module is used for removing background objects in the first image based on an automatic particle size distribution algorithm and the first threshold value to obtain a second image;
the filling module is used for filling each gravel in the second image by adopting an area filling technology to obtain a third image;
the segmentation module is used for taking the second threshold value as an H value in H-minima transformation and segmenting each gravel in the third image based on a watershed algorithm of the H-minima transformation to obtain a fourth image;
and the drawing module is used for measuring the short axis of each gravel in the fourth image by adopting Hotelling transformation so as to classify each gravel in the fourth image and draw a particle size distribution diagram of each type of gravel.
Preferably, the apparatus further comprises:
the image acquisition module is used for acquiring a plurality of sample original color images; wherein the sample original color image comprises a plurality of gravel and background objects;
the down-sampling module is used for carrying out down-sampling on each sample original image by adopting discrete wavelet transform to obtain a first sample image corresponding to each sample original image;
a threshold obtaining module, configured to obtain a first sample threshold and a second sample threshold corresponding to each first sample image, and combine each sample original image and the corresponding first sample threshold and second sample threshold as a sample;
and the training module is used for combining a plurality of samples to form a training set, and training the neural network model based on the training set to adjust the parameters of the neural network model.
According to a further aspect of the invention, there is provided an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method as provided in the first aspect when executing the program.
According to a further aspect of the present invention, there is provided a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the method as provided by the first aspect.
Generally speaking, compared with the prior art, the technical scheme of the invention captures 2 key parameters (namely the first threshold and the second threshold) of each digital image (namely the first image to be measured) through the neural network model, can automatically and accurately measure the particle size distribution of the gravel, effectively overcomes the problem that the prior art cannot fully identify the 2 key parameters of each digital image, and improves the accuracy of the measurement of the particle size distribution of the gravel.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. In addition, the technical features involved in the embodiments of the present invention described below may be combined with each other as long as they do not conflict with each other.
It should be noted that, in the first place, the embodiments of the present invention aim to overcome the disadvantages of the prior art and provide a method for measuring the particle size distribution of river bed gravels based on digital images, which facilitates the full-automatic accurate measurement of the particle size distribution of the gravels, has the ability to simultaneously reduce the quantification of the particle size distribution of the gravels, the labor-intensive and time-consuming laboratory, and automatically and accurately measures the particle size distribution of the gravels with less labor intensity for each digital image. The technical scheme of the invention is as follows:
fig. 1 is a flow chart of a method for measuring a particle size distribution of gravel according to an embodiment of the present invention, as shown in fig. 1, the method includes:
step S1, inputting a first image to be detected into a preset neural network model, and obtaining a first threshold value and a second threshold value corresponding to the first image output by the neural network model; wherein the first image comprises a plurality of gravel and background objects; wherein the first threshold is used for identifying sand as background, and the second threshold is used for controlling WST over-segmentation by using the threshold of H-minima transformation.
It should be noted that Artificial Neural Networks (ANNs) are a branch of artificial intelligence and perform well in various fields. In the embodiment of the invention, the preset neural network model is based on a back propagation fuzzy neural network (CFNN) to learn and infer the relationship between the input (a first image) of the CFNN and the corresponding output (a first threshold and a second threshold), the images are similar due to gravel and sand background objects, and the gravel and sand background objects which are distinguished are a fuzzy problem without absolute standards, so that the neural fuzzy network which can better simulate a human fuzzy judgment process is adopted, and the accuracy of an output result is higher compared with a common neural network classification algorithm.
Wherein the first image is an image input to the neural network model, which includes a plurality of gravels and background objects, which are typically sand.
And step S2, removing background objects in the first image based on an automatic particle size distribution algorithm and the first threshold value to obtain a second image.
Specifically, an appropriate binary threshold is determined in the AGS, so that gravel and sand can be distinguished from each other (usually, the white part is gravel and the black part is sand) from the grayed binary image of the colored riverbed image, namely the grayscale image, thereby obtaining an image only containing gravel and laying a foundation for subsequent measurement of gravel particle size distribution. The first threshold in the embodiment of the present invention, i.e. the binary threshold mentioned above, is used to identify a background object, such as sand, in the first image.
And taking the first threshold as a binary threshold in the AGS to remove background scenes in the first image, and taking the image without the background scenes as a second image.
And step S3, filling each gravel in the second image by adopting an area filling technology to obtain a third image.
And step S4, taking the second threshold as an H value in H-minima transformation, and segmenting each gravel in the third image based on a watershed algorithm of the H-minima transformation to obtain a fourth image.
In particular, the watershed transform algorithm (WST) is one of the most commonly used image segmentation methods in image processing, however, over-segmentation often occurs in segmentation procedures. In order to avoid over-segmentation, a second threshold value is used as an H value in the H-minima transformation, each gravel in the third image is segmented based on a watershed algorithm of the H-minima transformation, and the segmented image is used as a fourth image.
And step S5, measuring the short axis of each gravel in the fourth image by adopting Hotelling transformation to classify each gravel in the fourth image, and drawing a particle size distribution diagram of each type of gravel.
According to the method provided by the embodiment of the invention, 2 key parameters (namely the first threshold and the second threshold) of each digital image (namely the first image to be measured) are captured through the neural network model, the particle size distribution of the gravel can be automatically and accurately measured, the problem that the prior art cannot fully identify the 2 key parameters of each digital image is effectively solved, and the accuracy of measuring the particle size distribution of the gravel is improved.
Based on the above embodiment, in the embodiment of the present invention, the neural network model is obtained according to the following method:
acquiring an original color image to be detected; wherein the original color image includes a plurality of gravel and background objects. And performing downsampling on the original color image by adopting discrete wavelet transform to obtain a first image to be detected.
In particular, the input metric is reduced using a Discrete Wavelet Transform (DWT). For example, an original color image is a 256-metric input signal, down-sampled by DWT to 2 128-metric signals, where the noise is filtered by a high-pass filter and an approximation is retained by a low-pass filter. Starting with 256 metrics, the DWT based down-sampling procedure is repeated five times and after the 5 th down-sampling an 8-metric signal is generated by the low-pass filter as the first image.
Based on the above embodiment, in the embodiment of the present invention, the inputting the first image to be measured to the preset neural network model further includes:
obtaining a plurality of sample original color images; wherein the sample original color image includes a plurality of gravel and background objects.
Specifically, the steps of obtaining a plurality of sample original color images are as follows: bed images of 20 river sections and 40-80 river beds per river section were taken in a square area of 1 square meter. The collected images are classified into 2 types according to the boundary density: class a (with no significant sand) and class B (with significant sand). For a few high boundary density but not sandy images, manual image analysis manually removes these poor quality images, taking each of the remaining images as a sample original color image.
And performing downsampling on each sample original image by adopting discrete wavelet transform to obtain a first sample image corresponding to each sample original image.
Specifically, for each sample original color image, the Discrete Wavelet Transform (DWT) is used to reduce the input metric. For example, an original color image is a 256-metric input signal, down-sampled by DWT to 2 128-metric signals, where the noise is filtered by a high-pass filter and an approximation is retained by a low-pass filter. Starting with 256 metrics, the DWT based down-sampling procedure is repeated five times and after the 5 th down-sampling, an 8-metric signal is generated by the low-pass filter as the first sample image corresponding to the original color image of the sample.
And acquiring a first sample threshold value and a second sample threshold value corresponding to each first sample image, and combining each sample original image and the corresponding first sample threshold value and second sample threshold value to form a sample.
Specifically, a first sample threshold T corresponding to each first sample image is used for identifying a background object in the first sample image, and a second sample threshold H corresponding to each first sample image is an H value in H-minima transformation performed on the first sample image. In the embodiment of the present invention, a method for calculating Accuracy (AR) based on AGS obtains a first sample threshold T and a second sample threshold H corresponding to each first sample image, and includes the following specific steps: see first the following formula, where tob,tesAnd n is the observed, measured and total grain size grade numbers (increased from 4 to 9psi in 0.5psi increments). In each first sample image, AGS measures grain size by trying different T and H. T is in [50, 250 ]]Is searched at 5 intervals, and H is in [1, 15 ]]Is searched at intervals of 1. Therefore, a total of 615(═ 15 × 41) ARs need to be calculated for each first sample image, and thus, for each first sample image, T and H are obtained in association with the maximum AR value.
A first portion of the samples are combined in a plurality of the samples to form a training set, and the neural network model is trained based on the training set to adjust parameters of the neural network model.
Based on the foregoing embodiments, in the embodiments of the present invention, training the neural network model based on the training set to adjust parameters of the neural network model includes:
and for any one sample, inputting the first sample image in the sample into the neural network model, and outputting a first prediction threshold value and a second prediction threshold value corresponding to the first sample image.
Calculating a loss value by adopting a preset loss function according to the first prediction threshold value and the first sample threshold value in the samples, and the second prediction threshold value and the second sample threshold value in the samples, wherein the loss value is a weighted sum of a first prediction threshold value accumulated error and a second prediction threshold value accumulated error, and the first prediction threshold value accumulated error is an absolute value of a difference between the first prediction threshold value and the first sample prediction threshold value of each sample; the second prediction threshold accumulated error is the second prediction threshold of each sample and the absolute value of the second sample prediction threshold difference.
And if the loss value is smaller than a preset threshold value, finishing the training of the neural network model.
Based on the above embodiment, in the embodiment of the present invention, a second part of the samples may be further combined to form a validation set in a plurality of the samples, and the optimal neural network model may be determined based on the validation set.
Based on the above embodiments, the embodiments of the present invention are described as a preferred embodiment of a CFNN:
in inputting the first image selected in the above embodiments into the CFNN, the CFNN analyzes the characteristics of the first image by calculating the probability of occurrence of each gray level, where n is the total number of pixels (e.g., n is 1000 × 1000), and n is the total number of pixels in the first image
kIs the gray scale g
kP (g) is the number of pixels
k) Has 256 measurements (0-255 gray levels), and
according to the input first image, the CFNN calculates the characteristics of the first image, and then performs pattern matching (performed by a gaussian function) to output a first threshold and a second threshold corresponding to the first image.
Based on the above embodiment, an embodiment of the present invention further provides a device for measuring a particle size distribution of gravel, fig. 2 is a schematic structural diagram of the device for measuring a particle size distribution of gravel provided by an embodiment of the present invention, as shown in fig. 2, the device includes:
the input module 201 is configured to input a first image to be detected to a preset neural network model, so as to obtain a first threshold and a second threshold corresponding to the first image output by the neural network model; wherein the first image comprises a plurality of gravel and background objects. And the background removing module 202 is configured to remove a background scene in the first image based on an automatic particle size distribution algorithm and the first threshold to obtain a second image. And the filling module 203 is configured to fill each gravel in the second image by using a region filling technique, so as to obtain a third image. And a segmentation module 204, configured to use the second threshold as an H value in an H-minima transformation, and segment each gravel in the third image based on a watershed algorithm of the H-minima transformation to obtain a fourth image. A drawing module 205, configured to measure a short axis of each gravel in the fourth image by using a Hotelling transform, to classify each gravel in the fourth image, and to draw a particle size distribution map of each type of gravel.
The apparatus provided in the embodiment of the present invention is used for executing the method in the above embodiment, and the method has been described in detail in the above embodiment, so the apparatus is not described herein again. The device provided by the embodiment of the invention can automatically and accurately measure the particle size distribution of the gravel by capturing 2 key parameters (namely the first threshold value and the second threshold value) of each digital image (namely the first image to be measured) through the neural network model, effectively overcomes the problem that the prior art cannot fully identify 2 key parameters of each digital image, and improves the accuracy of measuring the particle size distribution of the gravel.
Based on the above embodiment, the apparatus provided in the embodiment of the present invention further includes:
the image acquisition module is used for acquiring a plurality of sample original color images; wherein the sample original color image includes a plurality of gravel and background objects.
And the downsampling module is used for downsampling each sample original image by adopting discrete wavelet transform to obtain a first sample image corresponding to each sample original image.
And the threshold acquisition module is used for acquiring a first sample threshold and a second sample threshold corresponding to each first sample image, and combining each sample original image and the corresponding first sample threshold and second sample threshold as a sample.
And the training module is used for combining a plurality of samples to form a training set, and training the neural network model based on the training set to adjust the parameters of the neural network model.
In summary, the method and the apparatus provided in the embodiments of the present invention have the following advantages:
a fine automatic grain size sorting (R-AGS) method is provided, AGS and CFNN are fused, in order to ensure that the R-AGS has strong robustness and can be applied to complex images of natural river beds, the constructed CFNN is enough to provide a proper binary threshold value for each river bed image so as to distinguish gravel and sand from the river bed image, and the CFNN is allocated to H-minima to transform a proper threshold value so as to effectively control WST over-segmentation, so the R-AGS is superior to the prior AGS in terms of gravel particle size distribution measurement.
Furthermore, when the image sample under investigation is significantly different from the image of this study, it is easy to reconstruct the CFNN by updating and/or adding rule nodes, and therefore its applicability and utility can be expanded.
In summary, the R-AGS presented by the embodiments of the present invention not only can automatically and adaptively process various captured riverbed images to obtain corresponding gravel size distributions, thereby replacing complex and time-consuming manual sampling methods, but also has the ability to simultaneously reduce the quantification of gravel size distributions, the labor-intensive and time-consuming laboratory, and automatically and accurately measure the gravel size distributions with less labor intensity for each digital image.
Fig. 3 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 3, the electronic device may include: a processor (processor)301, a communication Interface (communication Interface)302, a memory (memory)303 and a communication bus 304, wherein the processor 301, the communication Interface 302 and the memory 303 complete communication with each other through the communication bus 304. The processor 301 may invoke a computer program stored on the memory 303 and executable on the processor 301 to perform the methods provided by the various embodiments described above, including, for example: inputting a first image to be detected into a preset neural network model to obtain a first threshold value and a second threshold value corresponding to the first image output by the neural network model; wherein the first image comprises a plurality of gravel and background objects; removing background objects in the first image based on an automatic particle size distribution algorithm and the first threshold value to obtain a second image; filling each gravel in the second image by adopting an area filling technology to obtain a third image; taking the second threshold value as an H value in H-minima transformation, and segmenting each gravel in the third image based on a watershed algorithm of the H-minima transformation to obtain a fourth image; and measuring the short axis of each gravel in the fourth image by adopting a Hotelling transformation to classify each gravel in the fourth image, and drawing a particle size distribution diagram of each type of gravel.
In addition, the logic instructions in the memory 303 may be implemented in the form of software functional units and stored in a computer readable storage medium when the logic instructions are sold or used as independent products. Based on such understanding, the technical solutions of the embodiments of the present invention may be essentially implemented or make a contribution to the prior art, or may be implemented in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the methods described in the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Embodiments of the present invention further provide a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program is implemented to perform the transmission method provided in the foregoing embodiments when executed by a processor, and the method includes: inputting a first image to be detected into a preset neural network model to obtain a first threshold value and a second threshold value corresponding to the first image output by the neural network model; wherein the first image comprises a plurality of gravel and background objects; removing background objects in the first image based on an automatic particle size distribution algorithm and the first threshold value to obtain a second image; filling each gravel in the second image by adopting an area filling technology to obtain a third image; taking the second threshold value as an H value in H-minima transformation, and segmenting each gravel in the third image based on a watershed algorithm of the H-minima transformation to obtain a fourth image; and measuring the short axis of each gravel in the fourth image by adopting a Hotelling transformation to classify each gravel in the fourth image, and drawing a particle size distribution diagram of each type of gravel.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
It will be understood by those skilled in the art that the foregoing is only a preferred embodiment of the present invention, and is not intended to limit the invention, and that any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the scope of the present invention.