> 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/object-classifier.md).

# Object Classifier

The object classifier can be trained to distinguish between immuno positive cells, immuno negative cells and no cells.

{% hint style="info" %}
By still having the drawing tool selected but holding the space bar you can freely move around the image and draw again once you let go of the space bar. Alternatively, choose the <img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2F4mQmeXLomYm6CYFefZu8%2Fimage.png?alt=media&amp;token=f6a6545f-b361-4dda-9262-f1635d552709" alt="" data-size="line"> icon to move again.&#x20;

**By choosing a class and pressing the SPACE bar the class gets&#x20;*****hidden and doesn't show***
{% endhint %}

1. Under *<mark style="color:green;">Classify, Object Classification, Train object classifier</mark>* or *<mark style="color:green;">ctrl+L and search it</mark>*, open the *<mark style="color:green;">**PlugIn**</mark>*.&#x20;

{% hint style="info" %}
The object classifier might give you an error message at the beginning, but as soon as you have 2 or more classes defined, it will be fine
{% endhint %}

* Under the **Annotations** tab choose the classes created for the cell classification, set on auto draw, and *<mark style="color:green;">draw</mark>*![](https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FVEExFyymil8uMlb5vvxI%2Fimage.png?alt=media\&token=b523aed2-b8de-4dff-828b-d1dfed415e95) *<mark style="color:green;">over some positive cells, negative cells, and no cell</mark>* with the according **class on Auto se**t chosen.&#x20;

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2Fy0OSMKMswsH4rKXANQnc%2Fimage.png?alt=media&amp;token=a4cc115c-e998-450e-9e29-bb85a8afddd6" alt=""><figcaption></figcaption></figure>

3. The closer you zoom into the image, the more accurate you can draw, as the image size increases but the brush stays the same.
4. *<mark style="color:green;">Click on live update</mark>* and the detected objects will get a suggested class, visible in the marked colors. If the class isn’t right, you can easily change it by drawing over it with the right class.

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FqHtEwniJYrplwReqa3d9%2Fimage.png?alt=media&amp;token=4040b989-e12c-4983-99f7-05b0fd8cf93e" alt=""><figcaption><p>Choose the classes created for the cell classification and draw over some positive cells, negative cells and no cell with the according class chosen </p></figcaption></figure>

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FpCfN45NPAJTHUocxZ0MN%2Fimage.png?alt=media&amp;token=27023e69-9867-46d7-9893-54dba6c5f98a" alt=""><figcaption><p>Automatic classification of objects based on primary selections</p></figcaption></figure>

5. The object classifier will be trained based on those selections; therefore all the detections must have the right class.
6. Once satisfied with the classification of the objects the classifier should be *<mark style="color:green;">**saved as ObjectClassifier if you only have 1 tissue type, and as ObjectClassifier\_componentx if you have multiple types.**</mark>* The name must be chosen the same as this will ensure the script runs properly. The ObjectClassifier will be saved in a subfolder of your project directly by QuPath.

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FkjZHKhQqJq2buB7TrUIf%2Fimage.png?alt=media&amp;token=65d4688b-f5bd-47c6-bbe9-fbd946c47d09" alt=""><figcaption><p>Within your ProjectFolder a subfolder classifier > object_classifiers get created</p></figcaption></figure>

7. A random region in a slide should be chosen to test the accuracy of the object classifier. Therefore choose a random region in a slide and *<mark style="color:green;">run the "EstimateStainVectors"</mark>* Script followed by the *<mark style="color:green;">"CellDetection" Script</mark>*<mark style="color:green;">.</mark> Make sure that the region is selected whilst running the cell detection.&#x20;
8. If you have closed the Train object classifier window, you can reopen it under *<mark style="color:green;">Classify > Object classification > Train object classifier</mark>*
9. By *<mark style="color:green;">clicking on load</mark>* <mark style="color:green;"></mark><mark style="color:green;">training</mark> in the Train object classifier box *<mark style="color:green;">click the initial training image can be added and applied</mark>* (your training image might be called Sparse Image (18 Regions))*<mark style="color:green;">.</mark>* Make sure that the live update is selected then the detected cells and artifacts are classified.&#x20;

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FA52V34BMq3rlp8EGyYTB%2Fimage.png?alt=media&amp;token=482a0d7b-86d4-4871-8d6a-859aa68c5221" alt=""><figcaption><p>Using the training images to see how well it applies to regions within the slides</p></figcaption></figure>

10. The classification of an object can easily be changed by *<mark style="color:green;">drawing over it with another classification</mark>*. It should be ensured that all the objects are correctly classified before *<mark style="color:green;">adding them as training images</mark>* and the repetition of the process.
11. Once satisfied with the classified objects, add the image to the "*<mark style="color:green;">Load training</mark>*" images as in step 8. Repeat steps 6-10 till the object classification is highly accurate.&#x20;

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FEG3CzPulo8nkRHbB0rWc%2Fimage.png?alt=media&amp;token=55613c57-c1da-4723-b3f1-6cdccbab4f1f" alt=""><figcaption><p>Sparse image (18 regions) was the initial training image. The Object Classifier was then tested on the slide..R3-S17.mrsx. The detections wrongly classified were corrected by overdrawing them with the right classification. Once all the detection had the right Classification the slide was added to the Load training list, and the process was repeated on a different slide until satisfaction of the first classification of the detections on the slide. </p></figcaption></figure>

10. The objects in the classifier should be *<mark style="color:green;">**saved as ObjectClassifier if you only have 1 tissue type, and as ObjectClassifier\_Component1, e.g. ObjectClassifier\_NP if you have multiple types.**</mark>*

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FW1NA2vLod12CPoZ7Zg5V%2Fimage.png?alt=media&amp;token=edb631ba-4028-4abe-9419-da518661b204" alt=""><figcaption><p>Copy the created scripts and classifiers folder from the project_classifiers to the project_regions</p></figcaption></figure>

{% hint style="warning" %}
Copy the created classifiers golder as well as the scripts folder from the classifiers folder to the regions folder. This is needed as we will run the final script within the regions folder but need to call the object classifiers.&#x20;
{% endhint %}
