A method and system for judging the quality of pathological sections based on image processing
Through image processing technology, the OpenCV algorithm is used to preprocess, edge extract and shape match the images of wax blocks and pathological slices, solving the efficiency and accuracy problems of pathological slice quality determination in the existing technology, and realizing machine-intelligent quality. judgment, reducing workload and errors.
Patent Information
- Application Number
- CN202410314151.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-19
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-03-19
AI Technical Summary
In the existing technology, the machine-based intelligent judgment method of pathological slice quality mainly relies on stained slices, and cannot effectively judge the consistency of tissue and slices, integrity of sections, and contamination issues, resulting in manual review difficulties and low efficiency.
Through image processing technology, images of wax blocks and pathological sections are obtained, and preprocessing, edge extraction, shape matching, pixel calculation and image alignment are performed. The OpenCV algorithm is used to determine the consistency, integrity and contamination of the image to achieve machine intelligence. Quality judgment.
It greatly reduces the workload and time, reduces errors, and improves the accuracy and efficiency of pathological slice quality determination. It does not require the use of expensive scanners and is simple to maintain.
Smart Images

Figure CN118243695B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a method and system for judging the quality of pathological slices based on image processing. Background Art
[0002] Pathological specimens are made into tissue wax blocks through fixation, sampling, dehydration and embedding, and then the tissue wax blocks are sliced and stained to make pathological sections.
[0003] Pathology section quality control is the key link and foundation of clinical pathology quality control. The quality of pathology section production must meet the prescribed quality control standards and requirements. At present, the quality evaluation of pathology sections is mainly based on the evaluation of pathology technicians and doctors. Due to the huge amount of section data, the visual section quality evaluation must be transformed from manual review to machine intelligent screening. So far, the machine intelligent judgment method of pathology section quality has only been judged through stained pathology sections. However, some section quality problems cannot be judged by pathology sections alone, and need to be compared with the tissue in the wax block, such as whether the tissue is consistent with the section, whether the tissue section is complete, whether the section is contaminated, etc. Summary of the invention
[0004] In order to solve the deficiencies mentioned in the above background technology, the purpose of the present invention is to provide a pathological section quality judgment method and system based on image processing, which can use machine intelligent screening to assist technicians in efficiently and high-quality evaluation of the quality of pathological sections.
[0005] In the first aspect, the purpose of the present invention can be achieved by the following technical solutions:
[0006] In combination with the first aspect, in certain implementations of the first aspect, the method further includes: a pathological section quality determination method based on image processing, the method comprising the following steps:
[0007] Acquire a wax block image and a pathological section image, and preprocess the wax block image and the pathological section image to obtain a preprocessed wax block image and pathological section image;
[0008] The pre-processed wax block image and the pathological section image are subjected to edge extraction to obtain the edge contours of the wax block image and the pathological section image, and the edge contours of the wax block image and the pathological section image are matched to obtain the image similarity. According to the similarity, whether the wax block image and the pathological section image are consistent is determined. If they are inconsistent, the quality of the pathological section image is unqualified. If they are consistent, it is marked as a once-processed image.
[0009] Pixel calculation is performed on the wax block image and the pathological section image in the primary processing image to obtain the pixel area of the wax block image and the pixel area of the pathological section image, and the ratio of the pixel area of the wax block image to the pixel area of the pathological section image is calculated. According to the ratio, it is determined whether the pathological section is completely cut. If not, the quality of the pathological section image is unqualified. If it is completely cut, it is marked as a secondary processing image.
[0010] The wax block image in the secondary processed image is aligned with the pathological section image, and the difference part is obtained by subtracting the wax block image from the pathological section image. If the area of the difference part is a negative value, it is determined that there is no contamination in the pathological section image. If the area of the difference part is a positive value, it is determined that there is contamination in the pathological section image and the quality of the pathological section image is unqualified.
[0011] In another aspect of the present invention, in order to achieve the above-mentioned purpose, the process of preprocessing the wax block image and the pathological section image is disclosed:
[0012] The color channels of the wax block image and the pathological section image are separated, and the blue channel is selected to convert the original image into a black and white image; the hole filling operation is performed on the black and white image to remove the blank area of the tissue gap in the image to obtain the preprocessed wax block image and pathological section image.
[0013] In another aspect of the present invention, in order to achieve the above-mentioned purpose, the process of edge extraction of the pre-processed wax block image and the pathological section image is disclosed:
[0014] Use the edge extraction algorithm in OpenCV, findcontours() function, to obtain the contours of the wax block image and the pathological slice image respectively. The formula is as follows:
[0015] contours,_=cv2.findContours(image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
[0016] cv2.findContours is the edge extraction algorithm function in OpenCV. image is the input parameter of the function, which refers to the image whose contours are to be extracted. cv2.RETR_LIST and cv2.CHAIN_APPROX_SIMPLE are the hyperparameters in the algorithm. contours is the result of the function output, that is, the contour of the input image obtained by the function.
[0017] In another aspect of the present invention, in order to achieve the above-mentioned purpose, the edge contours of the wax block image and the pathological section image are matched to obtain the image similarity, and the shape matching method of the image contour in OpenCV is used, and the calculation process is as follows:
[0018] match=cv2.matchShapes(contour1,contour2,cv2.CONTOURS_MATCH_I1)
[0019] Among them, cv2.matchShapes is the shape matching method function of image contours in OpenCV, contour1 and contour2 are the parameters input to the function, which respectively refer to the contours of the two images whose similarity is to be calculated, and match is the result of the function output, which is the contour similarity result obtained by the function.
[0020] In another aspect of the present invention, in order to achieve the above-mentioned purpose, the process of calculating the ratio of the pixel area of the wax block image to the pixel area of the pathological section image and determining whether the pathological section is completely cut according to the ratio is disclosed:
[0021] The area of the wax block image is set to X, and the area of the pathological section image is set to Y. Y / X=Z, where Z is the ratio of the area of the pathological section image to the area of the wax block image. A ratio threshold Z0 is set. If Z≥Z0, the pathological section image is fully cut; if Z<Z0, the pathological section image is not fully cut.
[0022] In another aspect of the present invention, in order to achieve the above-mentioned object, the process of aligning the preprocessed wax block image with the pathological section image is disclosed, comprising:
[0023] Use the OpenCV algorithm to obtain the maximum connected domain in the two images respectively, and use the maximum connected tissue as the feature area for the alignment operation of the two images; then calculate the positions of the "top, bottom, and rightmost" pixels in the two images respectively as the mapping points before and after alignment; then use the perspective transformation algorithm in the OpenCV algorithm library to align the wax block image with the pathological section image.
[0024] In another aspect of the present invention, in order to achieve the above object, the calculation process of obtaining the maximum connected domain of an image using the OpenCV algorithm is disclosed as follows:
[0025] First, use the cv2.findContours function to find all the boundaries in the binary image; then use the cv2.contourArea function to calculate the area within each boundary and find the boundary with the largest internal area; finally, use the cv2.fillPoly function to fill the interior of the boundaries that are not the largest in area as the background in turn. Finally, the foreground area retained in the image is the largest connected domain.
[0026] In another aspect of the present invention, in order to achieve the above object, the process of aligning the wax block image with the pathological slice image using the perspective transformation algorithm in the OpenCV algorithm library is disclosed as follows:
[0027] First, obtain the three feature points of the same tissue position on the wax block image and the pathological section image, and take the "top, bottom, and rightmost" pixel positions on the two black and white images as the mapping points before and after alignment; then use these two sets of points to generate the perspective transformation matrix through the cv2.getPerspectiveTransform function. The function is as follows:
[0028] m=cv2.getPerspectiveTransform(src,dst)
[0029] Where m is the calculated perspective transformation matrix, src is the set of coordinates of three characteristic pixel points on the pathological image, and dst is the set of coordinates of three characteristic pixel points on the wax block image;
[0030] Then use the cv2.warpPerspective function to perform perspective transformation according to the perspective transformation matrix. The function is as follows:
[0031] img1=cv2.warpPerspective(img2,m,(width,height))
[0032] img1 is the wax block image after alignment with the pathological slice image, img2 is the wax block image before alignment, m is the perspective transformation matrix, (width, height) is the desired image width and height after the wax block image is transformed, and the width and height of the pathological slice image are used here.
[0033] In a second aspect, in order to achieve the above-mentioned purpose, the present invention discloses a pathological section quality determination system based on image processing, comprising:
[0034] An image processing module is used to obtain a wax block image and a pathological section image, and preprocess the wax block image and the pathological section image to obtain a preprocessed wax block image and pathological section image;
[0035] The contour matching module is used to extract the edges of the pre-processed wax block image and the pathological section image to obtain the edge contours of the wax block image and the pathological section image, match the edge contours of the wax block image and the pathological section image to obtain the image similarity, and determine whether the wax block image and the pathological section image are consistent according to the similarity. If they are inconsistent, the quality of the pathological section image is unqualified. If they are consistent, it is marked as a once-processed image;
[0036] A pixel comparison module is used to perform pixel calculation on the wax block image and the pathological section image in the primary processing image to obtain the pixel area of the wax block image and the pixel area of the pathological section image, calculate the ratio of the pixel area of the wax block image and the pixel area of the pathological section image, and determine whether the pathological section is completely cut according to the ratio. If not, the pathological section image quality is unqualified; if fully cut, it is marked as a secondary processing image;
[0037] The alignment difference module is used to align the wax block image in the secondary processed image with the pathological section image, and to obtain the difference part by subtracting the wax block image from the pathological section image. If the area of the difference part is a negative value, it is determined that there is no contamination in the pathological section image. If the area of the difference part is a positive value, it is determined that there is contamination in the pathological section image and the quality of the pathological section image is unqualified.
[0038] In conjunction with the second aspect, in some implementations of the second aspect, the system further includes: a process in which the image processing module preprocesses the wax block image and the pathological section image:
[0039] The color channels of the wax block image and the pathological section image are separated, and the blue channel is selected to convert the original image into a black and white image; the hole filling operation is performed on the black and white image to remove the blank area of the tissue gap in the image, and the preprocessed wax block image and pathological section image are obtained;
[0040] Preferably, the process of edge extraction of the pre-processed wax block image and the pathological slice image in the contour matching module is as follows:
[0041] Use the edge extraction algorithm in OpenCV, findcontours() function, to obtain the contours of the wax block image and the pathological slice image respectively. The formula is as follows:
[0042] contours,_=cv2.findContours(image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
[0043] cv2.findContours is the edge extraction algorithm function in OpenCV. image is the input parameter of the function, which refers to the image whose contours are to be extracted. cv2.RETR_LIST and cv2.CHAIN_APPROX_SIMPLE are the hyperparameters in the algorithm. contours is the result of the function output, that is, the contour of the input image obtained by the function.
[0044] In the contour matching module, the edge contours of the wax block image and the pathological slice image are matched to obtain the image similarity. The shape matching method of the image contour in OpenCV is used. The calculation process is as follows:
[0045] match=cv2.matchShapes(contour1,contour2,cv2.CONTOURS_MATCH_I1)
[0046] Among them, cv2.matchShapes is the shape matching method function of image contours in OpenCV, contour1 and contour2 are the parameters input to the function, which refer to the contours of the two images whose similarity is to be calculated, and match is the result of the function output, which is the contour similarity result obtained by the function;
[0047] Preferably, the pixel comparison module calculates the ratio of the pixel area of the wax block image to the pixel area of the pathological section image, and determines whether the pathological section is completely cut according to the ratio:
[0048] The area of the wax block image is set as X, and the area of the pathological slice image is set as Y. Y / X=Z, where Z is the ratio of the area of the pathological slice image to the area of the wax block image. A ratio threshold Z0 is set. If Z≥Z0, the pathological slice image is fully cut; if Z<Z0, the pathological slice image is not fully cut.
[0049] Preferably, the process of aligning the preprocessed wax block image with the pathological section image in the alignment difference module includes:
[0050] Use the OpenCV algorithm to obtain the maximum connected domain in the two images respectively, and use the maximum connected tissue as the feature area for the alignment operation of the two images; then calculate the positions of the "top, bottom, and rightmost" pixels in the two images respectively as the mapping points before and after alignment; then use the perspective transformation algorithm in the OpenCV algorithm library to align the wax block image with the pathological slice image;
[0051] Preferably, the calculation process of obtaining the maximum connected domain of the image using the OpenCV algorithm in the alignment difference module is as follows:
[0052] First, use the cv2.findContours function to find all the boundaries in the binary image; then use the cv2.contourArea function to calculate the area within each boundary and find the boundary with the largest internal area; finally, use the cv2.fillPoly function to fill the inside of the boundary that is not the largest as the background in turn, and the foreground area retained in the final image is the largest connected domain;
[0053] Preferably, the perspective transformation algorithm in the OpenCV algorithm library is used in the alignment difference module to align the wax block image with the pathological slice image as follows:
[0054] First, obtain the three feature points of the same tissue position on the wax block image and the pathological section image, and take the top, bottom, and rightmost pixel positions on the two black and white images as the mapping points before and after alignment; then use these two sets of points to generate the perspective transformation matrix through the cv2.getPerspectiveTransform function. The function is as follows:
[0055] m=cv2.getPerspectiveTransform(src,dst)
[0056] Where m is the calculated perspective transformation matrix, src is the set of coordinates of three characteristic pixel points on the pathological image, and dst is the set of coordinates of three characteristic pixel points on the wax block image;
[0057] Then use the cv2.warpPerspective function to perform perspective transformation according to the perspective transformation matrix. The function is as follows:
[0058] img1=cv2.warpPerspective(img2,m,(width,height))
[0059] img1 is the wax block image after alignment with the pathological slice image, img2 is the wax block image before alignment, m is the perspective transformation matrix, (width, height) is the desired image width and height after the wax block image is transformed, and the width and height of the pathological slice image are used here.
[0060] Beneficial effects of the present invention:
[0061] The present invention can detect whether the tissue is consistent with the slice, whether the tissue section is complete, whether the slice is contaminated, etc. by comparing the wax block and the slice.
[0062] The present invention uses an image processing-assisted determination method, which greatly reduces workload, saves time, and reduces work errors.
[0063] The present invention can obtain the images of wax blocks and slices by using a camera without using a scanner, has low cost, high speed, and is simple and easy to maintain. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art description are briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0065] Figure 1 It is a schematic flow chart of the method of the present invention;
[0066] Figure 2 It is a schematic diagram of the wax block and pathological section image of the present invention;
[0067] Figure 3 It is a schematic diagram of a wax block image and a pathological section image group of the present invention;
[0068] Figure 4 is a schematic diagram of the image processing results of the wax block and the pathological section image of the present invention;
[0069] Figure 5 It is a schematic diagram of a group of incompletely cut wax blocks and pathological section images of the present invention;
[0070] Figure 6 It is a schematic diagram of a group of wax blocks and pathological slice images with contamination according to the present invention;
[0071] Figure 7 It is a schematic diagram of the system structure of the present invention. DETAILED DESCRIPTION
[0072] 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.
[0073] Embodiment 1:
[0074] The following is an introduction to the relevant terms involved in the embodiments of the present application:
[0075] Pathological section: Take a certain size of lesion tissue, make a pathological section using pathological histological methods [usually embed the lesion tissue in paraffin blocks, cut it into thin slices with a slicer, and then stain it with hematoxylin-eosin (HE)], and further examine the lesion under a microscope. The occurrence and development process of the lesion is finally made a pathological diagnosis.
[0076] Edge extraction refers to the processing of image contours in digital image processing. For the boundary, the place where the gray value changes drastically is defined as the edge. That is, the inflection point, which refers to the point where the function changes concave and convex. The place where the second-order derivative is zero. It is not the first-order derivative, because the first-order derivative is zero, indicating an extreme point.
[0077] Edge extraction: The basic idea of edge detection is to first use the edge enhancement operator to highlight the local edges in the image, then define the "edge strength" of the pixel, and extract the edge point set by setting the threshold. Due to the presence of noise and blur, the detected boundary may become wider or discontinuous at a certain point. Therefore, boundary detection includes two basic contents: (1) Use the edge operator to extract the edge point set that reflects the grayscale change. (2) Eliminate certain boundary points in the edge point set or fill the boundary discontinuities, and connect these edges into a complete line.
[0078] OpenCV: OpenCV is a cross-platform computer vision and machine learning software library released under the Apache 2.0 license (open source), which can run on Linux, Windows, Android and Mac OS operating systems. It is lightweight and efficient - consisting of a series of C functions and a small number of C++ classes, while providing interfaces for languages such as Python, Ruby, and MATLAB, and implementing many common algorithms in image processing and computer vision.
[0079] like Figure 1 As shown, a method for judging the quality of pathological sections based on image processing is characterized in that the method comprises the following steps:
[0080] Acquire a wax block image and a pathological section image, and preprocess the wax block image and the pathological section image to obtain a preprocessed wax block image and pathological section image;
[0081] The wax block image and the pathological section image are acquired using a color camera;
[0082] The color channels of the wax block image and the pathological section image in RGB color mode are separated, and the blue channel is selected to convert the original image into a black and white image; the hole filling operation is performed on the black and white image to remove the blank area of the tissue gap in the image, and the preprocessed wax block image and pathological section image are obtained;
[0083] The pre-processed wax block image and the pathological section image are subjected to edge extraction to obtain the edge contours of the wax block image and the pathological section image, and the edge contours of the wax block image and the pathological section image are matched to obtain the image similarity. According to the similarity, whether the wax block image and the pathological section image are consistent is determined. If they are inconsistent, the quality of the pathological section image is unqualified. If they are consistent, it is marked as a once-processed image.
[0084] Furthermore, the edge extraction process of the pre-processed wax block image and the pathological section image is as follows:
[0085] Use the edge extraction algorithm in OpenCV, findcontours() function, to obtain the contours of the wax block image and the pathological slice image respectively. The formula is as follows:
[0086] contours,_=cv2.findContours(image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
[0087] cv2.findContours is the edge extraction algorithm function in OpenCV. image is the input parameter of the function, which refers to the image whose contours are to be extracted. cv2.RETR_LIST and cv2.CHAIN_APPROX_SIMPLE are the hyperparameters in the algorithm. contours is the result of the function output, that is, the contour of the input image obtained by the function.
[0088] Among them, the edge contours of the wax block image and the pathological section image are matched to obtain the image similarity. The shape matching method of the image contour in OpenCV is used. The calculation process is as follows:
[0089] match=cv2.matchShapes(contour1,contour2,cv2.CONTOURS_MATCH_I1)
[0090] Among them, cv2.matchShapes is the shape matching method function of image contours in OpenCV, contour1 and contour2 are the parameters input to the function, which respectively refer to the contours of the two images whose similarity is to be calculated, and match is the result of the function output, which is the contour similarity result obtained by the function.
[0091] Pixel calculation is performed on the wax block image and the pathological section image in the primary processing image to obtain the pixel area of the wax block image and the pixel area of the pathological section image, and the ratio of the pixel area of the wax block image to the pixel area of the pathological section image is calculated. According to the ratio, it is determined whether the pathological section is completely cut. If not, the quality of the pathological section image is unqualified. If it is completely cut, it is marked as a secondary processing image.
[0092] Furthermore, the ratio of the pixel area of the wax block image to the pixel area of the pathological section image is calculated, and the process of determining whether the pathological section is completely cut is determined according to the ratio:
[0093] The area of the wax block image is set to X, and the area of the pathological section image is set to Y. Y / X=Z, where Z is the ratio of the area of the pathological section image to the area of the wax block image. A ratio threshold Z0 is set. If Z≥Z0, the pathological section image is fully cut; if Z<Z0, the pathological section image is not fully cut.
[0094] In this embodiment, Z0 is 0.8;
[0095] The wax block image in the secondary processed image is aligned with the pathological section image, and the difference part is obtained by subtracting the wax block image from the pathological section image. If the area of the difference part is a negative value, it is determined that there is no contamination in the pathological section image. If the area of the difference part is a positive value, it is determined that there is contamination in the pathological section image and the quality of the pathological section image is unqualified.
[0096] The process of aligning the preprocessed wax block image with the pathological section image includes:
[0097] Use the OpenCV algorithm to obtain the maximum connected domain in the two images respectively, and use the maximum connected tissue as the feature area for the alignment operation of the two images; then calculate the positions of the "top, bottom, and rightmost" pixels in the two images respectively as the mapping points before and after alignment; then use the perspective transformation algorithm in the OpenCV algorithm library to align the wax block image with the pathological section image.
[0098] The calculation process of obtaining the maximum connected domain of an image using the OpenCV algorithm is as follows:
[0099] First, use the cv2.findContours function to find all the boundaries in the binary image; then use the cv2.contourArea function to calculate the area within each boundary and find the boundary with the largest internal area; finally, use the cv2.fillPoly function to fill the interior of the boundaries that are not the largest in area as the background in turn. Finally, the foreground area retained in the image is the largest connected domain.
[0100] Using the perspective transformation algorithm in the OpenCV algorithm library, the process of aligning the wax block image to the pathological slice image is as follows:
[0101] First, obtain the three feature points of the same tissue position on the wax block image and the pathological section image, and take the "top, bottom, and rightmost" pixel positions on the two black and white images as the mapping points before and after alignment; then use these two sets of points to generate the perspective transformation matrix through the cv2.getPerspectiveTransform function. The function is as follows:
[0102] m=cv2.getPerspectiveTransform(src,dst)
[0103] Where m is the calculated perspective transformation matrix, src is the set of coordinates of three characteristic pixel points on the pathological image, and dst is the set of coordinates of three characteristic pixel points on the wax block image;
[0104] Then use the cv2.warpPerspective function to perform perspective transformation according to the perspective transformation matrix. The function is as follows:
[0105] img1=cv2.warpPerspective(img2,m,(width,height))
[0106] img1 is the wax block image after alignment with the pathological slice image, img2 is the wax block image before alignment, m is the perspective transformation matrix, (width, height) is the desired image width and height after the wax block image is transformed, and the width and height of the pathological slice image are used here.
[0107] Specifically, the present invention is further described below by way of embodiments:
[0108] like Figure 3 As shown, Figure 3 (a) is a set of wax blocks and images of pathological sections. It can be seen from the image that the shape of the pathological section is basically consistent with the wax block, so it can be considered that the wax block and the pathological section are consistent; the area of the pathological section is basically consistent with the wax block, so it can be considered that the pathological section is completely cut; there is no area in the section image that is larger than the wax block image, so it is considered that there is no contamination in the pathological section. Based on the three aspects, it can be considered that the quality of the pathological section is qualified. Figure 3 (b) The shape of the pathological section is quite different from that of the wax block, and the wax block and the pathological section are inconsistent. Figure 3 (c) The shape of the pathological section is basically the same as the wax block, so it can be considered that the wax block and the pathological section are consistent; however, further inspection shows that the area of the pathological section is smaller than the wax block, so it can be considered that the pathological section is not completely cut. Figure 3 (d) The shape of the pathological section is basically consistent with the wax block, so it can be considered that the wax block and the pathological section are consistent; further inspection shows that the pathological section is completely cut; but further inspection shows that tissues that are not in the wax block image appear on the pathological section, so this part is contaminated. In summary, Figure 3 The pathological sections of (bd) are all samples of unqualified quality.
[0109] Figure 4The following is a set of image processing results of matching wax blocks and pathological sections. (a) is the original RGB image, (b) is the black-and-white image, and (c) is the black-and-white image after removing the holes in the black-and-white image. The purpose of obtaining the black-and-white image is to facilitate the contour extraction of the subsequent algorithm. (d) is the extracted edge contour image. After extracting the edge images of the wax block image and the pathological section image, the shape matching method of the image contour is used to compare the image similarity based on the edge contours of the two images. The contour similarity value of the two images obtained by the current algorithm is 0.363. According to the principle of the shape matching method of the image contour, the more similar the two images are, the closer the result returned by the method is to 0. The contour similarity of the current two images is less than the set threshold of 0.8, indicating that the current wax block image contour is similar to the pathological section image contour. The conclusion obtained by the algorithm is consistent with the conclusion of the technicians, both of which are consistent with the wax block image and the section image, demonstrating the reliability of the current algorithm.
[0110] like Figure 5 (a) is a wax block image and a pathological section image group. Figure 5 (b) is a black and white image. The number of pixels in the black area of the wax block image and the pathological slice image is calculated respectively. The area of the wax block image is X = 23469 pixels, and the area of the slice image is Y = 13825 pixels. According to Y / X = Z, the value of Z is 0.589. This evaluation believes that Z ≥ 0.8 is considered to be fully cut, and Z < 0.8 is considered to be incomplete. Therefore, this group of wax block and slice image group determined that the wax block was not fully cut.
[0111] Figure 6 (a) is a group of contaminated wax blocks and pathological section images. Figure 6 (b) a black and white image with holes removed from the image group, Figure 6 (c) is the largest connected domain in the two images. Figure 6 (d) is the calculated three sets of pixel position mapping points of the image: the top, bottom, and right. Figure 6 (e) is a wax block image after perspective transformation using the OpenCV algorithm library based on the three groups of mapping points. After image alignment, the positions of the tissues in the two images are basically aligned. Figure 6 (f) is the positive result obtained by subtracting the wax block image from the pathological slice image. The area of this part is calculated to be 13461 pixels, which is 13461 / (600*600)=0.037 of the original image size. The acceptable error threshold is set to 0.01, that is, 600 error pixels are allowed on a 600*600 image. The current ratio exceeds the set threshold, and it is considered that there is contamination on the pathological slice. This conclusion is consistent with Figure 6 The contaminated areas visible in (a) are consistent.
[0112] Embodiment 2: In the second aspect, as Figure 7 As shown, in order to achieve the above-mentioned purpose, the present invention discloses a pathological section quality judgment system based on image processing, comprising:
[0113] An image processing module is used to obtain a wax block image and a pathological section image, and preprocess the wax block image and the pathological section image to obtain a preprocessed wax block image and pathological section image;
[0114] The contour matching module is used to extract the edges of the pre-processed wax block image and the pathological section image to obtain the edge contours of the wax block image and the pathological section image, match the edge contours of the wax block image and the pathological section image to obtain the image similarity, and determine whether the wax block image and the pathological section image are consistent according to the similarity. If they are inconsistent, the quality of the pathological section image is unqualified. If they are consistent, it is marked as a once-processed image;
[0115] A pixel comparison module is used to perform pixel calculation on the wax block image and the pathological section image in the primary processing image to obtain the pixel area of the wax block image and the pixel area of the pathological section image, calculate the ratio of the pixel area of the wax block image and the pixel area of the pathological section image, and determine whether the pathological section is completely cut according to the ratio. If not, the pathological section image quality is unqualified; if fully cut, it is marked as a secondary processing image;
[0116] The alignment difference module is used to align the wax block image in the secondary processed image with the pathological section image, and to obtain the difference part by subtracting the wax block image from the pathological section image. If the area of the difference part is a negative value, it is determined that there is no contamination in the pathological section image. If the area of the difference part is a positive value, it is determined that there is contamination in the pathological section image and the quality of the pathological section image is unqualified.
[0117] In conjunction with the second aspect, in some implementations of the second aspect, the system further includes: a process in which the image processing module preprocesses the wax block image and the pathological section image:
[0118] The color channels of the wax block image and the pathological section image are separated, and the blue channel is selected to convert the original image into a black and white image; the hole filling operation is performed on the black and white image to remove the blank area of the tissue gap in the image, and the preprocessed wax block image and pathological section image are obtained;
[0119] Preferably, the process of edge extraction of the pre-processed wax block image and the pathological slice image in the contour matching module is as follows:
[0120] Use the edge extraction algorithm in OpenCV, findcontours() function, to obtain the contours of the wax block image and the pathological slice image respectively. The formula is as follows:
[0121] contours,_=cv2.findContours(image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
[0122] cv2.findContours is the edge extraction algorithm function in OpenCV. image is the input parameter of the function, which refers to the image whose contours are to be extracted. cv2.RETR_LIST and cv2.CHAIN_APPROX_SIMPLE are the hyperparameters in the algorithm. contours is the result of the function output, that is, the contour of the input image obtained by the function.
[0123] In the contour matching module, the edge contours of the wax block image and the pathological slice image are matched to obtain the image similarity. The shape matching method of the image contour in OpenCV is used. The calculation process is as follows:
[0124] match=cv2.matchShapes(contour1,contour2,cv2.CONTOURS_MATCH_I1)
[0125] Among them, cv2.matchShapes is the shape matching method function of image contours in OpenCV, contour1 and contour2 are the parameters input to the function, which refer to the contours of the two images whose similarity is to be calculated, and match is the result of the function output, which is the contour similarity result obtained by the function;
[0126] Preferably, the pixel comparison module calculates the ratio of the pixel area of the wax block image to the pixel area of the pathological section image, and determines whether the pathological section is completely cut according to the ratio:
[0127] The area of the wax block image is set as X, and the area of the pathological slice image is set as Y. Y / X=Z, where Z is the ratio of the area of the pathological slice image to the area of the wax block image. A ratio threshold Z0 is set. If Z≥Z0, the pathological slice image is fully cut; if Z<Z0, the pathological slice image is not fully cut.
[0128] Preferably, the process of aligning the preprocessed wax block image with the pathological section image in the alignment difference module includes:
[0129] Use the OpenCV algorithm to obtain the maximum connected domain in the two images respectively, and use the maximum connected tissue as the feature area for the alignment operation of the two images; then calculate the positions of the "top, bottom, and rightmost" pixels in the two images respectively as the mapping points before and after alignment; then use the perspective transformation algorithm in the OpenCV algorithm library to align the wax block image with the pathological slice image;
[0130] Preferably, the calculation process of obtaining the maximum connected domain of the image using the OpenCV algorithm in the alignment difference module is as follows:
[0131] First, use the cv2.findContours function to find all the boundaries in the binary image; then use the cv2.contourArea function to calculate the area within each boundary and find the boundary with the largest internal area; finally, use the cv2.fillPoly function to fill the inside of the boundary that is not the largest as the background in turn, and the foreground area retained in the final image is the largest connected domain;
[0132] Preferably, the perspective transformation algorithm in the OpenCV algorithm library is used in the alignment difference module to align the wax block image with the pathological slice image as follows:
[0133] First, obtain the three feature points of the same tissue position on the wax block image and the pathological section image, and take the top, bottom, and rightmost pixel positions on the two black and white images as the mapping points before and after alignment; then use these two sets of points to generate the perspective transformation matrix through the cv2.getPerspectiveTransform function. The function is as follows:
[0134] m=cv2.getPerspectiveTransform(src,dst)
[0135] Where m is the calculated perspective transformation matrix, src is the set of coordinates of three characteristic pixel points on the pathological image, and dst is the set of coordinates of three characteristic pixel points on the wax block image;
[0136] Then use the cv2.warpPerspective function to perform perspective transformation according to the perspective transformation matrix. The function is as follows:
[0137] img1=cv2.warpPerspective(img2,m,(width,height))
[0138] img1 is the wax block image after alignment with the pathological slice image, img2 is the wax block image before alignment, m is the perspective transformation matrix, (width, height) is the desired image width and height after the wax block image is transformed, and the width and height of the pathological slice image are used here.
[0139] Based on the same inventive concept, the present invention also provides a computer device, which includes: one or more processors, and a memory for storing one or more computer programs; the program includes program instructions, and the processor is used to execute the program instructions stored in the memory. 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 gates or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, which is used to implement one or more instructions, specifically for loading and executing one or more instructions in a computer storage medium to implement the above method.
[0140] It needs to be further explained that, based on the same inventive concept, the present invention also provides a computer storage medium, on which a computer program is stored, and the computer program is executed by a processor to execute the above method. The storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electrical, magnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0141] In the description of this specification, the description with reference to the terms "one embodiment", "example", "specific example", etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0142] The above shows and describes the basic principles, main features and advantages of the present disclosure. Those skilled in the art should understand that the present disclosure is not limited by the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present disclosure. Without departing from the spirit and scope of the present disclosure, the present disclosure may have various changes and improvements, and these changes and improvements fall within the scope of the present disclosure to be protected.
Claims
1. A method for judging the quality of pathological sections based on image processing, characterized in that: The method comprises the following steps: Acquire a wax block image and a pathological section image, and preprocess the wax block image and the pathological section image to obtain a preprocessed wax block image and pathological section image; The pre-processed wax block image and the pathological section image are subjected to edge extraction to obtain the edge contours of the wax block image and the pathological section image, and the edge contours of the wax block image and the pathological section image are matched to obtain the image similarity. According to the similarity, whether the wax block image and the pathological section image are consistent is determined. If they are inconsistent, the quality of the pathological section image is unqualified. If they are consistent, it is marked as a once-processed image. Pixel calculation is performed on the wax block image and the pathological section image in the primary processing image to obtain the pixel area of the wax block image and the pixel area of the pathological section image, and the ratio of the pixel area of the wax block image to the pixel area of the pathological section image is calculated. According to the ratio, it is determined whether the pathological section is completely cut. If not, the quality of the pathological section image is unqualified. If it is completely cut, it is marked as a secondary processing image. The wax block image in the secondary processed image is aligned with the pathological section image, and the difference part is obtained by subtracting the wax block image from the pathological section image. If the area of the difference part is a negative value, it is determined that there is no contamination in the pathological section image. If the area of the difference part is a positive value, it is determined that there is contamination in the pathological section image and the quality of the pathological section image is unqualified.
2. The method for determining the quality of pathological sections based on image processing according to claim 1, characterized in that: The process of preprocessing the wax block image and the pathological section image: The color channels of the wax block image and the pathological section image are separated, and the blue channel is selected to convert the original image into a black and white image; the hole filling operation is performed on the black and white image to remove the blank area of the tissue gap in the image to obtain the preprocessed wax block image and pathological section image.
3. The method for judging the quality of pathological sections based on image processing according to claim 1, characterized in that: The process of edge extraction of the pre-processed wax block image and the pathological section image: Use the edge extraction algorithm in OpenCV, findcontours() function, to obtain the contours of the wax block image and the pathological slice image respectively. The formula is as follows: contours,_=cv2.findContours(image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE) cv2.findContours is the edge extraction algorithm function in OpenCV. image is the input parameter of the function, which refers to the image whose contours are to be extracted. cv2.RETR_LIST and cv2.CHAIN_APPROX_SIMPLE are the hyperparameters in the algorithm. contours is the result of the function output, that is, the contour of the input image obtained by the function.
4. The method for judging the quality of pathological sections based on image processing according to claim 1, characterized in that: The edge contours of the wax block image and the pathological slice image are matched to obtain the image similarity, using the shape matching method of the image contour in OpenCV, and the calculation process is as follows: match = cv2.matchShapes(contour1, contour2, cv2.CONTOURS_MATCH_I1) where cv2.matchShapes is the shape matching method function of image contours in OpenCV, contour1 and contour2 are the parameters input to the function, which respectively refer to the contours of the two images whose similarity is to be calculated, and match is the result of the function output, which is the contour similarity result obtained by the function.
5. The method for judging the quality of pathological sections based on image processing according to claim 1, characterized in that: The process of calculating the ratio of the pixel area of the wax block image to the pixel area of the pathological section image, and determining whether the pathological section is completely cut according to the ratio: The area of the wax block image is set to X, and the area of the pathological section image is set to Y. Y / X=Z, where Z is the ratio of the area of the pathological section image to the area of the wax block image. A ratio threshold Z0 is set. If Z≥Z0, the pathological section image is fully cut; if Z<Z0, the pathological section image is not fully cut.
6. The method for judging the quality of pathological sections based on image processing according to claim 1, characterized in that: The process of aligning the preprocessed wax block image with the pathological section image comprises: The OpenCV algorithm is used to obtain the maximum connected domain in the two images respectively, and the maximum connected tissue is used as the feature area for the alignment operation of the two images; then the positions of the top, bottom and rightmost pixels in the two images are calculated respectively as the mapping points before and after alignment; then the perspective transformation algorithm in the OpenCV algorithm library is used to align the wax block image with the pathological section image.
7. The method for judging the quality of pathological sections based on image processing according to claim 6, characterized in that: The calculation process of obtaining the maximum connected domain of an image using the OpenCV algorithm is as follows: First, use the cv2.findContours function to find all the boundaries in the binary image; then use the cv2.contourArea function to calculate the area within each boundary and find the boundary with the largest internal area; finally, use the cv2.fillPoly function to fill the interior of the boundaries that are not the largest in area as the background in turn, and finally the foreground area retained in the image is the largest connected domain.
8. The method for judging the quality of pathological sections based on image processing according to claim 6, characterized in that: The process of aligning the wax block image with the pathological slice image using the perspective transformation algorithm in the OpenCV algorithm library is as follows: First, obtain the three feature points of the same tissue position on the wax block image and the pathological section image, and take the top, bottom, and rightmost pixel positions on the two black and white images as the mapping points before and after alignment; then use these two sets of points to generate the perspective transformation matrix through the cv2.getPerspectiveTransform function. The function is as follows: m=cv2.getPerspectiveTransform(src,dst) Where m is the calculated perspective transformation matrix, src is the set of coordinates of three characteristic pixel points on the pathological image, and dst is the set of coordinates of three characteristic pixel points on the wax block image; Then use the cv2.warpPerspective function to perform perspective transformation according to the perspective transformation matrix. The function is as follows: img1=cv2.warpPerspective(img2,m,(width,height)) img1 is the wax block image after alignment with the pathological slice image, img2 is the wax block image before alignment, m is the perspective transformation matrix, width and height are the desired image width and height after the wax block image is transformed, and the width and height of the pathological slice image are used.
9. A pathological section quality identification system based on image processing, characterized in that: include: An image processing module is used to obtain a wax block image and a pathological section image, and preprocess the wax block image and the pathological section image to obtain a preprocessed wax block image and pathological section image; The contour matching module is used to extract the edges of the pre-processed wax block image and the pathological section image to obtain the edge contours of the wax block image and the pathological section image, match the edge contours of the wax block image and the pathological section image to obtain the image similarity, and determine whether the wax block image and the pathological section image are consistent according to the similarity. If they are inconsistent, the quality of the pathological section image is unqualified. If they are consistent, it is marked as a once-processed image; A pixel comparison module is used to perform pixel calculation on the wax block image and the pathological section image in the primary processing image to obtain the pixel area of the wax block image and the pixel area of the pathological section image, calculate the ratio of the pixel area of the wax block image and the pixel area of the pathological section image, and determine whether the pathological section is completely cut according to the ratio. If not, the pathological section image quality is unqualified; if fully cut, it is marked as a secondary processing image; The alignment difference module is used to align the wax block image in the secondary processed image with the pathological section image, and to obtain the difference part by subtracting the wax block image from the pathological section image. If the area of the difference part is a negative value, it is determined that there is no contamination in the pathological section image. If the area of the difference part is a positive value, it is determined that there is contamination in the pathological section image and the quality of the pathological section image is unqualified.
10. The pathological section quality identification system based on image processing according to claim 9, characterized in that: The image processing module pre-processes the wax block image and the pathological section image: The color channels of the wax block image and the pathological section image are separated, and the blue channel is selected to convert the original image into a black and white image; the hole filling operation is performed on the black and white image to remove the blank area of the tissue gap in the image, and the preprocessed wax block image and pathological section image are obtained; The process of edge extraction between the pre-processed wax block image and the pathological section image in the contour matching module: Use the edge extraction algorithm in OpenCV, findcontours() function, to obtain the contours of the wax block image and the pathological slice image respectively. The formula is as follows: contours,_=cv2.findContours(image,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE) cv2.findContours is the edge extraction algorithm function in OpenCV. image is the input parameter of the function, which refers to the image to be extracted. cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE are the hyperparameters in the algorithm. contours is the result of the function output, that is, the contour of the input image obtained by the function. In the contour matching module, the edge contours of the wax block image and the pathological slice image are matched to obtain the image similarity. The shape matching method of the image contour in OpenCV is used. The calculation process is as follows: match = cv2.matchShapes(contour1, contour2, cv2.CONTOURS_MATCH_I1) where cv2.matchShapes is the shape matching method function of image contours in OpenCV, contour1 and contour2 are the input parameters of the function, which refer to the contours of the two images to be calculated for similarity, and match is the result of the function output, which is the contour similarity result obtained by the function; The pixel comparison module calculates the ratio of the pixel area of the wax block image to the pixel area of the pathological section image, and determines whether the pathological section is completely cut according to the ratio: The area of the wax block image is set as X, and the area of the pathological slice image is set as Y. Y / X=Z, where Z is the ratio of the area of the pathological slice image to the area of the wax block image. A ratio threshold Z0 is set. If Z≥Z0, the pathological slice image is fully cut; if Z<Z0, the pathological slice image is not fully cut. The process of aligning the preprocessed wax block image with the pathological section image in the alignment difference module includes: Use OpenCV algorithm to obtain the maximum connected domain in the two images respectively, and use the maximum connected tissue as the feature area for the alignment operation of the two images; then calculate the positions of the "top, bottom, and rightmost" pixels in the two images respectively as the mapping points before and after alignment; Then, the perspective transformation algorithm in the OpenCV algorithm library is used to align the wax block image with the pathological section image; The calculation process of using OpenCV algorithm to obtain the maximum connected domain of the image in the alignment difference module is as follows: First, use the cv2.findContours function to find all the boundaries in the binary image; then use the cv2.contourArea function to calculate the area within each boundary and find the boundary with the largest internal area; finally, use the cv2.fillPoly function to fill the inside of the boundary that is not the largest as the background in turn, and the foreground area retained in the final image is the largest connected domain; The alignment difference module uses the perspective transformation algorithm in the OpenCV algorithm library to align the wax block image with the pathological slice image as follows: First, obtain the three feature points of the same tissue position on the wax block image and the pathological section image, and take the top, bottom, and rightmost pixel positions on the two black and white images as the mapping points before and after alignment; then use these two sets of points to generate the perspective transformation matrix through the cv2.getPerspectiveTransform function. The function is as follows: m=cv2.getPerspectiveTransform(src,dst) Where m is the calculated perspective transformation matrix, src is the set of coordinates of three characteristic pixel points on the pathological image, and dst is the set of coordinates of three characteristic pixel points on the wax block image; Then use the cv2.warpPerspective function to perform perspective transformation according to the perspective transformation matrix. The function is as follows: img1=cv2.warpPerspective(img2,m,(width,height)) img1 is the wax block image after alignment with the pathological slice image, img2 is the wax block image before alignment, m is the perspective transformation matrix, width and height are the desired image width and height after the wax block image is transformed, respectively. The width and height of the pathological slice image are used here.
