# Automatic General Tissue Detection

{% hint style="warning" %}
Make sure to open the Project\_Regions for this part.&#x20;
{% endhint %}

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FWrV9NjMAA8GtDWc1UQYi%2Fimage.png?alt=media&#x26;token=d2a1e78c-881c-484c-a228-91eb6f20aadd" alt=""><figcaption><p>TissueDetection thresholder</p></figcaption></figure>

1. Under *<mark style="color:green;">Classify</mark>*, choose *<mark style="color:green;">pixel classification, create thresholder</mark>*&#x20;

   The following parameters can be adjusted:&#x20;

The colour will indicate what is detected as "Region" and what needs to be "Ignored\*".

<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><p><mark style="color:green;"><strong>Resolution</strong></mark></p><p></p><p>Choose the lowest that still gives you an adequate detection</p></td><td></td><td></td></tr><tr><td><p><mark style="color:green;"><strong>Channel</strong></mark></p><p></p><p>Choose average channels do detect all the tissue</p><p>If interested in only hematoxylin or DAB choose adequate</p></td><td></td><td></td></tr><tr><td><p><mark style="color:green;"><strong>Prefilter</strong></mark> </p><p></p><p>Gaussian ; performs weighted average of surrounding pixel based on gaussian distribution (chosen in our case)</p></td><td></td><td></td></tr><tr><td><p><mark style="color:green;"><strong>Smoothing sigma</strong></mark></p><p></p><p>Defines the amount of blurring</p></td><td></td><td></td></tr><tr><td><p><mark style="color:green;"><strong>Threshold</strong></mark></p><p></p><p>Set threshold that it detect the tissue</p></td><td>In the above example it is at 250</td><td></td></tr><tr><td><p><mark style="color:green;"><strong>Above threshold</strong></mark></p><p></p><p>Set Class Ignore*</p></td><td></td><td></td></tr><tr><td><p><mark style="color:green;"><strong>Below threshold</strong></mark></p><p></p><p>Set Class Region</p></td><td></td><td></td></tr><tr><td><p><mark style="color:green;"><strong>Region</strong></mark></p><p></p><p>Everywhere</p></td><td></td><td></td></tr><tr><td><p><mark style="color:green;"><strong>Classifier name</strong></mark> </p><p></p><p>TissueDetection</p></td><td></td><td></td></tr></tbody></table>

The threshold should be tested on multiple slides with different intensities to ensure optimal tissue detection for the entire batch.&#x20;

2. The classifier needs to be *<mark style="color:green;">saved as TissueDetection</mark>* to run the script.&#x20;

{% hint style="info" %}
The classifier needs to be saved with the same spelling "**TissueDetection**" as this is used in the script.
{% endhint %}

3. As a next step download (![](https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FObAaazjAoWfDdbIa6orU%2Fimage.png?alt=media\&token=70148d45-019b-4a4e-8384-c1a1ecad5e2d)) the [AutomaticTissueDetetion.groovy](https://github.com/anuesch/Disc4All_QuPath_H-DAB_Script/blob/QuPath/AutomaticTissueDetetion.groovy) script and copy it into your project-region folder. Click *<mark style="color:green;">Ctrl+L</mark>*, open up the *<mark style="color:green;">script editor</mark>* under *<mark style="color:green;">File, Open,</mark>* open the downloaded script.&#x20;
4. Replace the SetColorDeconvolustionStains with the values from your own EstimateStainingVector values, [previously](https://disc4all-qupath.gitbook.io/qupath-project/qupath-h-dab-docs/qupath-h-dab-tutorial/estimating-stain-vectors) saved in a script.&#x20;

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2Fwko0miBXIIVdyR2JPYnI%2Fimage.png?alt=media&#x26;token=40449019-7e03-4a4e-ae39-cd951a3f6061" alt=""><figcaption><p>Script Editor, and how to run it for the whokle project</p></figcaption></figure>

5. Click on the three little dots in the right corner, and run the script for the whole project (with saving). The script uses your predefined thresholder, to detect the tissue and removes in another line the sample's edges, as staining often shows an edge effect.&#x20;
6. After the automatic detection is run, each slide should be checked and if necessary regions can be removed from the analysis (shown in the image below)

<figure><img src="https://2829430504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSleK316zl0BYwa7DfK2J%2Fuploads%2FiU2YW4yNggRLiBNl1UGd%2Fimage.png?alt=media&#x26;token=f80d6e4f-f5bc-4fdc-94ca-5323d50fe632" alt=""><figcaption><p>Tissue folds and other regions of no interest can be removed</p></figcaption></figure>
