Lesson 1 of 20

One map — the red dots are lymphocytes

how an H&E slide becomes a grid

One map — the red dots are lymphocytes
A pathology slide is cut into tiles, and for each tile a machine answered yes or no. Paint those answers and you have a TIL map.

Shave a thin slice of cancer tissue onto a glass slide, stain it with haematoxylin and eosin (H&E), and the nuclei come out purple and the cytoplasm pink. A pathologist looks at that slide down a microscope and makes a diagnosis.

What is in the picture is not only cancer cells. Lymphocytes — the immune cells the body sent to attack the tumour — are in there too. Small, dark, round nuclei packed close together: that is them.

How many of those lymphocytes have arrived has been an important marker for a long time. Tumours with more of them have been reported to do better, in several cancer types. But how do you count "how many"?

The map has only three colours.

ColourRGBMeaning
black(0, 0, 0)no tissue — bare glass
blue(0, 0, 255)tissue, but no lymphocyte
red(255, 0, 0)this tile has a lymphocyte

So this file is not a photograph. It is a table of verdicts painted in colour. One pixel corresponds to one 50 µm tile of tissue.

Three colours and nothing else. No in-between shades — because this picture is already decided.
Python Runs in your browser

Turning the three colours into 0 · 1 · 2 makes them easier to handle. That is all the read_map() of the til package we use throughout this course does.

def read_map(path):
    a = np.array(Image.open(path).convert("RGB"))
    R, G, B = a[:, :, 0], a[:, :, 1], a[:, :, 2]
    code = np.zeros(a.shape[:2], np.uint8)
    code[(R == 0)   & (G == 0) & (B == 255)] = 1   # tissue
    code[(R == 255) & (G == 0) & (B == 0)  ] = 2   # lymphocytes
    return code
One cell is 50 × 50 µm, so 25,197 tissue cells is roughly 63 mm².
Python Runs in your browser
Put the two side by side and you can see at a glance why this number matters.
Python Runs in your browser
Open the eight maps that ship with the course. The tile counts and the infiltration rate come with them.
Loading…
🤔 Check yourself
What does one pixel of a TIL map mean?
🤔 Check yourself
Why are there no intermediate colours (say, pale pink) in this map?