How do I change colours?#

What will I learn?

  • How to adjust the brightness & contrast

  • How to change fluorescence channel colours

  • How to separate stains in brightfield images

We started the first chapter with 3 core facts:

  • Images are composed of pixels

  • Pixels have numeric values

  • Colours are used to display pixels based on those numeric values

While the numbers are what matters for analysis, the colours are still very useful for our visual interpretation.

This chapter explores how we can change what we see – without necessarily changing our data.

How to adjust the brightness and contrast#

../../_images/spooked.png

Fig. 11 Why is he so nervous?#

What to do

  1. Open the image spooked.png.

    • Choose Other as the image type

  2. Open QuPath Brightness & Contrast dialog using any of these (equivalent) methods

    • View ‣ Brightness/Contrast

    • Click on the toolbar button ../../_images/CONTRAST.png

    • Use the shortcut Shift+C

  3. Move the Channel min, Channel max and Gamma sliders.

  4. Press the Reset button to return everything to normal.

View ‣ Brightness/Contrast ../../_images/CONTRAST.png is extremely useful – that’s why there are 3 ways to open it. Sometimes, you need to change the brightness and contrast because important details aren’t visible otherwise.

However, it’s important to be cautious and make sure you know what’s happening. Specifically, you need to know whether changing the sliders is changing your data, or only how it is displayed.

Question

Move the Channel min and Channel max sliders in QuPath’s Brightness & Contrast window.

Do these sliders change the numeric values of the pixels, or only the colours used to display pixels in the viewer?

How do you know?

Question

What is making the guy in spooked.png look so nervous?

Go easy on gamma!

It’s normal to have to adjust the Channel min and Channel max sliders for fluorescence images. Changing the Gamma is less common – if you use a gamma that isn’t 1.0, you should mention this in any figure legends.

For more information and best practice guidelines, check out

Schmied, C., Nelson, M.S., Avilov, S. et al. Community-developed checklists for publishing images and image analyses. Nat Methods 21, 170–181 (2024). https://doi.org/10.1038/s41592-023-01987-9

How to change fluorescence channel colours#

Toggle channels on and off#

../../_images/multiplex_stain_select.png

Fig. 12 Set fluorescence image type#

What to do

  1. Open LuCa-7color_[13860,52919]_1x1.tif

    • Choose Fluorescence as the image type

  2. Open the brightness and contrast dialog ../../_images/CONTRAST.png

  3. Use the checkboxes to turn channels on and off

  4. Type a number (e.g. 1, 2, 3) and see what happens

In images with multiple channels, it’s possible to toggle individual channels on and off using the brightness & contrast dialog ../../_images/CONTRAST.png.

However, you can also quickly change turn channels on or off by simply typing the number of the channel using your keyboard – and this works even if the brightness & contrast dialog isn’t open.

Change the brightness & contrast for each channel#

../../_images/B_C_window.png

Fig. 13 Brightness and contrast window of a multiplex image#

What to do

  1. Select a channel by clicking on it (it’ll be highlighted in blue)

  2. Make sure the channel’s Show checkbox is turned on

  3. Explore how the Channel min and Channel max sliders are influenced by which channel is selected

  4. Press the Auto and Reset buttons

When a channel is selected, moving the Channel min and Channel max sliders should adjust the brightness and contrast only for that channel.

Pressing Auto asks QuPath to try to set the sliders automatically to values that (hopefully) are sensible. Pressing Reset should set the Channel min to the lowest pixel value and Channel max to the highest pixel value[1]. This behaviour is similar to the equivalent buttons in ImageJ.

Puzzle

  1. Open the message.tif image.

  2. Using the settings in the brightness & contrast dialog, see if you can find anything unusual in the image.

Changing channel names & colours#

What to do

  1. Double-click on a channel, e.g. CD8 (Opal 540)

  2. Enter a new channel name.

  3. Select a new channel colour.

  4. Click Apply

View ‣ Brightness/Contrast ../../_images/CONTRAST.png also makes it possible for you to change channel names and colours.

Both can be changed by double-clicking. Alternatively, you can click directly on the small colour square to change the channel colour only.

Question

What do the Show grayscale and Invert background checkboxes do?

How to separate stains in brightfield images#

Digital stain separation with colour deconvolution#

What to do

  1. Open CMU-1.svs.

    • Choose Brightfield (H & E) as the image type

  2. Open the brightness and contrast dialog ../../_images/CONTRAST.png

  3. Click on Hematoxylin to view a stain-separated image

  4. See how the numbers in the bottom right change when you move the cursor over the image

Setting the image type to Brightfield H & E gave QuPath the information it needed to digitally separate the stains using a process called colour deconvolution[2].

This is based on a default estimate of the stain colours: it won’t be perfect, but it’s often good enough to be useful.

After selecting Hematoxylin, when you move your cursor over the image, you no longer see the original pixel values. Rather, you see the colour deconvolved values that are related to the staining that is present.

Importantly, QuPath’s approach to colour deconvolution doesn’t permanently change the pixel values. You can easily switch back to the original image through the brightness/contrast dialog. The separation is really a visualization trick to help us understand the image a bit better.

../../_images/bandc_examples.png

Fig. 14 Digital stain separation using the brightness/contrast dialog.#

Type matters#

What to do

  1. Go back to the Image tab double click Image type.

  2. Change the type to Brightfield (H-DAB).

  3. See how the channels available in the brightness/contrast dialog change

  4. Repeat the process, setting the image to have different types.

Setting the image type in QuPath changes the channels that are available in the brightness and contrast dialog.

What’s more, not all channels are quite the same.

With a fluorescence image (e.g. LuCa-7color_[13860,52919]_1x1.tif), the channels that we could see where those that were stored in the original file. But for the brightfield CMU-1.svs, the channels QuPath shows are calculated digitally – and depend upon the image type.

This is why it’s important to get into the habit of setting the type of an image in QuPath: it influences how the software will behave. It doesn’t matter for every command, but it does matter for some important ones – including cell detection.