Session 3 - Pixel Classifier#

Goal: Learn how to use a machine-learning pixel classifier to segment Regions of Interest

1. Preparation#

  1. First, export an image of your manual annotations using the method discussed in Session1 (File > Export images > Rendered RGB (with overlays))

  2. Delete the Tumor annotation, leave the tissue Region* annotation alone.
    DeleteAnnotation.PNG

  3. Make sure the tissue annotation is locked (it should be already).
    _images/LockedAnnotation.PNG

    • If you don’t see the lock symbol, right click the annotation in the Annotation list and click Lock.

  4. Turn on all channels except the blank channels.

2. Train a Classifier#

  1. Within the class list, select ‘Tumor’ and then click “Auto set”
    Autoset.PNG

  2. Use the Polyline tool to draw some squiggles over the cancer region. https://qupath.readthedocs.io/en/0.5/_images/POLYLINE_TOOL.png
    These will be automatically assigned the “Tumor” class
    Get near the edges without going over into the tissue stroma

  3. Within the class list, click on ‘Ignore*’

  4. Draw some lines over the non-cancer (S100 negative) region using the Polyline tool. Also draw 1 small line in the non-tissue background region

  5. Open up the classifier training window: Classify > Pixel classification > Train pixel classifier

  6. Click on Live Prediction

  7. You’ll see results that look something like this:

PixelClassifierRound1.PNG

If you can’t see anything, make sure the C button is selected and that the transparency slider is all the way to the right _images/ClassificationOn.PNG

  1. Iterate! Add new annotations to correct errors until the results looks better. You’ll find that some small issues won’t go away with additional training.

  2. Adjust Classifier Features and Settings Choosing the best features and settings for a classifier is both essential and complex. We’ll begin talking about it now, and we’ll keep coming back to it throughout the course.

    1. Increase the resolution (lower pixel size) to smooth the results, decrease the resolution (higher pixel size) to make it process faster

    2. To change the features that the ML algorithm uses for its math, click “Edit” next to “Default Multiscale Features”

EditFeatures.PNG

Recommended settings for this example:

  • Resolution: High (1.30 um/pixel)

  • Channels: Hoechst, AF1, PDL1, CD45, S100a

  • Scales: 1.0, 2.0, 4.0

  • Features: Gaussian, Laplacian of Gaussian

  1. Iterate until you are happy.

  2. In the classifier training window, name your classifier ‘TumorPixelClassifier’ and click Save

  3. In the main window - File > Save to save your image and training annotations. DO IT NOW.

3. Include multiple images in training#

A classifier trained on a single image cannot be extrapolated to other images. You must always train on a representative sample of the data in your project.

  1. Double check that you have saved your current image.

  2. Within the Project tab, double click on LungImg1.ome.tiff to open it.

ProjectTab.PNG

The classifier probably does not look good!

  1. Load the LungImg2 training data. Within the classifier trianing window, go to: Load training, select LungImg2.ome.tiff, then click > and Apply

_images/LoadTraining.PNG
  1. Add new training annotations to improve the classifier. Also, try adjusting the features, sizes, and channels to see how these paramters affect the results.

  2. When it looks (acceptably) good, repeat steps 2-4 above with LungImg3.

  3. At the end, revisit LungImg2 to make sure these changes didn’t ruin anything.

  4. Save the classifier. It will ask you if you want to overwrite the existing file- click Yes.

4. Creating Objects using the classifier#

The classifier itself is just a way to determine if a pixel belongs to the tumor or not, depending on intensity and context. Creating the object that outlines the tumor (segmentation) is a separate step.

  1. Before creating the object, we are going to save a copy of our training annotations. First, save your current image! Then, go to your project folder by right clicking on the name of any image in the Project tab and selecting Open directory > Project... _images/ProjectDir.PNG

  2. Go up one more folder to copy-paste the entire QuPath project folder to create a duplicate. Name it something like ‘Tumor Classifier Training’

  3. Make sure you have LungImg2 open. To delete all of the training annotations, hold Ctrl and click on the classes ‘Tumor’ and ‘Ignore*’. Then, right click > Select objects by classification. Then, Delete _images/SelectByClass.gif

  4. Load the pixel classifier: Classify > Pixel classification > Load Pixel Classifier. In the dropdown, choose the Tumor clasisfier you just made.

  5. Select the Tissue annotation by using the same process as Step 3. Select the ‘Region*’ class, right click > Select objects by classification. With it selected, in the Load pixel classifier window, click Create Objects and when it asks about Parent Objects, choose Current Selection
    _images/CreateObjectsPC.PNG

  6. This will bring up the Create objects window, similar to when we created the tissue annotation. Use these settings:

  • New object type: Annotation

  • Minimum object size: 500

  • Minimum hole size: 500

  1. The Tumor region should be a “child” of the tissue region. To validate, look at your Hierarchy tab. The tumor should be “under” the Region* annotation.
    _images/ChildObjHier.gif

If they are the same level, delete the tumor, select the tissue, and then remake the tumor.