<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Tissue Detection
Overview
Step1:  Constants and Prepwork
Step2:  First, let's fetch the slide thumbnail
Step3:  (Optional) Color normalization of thumbnail
See documentation for color_normalization module.
Now we fetch the tissue mask
This is the method you want to use
Step4:  Get the tissue masks
Step5:  Visualize the result
Step6:  Note effect of hyperparameters
<ASSISTANT_TASK:>
Python Code:
import girder_client
import numpy as np
from matplotlib import pylab as plt
from matplotlib.colors import ListedColormap
from histomicstk.saliency.tissue_detection import (
    get_slide_thumbnail, get_tissue_mask)
%matplotlib inline
Explanation: Tissue Detection
Overview: 
This includes tools to detect tissue from an item (slide) using its thumbnail. The basic functionality includes a series of gaussian smoothing and otsu thresholding steps to detect background versus foreground pixels. Optionally, an initial step is performed whereby color deconvolution is used to deparate hematoxylin and eosin stains (assuming H&E stained slides) to make sure only cellular areas are segmented. This proves to be useful in getting rid of sharpie markers. A size threshold is used to keep only largest contiguous tissue regions.
Where to look?
|_ histomicstk/
  |_saliency/
     |_tissue_detection.py 
     |_tests/
        |_test_saliency.py
End of explanation
APIURL = 'http://candygram.neurology.emory.edu:8080/api/v1/'
# SAMPLE_SLIDE_ID = '5d586d57bd4404c6b1f28640'
SAMPLE_SLIDE_ID = "5d817f5abd4404c6b1f744bb"
gc = girder_client.GirderClient(apiUrl=APIURL)
# gc.authenticate(interactive=True)
_ = gc.authenticate(apiKey='kri19nTIGOkWH01TbzRqfohaaDWb6kPecRqGmemb')
Explanation: Constants and Prepwork
End of explanation
thumbnail_rgb = get_slide_thumbnail(gc, SAMPLE_SLIDE_ID)
plt.imshow(thumbnail_rgb)
Explanation: First, let's fetch the slide thumbnail
End of explanation
print(get_tissue_mask.__doc__)
Explanation: (Optional) Color normalization of thumbnail
See documentation for color_normalization module.
Now we fetch the tissue mask
This is the method you want to use
End of explanation
labeled, mask = get_tissue_mask(
    thumbnail_rgb, deconvolve_first=True,
    n_thresholding_steps=2, sigma=0., min_size=30)
Explanation: Get the tissue masks
End of explanation
vals = np.random.rand(256,3)
vals[0, ...] = [0.9, 0.9, 0.9]
cMap = ListedColormap(1 - vals)
f, ax = plt.subplots(1, 3, figsize=(20, 20))
ax[0].imshow(thumbnail_rgb)
ax[1].imshow(labeled, cmap=cMap) # all tissue regions
ax[2].imshow(mask, cmap=cMap) # largest tissue region
plt.show()
Explanation: Visualize the result
End of explanation
for deconvolve_first in [False, True]:
    for n_thresholding_steps in [1, 2]:
        labeled, mask = get_tissue_mask(
            thumbnail_rgb, deconvolve_first=deconvolve_first,
            n_thresholding_steps=n_thresholding_steps, sigma=0., min_size=30)
        f, ax = plt.subplots(1, 3, figsize=(20, 5))
        ax[0].imshow(thumbnail_rgb)
        ax[1].imshow(labeled, cmap=cMap)
        ax[2].imshow(mask, cmap=cMap)
        plt.suptitle("deconvolve = %s, n_thresholding_steps = %d" % (deconvolve_first, n_thresholding_steps), fontsize=20)
        plt.show()
Explanation: Note effect of hyperparameters
End of explanation
<END_TASK>