Description of the embodiments
Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to like or similar modules or modules having like or similar functions throughout. The embodiments described below by referring to the drawings are illustrative only and are not to be construed as limiting the invention. On the contrary, the embodiments of the invention include all alternatives, modifications and equivalents as may be included within the spirit and scope of the appended claims.
According to the embodiment of the invention, the straight line is determined by the pixels with the cell edges along the two pixels with the preset forward and backward distances, the coordinate difference value between the pixel and the straight line is the curve direction of the pixel, the first gradient direction and the curve direction of each pixel corresponding to the cell edges are calculated, the first gradient direction is corrected by the sign of the first gradient direction and the sign of the curve direction, the second gradient direction is obtained, the accuracy of calculating the circle center of the cell is improved, and the accuracy of cell counting is further ensured.
Fig. 2 is a flowchart of a gradient direction correction method according to an embodiment of the invention. As shown in fig. 2, the method includes the following steps.
Step S201: cell images containing cell edge information are acquired.
In the embodiment of the invention, the cell image can be a color image or a gray image obtained by shooting a glass slide filled with cell liquid under a microscope light path, wherein the color image or the gray image contains cell edge information. If the image is a color image, a gray image can be obtained through conversion, and then the gray image is converted into other cell images for later steps.
The cell image shown in fig. 1 is a gradient image converted from a gray scale image, and the cell image shown in fig. 3 is a gradient binarized image converted from a gradient image. In both fig. 1 and 3, a large circle is covered with a small circle or arc, and the large circle and the enclosed area thereof represent a cell. For each cell, the large circle, the small circle, and the circular arc are all called cell edges, and all three cover a number of pixels. The cell edge information includes the positions of the covered pixels of the large circle, the small circle and the circular arc, the corresponding pixel values, and the like. In fig. 3, the pixel value of the cell edge cover pixel is 255, and the pixel values of the other pixels are 0.
Step S202: cell edge information of single pixel thickness is extracted from the cell image.
Because the storage mode and the traversing mode of the cell image are in a row-column sequence mode, in order to facilitate the processing of pixels where cell edges are located in subsequent steps, as one embodiment of the invention, cell edge information is extracted from the cell image, and the cell edge information is stored in a one-dimensional array front-back sequence mode.
In order to improve the accuracy of calculating the center of the cell, the cell edge is processed into the cell edge with single pixel thickness, and then the extraction is carried out. As an embodiment of the present invention, as shown in fig. 4, the method of processing the cell edge to a single pixel thickness includes the following steps.
Step S401: judging whether each pixel corresponding to the cell edge meets a preset condition in the four adjacent areas.
Step S402: and removing the pixels meeting the preset conditions to obtain the cell edge with the single pixel thickness.
Fig. 5 lists 4 kinds of center points and the pixel distribution in the four fields. In the embodiment of the present invention, for each pixel corresponding to the edge of the cell, it is determined whether the pixels in the four neighboring regions thereof satisfy any distribution condition as shown in fig. 5, that is, whether the pixel values of the left and upper two pixels thereof are identical to each other, or whether the pixel values of the right and upper two pixels thereof are identical to each other, or whether the pixel values of the left and lower two pixels thereof are identical to each other, or whether the pixel values of the right and lower two pixels thereof are identical to each other, with respect to each pixel. If any distribution condition is satisfied, the pixel values are the same, and the thickness of the non-single pixel is judged, and the pixel (center point) needs to be removed; if none of the 4 cases is satisfied, it is determined as a single pixel thickness. The removal is to set the pixel value of the pixel to other values, such as to the same value as the background. Thereby obtaining a cell edge of single pixel thickness.
In the embodiment of the invention, the method for extracting the cell edge information with single pixel thickness comprises the following steps.
First, connected regions are divided in the gradient binarized image so that connected regions have the same region value and non-connected regions have different region values. The connected region division may use the existing eight-neighborhood marking algorithm, etc., and will not be described here again. Thus, a cell edge becomes a connected region, and a plurality of pixels covered by the connected region have the same region value, and as shown in fig. 6, the region value of the cell edge is 1; different cell edges are areas of non-connectivity, which cover pixels with different area values.
Then, the starting point of each connected region, i.e., the starting point of each cell edge is found. And taking any pixel covered by the cell edge as a central point, and counting the number of pixels with the same regional value as the pixels in the eight neighborhood. If the number is only 1, the pixel is set as the starting point of the connected area, namely the pixel is used as the starting point of the cell edge, and the next step is carried out; if the number is greater than 1, moving the center point to the pixel covered by the next cell edge, and repeating the operation of searching the starting point; if the pixel covered by the cell edge is not able to determine the starting point, the last center point is set as the starting point of the cell edge.
Finally, pixels covered by the cell edge from the starting point are stored in a one-dimensional array in a sequential manner. And taking the starting point as a central point, storing the information of the central point into an array, searching pixels with the area value equal to the area value in the eight adjacent domains according to the clockwise direction or the anticlockwise direction, moving the central point to the pixels after searching, and storing the information of the new central point into the array. The above operation is repeated until all pixels covered by the cell edge are traversed.
Step S203: the first gradient direction and curve direction of each pixel corresponding to the cell edge are calculated.
In the embodiment of the invention, the first gradient direction of each pixel corresponding to the cell edge is calculated according to the gray level diagram. The first gradient direction is defined in the field of image processing, and comprises a gradient direction in the X direction and a gradient direction in the Y direction. And calculating the curve direction of each pixel corresponding to the cell edge according to the gradient binarized image or the cell edge information extracted in the step 202. The curve direction of a pixel where the cell edge is located is: and determining a straight line by two pixels of which the front preset distance and the rear preset distance are along the edge of the cell, wherein the coordinate difference value between the vertical foot of the pixel to the straight line and the pixel is a curve direction. The curved direction also includes a curved direction of the X direction and a curved direction of the Y direction, corresponding to the first gradient direction.
Fig. 7 is a schematic diagram illustrating a curve direction of a pixel a according to an embodiment of the invention. Fig. 8 is a schematic diagram illustrating a curve direction of a pixel B according to an embodiment of the invention. As shown in fig. 7, the coordinates of the pixel a are (100 ), the front 5 pixels and the back 5 pixels along the cell edge are the pixel P1, the pixel P2 (the preset distance is 5 pixels, which is not limited herein), the pixel P1 and the pixel P2 determine a straight line, the vertical foot of the pixel a to the straight line is the pixel P, the coordinates of the pixel P are (150, 160), and the coordinate difference between the pixel P and the pixel a, that is, the curve direction of the pixel a is (50, 60); similarly, as shown in fig. 8, the coordinates of the pixel B are (400,180), which are the pixels P1 and P2 along the cell edge, the pixels P1 and P2 define a straight line, the vertical leg of the pixel B to the straight line is the pixel P, and the coordinates of the pixel P are (380, 190), so that the difference between the coordinates of the pixel P and the pixel B, i.e., the curve direction of the pixel B is (-20, 10).
Step S204: and correcting the first gradient direction according to the signs of the first gradient directions and the signs of the curve directions of all pixels corresponding to the cell edge to obtain a second gradient direction.
As an embodiment of the present invention, a process of correcting the first gradient direction of all pixels corresponding to the cell edge is shown in fig. 9, and the method includes the following steps.
Step S901: for all pixels corresponding to the cell edge, the sign of the first gradient direction and the sign of the curve direction are extracted.
Step S902: if the number of pixels with different numbers in the first gradient direction and the curve direction is more than that of pixels with the same number, the first gradient directions of all pixels corresponding to the cell edge are inverted to obtain a second gradient direction.
As shown in fig. 10, the left side is the gradient direction of the X direction of all pixels corresponding to a certain cell edge, and the right side is the sign of the curve direction of the X direction of all pixels corresponding to the cell edge (1 indicates positive sign, -1 indicates negative sign). And judging whether the gradient direction of each pixel in the X direction and the curve direction of the X direction are different numbers or same numbers. The method of judgment may be to multiply the two and then extract the symbol, which is not limited herein. As shown in fig. 11, the gradient direction in the X direction and the curve direction in the X direction are different numbers, i.e., the number of pixels with different numbers is greater than that of pixels with the same number. The gradient directions in the X direction of all pixels corresponding to the cell edge are inverted to obtain the corrected gradient directions in the X direction, as shown in fig. 12. Similarly, the same processing is performed on the gradient direction in the Y direction and the curve direction in the Y direction of all pixels corresponding to the cell edge, and the corrected gradient direction in the Y direction is obtained. The corrected gradient direction in the X direction and the corrected gradient direction in the Y direction are the second gradient direction. The second gradient direction obtained after correction is to actually correct the arrows on the right in fig. 1 from the opposite direction of the circle center to the direction of the circle center, so that the voting value in the cells of the virtual focus is increased.
In the embodiment of the invention, if the number of pixels with the same sign in the first gradient direction and the curve direction is more than that of pixels with different signs, the first gradient direction of all pixels corresponding to the cell edge is kept unchanged, and the circle center of the cell is calculated according to the first gradient direction kept unchanged in the subsequent steps. The first gradient method which is kept unchanged can also be endowed with the second gradient direction, and the subsequent step calculates the circle center of the cell according to the second gradient direction.
Step S205: and calculating the center of the cell according to the second gradient direction of each pixel corresponding to the edge of the cell.
In the embodiment of the invention, the circle center of the cell is calculated according to the second gradient direction of each pixel corresponding to the edge of the cell, i.e. voting is performed towards the direction of the circle center as much as possible so as to judge the circle center position of the cell. As shown in fig. 13, the left side is a cell image of cells which have not been subjected to correction treatment and cell sorting, the middle is a cell image of cells which have been subjected to cell sorting without correction treatment, and the right side is a cell image of cells which have been subjected to cell sorting after correction treatment. It can be seen that the middle cell image is circled with cells (the position indicated by the arrow), and the cells which are circled in the right cell image are circled (the position indicated by the arrow) after the gradient direction correction treatment, so that the accuracy of cell counting is ensured.
According to the embodiment of the invention, the straight line is determined by the pixels with the cell edges along the two pixels with the preset forward and backward distances, the coordinate difference value between the pixel and the straight line is the curve direction of the pixel, the first gradient direction and the curve direction of each pixel corresponding to the cell edges are calculated, the first gradient direction is corrected by the sign of the first gradient direction and the sign of the curve direction, the second gradient direction is obtained, the accuracy of calculating the circle center of the cell is improved, and the accuracy of cell counting is further ensured.
Fig. 14 is a block diagram of a gradient direction correcting device according to a second embodiment of the present invention, and as shown in fig. 14, the device includes: an acquisition unit 1401, a first calculation unit 1402, and a correction unit 1403.
The acquisition unit is used for acquiring a cell image containing cell edge information.
The first calculating unit is used for calculating a first gradient direction and a curve direction of each pixel corresponding to the cell edge, wherein a straight line is determined by two pixels of the pixel where the cell edge is located along the cell edge by a preset distance and a preset distance, and the coordinate difference value of the vertical foot and the pixel from the pixel to the straight line is the curve direction.
The correction unit is used for correcting the first gradient direction according to the signs of the first gradient directions and the signs of the curve directions of all pixels corresponding to the cell edge to obtain a second gradient direction.
Preferably, the correction unit 1403 includes a sign sub-unit and an inversion sub-unit.
The sign subunit is configured to extract, for all pixels corresponding to the cell edge, a sign of the first gradient direction and a sign of the curve direction.
The inverting subunit is configured to invert the first gradient directions of all pixels corresponding to the cell edge to obtain a second gradient direction if the pixels with different numbers in the first gradient direction and the curve direction are more than the pixels with the same number.
Preferably, the first gradient direction includes a gradient direction of the X direction and a gradient direction of the Y direction, and the curved direction includes a curved direction of the X direction and a curved direction of the Y direction.
Further, the gradient direction correcting device further comprises an extraction unit. The extraction unit is used for extracting cell edge information of single pixel thickness from the cell image.
Further, the gradient direction correcting device further includes a second calculating unit. The second calculating unit is used for calculating the circle center of the cell according to the second gradient direction of each pixel corresponding to the edge of the cell.
The gradient direction correcting method operated in the gradient direction correcting device corresponds to the method described in the first embodiment one by one, and will not be described herein.
According to the embodiment of the invention, the straight line is determined by the pixels with the cell edges along the two pixels with the preset forward and backward distances, the coordinate difference value between the pixel and the straight line is the curve direction of the pixel, the first gradient direction and the curve direction of each pixel corresponding to the cell edges are calculated, the first gradient direction is corrected by the sign of the first gradient direction and the sign of the curve direction, the second gradient direction is obtained, the accuracy of calculating the circle center of the cell is improved, and the accuracy of cell counting is further ensured.
While embodiments of the present invention have been shown and described above, it will be understood that the above embodiments are illustrative and not to be construed as limiting the invention, and that variations, modifications, alternatives and variations may be made to the above embodiments by one of ordinary skill in the art within the scope of the invention.