A multi-color domain pathological section artifact detection method based on contrastive learning
By employing a multi-color-domain pathological slide artifact detection method based on contrastive learning, and utilizing HSV and LAB color domain conversion and Siamese network structure, the diversity and complexity of pathological slide artifact detection are addressed, achieving high-precision automated artifact detection and improving detection efficiency and reliability.
Patent Information
- Application Number
- CN202411254866.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2044-09-09
AI Technical Summary
Existing methods for detecting artifacts in pathological sections suffer from artifact diversity and complexity, insufficient model generalization ability, and weak color perception in H&E stained pathological images, leading to artifacts being confused with normal tissues. Existing methods are inefficient and costly.
A multi-color domain pathological slide artifact detection method based on contrastive learning is adopted. The whole pathological slide is cropped into sub-image blocks, which are converted to HSV and LAB color domains using OpenCV. A Siamese network structure is designed and a joint loss function is introduced. The artifact recognition and classification are performed by combining MobileNetV2 and GhostNetV2 feature extractors.
It improves the accuracy and efficiency of automated detection of artifacts in pathological slides, enhances the ability to distinguish pathological images, reduces false artifacts, and lowers quality control costs.
Smart Images

Figure CN119168980B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of digital image processing technology, and more specifically, to a method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning. Background Technology
[0002] In recent years, breast cancer, colorectal cancer, and lung cancer have all shown a significant upward trend in my country. Clinically, tumors can be detected through various methods, such as X-ray examination, color Doppler ultrasound, MRI, and histopathological examination, among which histopathological examination is recognized as the gold standard for tumor diagnosis.
[0003] Histopathological examination refers to the observation of magnified pathological tissue sections by pathologists using a microscope. However, the rapid development of digital pathology scanners has enabled the persistence of pathological sections into high-resolution digital images. In the daily work of many hospital pathology departments, the digitization of histopathological sections has become an indispensable part. Simultaneously, digitized pathological images are widely used in pathology slide interpretation meetings, teaching, and examinations. Digitized histopathological sections are also used in the research of computer-aided diagnostic systems, promoting the application and development of histopathology.
[0004] During the preparation of pathological slides, unexpected artifacts may be introduced due to staff errors, such as folds, cracks, looseness, scalpel marks, and tissue bubbles. On the one hand, these artifacts can obscure or damage the original tissue area, thus affecting the pathologist's reading and diagnosis. On the other hand, they can also affect the performance of CAD (Cartography-Based Editing) and even cause serious diagnostic misinterpretations.
[0005] In the current quality control process for pathology, most hospitals conduct random checks on pathology slides under a microscope to detect artifacts, and the proportion of whole slides checked is generally no more than half. On the one hand, hospitals receive a large number of slides daily, resulting in high quality control costs and insufficient staff; on the other hand, the results of microscopic detection are poor and subject to subjective differences.
[0006] With the development of deep learning technology, researchers have developed various algorithms to automatically identify and classify artifacts in pathological images. These algorithms are typically based on Convolutional Neural Networks (CNNs), capable of learning artifact features from pathological images. However, deep learning-based artifact detection methods still face several challenges. First, the diversity and complexity of artifacts necessitate that CNN models possess high generalization capabilities to identify artifacts in pathological images with different staining methods and from different sampling sites. Furthermore, the inference performance of the model is a current research focus, as doctors and technicians desire rapid results in practical applications. For artifact detection, most existing methods have weak color perception in hematoxylin-eosin (H&E) stained pathological images, thus failing to effectively distinguish artifacts from normal tissue. Additionally, due to insufficient data, most methods only differentiate whether image patches contain artifacts. Since different artifacts have different causes, conducting multi-classification tasks for artifacts within image patches is of practical significance. Secondly, existing methods have a weak ability to perceive color in H&E stained pathological images, and some artifacts are easily confused with normal tissues, such as mild folds, cracks, and looseness. Summary of the Invention
[0007] To overcome the shortcomings of existing technologies, this invention provides a multi-color domain pathological slide artifact detection method based on contrastive learning, which has the advantage of high artifact recognition accuracy.
[0008] To achieve the above objectives, the present invention provides the following technical solution: a method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning, comprising the following steps: Step 1: Using a pathological whole slide cropping algorithm, crop all whole slide images into several sub-image blocks; Step 2: Design and implement the first feature extractor; Step 3: For the pathological sub-image blocks selected in Step 2, use OpenCV to convert the RGB color space image into HSV and LAB color space images; Step 4: Design a second feature extractor to extract key features from the three color domain pathological images obtained in Step 3; Step 5: Construct the Siamese network structure and introduce the joint loss function; Step 6: During the testing phase, repeat steps 1 and 2 to obtain the original RGB color gamut image. The obtained image is then fed into the second feature extractor trained in step 4 and processed by the classifier to finally obtain the classification prediction result of the pathological image block.
[0009] As a preferred embodiment of the present invention, step 1 specifically comprises the following steps: Step 1.1: Define the folder path to be imported, and at the same time, install and configure the OpenSlide tool, and then load the whole pathology slide image; Step 1.2: In the image preprocessing stage, the read_region method of OpenSlide is used to obtain the required sub-image patches.
[0010] As a preferred technical solution of the present invention, in step 1.2, coordinate parameters, level parameters, and region size parameters need to be passed in. The coordinate parameters are specified in tuple form, including x and y coordinates, to determine the position of the image block in the whole slice. The level parameters specify the pyramid level of the pathological whole slice. The region size parameters define the pixel size of the image block to be acquired, including but not limited to 256*256 pixels, 512*512 pixels, and 1024*1024 pixels.
[0011] As a preferred embodiment of the present invention, step 2 includes the following steps: Step 2.1: Design the first feature extractor, using MobileNetV2 as the main network, pre-training MobileNetV2 on ImageNet and saving the weight parameter file; Step 2.2: Modify the network structure of MobileNetV2, replace the ReLU activation function with the Leaky ReLU function, and add an ECA attention module between the 3*3 depth separable convolution and the 1*1 convolution; Step 2.3: Transfer the pre-trained model parameters to the optimized model architecture and perform further fine-tuning on a complete dataset containing valid and invalid whole pathological slides; Step 2.4: After fine-tuning, the model's first feature extractor can efficiently identify and distinguish between valid and invalid image blocks, and then cache the valid image blocks in the specified file directory.
[0012] As a preferred embodiment of the present invention, step 3 specifically comprises the following steps: Step 3.1: Starting from all the RGB color gamut image patches selected in Step 2, ensure that there is a set of high-quality image patches as the base; Step 3.2: In the Dataset class of the deep learning algorithm, redefine a subclass; Step 3.3: In the __getitem__ method of the newly defined Dataset subclass, use the cvtColor function of the OpenCV library to convert the RGB image into an HSV and LAB color space image; Step 3.4: The return value of the __getitem__ method includes the original RGB image object, the converted HSV image object, and the LAB image object.
[0013] As a preferred embodiment of the present invention, step 4 is specifically performed as follows: Step 4.1: Introduce the second feature extractor GhostNetV2 and separate its classifier part; Step 4.2: The pathological images of the three color domains obtained in step 3 are used as inputs and fed into the independent GhostNetV2 feature extractor.
[0014] As a preferred embodiment of the present invention, step 5 specifically comprises the following steps: Step 5.1: Perform pairwise comparisons on the three obtained feature vectors and calculate the cosine similarity. Step 5.2: Concatenate the classifier obtained from Step 4.1 to the RGB color domain branch, output the features obtained from this branch to the classifier, and use the cross-entropy loss function for constraint. Step 5.3: Based on the similarity loss function and cross-entropy loss function obtained in the previous steps, construct a joint loss function to constrain the training of the network; Step 5.4: Input the actual data into the network model that has been constructed, and perform 10-fold cross-validation. Select the model with the best fold in the validation and save it.
[0015] As a preferred embodiment of the present invention, the specific formula for calculating the loss function in step 5.1 is as follows: ; ; ; ; Wherein, the RGB feature vector is HSV feature vector is The LAB feature vector is ; For normalization operations, The standard function for cosine similarity is... This is a numerical control coefficient. , and These are the similarity values calculated pairwise. It is the average of the three values mentioned above.
[0016] As a preferred embodiment of the present invention, in step 5.2, the cross-entropy loss function formula is as follows: ; Where, in the formula, In This represents cross-entropy; the default value is multivariate cross-entropy. Indicates the total number of images. Indicates the current image. It is a sample The tag can only take values within the range of 1. , This represents the predicted probability value, and its range is as follows: , It is the standard logarithmic function; In step 5.3, the specific formula for the joint loss function is as follows: .
[0017] As a preferred embodiment of the present invention, step 6 includes the following steps: Step 6.1: During the testing phase, repeat steps 1 to 2 to obtain the original RGB color gamut image. Step 6.2: Input the obtained RGB color gamut image into the model trained in steps 1 to 5; the model uses its learned feature extraction and classification capabilities to perform in-depth analysis of the image patch, and the classifier outputs the prediction results of the pathological image patch. Step 6.3: After completing the classification prediction, save the classification result of each image patch and its coordinates in the original image; Step 6.4: Perform statistical analysis on the image blocks in the entire pathological slide, calculate the number and proportion of various artifact image blocks; determine whether the proportion of each artifact exceeds the preset range by setting a threshold; if it exceeds the threshold, the entire pathological slide is deemed unqualified.
[0018] Compared with existing technologies, the beneficial effects of this invention are as follows: This invention has a better effect on artifact detection. By utilizing the idea of contrastive learning and multi-color domain learning of images, it achieves high-precision automated detection of artifacts in pathological slides. By introducing three color domains—RGB, HSV, and LAB—and feeding them into a feature extractor with shared parameters, it extracts image features that are easier to perceive color differences. An improved MobileNetV2 is used as the first feature extractor to effectively filter out invalid background images, while the second feature extractor, GhostNetV2, focuses on extracting multi-color features from valid images. Parameter transfer learning of the feature extractor is achieved through the ImageNet natural image dataset, accelerating the convergence of model training. During training, a joint loss function is designed, combining cross-entropy loss and similarity contrast loss to enhance the network's contrastive learning ability, thereby improving the discrimination power of pathological images. Finally, the trained network model parameters are fixed, RGB color domain image patches are obtained according to the training process, and input into the trained network to identify various artifacts in the images. This not only improves the efficiency of automatic artifact detection in tissue pathology images but also enhances its reliability. Attached Figure Description
[0019] Figure 1 This is a flowchart of the steps of the present invention; Figure 2 This is a flowchart of step 1 of the present invention; Figure 3 This is a flowchart of step 2 of the present invention; Figure 4 This is a flowchart of step 3 of the present invention; Figure 5 This is a flowchart of step 4 of the present invention; Figure 6 This is a flowchart of step 5 of the present invention; Figure 7 This is a flowchart of step 6 of the present invention; Figure 8 This is a flowchart of the training phase of the present invention. Detailed Implementation
[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] Please see Figures 1-8 The following describes any one embodiment of the present invention for further explanation: A method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning includes the following steps: Step 1: Using a pathological whole slide cropping algorithm, crop all whole slide images into several sub-image blocks; Step 2: Design and implement the first feature extractor; its task is to filter out invalid pathological sub-image patches, thereby improving the quality and efficiency of subsequent analysis. Step 3: For the pathological sub-image patches selected in Step 2, use OpenCV to convert the RGB color space images to HSV and LAB color space images. This conversion process not only enriches the image's feature information but also provides more dimensions of data for subsequent feature extraction and analysis. Simultaneously, these three color space image patches are temporarily stored for later processing. Step 4: Design a second feature extractor specifically designed to extract key features from the three color domain pathological images obtained in Step 3. Step 5: Construct a Siamese network structure and introduce a joint loss function; optimize the overall network training process. The Siamese network improves the consistency of feature extraction and classification through collaborative learning, while the joint loss function ensures the stability and effectiveness of network training. Step 6: During the testing phase, repeat steps 1 and 2 to obtain the original RGB color gamut image. The obtained image is then fed into the second feature extractor trained in step 4 and processed by the classifier to finally obtain the classification prediction result of the pathological image block.
[0022] In step 1, the specific steps are as follows: Step 1.1: Define the folder path to be imported. At the same time, install and configure the OpenSlide tool, which is a key tool for processing whole pathology slide images. Then load the whole pathology slide images to prepare for subsequent image block cropping. Step 1.2: In the image preprocessing stage, the read_region method of OpenSlide is used to obtain the required sub-image patches.
[0023] In step 1.2, coordinate parameters, level parameters, and region size parameters need to be passed in; Coordinates: Specified in tuple form, mainly containing x and y coordinates, which determine the position of the image patch in the whole slice; Level: Specifies the pyramid level of the whole pathology slide, which affects the resolution and detail of the acquired image patches; Region size: Defines the pixel size of the image block to be acquired. In this invention, it is preset to 256*256 pixels. Optionally, the size of the small image sliced in step 2 can be selected as 512*512, 1024*1024 pixels, etc.
[0024] In step 2, the purpose is to effectively filter out invalid image blocks, and the specific steps are as follows: Step 2.1: Design the first feature extractor, using MobileNetV2 as the main network, pre-training MobileNetV2 on ImageNet and saving the weight parameter file; Step 2.2: Modify the MobileNetV2 network structure by replacing the ReLU activation function with the Leaky ReLU function. Leaky ReLU helps to expand the range of the ReLU function, which helps to address the zero gradient problem for negative values. An ECA attention module is added between the 3x3 depthwise separable convolutions and the 1x1 convolutions. The ECA attention mechanism uses 1D convolutions to efficiently achieve local cross-channel interaction, avoiding dimensionality reduction to further improve computational efficiency. Step 2.3: Transfer the pre-trained model parameters to the optimized model architecture and perform further fine-tuning on a complete dataset containing valid and invalid whole pathological slides; this process involves applying the weights of the existing model to the improved model framework and then training it on a specific dataset to optimize the model's performance and accuracy; in this way, it can be ensured that the model is more accurate and reliable when processing specific pathological images. Step 2.4: After fine-tuning, the model's first feature extractor can efficiently identify and distinguish between valid and invalid image blocks, and then cache the valid image blocks in the specified file directory.
[0025] Step 3 aims to obtain multi-color gamut images of valid sub-image blocks, and its specific implementation is as follows: Step 3.1: Starting from all the RGB color gamut image patches selected in Step 2, ensure that there is a set of high-quality image patches as the base; Step 3.2: In the Dataset class of the deep learning algorithm, redefine a subclass; this step is to enable the model to better process and understand image data of different color gamuts. Step 3.3: In the __getitem__ method of the newly defined Dataset subclass, use the cvtColor function of the OpenCV library to convert the RGB image into an HSV and LAB color space image; Step 3.4: The return value of the __getitem__ method includes the original RGB image object, the converted HSV image object, and the LAB image object. In this way, the model can process images of multiple color domains simultaneously within a unified framework, enhancing its ability to understand and analyze image features.
[0026] In step 4, the objective is to extract key features from the pathological images obtained in step 3, which come in three different color domains (RGB, HSV, LAB). The specific steps are as follows: Step 4.1: Introduce the second feature extractor GhostNetV2 and separate its classifier part; Step 4.2: The pathological images of the three color domains (RGB, HSV, LAB) obtained in Step 3 are used as input and fed into the independent GhostNetV2 feature extractor. Through this process, we can extract unique feature vectors from each color domain, providing rich information for subsequent classification and identification.
[0027] In step 5, the goal is to design a twin network structure and introduce a joint loss function. The specific steps are as follows: Step 5.1: Perform pairwise comparisons on the three obtained feature vectors and calculate the cosine similarity. The specific formula for calculating the loss function is as follows: ; ; ; ; Wherein, the RGB feature vector is HSV feature vector is The LAB feature vector is ; For normalization operations, The standard function for cosine similarity is... This is a numerical control coefficient. , and These are the similarity values calculated pairwise. It is the average of the three values mentioned above.
[0028] Step 5.2: Concatenate the classifier obtained from Step 4.1 to the RGB color domain branch, output the features obtained from this branch to the classifier, and use the cross-entropy loss function for constraint. The formula for the cross-entropy loss function is as follows: ; Where, in the formula, In This represents cross-entropy; the default value is multivariate cross-entropy. Indicates the total number of images. Indicates the current image. It is a sample The tag can only take values within the range of 1. , This represents the predicted probability value, and its range is as follows: , It is a standard logarithmic function.
[0029] Step 5.3: Based on the similarity loss function and cross-entropy loss function obtained in the previous steps, construct a joint loss function to constrain the training of the network; The specific formula for the joint loss function is as follows: .
[0030] Step 5.4: Input the actual data into the network model that has been constructed, and perform 10-fold cross-validation. Select the model with the best fold in the validation and save it.
[0031] Step 6 includes the following steps: Step 6.1: During the testing phase, repeat steps 1 to 2 to obtain the original RGB color gamut image. Step 6.2: Input the obtained RGB color gamut image into the model trained in steps 1 to 5; the model uses its learned feature extraction and classification capabilities to perform in-depth analysis of the image patch, and the classifier outputs the prediction results of the pathological image patch. Step 6.3: After completing the classification prediction, save the classification result of each image patch and its coordinates in the original image; Step 6.4: Perform statistical analysis on the image blocks in the entire pathological slide to calculate the number and proportion of various artifact image blocks. By setting reasonable thresholds, determine whether the proportion of each artifact exceeds a preset range. If it exceeds the threshold, the entire pathological slide is deemed unqualified, thereby achieving effective monitoring of pathological image quality.
[0032] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0033] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning, characterized in that, Includes the following steps: Step 1: Using a pathological whole slide cropping algorithm, crop all whole slide images into several sub-image blocks; Step 2: Design and implement the first feature extractor; Step 3: For the pathological sub-image blocks selected in Step 2, use OpenCV to convert the RGB color space image into HSV and LAB color space images; Step 3.1: Starting from all the RGB color gamut image patches selected in Step 2, ensure that there is a set of high-quality image patches as the base; Step 3.2: In the Dataset class of the deep learning algorithm, redefine a subclass; Step 3.3: In the __getitem__ method of the newly defined Dataset subclass, use the cvtColor function of the OpenCV library to convert the RGB image into an HSV and LAB color space image; Step 3.4: The return value of the __getitem__ method includes the original RGB image object, the converted HSV image object, and the LAB image object. Step 4: Design a second feature extractor to extract key features from the three color domain pathological images obtained in Step 3; Step 4.1: Introduce the second feature extractor GhostNetV2 and separate its classifier part; Step 4.2: Take the pathological images of the three color domains obtained in step 3 as input and feed them into the independent GhostNetV2 feature extractor. Step 5: Construct the Siamese network structure and introduce the joint loss function; Step 5.1: Perform pairwise comparisons on the three obtained feature vectors and calculate the cosine similarity. The specific formula for calculating the loss function is as follows: ; ; ; ; Wherein, the RGB feature vector is HSV feature vector is The LAB feature vector is ; For normalization operations, The standard function for cosine similarity is... This is a numerical control coefficient. , and These are the similarity values calculated pairwise. for , , The average of the three values; Step 5.2: Concatenate the classifier obtained from Step 4.1 to the RGB color domain branch, output the features obtained from this branch to the classifier, and use the cross-entropy loss function for constraint. Step 5.3: Based on the similarity loss function and cross-entropy loss function obtained in Steps 5.1 and 5.2, construct a joint loss function to constrain the training of the network; Step 5.4: Input the actual data into the constructed network model and perform 10-fold cross-validation. Select the model with the best fold in the validation and save it. Step 6: During the testing phase, repeat steps 1 and 2 to obtain the original RGB color gamut image. The obtained image is then fed into the second feature extractor trained in step 4 and processed by the classifier to finally obtain the classification prediction result of the pathological image block.
2. The method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning according to claim 1, characterized in that: In step 1, the specific steps are as follows: Step 1.1: Define the folder path to be imported, and at the same time, install and configure the OpenSlide tool, and then load the whole pathology slide image; Step 1.2: In the image preprocessing stage, the read_region method of OpenSlide is used to obtain the required sub-image patches.
3. The method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning according to claim 2, characterized in that: In step 1.2, coordinate parameters, level parameters, and region size parameters need to be passed in. The coordinate parameters are specified in tuple form, containing x and y coordinates, to determine the position of the image patch in the whole slice. The level parameters specify the pyramid level of the pathological whole slice. The region size parameters define the pixel size of the image patch to be acquired, including 256×256 pixels, 512×512 pixels, and 1024×1024 pixels.
4. The method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning according to claim 1, characterized in that: Step 2 includes the following steps: Step 2.1: Design the first feature extractor, using MobileNetV2 as the main network, pre-training MobileNetV2 on ImageNet and saving the weight parameter file; Step 2.2: Modify the network structure of MobileNetV2, replace the ReLU activation function with the Leaky ReLU function, and add an ECA attention module between the 3*3 depth separable convolution and the 1×1 convolution; Step 2.3: Transfer the pre-trained model parameters to the optimized model architecture and perform further fine-tuning on a complete dataset containing valid and invalid whole pathological slides; Step 2.4: After fine-tuning, the model's first feature extractor identifies and distinguishes between valid and invalid image blocks, and then caches the valid image blocks in the specified file directory.
5. The method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning according to claim 1, characterized in that: In step 5.2, the cross-entropy loss function formula is as follows: ; Where, in the formula, In Represents multivariate cross-entropy; Indicates the total number of images. Indicates the current image. It is a sample The tag has a value range of . , This represents the predicted probability value, and its range is... , It is the standard logarithmic function; In step 5.3, the specific formula for the joint loss function is as follows: 。 6. The method for detecting artifacts in multi-color-domain pathological slides based on contrastive learning according to claim 1, characterized in that: Step 6 includes the following steps: Step 6.1: During the testing phase, repeat steps 1 to 2 to obtain the original RGB color gamut image. Step 6.2: Input the obtained RGB color gamut image into the model trained in steps 1 to 5; The model uses its learned feature extraction and classification capabilities to perform in-depth analysis of image patches, and the classifier outputs the prediction results of pathological image patches. Step 6.3: After completing the classification prediction, save the classification result of each image patch and its coordinates in the original image; Step 6.4: Perform statistical analysis on the image patches in the entire pathological slide, and calculate the number and proportion of various artifact image patches; By setting a threshold, it is determined whether the proportion of each artifact exceeds the preset range; If the threshold is exceeded, the entire pathological slide is deemed unqualified.
