A cell counting method for Anabaena based on microscope images
Through microscope image processing and binarization technology, an Anabaena cell statistical method is generated, which solves the problem of missed detection in deep learning model identification, improves the accuracy and efficiency of cell statistics, and is suitable for different forms of Anabaena cells and expands The scope of application of statistics.
Patent Information
- Application Number
- CN202210099792.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-27
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-01-27
AI Technical Summary
The existing Anabaena cell identification method based on deep learning models can easily lead to missed detection, resulting in large deviations between algae density and biomass indicators and the actual situation.
An Anabaena cell statistics method based on microscope images is adopted, including the steps of image preprocessing, image binarization, calculating the minimum circumscribed rectangle, detecting the Anabaena binary image and calculating the number of cells. These steps are used to generate cell statistics. Binary images of Anabaena algae reduce dependence on deep learning models and improve the accuracy of cell statistics.
This method reduces data annotation work, improves model training and optimization efficiency, enhances the accuracy of cell pixel area calculation, is suitable for different forms of Anabaena cells, expands the applicable scope of statistics, and provides information for later algorithm optimization and maintenance. independent module.
Smart Images

Figure CN114511530B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of water ecological environment monitoring, and in particular relates to a method for counting Anabaena cells based on microscope images. Background Art
[0002] Using a microscope and a high-definition industrial camera to collect algae images, and then identifying the fish algae and its pixel coordinates through a deep learning detection model, it is necessary to design an image pattern recognition method to count the number of fish algae cells in the image. Patent Publication No. CN111443028A proposes a method for identifying and counting algae based on a deep learning model. When this method counts fish algae, the deep learning detection model is prone to missed detection, resulting in a large deviation between the performance indicators such as algae density and biomass and the actual situation. Summary of the invention
[0003] The purpose of the present invention is to provide a method for counting Anabaena cells based on microscope images, thereby achieving accurate counting of Anabaena cells.
[0004] To achieve the above object, the present invention provides a method for counting Anabaena cells based on microscope images, comprising:
[0005] Step ⑴ Image preprocessing: enhance the contrast of the image;
[0006] Step ⑵ Image binarization: Find the anabaena area in the image;
[0007] Step (3) calculating the minimum bounding rectangle of the anabaena: calculating the outer contours of the binary image and finding the minimum bounding rectangle of these contours;
[0008] Step (4) detecting the binary image of Anabaena: generating a binary image of Anabaena for cell counting according to the minimum bounding rectangle of Anabaena;
[0009] Step (5) calculating the number of Anabaena cells: using the binary image calculated in step (4) to count the number of Anabaena cells.
[0010] Optionally, calculating the minimum bounding rectangle of Anabaena in step (3) includes: first calculating the outer contour based on the binary image, setting the outer contour of the threshold, secondly calculating the minimum bounding rectangle of the outer contour for the outer contour that meets the set threshold, calculating the minimum bounding rectangle structure based on the minimum bounding rectangle, and finally deleting the misdetected minimum bounding rectangle of the minimum bounding rectangle structure.
[0011] Optionally, step (3) of calculating the minimum circumscribed rectangular structure includes the following steps:
[0012] ⑴ Calculate the coordinates of the four vertices using the width, height, and rotation angle of the minimum circumscribed rectangle. The vertex coordinates are stored in pts[0], pts[1], pts[2], and pts[3] in a clockwise direction.
[0013] ⑵Find the long side and short side of the minimum circumscribed rectangle, save the length of its long side in the width variable of the data structure, and save the length of its short side in the height variable of the data structure;
[0014] (3) Calculate the ratio of the long side to the short side of the minimum circumscribed rectangle, and calculate its shape attribute according to the ratio. In the present invention, the shape attribute of the minimum circumscribed rectangle is divided into three forms: general shape, long strip shape and square shape, and the corresponding shape variable values are 0, 1 and 2;
[0015] (4) Combine pts[0] and pts[1] into a line segment line1, and combine pts[1] and pts[2] into another line segment line2. By determining the lengths of the two line segments, we can find the line segment corresponding to the long side.
[0016] ⑸ Calculate the distance in the x direction and the distance in the y direction of the coordinates of the two vertices of any long side segment, and determine its direction attribute. The direction attribute has only two states: horizontal and vertical, and is stored in the direction variable;
[0017] (6) Compare the x-axis or y-axis coordinate values of the long side line segment according to the directional characteristics, save the long side line segment with a smaller value in the lineL variable, and save the long side line segment with a larger value in the lineR variable;
[0018] ⑺lineL and lineR are also a structure. It has two parameters, namely the slope k and the intercept b on the y-axis. The parameters k and b of the line equations of lineL and lineR in the data structure are calculated respectively through the coordinates of the two vertices on the line segment.
[0019] Optionally, step (4) of deleting the misdetected minimum bounding rectangle includes:
[0020] ⑴Find the shape value of the smallest circumscribed rectangular structure and find the structure with shape = 1;
[0021] (2) Further analyze the structure with shape = 1, and calculate the ratio of the width variable value to the image length according to its direction value. If the ratio is greater than the set threshold (0.75), the structure is used as the reference structure;
[0022] ⑶ Based on the reference structure, analyze the positional relationship between the vertex coordinates of other structures and the reference structures lineL and lineR;
[0023] (4) When calculating the projection of a point to a line segment, if direction = 0 in the reference structure, first find the vertex with the maximum y axis and the vertex with the minimum y axis, substitute the x coordinate value of the vertex with the maximum y axis into the line equation of lineL, and calculate the coordinate value of the projection of the point to lineL in the corresponding y direction;
[0024] ⑸ When calculating the projection of a point to a line segment, if direction = 1 in the reference structure, first find the vertex with the largest x-axis and the vertex with the smallest x-axis, substitute the y-coordinate value of the vertex with the largest x-axis into the line equation of lineL, and calculate the coordinate value of the point projected onto lineL in the corresponding x-direction;
[0025] ⑹When the reference structure direction = 0, delete other structures above lineL or below lineR; when the reference structure direction = 1, delete other structures to the left of lineL or to the right of lineR.
[0026] Optionally, step (4) of detecting the binary image of Anabaena includes:
[0027] ⑴ Update the original binary image by combining the minimum circumscribed rectangle structure to form a cleaner binary image;
[0028] ⑵First, generate a binary image with the same resolution as the original binary image, and fill the image with 0 by default;
[0029] ⑶ Perform an AND operation on the Mask image generated in step ⑵ and the original binary image to obtain a binary image after filtering out the false detection data;
[0030] (4) Calculate the contour of the binary image in step (3) and its hierarchical relationship;
[0031] ⑸ Generate a binary image of Anabaena based on the detected contour data.
[0032] Optionally, step (6) generates a binary image of Anabaena according to the contour data, including:
[0033] ⑴First, find the data with Parent = -1 from the hierarchy of the contour. These data are all outer contours. Calculate their minimum enclosing rectangle, and then match them with the width and height in the data structure to find the corresponding outer contour point set;
[0034] ⑵ Generate a new binary image, the resolution of the binary image is consistent with the resolution of the original image, the initial value of each pixel of the binary image is 0, fill the area surrounded by the outer contour point set found in step ⑴, the filling value is 255, and generate a binary image of Anabaena;
[0035] ⑶ When using OTSU binary segmentation image, it is inevitable that there will be holes (black) inside the cell area (white), which will cause the calculated pixel area of Anabaena cells to be smaller;
[0036] (4) If shape = 2 in the data structure, it means that the Anabaena cell is likely to be closed or curled. First, fill the outer contour according to step (2) to obtain a binary image contourImg1;
[0037] ⑸ Find the data whose Parent is not equal to -1 from the hierarchy of the contour. These data are inner contours. Calculate their pixel area. If the area is greater than the set threshold, save their corresponding contour point set.
[0038] (6) Generate a new binary image. The resolution of the binary image is consistent with that of the original image. The initial value of each pixel in the binary image is 0. Fill the area surrounded by all the inner contour points in step (5) with a filling value of 255 to obtain a binary image contourImg2.
[0039] ⑺Subtract contourImg2 from contourImg1 to obtain the binary image of Anabaena;
[0040] ⑻If the square Anabaena is closed, then contourImg2 has a white area, and the binary image of the actual Anabaena cell area in the image can be obtained through step ⑺; if the square Anabaena is not closed, then contourImg2 does not have a white area, and the binary image of Anabaena obtained in step ⑺ is actually contourImg1.
[0041] Optionally, step (5) of calculating the number of Anabaena cells comprises the following steps:
[0042] (1) On the binary image of Anabaena, recalculate the outer contour in the image and calculate its circumscribed rectangle;
[0043] (2) Divide the long side of the circumscribed rectangle by the short side and calculate its long-short side ratio. If the ratio is greater than the set threshold (4.0), it is considered that the shape of the fish algae in the image is a long strip;
[0044] ⑶ If the shape of Anabaena is long strip, find the short side of the circumscribed rectangle and use the short side to correct the pixel size of the unit cell of Anabaena;
[0045] (4) Calculate the pixel area of the binary image and divide it by the corrected unit cell pixel size to obtain the number of Anabaena cells;
[0046] ⑸ If the shape of Anabaena is not long strip, then the spot detection method is first used to detect Anabaena cells from the grayscale image;
[0047] (6) If multiple Anabaena cells of similar size are detected in step (5), their mean is used to correct the unit cell pixel size;
[0048] (7) Execute step (4) to count the number of cells of Anabaena;
[0049] ⑻If multiple Anabaena cells of similar size are not detected in step ⑸, the unit cell pixel size is not corrected, and the pixel area of the binary image is directly divided by the default cell pixel size to obtain the number of Anabaena cells.
[0050] Optionally, when counting the number of cells through a binary image, the pixel size of the unit cell is first corrected according to the morphology of the anabaena in the image, and then the pixel area of the white area in the binary image is calculated and divided by the corrected pixel size of the unit cell to calculate the number of cells.
[0051] Technical effects of the invention: The invention discloses a method for counting Anabaena cells based on microscope images, which does not require the detection of Anabaena cells in a deep learning model, reduces data annotation work, and improves the efficiency of model training and model optimization; for closed, encircling and curled Anabaena, the invention designs an effective binary image calculation method, which can better extract its actual binary image and improve the accuracy of cell pixel area calculation; under the same resolution, there will be a certain difference in the size of Anabaena cells, and the invention can correct its unit cell pixel size in a targeted manner according to the morphological characteristics on the Anabaena image, which not only improves the accuracy of cell statistics, but also expands its scope of application; the Anabaena cell counting method is an independent module, which is convenient for the optimization and maintenance of the algorithm in the later stage. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0053] Figure 1 Schematic diagram of the process of the method for counting Anabaena cells based on microscope images according to an embodiment of the present invention;
[0054] Figure 2 is a flowchart of image preprocessing according to an embodiment of the present invention;
[0055] Figure 3 is a flow chart of calculating the minimum bounding rectangle of Anabaena according to an embodiment of the present invention;
[0056] Figure 4 This is a flow chart of calculating the minimum circumscribed rectangle structure according to an embodiment of the present invention;
[0057] Figure 5 This is an example diagram of deleting an incorrectly detected circumscribed rectangular structure according to an embodiment of the present invention;
[0058] Figure 6 is a flow chart of detecting anabaena binary images according to an embodiment of the present invention;
[0059] Figure 7 is a flow chart of generating a binary image of Anabaena according to an embodiment of the present invention;
[0060] Figure 8 This is an effect diagram of generating a binary image of Anabaena according to an embodiment of the present invention;
[0061] Fig. 9 is a flow chart of calculating the number of Anabaena cells according to an embodiment of the present invention;
[0062] Fig.10 This is a statistical effect diagram of Anabaena cells according to an embodiment of the present invention. DETAILED DESCRIPTION
[0063] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0064] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0065] like Figure 1 As shown, this embodiment provides a method for counting Anabaena cells based on microscope images, comprising the following steps:
[0066] ⑴Image preprocessing: enhance the contrast of the image;
[0067] ⑵Image binarization: find the anabaena area in the image;
[0068] ⑶ Calculate the minimum enclosing rectangle of Anabaena: calculate the outer contours of the binary image and find the minimum enclosing rectangle of these contours;
[0069] (4) Detection of binary image of Anabaena: Generate binary image of Anabaena for cell counting according to the minimum bounding rectangle of Anabaena;
[0070] (5) Calculate the number of Anabaena cells: Count the number of Anabaena cells using the binary image calculated in step (4).
[0071] like Figure 2 As shown, the image preprocessing module includes the following contents:
[0072] ⑴ First, scale the image to improve overall operating efficiency;
[0073] (2) Convert the scaled color image data into a grayscale image;
[0074] ⑶ Perform median filtering to denoise the grayscale image;
[0075] (4) Use CLAHE (contrast limited adaptive histogram equalization) algorithm to perform contrast stretching operation on the image;
[0076] ⑸ Since the image data after stretching by the CLAHE algorithm will have more noise points, it is necessary to further reduce the noise through the Gaussian blurring algorithm.
[0077] The OTSU method was used to binarize the image. After binarization, the Anabaena cell area on the image was white (255), and the remaining pixel values were 0.
[0078] Then the binary image is subjected to morphological Dilate processing to connect the disconnected white areas in the image.
[0079] like Figure 3 As shown, the calculation of the minimum bounding rectangle of Anabaena includes the following contents:
[0080] ⑴ Calculate the outer contour on the binary image;
[0081] ⑵ For contours whose pixel areas meet the set threshold, calculate their minimum circumscribed rectangles;
[0082] ⑶ Calculate the parameters of each minimum enclosing rectangle and construct a data structure (struct), which contains pts variables, width variables, height variables, shape variables, angle variables, direction variables, lineL variables and lineR variables. They respectively represent the coordinates of the four vertices of the minimum enclosing rectangle, the long side of the minimum enclosing rectangle, the short side of the minimum enclosing rectangle, the shape attribute of the minimum enclosing rectangle (0 represents a general shape, 1 represents a long strip, and 2 represents a square), the rotation angle of the minimum enclosing rectangle, the direction attribute of the minimum enclosing rectangle (0 represents the horizontal direction, 1 represents the vertical direction), the left long side line segment of the minimum enclosing rectangle, and the right long side line segment of the minimum enclosing rectangle;
[0083] ⑷Through observation, we found that: when the shape of the anabaena in the image is long and narrow, the gaps between some algae cells will be larger, and the white area representing the algae cells in the binary image will be disconnected. Therefore, when deleting the misdetected minimum bounding rectangle, in order to avoid deleting the disconnected anabaena cells in the binary image, we filter the misdetected data by calculating the projection of other bounding rectangle vertices to the long side of the reference bounding rectangle.
[0084] like Figure 4 As shown, the calculation of the minimum circumscribed rectangle structure includes the following contents:
[0085] ⑴ Calculate the coordinates of the four vertices of the minimum enclosing rectangle through its rotation angle, width, and height data, and store them in the pts variable of the data structure. The pts vertex coordinates are stored in the clockwise direction of the minimum enclosing rectangle, namely pts[0], pts[1], pts[2], and pts[3];
[0086] ⑵Save the long side of the minimum circumscribed rectangle in the width variable of the data structure, and the short side in the height variable of the data structure;
[0087] ⑶The shape variable in data is set to 0 by default. Divide the width of data by the height and calculate the ratio of the long side to the short side. If the ratio is greater than the set threshold (4.0), then its shape is a long strip, and the shape variable of the data structure is set to 1. If the ratio of the long side to the short side is less than the set threshold (1.5), then its shape is a square, and the shape variable of the data structure is set to 2;
[0088] ⑷Put pts[0] and pts[1] together to form line1, and pts[1] and pts[2] together to form line2. If the length of line1 (the distance between the two vertices) is greater than the length of line2, then line1 is the first long edge lineTemp1, and the corresponding line segment composed of pts[3] and pts[2] is the second long edge lineTemp2. Similarly, if the length of line2 (the distance between the two vertices) is greater than the length of line1, then line2 is the first long edge lineTemp1, and the corresponding line segment composed of pts[0] and pts[3] is the second long edge lineTemp2. Calculate the distance dx in the X-axis direction and the distance dy in the Y-axis direction between the two vertices corresponding to lineTemp1. If the absolute value of dx is greater than the absolute value of dy, then set the value of the direction variable in data to 0, otherwise set it to 1.
[0089] ⑸ Further analyze lineTemp1 and lineTemp2 in step ⑷. If the value of the direction variable of data is 0, then determine the minimum y coordinate value of the vertices of lineTemp1 and lineTemp2. If the minimum y coordinate value of the vertex of lineTemp1 is greater than the minimum y coordinate value of the vertex of lineTemp2, then save lineTemp2 in the lineL variable of the data structure and save lineTemp1 in the lineR variable of the data structure. If the value of the direction variable of data is 1, then determine the minimum x coordinate value of the vertices of lineTemp1 and lineTemp2. If the minimum x coordinate value of the vertex of lineTemp1 is greater than the minimum x coordinate value of the vertex of lineTemp2, then save lineTemp2 in the lineL variable of the data structure and save lineTemp1 in the lineR variable of the data structure.
[0090] ⑹lineL and lineR in the data structure are also a structure. It has two parameters, namely the slope k and the intercept b on the y-axis (using the slope-intercept form of the straight line equation y=kx+b). The parameters k and b of the line equations of lineL and lineR in the data structure are calculated respectively through the coordinates of the two vertices on the line segment.
[0091] In order to better illustrate the specific method of deleting the misdetected bounding rectangle structure, we will explain it with an example diagram. Figure 5 As shown, it includes the following:
[0092] ⑴The numbers 1, 2, 3, and 4 represent a minimum circumscribed rectangular structure, respectively. A, B, C, and D are the four vertices (pts) of structure No. 1. The value of the direction variable in the structure is 0 (horizontal direction), the value of the shape variable is 1 (long strip), lineL corresponds to the line segment composed of BC, and lineR corresponds to the line segment composed of AD; F is the vertex with the smallest y-axis coordinate of structure No. 4; E is the vertex with the largest y-axis coordinate of structure No. 3; G is the vertex with the smallest y-axis coordinate of structure No. 2, and H is the vertex with the largest y-axis coordinate of structure No. 2.
[0093] (2) Structure No. 1 is the reference structure in this example. The schematic diagram will be used to illustrate how to delete the misdetected circumscribed rectangular structures (No. 3 and No. 4) and retain the structure No. 2.
[0094] ⑶ Because the value of the direction variable of structure 1 is 0, the vertices corresponding to the minimum and maximum y-axis coordinates of other structures (2, 3 and 4) are found along the y-axis; if the value of the direction variable is 1, the vertices corresponding to the minimum and maximum x-axis coordinates of other structures (2, 3 and 4) are found along the x-axis;
[0095] ⑷ Taking structure No. 2 as an example, calculate the projection dy1 of the maximum vertex H on the lineL (BC segment) of structure No. 1 and the projection dy2 of the minimum vertex G on the lineR (AD segment) of structure No. 1. If the value of dy1 is greater than 0, it means that structure No. 2 is below lineL. Otherwise, structure No. 2 is above lineL. If the value of dy2 is greater than 0, it means that structure No. 2 is below lineR. Otherwise, structure No. 2 is above lineR.
[0096] ⑸ When calculating the projection of a point to a line segment, if direction = 0 in the reference structure, then substitute the x-coordinate value of the point into the line equation to calculate the coordinate value of the point projected onto the line in the corresponding y direction; similarly, if direction = 1 in the reference structure, then substitute the y-coordinate value of the point projected onto the line in the corresponding x-coordinate value;
[0097] (6) In step (4), if dy1 is less than 0 (the structure is above lineL) or dy2 is greater than 0 (the structure is below lineR), the corresponding structure data will be deleted. It can be clearly observed from the figure that structure 2 does not meet the above two conditions, so structure 2 will be retained. Structure 3 meets the deletion condition of dy1 less than 0, and structure 4 meets the deletion condition of dy2 greater than 0, and they will both be deleted.
[0098] ⑺The above steps are simply: when the direction of the reference structure is horizontal, delete other structures above lineL or below lineR; when the direction of the reference structure is vertical, delete other structures on the left of lineL or on the right of lineR;
[0099] ⑻ The shape attribute of the structure must be 1 (long strip), and the value of its width long side must be greater than 3 / 4 of the image length to become a reference structure. In this example, only structure No. 1 is a reference structure;
[0100] ⑼ In step ⑺, the image length is determined by the value of the direction variable in data. When direction = 0, the image length is the image width; when direction = 1, the image length is the image height;
[0101] ⑽Only the reference structure can perform misdetection analysis and deletion operations on other structures. If the reference structure is not found in the image, the operation of deleting the misdetected circumscribed rectangular structure will not be performed.
[0102] like Figure 6 As shown, the detection of the binary image of Anabaena includes the following contents:
[0103] ⑴ The misdetected cell area in the original binary image is also white, which will affect the subsequent calculation. Therefore, it is necessary to combine the minimum circumscribed rectangle structure to update the original binary image to form a cleaner binary image;
[0104] ⑵First, generate a binary image with the same resolution as the original binary image, and fill the image with 0 by default. Then fill the area covered by it with the coordinates of the four vertices of the minimum circumscribed rectangle (fill with a value of 255) to generate a Mask image;
[0105] ⑶ Perform an AND operation on the Mask image generated in step ⑵ and the original binary image to obtain a binary image after filtering out the false detection data;
[0106] (4) Calculate the contour (inner and outer contours) of the binary image in step (3) and its hierarchy;
[0107] ⑸ A contour is a set of points (vector <point>contour), each contour corresponds to a hierarchy (hierarchical relationship), which is a structure vec4i, composed of 4 parameters: next, Previous, First_Child and Parent, which represent the ID of the next contour at the same level, the ID of the previous contour at the same level, the first child contour ID and the parent contour ID, respectively. The default value is -1;
[0108] (6) Generate a binary image of Anabaena based on the detected contour data.
[0109] like Figure 7 As shown, the generation of the Anabaena binary image according to the detected contour data includes the following contents:
[0110] ⑴ Since the minimum enclosing rectangle structure of the outer contour has been calculated before, there is no need to repeat the calculation here, and directly determine the value of shape in the data structure. If the value of shape is not equal to 2, it means that it is not a square fish algae. First, find the data with Parent = -1 in the hierarchy of the contour. These data are all outer contours, calculate their minimum enclosing rectangle, and then match them with the width and height in the data structure to find the corresponding outer contour contour point set;
[0111] ⑵ Generate a new binary image, the resolution of the binary image is consistent with the resolution of the original image, the initial value of each pixel of the binary image is 0, fill the area surrounded by the outer contour point set found in step ⑴, the filling value is 255, and generate a binary image of Anabaena;
[0112] ⑶ When using OTSU binary segmentation image, it is inevitable that there will be holes (black) inside the cell area (white), which will cause the calculated pixel area of Anabaena cells to be smaller. Step ⑵ can avoid this problem by filling the outer contour;
[0113] ⑷If shape=2 in the data structure, it means that the Anabaena cells are likely to be closed or curled. First, fill the outer contour according to step ⑵ to obtain a binary image contourImg1;
[0114] ⑸ Find the data whose Parent is not equal to -1 from the hierarchy of the contour. These data are inner contours. Calculate their pixel area. If the area is greater than the set threshold, save their corresponding contour point set.
[0115] (6) Generate a new binary image. The resolution of the binary image is consistent with that of the original image. The initial value of each pixel in the binary image is 0. Fill the area surrounded by all the inner contour points in step (5) with a filling value of 255 to obtain a binary image contourImg2.
[0116] ⑺Subtract contourImg2 from contourImg1 to obtain the binary image of Anabaena;
[0117] ⑻If the square Anabaena is closed, then contourImg2 has a white area, and the binary image of the actual Anabaena cell area in the image can be obtained through step ⑺; if the square Anabaena is not closed, then contourImg2 does not have a white area, and the binary image of Anabaena obtained in step ⑺ is actually contourImg1. Therefore, this method has good applicability.
[0118] like Figure 8 As shown, the black and white image is the binary image of Anabaena calculated by the present invention. Compared with the original image, it can be found that the present invention can achieve a relatively ideal effect regardless of whether the Anabaena is in a long strip or a curled shape.
[0119] like Fig. 9 As shown, the calculation of the number of Anabaena cells includes the following contents:
[0120] (1) On the binary image of Anabaena, recalculate the outer contour in the image and calculate its circumscribed rectangle;
[0121] (2) Divide the long side of the circumscribed rectangle by the short side and calculate its long-short side ratio. If the ratio is greater than the set threshold (4.0), it is considered that the shape of the fish algae in the image is a long strip;
[0122] ⑶ If the shape of Anabaena is long strip, find the short side of the circumscribed rectangle and use the short side to correct the pixel size of the unit cell of Anabaena;
[0123] (4) Calculate the pixel area of the binary image and divide it by the corrected unit cell pixel size to obtain the number of Anabaena cells;
[0124] ⑸ If the shape of Anabaena is not long strip, then the SimpleBlobDetector method is first used to detect Anabaena cells from the grayscale image;
[0125] (6) If multiple Anabaena cells of similar size are detected in step (5), their mean is used to correct the unit cell pixel size;
[0126] (7) Execute step (4) to count the number of cells of Anabaena;
[0127] ⑻If multiple Anabaena cells of similar size are not detected in step ⑸, the unit cell pixel size is not corrected, and the pixel area of the binary image is directly divided by the default cell pixel size to obtain the number of Anabaena cells.
[0128] like Fig.10 As shown, the dark numbers in the upper left corner of the Anabaena image are the number of cells counted by the present invention, and the bright numbers below are the number of Anabaena cells counted manually.
[0129] The above is only a preferred specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.< / point>
Claims
1. A method for counting cells of Anabaena based on microscope images, It is characterized in that The following steps are involved: Step ⑴ Image preprocessing: enhance the contrast of the image; Step ⑵ Image binarization: Find the anabaena area in the image; Step (3) calculating the minimum bounding rectangle of the anabaena: calculating the outer contours of the binary image and finding the minimum bounding rectangle of these contours; Step (4) Detecting the binary image of Anabaena: generating a binary image of Anabaena for cell counting according to the minimum bounding rectangle of Anabaena; Step (4) detecting the binary image of Anabaena specifically include: ⑴ Update the original binary image by combining the minimum circumscribed rectangle structure to form a cleaner binary image; ⑵First, generate a binary image with the same resolution as the original binary image, and fill the image with 0 by default; ⑶ Perform an AND operation on the Mask image generated in step ⑵ and the original binary image to obtain a binary image after filtering out the false detection data; (4) Calculate the contour of the binary image in step (3) and its hierarchical relationship; (5) Generating a binary image of Anabaena based on the detected contour data; Step (5) Generating a binary image of Anabaena based on the contour data specifically comprises: ⑴First, find the data with Parent=-1 from the hierarchy of the contour. These data are all outer contours. Calculate their minimum enclosing rectangle, and then match them with the width and height in the data structure to find the corresponding outer contour point set; ⑵ Generate a new binary image, the resolution of the binary image is consistent with the resolution of the original image, the initial value of each pixel of the binary image is 0, fill the area surrounded by the outer contour point set found in step ⑴, the filling value is 255, and generate a binary image of Anabaena; ⑶ When using OTSU binary segmentation image, it is inevitable that there will be holes (black) inside the cell area (white), which will cause the calculated pixel area of Anabaena cells to be smaller; (4) If shape=2 in the data structure, it means that the Anabaena cell is likely to be closed or curled. First, fill the outer contour according to step (2) to obtain a binary image contourImg1; ⑸ Find the data whose Parent is not equal to -1 from the hierarchy of the contour. These data are inner contours. Calculate their pixel area. If the area is greater than the set threshold, save their corresponding contour point set. (6) Generate a new binary image. The resolution of the binary image is consistent with that of the original image. The initial value of each pixel in the binary image is 0. Fill the area surrounded by all the inner contour points in step (5) with a filling value of 255 to obtain a binary image contourImg2. ⑺Subtract contourImg2 from contourImg1 to obtain the binary image of Anabaena; ⑻If the square Anabaena is closed, then contourImg2 has a white area, and the binary image of the actual Anabaena cell area in the image can be obtained through step ⑺; if the square Anabaena is not closed, then contourImg2 does not have a white area, and the binary image of Anabaena obtained in step ⑺ is actually contourImg1; Step (5) calculating the number of Anabaena cells: using the binary image calculated in step (4) to count the number of Anabaena cells.
2. The method for counting Anabaena cells based on microscope images according to claim 1, It is characterized in that Calculating the minimum bounding rectangle of the anabaena in step (3) includes: firstly calculating the outer contour based on the binary image, setting the outer contour of the threshold, secondly calculating the minimum bounding rectangle of the outer contour for the outer contour that meets the set threshold, calculating the minimum bounding rectangle structure based on the minimum bounding rectangle, and finally deleting the misdetected minimum bounding rectangle of the minimum bounding rectangle structure.
3. The method for counting Anabaena cells based on microscope images as claimed in claim 2, It is characterized in that Step (3) Calculating the minimum circumscribed rectangular structure includes the following steps: ⑴ Calculate the coordinates of the four vertices using the width, height, and rotation angle of the minimum circumscribed rectangle. The vertex coordinates are stored in pts[0], pts[1], pts[2], and pts[3] in a clockwise direction. ⑵Find the long side and short side of the minimum circumscribed rectangle, save the length of its long side in the width variable of the data structure, and save the length of its short side in the height variable of the data structure; (3) Calculate the ratio of the long side to the short side of the minimum circumscribed rectangle, and calculate its shape attribute according to the ratio. In the present invention, the shape attribute of the minimum circumscribed rectangle is divided into three forms: general shape, long strip shape and square shape, and the corresponding shape variable values are 0, 1 and 2; (4) Combine pts[0] and pts[1] into a line segment line1, and combine pts[1] and pts[2] into another line segment line2. By determining the lengths of the two line segments, we can find the line segment corresponding to the long side. ⑸ Calculate the distance in the x direction and the distance in the y direction of the coordinates of the two vertices of any long side segment, and determine its direction attribute. The direction attribute has only two states: horizontal and vertical, and is stored in the direction variable; (6) Compare the x-axis or y-axis coordinate values of the long side line segment according to the directional characteristics, save the long side line segment with a smaller value in the lineL variable, and save the long side line segment with a larger value in the lineR variable; ⑺lineL and lineR are also a structure. It has two parameters, namely the slope k and the intercept b on the y-axis. The parameters k and b of the line equations of lineL and lineR in the data structure are calculated respectively through the coordinates of the two vertices on the line segment.
4. The method for counting Anabaena cells based on microscope images as claimed in claim 3, It is characterized in that Step (4) of deleting the misdetected minimum bounding rectangle includes: ⑴Find the shape value of the smallest circumscribed rectangular structure and find the structure with shape=1; (2) Further analyze the structure of shape=1, and calculate the ratio of the width variable value to the image length according to its direction value. If the ratio is greater than the set threshold (0.75), the structure is used as the reference structure. ⑶ Based on the reference structure, analyze the positional relationship between the vertex coordinates of other structures and the reference structures lineL and lineR; (4) When calculating the projection of a point to a line segment, if direction=0 in the reference structure, first find the vertex with the maximum y axis and the vertex with the minimum y axis, substitute the x coordinate value of the vertex with the maximum y axis into the line equation of lineL, and calculate the coordinate value of the projection of the point to lineL in the corresponding y direction; ⑸ When calculating the projection of a point to a line segment, if direction=1 in the reference structure, first find the vertex with the largest x-axis and the vertex with the smallest x-axis, substitute the y-coordinate value of the vertex with the largest x-axis into the line equation of lineL, and calculate the coordinate value of the point projected onto lineL in the corresponding x-direction; ⑹When the reference structure direction=0, delete other structures above lineL or below lineR; when the reference structure direction=1, delete other structures to the left of lineL or to the right of lineR.
5. The method for counting Anabaena cells based on microscope images as claimed in claim 1, It is characterized in that Step (5) Calculating the number of Anabaena cells includes the following steps: (1) On the binary image of Anabaena, recalculate the outer contour in the image and calculate its circumscribed rectangle; (2) Divide the long side of the circumscribed rectangle by the short side and calculate its long-short side ratio. If the ratio is greater than the set threshold (4.0), it is considered that the shape of the fish algae in the image is a long strip; ⑶ If the shape of Anabaena is long strip, find the short side of the circumscribed rectangle and use the short side to correct the pixel size of the unit cell of Anabaena; (4) Calculate the pixel area of the binary image and divide it by the corrected unit cell pixel size to obtain the number of Anabaena cells; ⑸ If the shape of Anabaena is not long strip, then the spot detection method is first used to detect Anabaena cells from the grayscale image; (6) If multiple Anabaena cells of similar size are detected in step (5), their mean is used to correct the unit cell pixel size; (7) Execute step (4) to count the number of cells of Anabaena; ⑻If multiple Anabaena cells of similar size are not detected in step ⑸, the unit cell pixel size is not corrected, and the pixel area of the binary image is directly divided by the default cell pixel size to obtain the number of Anabaena cells.
6. The method for counting Anabaena cells based on microscope images as claimed in claim 5, It is characterized in that When counting cells using binary images, the pixel size of the unit cell is first corrected according to the morphology of Anabaena in the image, and then the pixel area of the white area in the binary image is calculated and divided by the corrected pixel size of the unit cell to calculate the number of cells.
