Disclosure of Invention
In order to solve the technical problems, the invention aims to provide a method and a system for detecting the scab defect of a flexible leather material based on artificial intelligence, and the adopted technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides an artificial intelligence-based method for detecting a mange defect in a flexible leather material, the method including:
acquiring a surface image to be detected of leather to be detected, and preprocessing the surface image to be detected to obtain a surface gray scale map;
obtaining a difference image by subtracting the gray average value of the surface gray image and a standard image, wherein the standard image is a surface image of the flawless leather; carrying out gray level quantization on the difference image to obtain a difference quantization image, wherein the difference quantization image is composed of different gray level channels;
clustering each gray level channel to obtain a plurality of clusters;
for each first pixel point in the difference quantization image, a cluster which is closest to the first pixel point in each gray level channel is a first cluster, and a leather pixel difference vector is obtained according to a vector from the first pixel point to each first cluster; fusing all leather pixel difference vectors corresponding to the first pixel point to obtain a first fusion vector;
obtaining a target pixel point in the difference value quantization image, wherein the target pixel point is a corresponding pixel point with the largest pixel value in the difference value image; the cluster which is closest to the target pixel point in each gray level channel is a second cluster; obtaining a leather maximum difference vector according to the vector from the target pixel point to each second cluster; fusing all the leather maximum difference vectors corresponding to each target pixel point to obtain a second fusion vector;
calculating the similarity between the first fusion vector and the second fusion vector of each first pixel point to obtain a leather difference value symbiotic image;
inputting the surface image to be detected and the leather difference value symbiosis image into a semantic segmentation network to obtain a defect detection result;
the step of clustering each gray level channel to obtain a plurality of clusters comprises:
and adopting a mean shift clustering algorithm for each gray level channel to find a plurality of clustering centers in each gray level channel, wherein the number of the clustering centers is the number of clusters obtained by clustering, and a plurality of clusters in each gray level channel are obtained.
Further, the step of fusing all leather pixel difference vectors corresponding to each first pixel point to obtain a first fusion vector includes: multiplying all the pixel difference vectors by respective weights to obtain a first fusion vector; the weight is a ratio of the number of pixels of the first cluster corresponding to the corresponding pixel difference vector to the total number of pixels of all the first clusters.
Further, the step of fusing the maximum difference vectors of all leathers corresponding to each target pixel point to obtain a second fused vector comprises: multiplying all the leather maximum difference vectors by respective weights to obtain a second fusion vector; and the weight is the ratio of the number of pixels of the second cluster corresponding to the maximum difference vector of the corresponding leather to the total number of pixels of all the second clusters.
Further, the method for calculating the similarity between the first fusion vector of each first pixel point and the second fusion vector of the target pixel point adopts cosine similarity.
Further, the step of preprocessing the surface image to be detected to obtain a surface gray scale image comprises: graying the surface image to be detected to obtain an initial gray image; and carrying out histogram equalization processing on the initial gray level image to obtain the surface gray level image.
Further, the step of calculating the similarity between the first fused vector and the second fused vector of each first pixel point further includes: when a plurality of target pixel points exist, calculating a second fusion vector of each target pixel point, and calculating the similarity between each second fusion vector and each first fusion vector according to the average value of the second fusion vectors of all the target pixel points.
Further, the step of obtaining a cluster closest to the first pixel point in each gray scale channel as a first cluster includes: and searching a cluster center which is closest to the first pixel point in a corresponding gray level channel by taking the first pixel point as a center, wherein a cluster corresponding to the cluster center is the first cluster.
In a second aspect, the embodiment of the present invention further provides an artificial intelligence-based flexible leather material mange defect detection system, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of any one of the above methods when executing the computer program.
The embodiment of the invention has the following beneficial effects:
the embodiment of the invention discloses a flexible leather material mange defect detection method based on artificial intelligence, which obtains a difference image between a surface image to be detected and a standard image of a defect-free leather area, quantizes the difference image to obtain a quantized image, clusters pixel points of each gray level in the quantized image to obtain a plurality of clusters, calculates a first fusion vector between each pixel point in the quantized image and the nearest cluster in each gray level and a second fusion vector between a target pixel point in the quantized image and the nearest cluster in each gray level, calculates the similarity between the first fusion vector and the second fusion vector to obtain a leather difference value symbiotic image taking the similarity as a pixel value, takes the leather difference value symbiotic image and the surface image to be detected as the input of a semantic segmentation network, and takes the leather difference value symbiotic image as the supervision information of the semantic segmentation network to enable the network to pay more attention to the area with larger similarity, the attention degree of the region with small similarity is reduced, the result output by the semantic segmentation network is more accurate, and the technical problem that noise points and texture features similar to scabies defects are easily identified as scabies in the prior art is solved.
Detailed Description
In order to further illustrate the technical means and effects of the present invention for achieving the predetermined objects, the following detailed description of the method and system for detecting scabies defect of flexible leather material based on artificial intelligence according to the present invention with reference to the accompanying drawings and preferred embodiments thereof will be made in detail. In the following description, different "one embodiment" or "another embodiment" refers to not necessarily the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
The following describes a specific scheme of the flexible leather material scab defect detection method and system based on artificial intelligence in detail with reference to the accompanying drawings.
Referring to fig. 1, a flowchart of a method for detecting scabies defects of a flexible leather material based on artificial intelligence according to an embodiment of the present invention is shown, where the method includes:
and S001, acquiring a surface image to be detected of the leather to be detected, and preprocessing the surface image to be detected to obtain a surface gray scale map.
The surface image to be measured is an image of the leather surface acquired by a camera, and the optimal angle of the acquired surface image to be measured is that the optical axis of the camera is vertical to the leather surface. The advantage of the image acquired at the angle is that the leather with scabies defects on the surface can be imaged clearly in the image of the surface to be measured, and the image does not interfere with the normal leather area.
The method comprises the steps of preprocessing a surface image to be detected before defect monitoring, wherein the preprocessing comprises the steps of graying the surface image to be detected to obtain an initial gray-scale image, and performing histogram equalization processing on the initial gray-scale image to obtain a surface gray-scale image. The histogram is adopted to carry out equalization processing on the initial gray level image, so that the overall brightness of the image can be improved, and the texture details in the image can be fully displayed.
S002, obtaining a difference image by subtracting the gray average value of the surface gray image and the standard image, wherein the standard image is the surface image of the flawless leather; and carrying out gray level quantization on the difference image to obtain a difference quantization image, wherein the difference quantization image consists of different gray level channels.
In order to obtain a more accurate gray level average value, the gray level average value of the standard image is the average value of the gray levels of a plurality of preprocessed standard images. Specifically, the step of preprocessing the standard image is the same as the step of preprocessing the surface image to be detected, that is, graying the plurality of standard images to obtain a standard grayscale image, and performing histogram equalization on the standard grayscale image to obtain a standard surface grayscale image. Number of standard surface gray scale maps is recorded as
And the number of pixels included in each standard surface grayscale image is recorded as
The first step
In a standard surface gray scale image
The pixel value of each pixel point is recorded as
And the mean gray scale value of the standard image is recorded as
Then, there are:
in the embodiments of the present invention
The value of (1) is 100, and in other embodiments, the number of the standard images may be selected according to actual requirements.
The pixel value of each pixel point in the difference image is the difference value between each corresponding pixel point and the gray level in the surface gray level image. Specifically, the surface gray scale map is
The pixel value of each pixel point is recorded as
In the difference map
The pixel value of each pixel point is recorded as
Then, there are:
the difference image is quantized into corresponding gray scale to obtain a difference quantization image, and color blocks and textures belonging to different gray scales are presented in the difference quantization image. Specifically, the gray values of different levels are placed in different gray level channels in the difference quantization map, and the levels of the gray values and the gray level channels are in a one-to-one correspondence relationship; in other words, the gray values of the pixels in one gray scale channel are the same, and the number of divided gray scales is equal to the number of gray scale channels. And obtaining a complete difference quantization image after overlapping the pixels of all the gray level channels. In the embodiment of the present invention, the quantization is seven gray levels, that is, there are seven gray level channels, and in other embodiments, different gray levels can be quantized according to requirements.
As an example, the quantization mode is rounding down, assuming that the maximum difference of the gray values in the difference map is 40, the gray value in the difference map is divided into 7 levels, the corresponding gray value interval is obtained after rounding down, the pixel point with the gray value in the interval [0,5] is quantized into the first gray level, the pixel point with the gray value in the interval [6,11] is quantized into the second gray level, the pixel point with the gray value in the interval [12,17] is quantized into the third gray level, the pixel point with the gray value in the interval [18,22] is quantized into the fourth gray level, the pixel point with the gray value in the interval [23,28] is quantized into the fifth gray level, the pixel point with the gray value in the interval [29,34] is quantized into the sixth gray level, the pixel point with the gray value in the interval [35,40] is quantized into the seventh gray level, the levels correspond to the gray value of [1 in turn, 7].
And step S003, clustering each gray level channel to obtain a plurality of clusters.
And the clustering mode adopts a mean shift clustering algorithm to find the clustering center of each pixel point. The specific implementation process of the mean shift clustering algorithm comprises the following steps: sliding window based algorithms find dense areas. The radius r of the sliding window and the randomly selected pixel point are used as a central point C, a circular area with the central point C as the center and the radius r is used as the sliding window, and sliding is started in the corresponding gray level channel; calculating the average value of vectors from all pixel points to the central point in each sliding window to obtain the offset mean value of each sliding window, and moving the central point to the position of the offset mean value; in particular, will be described in
As a central point, to
Sliding window of radius is noted
In the sliding window
Each pixel point is marked as
The number of pixels contained in the sliding window is recorded as
And the mean of the shifts are recorded as
Then, there are:
and moving the central point of the sliding window, and calculating the density of the pixel points in the sliding window until no direction exists to enable the sliding window to contain more points, namely the density of the pixel points of the sliding window is not increased any more. Wherein the time will be at
The window center in the state is recorded as
Time of day
The window center in the state is recorded as
At the time of day
The mean shift of the window under the state is recorded as
Then, there are:
when a plurality of sliding windows are overlapped, the window with the maximum density is reserved, the window center is a cluster center, and the number of the cluster centers is the number of clusters obtained by clustering, namely the number of cluster categories.
By adopting the clustering method, a plurality of clusters can be obtained in each gray level channel, different gray levels have different clusters, and the gray levels in each cluster are the same, namely the pixel values in each cluster are the same.
Step S004, for each first pixel point in the difference quantization image, a cluster which is closest to the first pixel point in each gray level channel is a first cluster, and a leather pixel difference vector is obtained according to a vector from the first pixel point to each first cluster; and fusing all leather pixel difference vectors corresponding to each first pixel point to obtain a first fusion vector.
Because the texture on the normal leather surface is the natural texture formed by animals in the growing period, when the area without the scabies defect exists, the first fusion vectors among the pixel points are similar, namely, a similar distribution rule exists around each pixel point. The scabies defect area is formed because the skin is unhaired and pustule grows due to the livestock tinea, scabs are formed on the surface of the leather or are formed on the surface of the leather after various skin diseases are healed, the scabies are usually in a scab shape or a longan shape, and the scabies on the surface of the leather have obvious visual difference with the normal texture; that is, when the scabies defect exists, the distribution situation around the scabies defect pixel is obviously different from the distribution situation around the normal leather pixel. Therefore, whether the gray level distribution rule of the target pixel point suspected to be the scab defect is similar to the gray level distribution rule of the pixel point surrounding the normal area is compared to determine that the target pixel point belongs to the scab defect pixel point.
Specifically, since the leather pixel difference vectors in each gray scale channel are obtained in the same way, the second one
The steps of obtaining the leather pixel difference vector in each gray level channel are as follows: centered on the first pixel point
Single gray scale gateSearching a cluster center closest to the first pixel point in the road, namely calculating the distance between the cluster center of each cluster and the coordinate position of the first pixel point, and marking the cluster corresponding to the cluster center with the minimum distance as a first cluster; obtaining the first cluster in which the coordinate position of the first pixel point is taken as a starting point
Vector with coordinate position of each pixel point as terminal point
And recording the number of the pixel points in the first cluster as
And the obtained vector sequence from the first pixel point to all the pixel points in the first cluster is recorded as
The first step
The leather pixel difference vector for each gray level channel is recorded as
Then, there are:
the step of obtaining the first fusion vector by fusion comprises the following steps: multiplying all the leather pixel difference vectors by respective weights to obtain a first fusion vector; the weight is the ratio of the number of pixels of the first cluster corresponding to the corresponding pixel difference vector to the total number of pixels of all the first clusters.
Specifically, will be
The number of pixels in the first cluster in each gray scale channel is noted
The number of gray scale channels is noted
The first step
The weight of the leather pixel difference vector corresponding to each gray level channel is recorded as
Then, there are:
the more the number of pixels in the first cluster is, the larger the proportion of the total number of pixels in all the first clusters is, which indicates that more pixels with corresponding gray levels are closest to the first pixel, so that the weight of the corresponding leather pixel difference vector is higher.
Fusing all leather pixel difference vectors of the first pixel point to obtain a first fusion vector, and recording the first fusion vector as a
Then, there are:
and obtaining a first fusion vector of each pixel point in the difference quantization image by adopting the same method.
Step S005, obtaining a target pixel point in the difference quantization image, wherein the target pixel point is the corresponding pixel point with the largest pixel value in the difference image; the cluster closest to the target pixel point in each gray level channel is a second cluster; obtaining a leather maximum difference vector according to the vector from the target pixel point to each second cluster; and fusing all the leather maximum difference vectors corresponding to each target pixel point to obtain a second fusion vector.
Due to the difference betweenThe gray value of the scabies area in the value map is higher than that of the normal area, namely, the color is brighter and lighter visually, so that the probability that the point with the largest gray value in the difference map is the scabies defect pixel point is higher, the part of pixel points are obtained, the coordinate positions of the part of pixel points are obtained, and the pixel points of the corresponding coordinate positions are found in the difference quantization map as target pixel points through the coordinate positions; finding the cluster closest to the target pixel point in each gray level channel of the difference quantization image as a second cluster to obtain a first cluster in the second cluster by taking the target pixel point as a starting point
Vector with coordinate position of each pixel point as terminal point
And recording the number of the pixel points in the first cluster as
And the obtained vector sequences from the target pixel point to all the pixel points in the second cluster are recorded as
First, a
The maximum difference vector of the leather for each gray level channel is recorded as
Then, there are:
the step of obtaining the second fusion vector by fusion comprises the following steps: multiplying the maximum difference vectors of all the leathers by the respective weights to obtain a second fusion vector; the weight is the ratio of the number of pixels of the second cluster corresponding to the corresponding maximum difference vector to the total number of pixels of all the second clusters.
In particular toTo be compared with
The number of pixels in the second cluster in each gray scale channel is noted
The first step
The weight of the leather maximum difference vector corresponding to each gray level channel is recorded as
Then, there are:
the larger the number of pixels in the second cluster is, the larger the proportion of the pixels in the total number of pixels in all the second clusters is, which indicates that more pixels with corresponding gray levels are closest to the target pixel, and therefore the weight of the corresponding leather maximum difference vector is higher.
Step S006, calculating the similarity between the first fusion vector of each first pixel point and the second fusion vector of the target pixel point to obtain a leather difference value symbiotic image.
And calculating the cosine similarity between the first fusion vector of each first pixel point and the second fusion vector of the target pixel point. Traversing each first pixel point in the difference image, and calculating the cosine similarity between each first pixel point and the target pixel point, namely, each first pixel point corresponds to one cosine similarity, so as to obtain a leather difference symbiotic image taking the cosine similarity as the pixel value of the pixel point.
Preferably, when a plurality of target pixel points exist, the second fusion vector of each target pixel point is calculated, and the similarity between each second fusion vector and each first fusion vector is calculated according to the average value of the second fusion vectors of all the target pixel points.
The cosine similarity can reflect the similarity of the two vectors, the spatial relation and distribution of normal leather pixels and scab pixels in the leather difference quantization diagram can be well reflected through the cosine similarity, and the greater the similarity is, the greater the possibility that the corresponding first pixel point has scab defects is; the smaller the similarity is, the less the possibility that the corresponding first pixel point is a scab defect.
And step S007, inputting the surface image to be detected and the leather difference value symbiotic image into a semantic segmentation network to obtain a defect detection result.
In the detection process, the surface image to be detected and the leather difference value symbiosis image are simultaneously input into the semantic segmentation network to obtain a detection result, and if a scab area exists in the surface image to be detected, the semantic segmentation result can obtain a corresponding semantic area of the scab area.
The semantic segmentation network adopts a two-input single-output coding and decoding structure, namely a neural network adopting two encoders and a decoder structure, and the training process of the semantic segmentation network comprises the following steps: the method comprises the steps of taking a surface image to be detected as a sample image, labeling different types of scabies areas in the sample image, labeling pixel points of scabies defect areas as 1, labeling pixel points of normal leather areas as 0, taking the sample image with the labels as the input of one encoder and the leather symbiotic image as the input of the other encoder in a semantic segmentation network, taking feature graphs extracted by the two encoders as the input of a decoder, and outputting a final segmentation result by the decoder. The loss function adopted by the semantic segmentation network is a cross entropy loss function. Adam is used as an optimization algorithm to optimize weight and deviation parameters of the neural network.
In the semantic segmentation network, labels are information for artificially labeling different types of defects, the labels are used as supervision information to enable the network to pay more attention to gray level difference between pixel values, and the leather difference value symbiotic image is used as the supervision information to enable the network to increase the attention to pixel points with larger similarity and reduce the attention to pixel points with smaller similarity.
In conclusion, the embodiment of the invention discloses a method for detecting the scab defect of a flexible leather material based on artificial intelligence, the method obtains a difference image between a surface image to be measured and a standard image of a non-defective leather area, quantizes the difference image to obtain a quantized image, clustering pixel points of each gray level in a quantized image to obtain a plurality of clusters, calculating a first fusion vector between each pixel point in the quantized image and the nearest cluster in each gray level and a second fusion vector between a target pixel point in the quantized image and the nearest cluster in each gray level, calculating the similarity between the first fusion vector and the second fusion vector to obtain a leather difference value symbiotic image taking the similarity as a pixel value, and taking the leather difference value symbiotic image and a surface image to be measured as the input of a semantic segmentation network, so that the output result of the semantic segmentation network is more accurate. The technical problem that noise points and texture features similar to scabies defects are easily identified as scabies in the prior art is solved.
Based on the same inventive concept as that of the foregoing method embodiment, another embodiment of the present invention further provides an artificial intelligence-based flexible leather material scab defect detection system, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the artificial intelligence-based flexible leather material scab defect detection method according to any one of the foregoing embodiments when executing the computer program, where the artificial intelligence-based flexible leather material scab defect detection method has been described in detail in the foregoing embodiments, and is not described again.
It should be noted that: the precedence order of the above embodiments of the present invention is only for description, and does not represent the merits of the embodiments. And that specific embodiments have been described above. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.