Segmentation method, recognition method, medium and device for cyanobacteria images
By denoising, grayscale and contour segmenting the cyanobacteria image, a three-channel color image segmentation network model was constructed, which solved the problem of low cyanobacteria image segmentation efficiency and low recognition accuracy, and achieved more efficient and accurate segmentation and recognition effects.
Patent Information
- Application Number
- CN202411002333.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-25
AI Technical Summary
In the existing technology, the efficiency of cyanobacteria image segmentation is not high, and the recognition accuracy needs to be improved. The traditional method is inefficient and the accuracy fluctuates greatly due to personal experience.
By obtaining the original image of the water sample and its preprocessed image, denoising, grayscale, binary segmentation and contour segmentation are performed to build a three-channel color image segmentation network model, train and apply it to improve segmentation accuracy and recognition accuracy.
It improves the efficiency and recognition accuracy of cyanobacteria image segmentation, reduces noise, enhances contour information, reduces noise from a single information source, and improves the reliability of segmentation results.
Smart Images

Figure CN118552571B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of image processing and recognition, and in particular to a segmentation method, a recognition method, a medium and a device for cyanobacteria images. Background Art
[0002] With the increasing awareness of environmental protection, the treatment of blue algae has attracted much attention. In traditional technology, microscopes are mainly used to continue the traditional "manual microscopic inspection" method to identify, record and count algae. This method is not only inefficient, but also has a large fluctuation in accuracy due to personal experience.
[0003] In recent years, some automatic algae counting products have emerged, but the segmentation efficiency is not high and the recognition accuracy needs to be improved. How to optimize and improve them is a technical problem that needs to be solved urgently in this field. Summary of the invention
[0004] Based on this, the purpose of the present application is to provide a segmentation method, recognition method, medium and device for cyanobacteria images to solve at least one technical problem mentioned in the above background technology.
[0005] In a first aspect, the present application provides a segmentation method for cyanobacteria images, comprising:
[0006] S1: Obtaining original images of several water samples and pre-processed images of the original images;
[0007] S2: according to the original image and the preprocessed image of the original image, obtaining the grayscale image of the original image and the grayscale image of the preprocessed image, and performing binary segmentation on the grayscale image of the preprocessed image to obtain a binary image corresponding to the preprocessed image;
[0008] S3: Obtain the contour edge in the binary image, and set a geometric threshold to segment contours of different shapes to obtain a preliminary segmentation contour map;
[0009] S4: Fuse the original image grayscale image, the preprocessed image grayscale image and the preliminary segmentation contour image to obtain a three-channel color image;
[0010] S5: constructing a segmentation network model with a three-channel color image as input and a cyanobacteria contour image as output, and constructing a training data set according to steps S1-S4, inputting the segmentation network model, so as to train and obtain a trained segmentation network model;
[0011] S6: Obtain the original image of the current water body sample, and according to steps S2-S4, obtain the current three-channel color image corresponding to the original image of the current water body sample;
[0012] S7: inputting the current three-channel color image into the trained segmentation network model to obtain the contour image of each cyanobacteria in the current three-channel color image;
[0013] S8: Using each cyanobacteria outline image in the current three-channel color image as a mask, and extracting all cyanobacteria target small images in the original image according to the mapping relationship between the target frame of each mask and the original image, to obtain the final cyanobacteria image segmentation result.
[0014] Further, the step of obtaining a preprocessed image of the original image includes:
[0015] De-noising the original image to obtain a denoised image;
[0016] Convert the denoised image to the YCrCb color space, obtain the initial brightness channel image and color channel image, and obtain the global mean of the initial brightness channel image;
[0017] Obtain the local mean map and local variance map of the initial brightness channel image;
[0018] According to the initial brightness channel image, the global mean of the initial brightness channel image, the local mean map and the local variance map of the initial brightness channel image, the brightness value of each pixel is calculated to obtain the final brightness channel image:
[0019] The color channel image and the final brightness channel image are fused to obtain a preprocessed image of the original image.
[0020] Furthermore, the specific steps of calculating the brightness value of each pixel and obtaining the final brightness channel image include:
[0021] 1-1
[0022] Among them, yImgEn is the final brightness channel image, lMImg is the local mean map of the initial brightness channel image, α is the weight coefficient, gMean is the global mean of the initial brightness channel image, yImg is the initial brightness channel image, and lVImg is the local variance map of the initial brightness channel image.
[0023] Furthermore, the specific steps of obtaining the binary image corresponding to the preprocessed image include:
[0024] Get the grayscale image of the preprocessed image;
[0025] A first threshold is set, pixels in the grayscale image of the preprocessed image that are higher than the threshold are modified to a first pixel value, and pixels that are lower than the threshold are modified to a second pixel value, to obtain a first binary image corresponding to the grayscale image of the preprocessed image;
[0026] A second threshold is set, pixels below the threshold in the grayscale image of the preprocessed image are modified to the first pixel value, and pixels above the threshold are modified to the second pixel value, so as to obtain a second binary image corresponding to the grayscale image of the preprocessed image;
[0027] Performing an AND operation on the first binary image and the second binary image to obtain a mask area image;
[0028] The grayscale mean of the mask area is obtained and the background error value is set to obtain the background pixel value interval, the pixels in the grayscale image whose grayscale values are within the interval are modified to the second pixel value, and the pixels in the grayscale image whose grayscale values are not within the interval are modified to the first pixel value, to obtain the final binary image.
[0029] Further, the steps of obtaining the contour edge in the binary image and setting a geometric threshold to segment contours of different shapes to obtain a preliminary segmentation contour map include:
[0030] Get all contours in the binary image and get the optimized binary image;
[0031] An area threshold is set to segment the algae contour in the optimized binary image and obtain a preliminary segmentation contour map.
[0032] Furthermore, the step of obtaining a preliminary segmentation contour map also includes:
[0033] Set the ellipticity threshold to obtain a circular outline in the algae outline; or / and, set the aspect ratio, curvature and rectangle saturation thresholds to obtain a square outline in the algae outline; or / and, set the straight line length and transverse line length thresholds to obtain a rectangular outline in the algae outline.
[0034] Furthermore, the specific structure of the segmentation model includes:
[0035] Input layer: used to input the acquired three-channel color image;
[0036] Initial layer: connected to the input layer, used to extract the image features of the three-channel color image and obtain the initial feature map;
[0037] The multi-layer perceptron convolutional layer is connected to the initial layer to extract the features of the initial feature map and obtain the second feature map;
[0038] The maximum pooling layer is connected to the multi-layer perceptron convolutional layer to downsample the second feature map to obtain an optimized feature map;
[0039] Middle layer: connected to the maximum pooling layer, used to extract the abstract features in the optimized feature map to obtain the final feature map;
[0040] Decoder: connected to the middle layer, used to upsample the final feature map to obtain the segmented image;
[0041] Output layer: connected to the decoder to output the segmented image.
[0042] In a second aspect, the present application also provides a method for identifying cyanobacteria images, comprising:
[0043] Establish and train a recognition network model that takes the cyanobacteria image segmentation results as input and the corresponding cyanobacteria names as output;
[0044] Acquire an original image of the current water sample, and obtain a current cyanobacteria image segmentation result according to any segmentation method described in the first aspect;
[0045] Input the current cyanobacteria image segmentation result into the trained recognition network model to obtain the corresponding cyanobacteria name;
[0046] According to the acquired names of cyanobacteria, the ecological data of various types of cyanobacteria are counted to complete the recognition of cyanobacteria images.
[0047] In a third aspect, the present application further provides a computer storage medium storing an executable program code; the executable program code is used to execute any of the above-mentioned segmentation methods for cyanobacteria images or any of the above-mentioned recognition methods for cyanobacteria images.
[0048] In a fourth aspect, the present application also provides a terminal device, comprising a memory and a processor; the memory stores a program code that can be executed by the processor; the program code is used to execute any of the above-mentioned segmentation methods for cyanobacteria images or any of the above-mentioned recognition methods for cyanobacteria images.
[0049] The present invention provides a segmentation method for cyanobacteria images. By acquiring original images of several water samples and pre-processed images thereof, random noise in the image is reduced, the image is made clearer, and details are more prominent, which is helpful to improve the accuracy and efficiency of subsequent processing tasks such as segmentation, classification and recognition. Then, according to the original image, the original image grayscale image and the pre-processed image grayscale image are acquired, and the pre-processed image grayscale image is binary-segmented to obtain a binary image corresponding to the pre-processed image, reduce the image grayscale level, highlight the key information of the image, reduce the amount of calculation, and improve the processing speed, so as to facilitate subsequent segmentation operations. Then, the contour edge in the binary image is acquired, and a geometric threshold is set to segment contours of different shapes to obtain a preliminary segmented contour map, and contours of different types are segmented. Classification, reduce the amount of processing in subsequent steps, fuse the original image grayscale image and the preprocessed image grayscale image and the preliminary segmentation contour image to obtain a three-channel color image, and then retain the detail information of the original image in subsequent segmentation, enhance the contour information and improve the segmentation accuracy. At the same time, by fusing information from different sources, it can reduce the noise that may exist in a single information source and improve the reliability of the segmentation results, thereby constructing and training a segmentation network model with a three-channel color image as input and a cyanobacteria contour image as output. Finally, the original image of the current water sample and the corresponding current three-channel color image are obtained, and the current three-channel color image is input into the trained segmentation network model to obtain the cyanobacteria contour images in the current three-channel color image, as well as the cyanobacteria target small image corresponding to the cyanobacteria contour image in the original image. The problem of low efficiency of cyanobacteria image segmentation and the need to improve recognition accuracy in the prior art is solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 is a flow chart of a segmentation method for cyanobacteria images according to an embodiment of the present invention;
[0051] Figure 2 is an original image of a water sample according to an embodiment of the present invention;
[0052] Figure 3 It is a preliminary segmentation contour map of an embodiment of the present invention;
[0053] Figure 4 Schematic diagram of the structure of a multi-layer perceptron convolutional layer in a segmentation network model of an embodiment of the present invention;
[0054] Figure 5 A schematic diagram of the main structure of a segmentation network model according to an embodiment of the present invention;
[0055] Figure 6 is a flow chart of a method for identifying cyanobacteria images according to an embodiment of the present invention;
[0056] Figure 7 Schematic diagram of the structure of the recognition network model according to an embodiment of the present invention. DETAILED DESCRIPTION
[0057] 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.
[0058] It should be noted that if the embodiments of the present invention involve directional indications, such as up, down, left, right, front, back, etc., then the directional indication is only used to explain the relative position relationship, movement status, etc. between the components in a certain specific posture. If the specific posture changes, the directional indication will also change accordingly. In addition, if the embodiments of the present invention involve descriptions of "first, second", "S1, S2", "step one, step two", etc., then such descriptions are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of indicated technical features or indicating the execution order of the method, etc. Those skilled in the art can understand that anything that does not violate the gist of the invention under the technical concept of the invention should be included in the protection scope of the present invention.
[0059] like Figure 1 As shown, the present invention provides a segmentation method for cyanobacteria images, comprising:
[0060] S1: Obtaining original images of several water samples and pre-processed images of the original images;
[0061] Specifically, it is optional but not limited to obtaining several liters of original water sample, removing the supernatant after sedimentation and stirring evenly, then extracting some liquid and preferably putting it into a glass slide and smearing it evenly, so as to use an image scanning device to obtain the original image of the water sample at a set collection interval.
[0062] More specifically, the image scanning equipment may be, but is not limited to, 3D line scan cameras, 3D structured light cameras, TOF cameras, laser scanners, multi-view stereo vision systems, grating projection measuring instruments, and other commonly used scanning equipment that can be used to acquire surface data of objects; the water sample volume and collection interval are arbitrarily set by technicians in this field according to on-site environment, process, and other conditions.
[0063] For example, obtain 1 liter of original water sample, add fixative and shake evenly, then put it into a container to settle for 24 hours, remove the supernatant, retain 30 ml of water sample, and stir and / or shake it evenly, then extract 0.1 ml of water sample and add it to a standard glass slide, cover it with a cover glass, so that the water sample is evenly distributed on the slide, establish a rectangular coordinate system with the lower left corner of the slide as the origin, the right side of the origin is the positive direction of the x-axis, and the top of the origin is the positive direction of the y-axis, use an image scanning device to collect an image every 10 fields of view along the x-axis and y-axis, and obtain the following Figure 2 The original image of the current water sample is shown.
[0064] Preferably, since different detection agencies may have different detection standards, different acquisition intervals may be set to acquire images of water samples.
[0065] More preferably, the step of obtaining a preprocessed image of the original image may optionally include, but is not limited to, denoising and brightness enhancement of the original image, and may optionally include:
[0066] S11: De-noising the original image to obtain a de-noised image;
[0067] Specifically, it is preferred to denoise the original image according to a three-dimensional block matching algorithm (BM3D denoising algorithm) to effectively reduce the noise level of the image and obtain the denoised original image; further, the denoising algorithm may also be selected from but not limited to commonly used image denoising algorithms including a block sparse representation denoising algorithm (K-SVD algorithm), a neural network denoising algorithm (TNRD algorithm), a weighted block sparse representation denoising algorithm (WNNM algorithm), and the like.
[0068] S12: converting the denoised image into the YCrCb color space, obtaining an initial brightness channel image and a color channel image, and obtaining a global mean of the initial brightness channel image;
[0069] Specifically, it is optional but not limited to converting the denoised image from the RGB color space to the YCrCb color space according to a general color conversion formula to obtain an initial brightness channel (Y channel) image and color channel (chrominance red channel (Cr channel), chrominance blue channel (Cb channel)) image, and adding the brightness values of all pixels in the initial brightness channel image and dividing by the number of pixels to obtain the global mean of the initial brightness channel image.
[0070] S13: Obtain a local mean map and a local variance map of the initial brightness channel image;
[0071] Specifically, it is optional but not limited to dividing the image into several sub-images of equal size, calculating the average brightness value of all pixels in each sub-image, obtaining the local mean of the corresponding sub-image, changing the brightness value of all pixels in each sub-image to the corresponding local mean, and re-stitching them into an image of the same size as the original image, which is the local mean map of the initial brightness channel image; calculating the variance of the brightness value of all pixels in each sub-image, obtaining the local variance of the corresponding sub-image, changing the brightness value of all pixels in each sub-image to the corresponding local variance, and re-stitching them into an image of the same size as the original image, which is the local variance map of the initial brightness channel image; it is worth noting that the specific size of the sub-image is arbitrarily set by a technician in this field according to the size of the original image, so that the image can be divided into several sub-images of equal size.
[0072] Preferably, the size of the sub-image is 5×5 pixels.
[0073] S14: Calculate the brightness value of each pixel according to the brightness calculation formula 1-1 to obtain the final brightness channel image:
[0074] 1-1
[0075] Among them, yImgEn is the final brightness channel image, lMImg is the local mean map of the initial brightness channel image, α is the weight coefficient, gMean is the global mean of the initial brightness channel image, yImg is the initial brightness channel image, and lVImg is the local variance map of the initial brightness channel image.
[0076] S15: Fusing the color channel image and the final brightness channel image to obtain a preprocessed image of the original image.
[0077] Specifically, the color channel image and the final brightness channel image are converted into the RGB color space according to the general color conversion formula to obtain the preprocessed image.
[0078] Preferably, the color conversion formula may be selected but not limited to the formulas 1-2, 1-3, and 1-4:
[0079] 1-2
[0080] 1-3
[0081] 1-4
[0082] Among them, R, G and B are the pixel values of each pixel in the red, green and blue channels respectively, Y is the brightness value of each pixel in the final brightness channel, Cr and Cb are the pixel values of each pixel in the chromaticity red channel and chromaticity blue channel in the YCrCb color space respectively.
[0083] S2: According to the original image and the preprocessed image of the original image, obtain the grayscale image of the original image and the grayscale image of the preprocessed image, and perform binary segmentation on the grayscale image of the preprocessed image to obtain a binary image corresponding to the preprocessed image; specifically, it is optional but not limited to graying the original image and the preprocessed image of the original image according to the weighted averaging method and / or the simple averaging method to obtain the grayscale image of the original image and the grayscale image of the preprocessed image, and modify the background area and the foreground area in the grayscale image of the preprocessed image to set pixels to obtain a binary image corresponding to the preprocessed image.
[0084] For example, the specific steps of obtaining the binary image corresponding to the preprocessed image may include but are not limited to:
[0085] S21: Obtaining a grayscale image of a preprocessed image;
[0086] For example, it is optional but not limited to obtaining the sum of the red channel value, green channel value and blue channel value of each pixel in the preprocessed image, and obtaining the gray value corresponding to each pixel according to the gray value calculation formula 2-1: 2-1
[0087] Among them, g is the grayscale value, R is the red channel value, G is the green channel value, and B is the blue channel value.
[0088] S22: setting a first threshold, modifying pixels in the grayscale image of the preprocessed image that are higher than the threshold to a first pixel value, and modifying pixels that are lower than the threshold to a second pixel value, to obtain a first binary image corresponding to the grayscale image of the preprocessed image;
[0089] S22: setting a second threshold, modifying pixels below the threshold in the grayscale image of the preprocessed image to the first pixel value, and modifying pixels above the threshold to the second pixel value, to obtain a second binary image corresponding to the grayscale image of the preprocessed image;
[0090] S23: performing an AND operation on the first binary image and the second binary image to obtain a mask area image;
[0091] S24: Obtain the grayscale mean of the mask area and set the background error value to obtain a background pixel value interval, modify the pixels in the grayscale image whose grayscale values are within the interval to the second pixel value, and modify the pixels in the grayscale image whose grayscale values are not within the interval to the first pixel value, to obtain a final binary image.
[0092] Specifically, the first threshold, the second threshold, the first pixel value, the second pixel value and the background error value can be set arbitrarily by those skilled in the art. Preferably, the first pixel value is 255 and the second pixel value is 0.
[0093] For example, according to the original image obtained in step S1 and the preprocessed image of the original image, the original image is grayed to obtain a grayscale image of the original image and a preprocessed image grayscale image of the preprocessed image of the original image, and then a first threshold bw_thresh1 and a second threshold bw_thresh2 are set to obtain a first binary image bw_image1 and a second binary image bw_image2 of the preprocessed image grayscale image, and then the first binary image bw_image1 and the second binary image bw_image2 are ANDed to obtain a mask area image background_mask, the grayscale mean gray_mean of the mask background_mask area is obtained and the background error value step is set to obtain a background pixel value interval [gray_mean-step, gray_mean+step], the pixels in the grayscale image whose grayscale values are in the interval [gray_mean-step, gray_mean+step] are modified to the second pixel value, and the pixels in the grayscale image whose grayscale values are not in the interval are modified to the first pixel value, to obtain a final binary image bw_image.
[0094] S3: Obtain the contour edge in the binary image, and set a geometric threshold to segment contours of different shapes to obtain a preliminary segmentation contour map;
[0095] Specifically, since various types of cyanobacteria in water samples have different appearances, it is optional but not limited to obtaining the contours of each cyanobacteria in the binary image according to a path search algorithm, and then calculating the area, ellipticity, curvature, aspect ratio and other geometric features of each contour, and then classifying each contour according to its geometric features to distinguish different types of cyanobacteria.
[0096] For example, it is optional but not limited to obtaining the number of pixels contained in each contour to obtain the area of each contour, obtaining the contour perimeter according to the pixels covered by the contour area itself, and then using the obtained contour area and contour perimeter to calculate the contour ellipticity, and then fitting an ellipse to the contour, obtaining the major axis length (major axis) and the minor axis length (minor axis) from the fitted ellipse, and obtaining the ratio of the major axis length to the minor axis length, which is the aspect ratio of the contour.
[0097] Preferably, the steps of obtaining the contour edge in the binary image and setting a geometric threshold to segment contours of different shapes to obtain a preliminary segmentation contour map may include, but are not limited to:
[0098] S31: Obtain all contours in the binary image to obtain an optimized binary image;
[0099] Specifically, since various types of cyanobacteria in water samples have different appearances, it is optional but not limited to segmenting the cyanobacteria outline according to a path search algorithm to distinguish different types of cyanobacteria.
[0100] Preferably, contour searching and traversal are performed on the binary image based on a recursive method to obtain an optimized binary image including contours of all cyanobacteria.
[0101] S32: Setting an area threshold to segment the algae contour in the optimized binary image to obtain a preliminary segmentation contour image.
[0102] Specifically, we first set an area threshold, and determine the area larger than the area threshold as the algae outline, so as to segment the algae outline in the optimized binary image for subsequent classification; and determine the area smaller than the area threshold as the non-algae outline, remove the interference of small debris, and reduce the amount of subsequent processing.
[0103] Preferably, step S32 also includes: setting an ellipticity threshold to obtain a circular outline in the algae outline; or / and, setting an aspect ratio, curvature and rectangular saturation threshold to obtain a square outline in the algae outline; or / and, setting a straight line length and a cross-sectional line length threshold to obtain a rectangular outline in the algae outline.
[0104] In this embodiment, according to the specific features of the circle, square, and rectangle, a specific parameter threshold is set to further classify the specific contour determined as the algae contour in step S32 into a contour of a certain shape, so that algae of different shapes can be separated, and then the specific algae type can be further identified according to the specific classification. For example, Figure 3 The preliminary segmentation contour map shown can be used to determine the types of algae with different contours, thereby improving work efficiency.
[0105] For example, the area threshold is set to 200 pixels, the ellipticity threshold is set to 0.9, the aspect ratio threshold is set to 0.8, the curvature threshold is set to 0.1, the straight line length threshold is set to 20 pixels, and the cross-section length threshold is set to 10 pixels.
[0106] S4: Fuse the original image grayscale image, the preprocessed image grayscale image and the preliminary segmentation contour image to obtain a three-channel color image;
[0107] Specifically, it is optional but not limited to first creating an empty three-channel color image whose size is the same as that of the original image, and then placing the grayscale image of the original image and the grayscale image of the preprocessed image on the red channel and green channel of the color image respectively, and finally, it is optional but not limited to using a pixel value-based fusion method to fuse the preliminary segmentation contour image with the blue channel of the color image to obtain the final required three-channel color image.
[0108] Preferably, the three-channel color image may be optimized by adjusting contrast and brightness, but is not limited to the optimization.
[0109] S5: constructing a segmentation network model with a three-channel color image as input and a cyanobacteria contour image as output, and constructing a training data set according to steps S1-S4, inputting the segmentation network model, so as to train and obtain a trained segmentation network model;
[0110] Specifically, the segmentation network model can use any image recognition model in the prior art to construct an initial segmentation network model, and then according to steps S1-S4, construct a training data set, and then input the training data set into the initial segmentation network model to train various parameters of the initial segmentation network model to obtain a trained segmentation network model. It is worth noting that this step is a preparatory work, which can be constructed and trained in advance, or can be carried out simultaneously with subsequent steps, as long as it is constructed and trained before the segmentation network model is needed for prediction.
[0111] More preferably, the specific structure of the segmentation network model may include but is not limited to:
[0112] Input layer, used to input the acquired three-channel color image;
[0113] The initial layer is connected to the input layer and is used to perform convolution operations using a 3x3 convolution kernel with a step size of 1. The image features of the three-channel color image are then extracted using the ReLU activation function and instance normalization to obtain the initial feature map.
[0114] The multi-layer perceptron convolutional layer Mlpconv is connected to the initial layer to extract the features of the initial feature map and obtain the second feature map. Compared with the traditional convolution operation, it helps the model learn more complex feature representations;
[0115] The maximum pooling layer is connected to the multi-layer perceptron convolutional layer to downsample the second feature map to halve the spatial size of the initial feature map and increase the channel depth while retaining important feature information to obtain an optimized feature map;
[0116] The middle layer is connected to the maximum pooling layer to further extract features from the optimized feature map and obtain the abstract features in the optimized feature map. At this time, the feature map has the smallest size but the largest number of channels, and the final feature map is obtained.
[0117] The decoder is connected to the middle layer and is used to upsample the final feature map, restore the size of the feature map to the size of the previous layer corresponding to the initial layer, multi-layer perceptron convolution layer, and maximum pooling layer, and then connect the output of the initial layer, multi-layer perceptron convolution layer, and maximum pooling layer to the input of the decoder layer through skip connections, so that the low-level features can be passed to the high-level for accurate positioning and obtain the segmented image;
[0118] The output layer, connected to the decoder, is used to output the segmented image.
[0119] In this embodiment, a preferred structure of the segmentation network model is given, using a U-net network model modified based on the multi-layer perceptron convolution layer (Mlpconv), the key feature of which is the jump connection between the initial layer, the multi-layer perceptron convolution layer and the maximum pooling layer and the decoder. These connections directly connect the outputs of the initial layer, the multi-layer perceptron convolution layer and the maximum pooling layer to the inputs of the corresponding layers of the decoder, helping to maintain position information and improve segmentation accuracy. At the same time, on this basis, the input image is segmented, which is conducive to channel dimensionality reduction and convenient for cross-channel feature fusion, while effectively reducing the number of parameters, reducing the amount of calculation, and improving the overall training speed.
[0120] More preferably, the multi-layer perceptron convolutional layer is as follows Figure 4 As shown, the size of the initial feature map obtained by the initial layer is Take 2 as an example, and perform two convolutions: the first convolution kernel size is , the feature map size is ; The second time using a special convolution kernel is Vertical slicing can directly reduce the number of channels, thereby reducing the amount of subsequent calculations. The second feature map obtained by the convolutional layer of the multi-layer perceptron is ,The two-layer convolution increases the complexity of the network and improves the overall accuracy of the network.
[0121] Preferably, the calculation formula of the image height and width after Mlpconv is as shown in Formula 5-1:
[0122] 5-1
[0123] Among them, f is the width of the convolution kernel, padding is the padding, and s is the step size.
[0124] Preferably, the main structure of the segmentation network model is as follows Figure 5 As shown in the figure, the final segmentation result can be obtained by connecting it with three 1x1x32 convolutional layers. The model has a certain guiding effect on the training direction of the segmentation network because it incorporates the preliminary contour map. The improvement of the Mlpconv layer on the traditional U-net increases the nonlinear ability of the network.
[0125] Further preferably, a training set is constructed using a three-channel color image, and the training set is input into the segmentation network model to optimize various parameters of the segmentation network model to obtain a final segmentation network model.
[0126] For example, it is optional but not limited to setting 98.0% of the three-channel color images as a training set, 1.5% of the three-channel color images as a test set, and 0.5% of the three-channel color images as a validation set, and inputting the training data set into the initial segmentation network model, optimizing the various parameters of the initial segmentation network model according to the test data set, and verifying the recognition accuracy of the segmentation network model through the validation data set to determine whether it meets the set conditions, so as to obtain the final segmentation network model. As shown in Table 1, compared with the watershed algorithm and the traditional U-net network segmentation results, the over-segmentation ratio and under-segmentation ratio of the final segmentation model are significantly reduced.
[0127] More preferably, a technician in this field sets relevant loss functions, optimization algorithms, etc. to obtain the desired neural network model, inputs the training data set into the neural network model for continuous iteration, and finally obtains a segmentation network model with a three-channel color image as input and a cyanobacteria contour image as output; specifically, optimization algorithms including stochastic gradient descent, Adam, RMSprop, etc. are used to update the neural network parameters to minimize the loss function.
[0128] Table 1: Comparison of segmentation results of various segmentation models
[0129]
[0130] S6: Obtain the original image of the current water body sample, and according to steps S2-S4, obtain the current three-channel color image corresponding to the original image of the current water body sample;
[0131] S7: inputting the current three-channel color image into the trained segmentation network model to obtain the contour image of each cyanobacteria in the current three-channel color image;
[0132] S8: Using each cyanobacteria outline image in the current three-channel color image as a mask, and extracting all cyanobacteria target small images in the original image according to the mapping relationship between the target frame of each mask and the original image, to obtain the final cyanobacteria image segmentation result.
[0133] Specifically, according to steps S2-S4, the original image of the current water sample and the corresponding current three-channel color image are obtained, the current three-channel color image is input into the trained segmentation network model, the contour image of each cyanobacteria in the current three-channel color image is obtained, and then the minimum bounding rectangle of each cyanobacteria contour image is calculated, and then according to the correspondence between the bounding rectangle and the current three-channel color image, all the cyanobacteria target small images in the original image can be obtained.
[0134] Preferably, the target frame may be, but is not limited to, a minimum circumscribed rectangle, a minimum circumscribed circle, or other graphics.
[0135] In this embodiment, a segmentation method for cyanobacteria images of the present invention is provided. By obtaining the original images of several water samples and their pre-processed images, random noise in the images is reduced, the images are made clearer, and the details are more prominent, which is helpful to improve the accuracy and efficiency of subsequent processing tasks such as segmentation, classification and recognition. Then, according to the original image, the original image grayscale image and the pre-processed image grayscale image are obtained, and the pre-processed image grayscale image is binary segmented to obtain a binary image corresponding to the pre-processed image, reduce the image grayscale level, highlight the key information of the image, reduce the amount of calculation, and improve the processing speed to facilitate subsequent segmentation operations. Then, the contour edge in the binary image is obtained, and a geometric threshold is set to segment contours of different shapes to obtain a preliminary segmented contour map, and different types of contours are segmented. The contour classification of the type is reduced, the processing amount of subsequent steps is reduced, the grayscale image of the original image and the grayscale image of the preprocessed image and the preliminary segmentation contour image are fused to obtain a three-channel color image, and the detail information of the original image is retained in the subsequent segmentation, and the contour information is enhanced to improve the segmentation accuracy. At the same time, by fusing information from different sources, the noise that may exist in a single information source can be reduced, and the reliability of the segmentation result can be improved, so as to construct and train a segmentation network model with a three-channel color image as input and a cyanobacteria contour image as output. Finally, the original image of the current water sample and the corresponding current three-channel color image are obtained, and the current three-channel color image is input into the trained segmentation network model to obtain the contour images of each cyanobacteria in the current three-channel color image, as well as the cyanobacteria target small image corresponding to the cyanobacteria contour image in the original image. The problem of low efficiency of cyanobacteria image segmentation and need to be improved in recognition accuracy in the prior art is solved.
[0136] like Figure 6 As shown, the present invention provides a method for identifying cyanobacteria images, comprising:
[0137] P1: Establish and train a recognition network model that takes the cyanobacteria image segmentation result as input and the corresponding cyanobacteria name as output; specifically, the recognition network model can use any image recognition model in the prior art to construct an initial recognition network model; then, based on the cyanobacteria image segmentation result obtained by the above-mentioned cyanobacteria image segmentation method, construct a training data set: then, based on the training data set, input the initial recognition network model to train the various parameters of the initial recognition network model to obtain the trained recognition network model. It is worth noting that this step is a preparatory work, which can be constructed and trained in advance, or it can be carried out simultaneously with the subsequent steps, as long as it is constructed and trained before the recognition network model is needed for prediction.
[0138] Preferably, 98.0% of the cyanobacteria image segmentation results are set as a training set, 1.8% of the cyanobacteria image segmentation results are set as a test set, and 0.2% of the cyanobacteria image segmentation results are set as a validation set. The training data set is input into the initial recognition network model, and the various parameters of the initial recognition network model are optimized according to the test data set. The recognition accuracy of the recognition network model is verified by the validation data set to determine whether it meets the set conditions to obtain the final recognition network model.
[0139] Preferably, the recognition network model is as follows Figure 7 As shown, it is optional but not limited to using the VGG-16 structure, and using the global average pooling layer GAP (global average pooling) instead of the fully connected layer of the model itself, directly associating the classification task with the feature map, identifying the original cyanobacteria outline map, and outputting the corresponding cyanobacteria name. For the application of the present invention, since the characteristics of various algae are inconsistent, different types of cyanobacteria can be identified by classifying the algae characteristics.
[0140] More preferably, the specific structure of the recognition network model may include, but is not limited to:
[0141] An identification input layer is used to input the acquired cyanobacteria image segmentation results;
[0142] The recognition middle layer is connected to the recognition input layer and is used to receive the input cyanobacteria image segmentation result and extract the features of the cyanobacteria image segmentation result; the recognition middle layer preferably includes a convolution layer and a pooling layer;
[0143] The double-layer global pooling layer is connected to the recognition intermediate layer to provide a simplified network structure to reduce the number of network parameters, improve the generalization ability and robustness of the model, while maintaining sufficient information for classification or regression tasks and reducing the possibility of overfitting;
[0144] The identification output layer is connected to the double-layer global pooling layer, and the name of the cyanobacteria corresponding to the cyanobacteria image segmentation result is output according to the characteristics of the acquired cyanobacteria image segmentation result.
[0145] Further preferably, relevant loss functions, optimization algorithms, etc. are set by a technician in this field to obtain the required recognition network model, and the training data set is input into the recognition network model for continuous iteration, and finally a recognition network model with the cyanobacteria image segmentation result as input and the corresponding cyanobacteria name as output is obtained; specifically, the optimization algorithm includes stochastic gradient descent, Adam, RMSprop, etc., which are used to update the neural network parameters to minimize the loss function.
[0146] P2: Obtain the original image of the current water sample, and obtain the current cyanobacteria image segmentation result according to any of the above methods;
[0147] P3: Input the current cyanobacteria image segmentation result into the trained recognition network model to obtain the corresponding cyanobacteria name;
[0148] Specifically, it is optional but not limited to obtaining the original image of the current water sample, and then obtaining the cyanobacteria image segmentation result of the original image of the current water sample according to the above-mentioned cyanobacteria image segmentation method, and inputting the trained recognition network model to obtain the name of the cyanobacteria corresponding to the cyanobacteria image segmentation result.
[0149] P4: According to the acquired names of cyanobacteria, the ecological data of various types of cyanobacteria are counted to complete the intelligent detection of typical harmful cyanobacteria.
[0150] Specifically, it is optional but not limited to counting all the names of cyanobacteria obtained in step P3 to calculate the density and biomass and other ecological data of various types of cyanobacteria in the water body, and according to the specific types of cyanobacterial toxins and odorous substances contained in each algae genus and the density and proportion of total cyanobacterial toxins and total odorous substances, so as to facilitate technical personnel in this field to evaluate the degree of eutrophication of water bodies, provide quantifiable reference indicators for water quality improvement, and complete the identification of cyanobacteria images.
[0151] For example, 10 different water samples are randomly selected, and the cyanobacteria image segmentation results corresponding to each water sample are obtained according to the segmentation method for cyanobacteria images. Then, they are input into the trained recognition network model respectively, and the recognition results are statistically analyzed to obtain the algae genus recognition accuracy table of typical harmful cyanobacteria, as shown in Table 2.
[0152] Table 2: Typical harmful cyanobacteria identification accuracy
[0153]
[0154] Preferably, it is optional but not limited to marking all the obtained cyanobacteria names at the positions of the cyanobacteria in the original image through an external rectangle intelligence, so as to more intuitively show the density and distribution of various types of cyanobacteria in the original image, and then scanning the original image through an intelligent counter to obtain all the annotations for statistics to obtain the ecological data of various types of cyanobacteria.
[0155] On the other hand, the present invention further provides a computer storage medium storing an executable program code; the executable program code is used to execute any of the above-mentioned segmentation methods for cyanobacteria images or recognition methods for cyanobacteria images.
[0156] On the other hand, the present invention also provides a terminal device, including a memory and a processor; the memory stores program codes that can be executed by the processor; the program codes are used to execute any of the above-mentioned segmentation methods for cyanobacteria images or recognition methods for cyanobacteria images.
[0157] Exemplarily, the program code may be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the program code in the terminal device.
[0158] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the terminal device may also include an input / output device, a network access device, a bus, etc.
[0159] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-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 any conventional processor, etc.
[0160] The memory may be an internal storage unit of the terminal device, such as a hard disk or a memory. The memory may also be an external storage device of the terminal device, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the terminal device. Further, the memory may also include both an internal storage unit of the terminal device and an external storage device. The memory is used to store the program code and other programs and data required by the terminal device. The memory may also be used to temporarily store data that has been output or is to be output.
[0161] The above-mentioned computer storage medium and terminal device are created based on the above-mentioned segmentation method for cyanobacteria images or the recognition method for cyanobacteria images. Their technical functions and beneficial effects are not repeated here. The various technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the various technical features in the above-mentioned embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0162] The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.
Claims
1. A segmentation method for cyanobacteria images, characterized in that: include: S1: Obtaining original images of several water samples and pre-processed images of the original images; S2: according to the original image and the preprocessed image of the original image, obtaining the grayscale image of the original image and the grayscale image of the preprocessed image, and performing binary segmentation on the grayscale image of the preprocessed image to obtain a binary image corresponding to the preprocessed image; S3: Obtain the contour edge in the binary image, and set a geometric threshold to segment contours of different shapes to obtain a preliminary segmentation contour map; S4: Fuse the original image grayscale image, the preprocessed image grayscale image and the preliminary segmentation contour image to obtain a three-channel color image; S5: constructing a segmentation network model with a three-channel color image as input and a cyanobacteria contour image as output, and constructing a training data set according to steps S1-S4, inputting the segmentation network model, so as to train and obtain a trained segmentation network model; S6: Obtain the original image of the current water body sample, and according to steps S2-S4, obtain the current three-channel color image corresponding to the original image of the current water body sample; S7: inputting the current three-channel color image into the trained segmentation network model to obtain the contour image of each cyanobacteria in the current three-channel color image; S8: using each cyanobacteria outline image in the current three-channel color image as a mask, and extracting all cyanobacteria target small images in the original image according to the mapping relationship between the target frame of each mask and the original image, which is the final cyanobacteria image segmentation result; The step of obtaining a preprocessed image of the original image includes: De-noising the original image to obtain a denoised image; Convert the denoised image to the YCrCb color space, obtain the initial brightness channel image and color channel image, and obtain the global mean of the initial brightness channel image; Obtain the local mean map and local variance map of the initial brightness channel image; According to formula 1-1, calculate the brightness value of each pixel to obtain the final brightness channel image; Fusing the color channel image and the final brightness channel image to obtain a preprocessed image of the original image; 1-1 Among them, yImgEn is the final brightness channel image, lMImg is the local mean map of the initial brightness channel image, α is the weight coefficient, gMean is the global mean of the initial brightness channel image, yImg is the initial brightness channel image, and lVImg is the local variance map of the initial brightness channel image.
2. The method according to claim 1, characterized in that The specific steps of obtaining the binary image corresponding to the preprocessed image include: Get the grayscale image of the preprocessed image; A first threshold is set, pixels in the grayscale image of the preprocessed image that are higher than the threshold are modified to a first pixel value, and pixels that are lower than the threshold are modified to a second pixel value, to obtain a first binary image corresponding to the grayscale image of the preprocessed image; A second threshold is set, pixels below the threshold in the grayscale image of the preprocessed image are modified to the first pixel value, and pixels above the threshold are modified to the second pixel value, so as to obtain a second binary image corresponding to the grayscale image of the preprocessed image; Performing an AND operation on the first binary image and the second binary image to obtain a mask area image; The grayscale mean of the mask area is obtained and the background error value is set to obtain the background pixel value interval, the pixels in the grayscale image whose grayscale values are within the interval are modified to the second pixel value, and the pixels in the grayscale image whose grayscale values are not within the interval are modified to the first pixel value, to obtain the final binary image.
3. The method according to claim 1, characterized in that The steps of obtaining the contour edge in the binary image and setting the geometric threshold to segment the contours of different shapes to obtain the preliminary segmentation contour map include: Get all contours in the binary image and get the optimized binary image; An area threshold is set to segment the algae contour in the optimized binary image and obtain a preliminary segmentation contour map.
4. The method according to claim 3, characterized in that The step of obtaining a preliminary segmentation contour map also includes: Set the ellipticity threshold to obtain a circular outline in the algae outline; or / and, set the aspect ratio, curvature and rectangle saturation thresholds to obtain a square outline in the algae outline; or / and, set the straight line length and transverse line length thresholds to obtain a rectangular outline in the algae outline.
5. The method according to any one of claims 1 to 4, characterized in that: The specific structure of the segmentation model includes: Input layer: used to input the acquired three-channel color image; Initial layer: connected to the input layer, used to extract the image features of the three-channel color image and obtain the initial feature map; The multi-layer perceptron convolutional layer is connected to the initial layer to extract the features of the initial feature map and obtain the second feature map; The maximum pooling layer is connected to the multi-layer perceptron convolutional layer to downsample the second feature map to obtain an optimized feature map; Middle layer: connected to the maximum pooling layer, used to extract the abstract features in the optimized feature map to obtain the final feature map; Decoder: connected to the middle layer, used to upsample the final feature map to obtain the segmented image; Output layer: connected to the decoder to output the segmented image.
6. A method for identifying cyanobacteria images, characterized in that: include: Establish and train a recognition network model that takes the cyanobacteria image segmentation results as input and the corresponding cyanobacteria names as output; Acquire the original image of the current water sample, and obtain the current cyanobacteria image segmentation result according to the segmentation method according to any one of claims 1 to 5; Input the current cyanobacteria image segmentation result into the trained recognition network model to obtain the corresponding cyanobacteria name; According to the acquired names of cyanobacteria, the ecological data of various types of cyanobacteria are counted to complete the recognition of cyanobacteria images.
7. A computer storage medium, characterized in that: An executable program code is stored; the executable program code is used to execute the segmentation method for cyanobacteria images described in any one of claims 1 to 5, or the recognition method for cyanobacteria images described in claim 6.
8. A terminal device, characterized in that: It comprises a memory and a processor; the memory stores a program code executable by the processor; the program code is used to execute the segmentation method for cyanobacteria images described in any one of claims 1 to 5, or the recognition method for cyanobacteria images described in claim 6.
Citation Information
Patent Citations
Automatic blue algae monitoring and early warning method and automatic blue algae monitoring and early warning system
CN110108704A
Electron microscope diatom image segmentation method and device fusing saliency and superpixels
CN110473212A
