> For the complete documentation index, see [llms.txt](https://disc4all-qupath.gitbook.io/qupath-project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://disc4all-qupath.gitbook.io/qupath-project/qupath-h-dab-docs/qupath-h-dab-tutorial/training-image-creation.md).

# Training Image Creation

The Positive Cell detection in QuPath is not accurate enough for very acellular tissue as the cell detection always recognises some tissue artefacts as cells, therefore we train an image.

To create a training image on which we can train QuPath to recognise positive cells, negative cells, and no cells we need to choose our regions of interest.&#x20;

{% hint style="warning" %}
If you want to run the analysis on different <mark style="color:purple;">**tissue components**</mark>, a training image for each of them needs to be created.&#x20;

The same applies if multiple sections are stained with <mark style="color:blue;">**different antibodies**</mark> on one slide. &#x20;

If you have different regions and antibodies, create a separate project for each antibody.&#x20;
{% endhint %}

1. *<mark style="color:green;">Click on ›</mark>*![](https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2F5wK6sdn4Zm4mF6YQdxjr%2Fimage.png?alt=media\&token=3f494bed-c978-4d92-be72-73b86a6bc0b7) *<mark style="color:green;">›</mark>* ![](https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FSgDjFPf7J09k8SY61bs0%2Fimage.png?alt=media\&token=9ee4d34b-795a-482f-89ec-f12262debe12) *<mark style="color:green;">(on the three dots)</mark>* › *<mark style="color:green;">Add/Remove</mark>* › *<mark style="color:green;">Add class</mark>*

   For my project, I have chosen the following classes,

   * Region
   * Ignore\*&#x20;
   * <mark style="color:red;">**PositiveCell**</mark>
   * <mark style="color:red;">**NegativeCell**</mark>
   * <mark style="color:red;">**NoCell**</mark>

   either

   * <mark style="color:purple;">TissueComponent1 (e.g. CEP)</mark>
   * <mark style="color:purple;">TissueComponent2 (e.g NP)</mark>
   * <mark style="color:purple;">TissueComponent3 (e.g. iAF)</mark>
   * <mark style="color:purple;">TisueComponent4 (e.g. oAF)</mark>

   or

   * <mark style="color:blue;">Antibody 1 (e.g. IL1)</mark>
   * <mark style="color:blue;">Antibody 2 (e.g. IL6)</mark>

   Colours can be changed by double-clicking on the coloured square in front of the class.&#x20;

{% hint style="warning" %}
The classification of the <mark style="color:red;">**PositiveCell, NegativeCell,**</mark> <mark style="color:red;"></mark><mark style="color:red;">and</mark> <mark style="color:red;"></mark><mark style="color:red;">**NoCell**</mark> must be set as such with <mark style="color:red;">**exactly this spelling**</mark> as those are used for the calculation of the immunopositivity rate with the Python script.

The other classes can be freely chosen. Check again that you have no spelling mistakes because this would lead to an error in the final code we are running.&#x20;
{% endhint %}

1. Once the classes are added *<mark style="color:green;">choose e.g TissueComponent1</mark>* and *<mark style="color:green;">click on auto set</mark>*, so that it automatically sets whatever you draw to the according class.
2. By *<mark style="color:green;">clicking on</mark>*  ![](https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FNhlWorDHSAT2cubLHMHT%2Fimage.png?alt=media\&token=5c1a875f-1c6e-4753-9ee0-a3975598ebeb) a raster will appear which can help draw squares of the same size (3x3). Fifteen to twenty regions in different slides should be chosen and saved as changes. They must represent the whole project and contain all sorts of different regions containing cells (pos/neg), tissue folds, dirt on the slide, etc. The more regions chosen to train on, the better the outcome will be, however too many can slow down the computer. Furthermore, the classifier will be optimised on additional regions later on. &#x20;

{% hint style="warning" %}
Repeat this step for every TissueComponet analysis.&#x20;
{% endhint %}

1. Once all the different regions are chosen a training image is created by *<mark style="color:green;">choosing under classify, training images, create training image</mark>*. *<mark style="color:green;">Change the classification to TissueComponent1</mark>* and click on  *<mark style="color:green;">Ok</mark>*.

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2Fa6LXwa2KZ9KJvsVgoNiv%2Fimage.png?alt=media&amp;token=90905a80-ac76-4527-8393-2c9433123e13" alt=""><figcaption><p>Creation of training image</p></figcaption></figure>

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FiEqYee15oGV01KfTfJYE%2Fimage.png?alt=media&amp;token=8bd37aad-9625-44c2-9c9a-fc65258333e3" alt=""><figcaption><p>Training image for TissueComponent4 (oAF)</p></figcaption></figure>

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FiOQs8ILadjOHjQjlDXx3%2Fimage.png?alt=media&amp;token=8a60f712-24d9-4f7d-ae92-0f0c628b0aa5" alt=""><figcaption><p>Training image for TissueComponent2 (NP)</p></figcaption></figure>

{% hint style="info" %}
If the question "What type of images is this?" pops up select H-DAB
{% endhint %}
