Detailed Description
It is to be understood that the following detailed description is exemplary and is intended to provide further explanation of the invention as claimed. 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.
It is noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of exemplary embodiments according to the invention. As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, and it should be understood that when the terms "comprises" and/or "comprising" are used in this specification, they specify the presence of stated features, steps, operations, devices, components, and/or combinations thereof, unless the context clearly indicates otherwise. It is to be understood that the scope of the invention is not to be limited to the specific embodiments described below; it is also to be understood that the terminology used in the examples is for the purpose of describing particular embodiments only, and is not intended to limit the scope of the present invention.
Components that can be used to perform the disclosed methods and systems are disclosed. These and other components are disclosed herein, and it is understood that when combinations, sub-groups, interactions, groups, etc. of these components are disclosed that while specific reference of each various individual and collective combinations and permutations of these components may not be explicitly disclosed, each is specifically contemplated and described herein for all methods and systems. This applies to all aspects of the present application including, but not limited to, steps in the disclosed methods. Thus, if there are a variety of additional steps that can be performed, it is understood that each of these additional steps can be performed using any particular embodiment or combination of embodiments of the disclosed methods.
As mentioned earlier, the automated detection of disease by applying plant leaf symptoms in cotton leaf blight detection can reduce a lot of monitoring work in the field of macrophytes, and is a relatively inexpensive and more efficient solution. The quality of the disease leaf segmentation can directly influence the reliability and accuracy of plant disease detection, however, the single traditional image segmentation method is greatly influenced by factors such as illumination, shadow, weather and the like, and is difficult to directly apply to cotton images in various complex natural environments, so that the detection of leaf blight is more difficult.
In view of the above, in one embodiment of the present invention, a cotton leaf blight detection method based on color features and super-pixel clustering is provided, which includes:
clustering the acquired cotton leaf images so as to increase the discrimination of a foreground region and a background region to which the leaf parts belong in the images;
recombining and enhancing the green part area of the image by using the RGB components;
performing self-adaptive threshold segmentation processing on the image to obtain an initial segmentation image;
and performing morphological processing and connected region area processing on the initial segmentation image, performing superpixel segmentation, detecting each superpixel block according to a threshold value, and outputting a detection result.
In one embodiment of the invention, the clustering employs a fuzzy C-means clustering algorithm (FCM), which is a partition-based algorithm, the basic idea being to maximize the similarity between objects partitioned into the same cluster and minimize the similarity between different clusters. The fuzzy C-means algorithm is an improvement of a common C-means algorithm, the probability that a sample belongs to a certain class is represented by using the membership degree, and the obtained clustering result is more flexible.
In a specific embodiment of the invention, the clustering number is set to be 5, the parameter m is set to be 2, clustering is carried out, finally, the cotton leaves and the background can be well distinguished according to a clustering result, and meanwhile, dead leaf parts and normal leaf parts are classified into one type, which is very beneficial to the extraction of the following leaves.
The RGB component recombination specifically comprises the following steps: the super-green color index, ExG, is used, minus the super-red color index ExR, ExG-ExR. The method has good effect on extracting green plant images, shadows, hay, soil images and the like can be obviously inhibited, and the green part of the images is more prominent.
The adaptive threshold segmentation processing is performed using an Otsu adaptive threshold algorithm. The algorithm divides the image into a background part and a target part according to the gray characteristic of the image, and automatically selects a threshold value for segmentation; and other parameters do not need to be set manually, so that the method is simple to realize and stable in performance. The method can accurately and effectively segment the cotton leaves from the image.
The morphological processing and the communicated region area processing specifically comprise performing processing by adopting morphological opening operation, morphological closing operation and setting an area threshold;
wherein the opening operation can eliminate elongated protrusions, remove burrs and petiole edges. The closed operation can effectively fill the holes on the blades and simultaneously smooth the damaged blade edges. In order to make the effect more obvious, the number of iterations selected in the invention is 3.
For ground weeds, the area occupied in the segmented image will be much smaller than the blades, and the processing is performed by setting an area threshold. Specifically, a connected region in the entire segmented image is detected, and a weed part is determined if the area is smaller than a threshold value, and the weed part is removed from the segmented image. And calculating the area of the final processing result, namely the area of the blade in the original image.
The super-pixel segmentation adopts a linear iterative clustering (SLIC) method, which converts a color image into a CIELAB color space and 5-dimensional feature vectors under XY coordinates, and then constructs a distance measurement standard for the 5-dimensional feature vectors to perform local clustering on image pixels. The extracted blade is segmented by the SLIC algorithm, compact and approximately uniform superpixels can be generated, and meanwhile, the operation speed and the object contour keeping aspect are excellent.
The specific method for detecting each super-pixel block according to the threshold and outputting the detection result comprises the following steps: by executing the superpixel segmentation algorithm by setting the size of each superpixel in advance, the leaf extracted from the original image is segmented into a plurality of superpixel blocks having the same or similar characteristics in color, brightness, and texture, and is also excellent for edge processing of an object. By taking each super-pixel block, the conversion is to the hsv color space. The set dead leaf threshold range is detected as a dead leaf portion if the pixel is therein.
And detecting the proportion occupied by the dead leaf area of the superpixel block, if the proportion is less than 20%, discarding the superpixel block, if the proportion is more than 80%, detecting the superpixel block as a dead leaf part, and only keeping the part detected as the dead leaf between the superpixel block and the superpixel block. By this method, errors caused by threshold setting can be effectively avoided. And finally, summarizing to obtain a dead leaf area of the whole cotton leaf, drawing the outline of a disease area in an original drawing, and simultaneously giving the disease degree of the leaf. The calculation here is the ratio of the area of the dead leaf region to the entire leaf (excluding the background).
In one embodiment of the present invention, the size of one super pixel set in advance is 500; the set dead leaf threshold range is (32,25,25), (78,255,255).
In one embodiment of the invention, a cotton leaf blight detection system based on color features and super-pixel clustering is provided, the system comprising:
the cotton leaf image acquisition module is used for acquiring cotton leaf image data;
the clustering module is used for clustering the cotton images so as to increase the distinguishing degree of a foreground region and a background region to which the leaf parts in the images belong;
the RGB component recombination module is used for enhancing the green part area of the image;
the adaptive threshold segmentation processing module is used for obtaining an initial segmentation image;
a morphological treatment and connected area treatment module for eliminating elongated protrusions, removing burrs and petiole edges; filling holes on the blades and smoothing damaged blade edges; and removing the weed part;
the super-pixel segmentation module is used for segmenting and distinguishing a dead leaf region and a normal leaf region of the extracted cotton leaves without considering edge segmentation;
and the result output module is used for detecting the dead leaf area of each superpixel block by setting a threshold value, processing according to the area ratio and outputting the disease degree and the detection result of the cotton leaves.
In a specific embodiment of the present invention, a non-transitory computer program product is provided, comprising computer executable code segments stored on a computer readable medium for performing the steps performed by the color feature and super pixel clustering based cotton leaf blight detection method described above.
In one embodiment of the present invention, a computer-readable storage medium is provided for storing computer instructions, which when executed by a processor, perform the steps of the cotton leaf blight detection method based on color features and super-pixel clustering.
The invention is further illustrated by the following examples, which are not to be construed as limiting the invention thereto. It should be understood that these examples are for illustrative purposes only and are not intended to limit the scope of the present invention.
Example 1
A cotton leaf blight detection method based on color features and super-pixel clustering comprises the following steps:
1. and (3) clustering the cotton leaves by using a fuzzy C-means clustering algorithm, and increasing the distinguishing degree of the leaves and the background in the image.
Cotton images in natural environments have a lot of interference factors such as illumination, shielding and shadow, and results obtained by directly applying a segmentation algorithm are usually poor. The leaves to be detected are extracted in advance, and the irrelevant background is removed and then the leaves are segmented, so that the segmentation accuracy can be effectively improved.
The fuzzy C-means clustering algorithm (FCM) is a partition-based algorithm, and the basic idea is to maximize the similarity between objects partitioned into the same cluster, and minimize the similarity between different clusters. The fuzzy C-means algorithm is an improvement of a common C-means algorithm, the probability that a sample belongs to a certain class is represented by using the membership degree, and the obtained clustering result is more flexible. According to the method, the number of clusters is set to be 5, the parameter m is set to be 2, the cotton leaves can be well distinguished from the background by the final clustering result, and meanwhile, the dead leaf part and the normal leaf part are classified into one type, so that the method is very beneficial to the extraction of the following leaves.
FCM by minimizing an objective function JmAnd (3) realizing clustering with the constraint conditions (2):
wherein c represents the number of clustering centers, and n is the number of samples. m is a membership factor representing how important the sample belongs to a class. u. ofijIndicating the degree of membership of sample j to class i. x is the number ofjIs the jth sample set, ciIs the cluster center of the i cluster, and | x | represents the euclidean distance.
The specific implementation flow of the FCM algorithm is as follows:
step 1: randomly selecting a random number with a value between 0 and 1, initializing a membership matrix U to meet the constraint condition in the formula (2), namely setting the membership sum of each sample to each class to be 1, and simultaneously setting the clustering number c and the parameter m.
Step 2: c of c clustering centers is calculated according to the membership matrix Ui:
And step 3: updating the membership value u according to the obtained clustering centerij:
And 4, step 4: comparing the membership degree matrix between two iterations by using a matrix norm, stopping the iteration if a given threshold condition is met, otherwise, circulating the steps 2 and 3, and continuously iterating and calculating the membership degree uijAnd cluster center ciAnd reaching the optimal state until the termination condition is met.
Termination conditions of the iteration:
||Uk+1-UK||<ε (5)
where k is the number of iteration steps and epsilon is the error threshold.
2. The RGB components were used to reconstruct the ultragreen index ExG, minus the ultrared index ExR, to enhance the contrast between the green part of the leaf and the background.
In the clustered image, the partial green area and the background area are not obvious, and some irrelevant areas exist, and are solved through RGB component recombination. For an RGB color image, the RGB color image is separated into three independent primary color planes of R, G and B, and each pixel point in the image is converted through different color characteristic combinations, so that the aim of enhancing the contrast ratio of a target crop and a background in the image can be fulfilled. The RGB components adopted in the invention are recombined into an ultragreen color index ExG, and an ultrared color index ExR is subtracted, namely ExG-ExR. The method has good effect on extracting green plant images, shadows, hay, soil images and the like can be obviously inhibited, and the green part of the images is more prominent.
ExG=2G-R-B (6)
ExR=1.4R-G-B (7)
3. And performing adaptive threshold segmentation on the image based on Otsu to obtain an initial segmented image.
In order to segment the cotton image obtained by the ExG-ExR in the previous step, whether each pixel belongs to the leaf or the background can be further judged by setting a fixed threshold. The method has the defects that a fixed threshold value cannot be applied to all images, and the segmentation effects of different images have certain difference. The Otsu self-adaptive threshold algorithm is used for segmenting the image, the image is divided into a background part and a target part according to the gray characteristic of the image, the threshold is automatically selected by the algorithm for segmentation, other parameters do not need to be set manually, and the method is simple to implement and stable in performance. The method can accurately and effectively segment the cotton leaves from the image.
4. The morphological method processes the holes and isolated points of the segmented image and removes the parts with smaller area of the connected region.
The background of the cotton image taken in the natural environment usually includes various weeds which are irregularly distributed and occupy a certain area of the image. Because the color of the weeds is very similar to the color of the leaves, the image preprocessing cannot be solved through clustering and RGB component recombination, so that the weeds are mistaken for the leaves by the Otsu algorithm and also occupy a part in the initial segmentation image, and therefore the weeds need to be processed. Morphological opening operations can eliminate long and thin protrusions, remove burrs and petiole edges. The closed operation can effectively fill the holes on the blades and simultaneously smooth the damaged blade edges. For the effect to be more pronounced, the number of iterations is chosen to be 3. For ground weeds, the area occupied in the segmented image will be much smaller than the blades, and the processing is performed by setting an area threshold. And detecting a connected region in the whole segmentation image, and removing the weed part if the area is smaller than the threshold value. And calculating the area of the final processing result, namely the area of the blade in the original image.
5. And extracting a blade part according to the segmentation image, and executing a superpixel segmentation algorithm.
From the processed segmented image, the leaf portion is extracted by applying to the original image, while the background is set to black by default. For the convenience of the following processing, the black background is replaced with green, and the background is considered to be a normal green part, which is more advantageous for further processing.
Superpixels can reduce computational overhead by replacing the standard pixel grid by combining pixels into original regions that are more perceptually meaningful than individual pixels, and improve the performance of the segmentation algorithm by reducing irrelevant details. The invention selects a linear iterative clustering (SLIC) method with simple thought and convenient realization, which carries out local clustering on image pixels by converting a color image into a CIELAB color space and 5-dimensional characteristic vectors under XY coordinates and then constructing a distance measurement standard for the 5-dimensional characteristic vectors. The extracted blade is segmented by the SLIC algorithm, compact and approximately uniform superpixels can be generated, and meanwhile, the operation speed and the object contour keeping aspect are excellent.
The specific implementation flow of the SLIC algorithm is as follows:
step 1: an initialization algorithm: let (r, g, b) be the three color components of the pixel, (x, y) be the two spatial coordinates of the pixel, ntpTotal number of pixels in the image, nspThe images are obtained by sampling regular networks with a space of s units, where s is [ n ]to/nsp]1/2。
And sampling the image according to the step length s of the standard grid, and calculating an initial super-pixel clustering center.
mi=[ri,gi,bi,xi,yi]T,i=1,2,...nsp (8)
The cluster center is moved to the minimum gradient position in the 3x3 domain, and for each pixel position p in the image, the label l (p) ═ 1 and d (p) ═ infinity of the distance are set.
Step 2: assigning samples to cluster centers: for each cluster mi,i=1,2,...,nspIn a respect of miIn the neighborhood of 2sx2s, m is calculatediA distance D from each pixel pi(p) of the formula (I). Then, for each p and i, 1,2spIf D isi<D (p), then D (p) is equal to DiAnd l (p) ═ i.
And step 3: updating a clustering center: let CiRepresenting a set of pixels in the image with a label L (p) ═ i, updating mi。
Wherein, | CiIs set CiWherein z is [ r, g, b, x, y ═ r]T。
And 4, step 4: and (3) testing the convergence: the euclidean norm of the difference between the average vectors in the current step and the previous step is calculated. Calculating the residual E, i.e. nspSum of the individual norms. If E<T, where T is a defined non-negative threshold, step 5 is entered, otherwise step 2 is returned.
And 5: post-processing super-pixel area: each region CiIn which all super-pixels are replaced by their mean value mi。
SLIC superpixels correspond to clusters in a space, this space coordinate is a color and space variable, and the space distance and the color distance need to be processed separately. First by normalizing the distances of the individual components and then combining them into a single measure. Let dcAnd dsThe color distance and the spatial Euclidean distance between two points in the cluster are respectively:
dc=[(rj-ri)2+(gj-gi)2+(bj-bi)2]1/2 (10)
ds=[(xj-xi)2+(yj-yi)2]1/2 (11)
then define D as the composite distance:
D=[(dc/dcm)2+(ds/dsm)2]1/2 (12)
in the formula dcmAnd dsmIs dcAnd dsThe maximum expected value of (c). The maximum spatial distance should correspond to the sampling interval, i.e. dsm=s=[ntp/nsp]1/2. The maximum color distance may vary from cluster to cluster or from image to image. The solution is that dcmSet to a constant c such that equation (12) is:
D=[(dc/c)2+(ds/s)2]1/2 (13)
in three dimensions the superpixel becomes a superpixel, dsIs defined as:
ds=[(xj-xi)2+(yj-yi)2+(zj-zi)2]1/2 (14)
where z is the coordinate of the third spatial direction, and a third spatial variable is added to equation 9, i.e., z ═ r, g, b, x, y, z]T。
6. And detecting whether each superpixel block is a disease area or not, and giving out the degree of the leaf diseases.
By executing the superpixel segmentation algorithm by setting the size of each superpixel in advance (500 in the present invention), the leaf extracted from the original image is segmented into a plurality of superpixel blocks having the same or similar characteristics in color, brightness, and texture, and is also excellent for edge processing of an object. By taking each super-pixel block, the conversion is to the hsv color space. The set dead-leaf threshold range is (32,25,25), (78,255,255), and if the pixel is among them, a dead-leaf portion is detected.
And detecting the proportion occupied by the dead leaf area of the superpixel block, if the proportion is less than 20%, discarding the superpixel block, if the proportion is more than 80%, detecting the superpixel block as a dead leaf part, and only keeping the part detected as the dead leaf between the superpixel block and the superpixel block. By this method, errors caused by threshold setting can be effectively avoided. And finally, summarizing to obtain a dead leaf area of the whole cotton leaf, drawing the outline of a disease area in an original drawing, and simultaneously giving the disease degree of the leaf. The calculation here is the ratio of the area of the dead leaf region to the entire leaf (excluding the background).
Example 2
A cotton leaf blight detection system based on color features and superpixel clustering, the system comprising:
the cotton leaf image acquisition module is used for acquiring cotton leaf image data;
the clustering module is used for clustering the cotton images so as to increase the distinguishing degree of a foreground region and a background region to which the leaf parts in the images belong;
the RGB component recombination module is used for enhancing the green part area of the image;
the adaptive threshold segmentation processing module is used for obtaining an initial segmentation image;
a morphological treatment and connected area treatment module for eliminating elongated protrusions, removing burrs and petiole edges; filling holes on the blades and smoothing damaged blade edges; and removing the weed part;
the super-pixel segmentation module is used for segmenting and distinguishing a dead leaf region and a normal leaf region of the extracted cotton leaves without considering edge segmentation;
and the result output module is used for detecting the dead leaf area of each superpixel block by setting a threshold value, processing according to the area ratio and outputting the disease degree and the detection result of the cotton leaves.
Example 3
An electronic device includes a memory, a processor, and a computer instruction stored in the memory and running on the processor, where the computer instruction is executed by the processor to complete each operation in the method of embodiment 1, and for brevity, details are not described here again.
The electronic device may be a mobile terminal and a non-mobile terminal, the non-mobile terminal includes a desktop computer, and the mobile terminal includes a Smart Phone (such as an Android Phone and an IOS Phone), Smart glasses, a Smart watch, a Smart bracelet, a tablet computer, a notebook computer, a personal digital assistant, and other mobile internet devices capable of performing wireless communication.
It is to be understood that in the present invention, the processor may be a central processing unit CPU, but may also be other general purpose processors, digital signal processors DSP, application specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory may include both read-only memory and random access memory, and may provide instructions and data to the processor, and a portion of the memory may also include non-volatile random access memory. For example, the memory may also store device type information.
In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in a processor or instructions in the form of software. The steps of a method disclosed in connection with the present invention may be embodied directly in a hardware processor, or in a combination of the hardware and software modules within the processor. The software modules may be located in ram, flash, rom, prom, or eprom, registers, among other storage media as is well known in the art. The storage medium is located in a memory, and a processor reads information in the memory and completes the steps of the method in combination with hardware of the processor. To avoid repetition, it is not described in detail here. Those of ordinary skill in the art will appreciate that the various illustrative elements, i.e., algorithm steps, described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is merely a division of one logic function, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some interfaces, and may be in an electrical, mechanical or other form.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied 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 method according to the embodiments of the present application. 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.
It should be noted that the above examples are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to the examples given, those skilled in the art can modify the technical solution of the present invention as needed or equivalent substitutions without departing from the spirit and scope of the technical solution of the present invention.