Oct 16, 2024

Public workspaceCorrecting mounting errors in histological images using Photoshop

This protocol is a draft, published without a DOI.
  • 1University of Oslo
Icon indicating open access to content
QR code linking to this content
Protocol CitationIngvild Elise Bjerke, Harry Carey 2024. Correcting mounting errors in histological images using Photoshop. Protocol exchange https://protocols.io/view/correcting-mounting-errors-in-histological-images-dmnf45bn
License: This is an open access protocol distributed under the terms of the Creative Commons Attribution License,  which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited
Protocol status: In development
We are still developing and optimizing this protocol
Created: September 19, 2024
Last Modified: October 16, 2024
Protocol Integer ID: 107943
Keywords: image processing, histology data, image analysis, QUINT workflow, photoshop
Funders Acknowledgement:
EU Horizon Europe
Grant ID: 101147319
Research Council of Norway
Grant ID: 269774
Abstract
This protocol describes how to adjust mounting errors in histological images using Photoshop. The protocol makes use of the Actions feature, which is useful for two purposes:
  • To prepare the actions on smaller versions of the images, useful if your images are large and take long to open and edit.
  • To adjust several channel images identically (for fluorescence data)

These purposes can also be combined, e.g. making Actions on a small version of a fluorescence image, followed by application to any number of channel images of the same image.

If your images are fairly small and only one channel per image (e.g. for brightfield), you probably do not need to use the Action function. However, the steps for editing the photo might still be useful.

Example image before (left) and after (right) photoshopping. The image consists of four individual tissue pieces that were mounted incorrectly.

Please note: If you use this protocol on tiled tiff images, they will no longer be tiled after opening and saving in Photoshop. A separate protocol on how to re-tile images is in progress.
Preparations
Preparations
5m
5m
Assess all the images in a brain to get an overview of changes that needs to be performed.
Make a copy of all images in a designated subfolder called "photoshop". This ensures that you do not accidentally overwrite original images until everything is ready.
Make sure your Rulers are set to Percent. Go to Edit > Preferences > Units & Rulers... Under Units, set the Rulers to "Percent". This is crucial for Actions made on small thumbnail images to work on the full-size ones.
Create an action implementing edits for each image
Create an action implementing edits for each image
Create a Photoshop Action named after the unique section ID for the image (e.g. "s061"). Organize actions into folders named after the unique ID for the subject (e.g. "Mouse486"). Organizing actions like this is good practice and also allows for running them automatically with Python later.


Note
If the Actions panel is not visible, navigate to Window > Actions in the upper menu.

Start recording. The recording starts automatically upon creating an action, and can be paused and re-started at any point using the controls at the bottom right of the actions panel.
In the Layers panel (bottom right of the screen), right click the layer representing your image and select "Layer from background". If the Layers panel is not visible, navigate to Window > Layers in the upper menu.
Use the lasso tool from the left-side menu to select areas to be transformed individually. Once an area is selected, press Layer > New > Layer from Cut (or use the hotkey CTRL + Shift + J). This will create a separate layer for the selected area (now visible in the Layers panel) that can be edited individually.


Note
The magnetic lasso tool is convenient for selecting tissue pieces with high precision. The magic wand tool can be useful for brightfield images, to delete all white background before selecting and manipulating individual pieces; however, it relies on color information and cannot be used for fluorescent images because it will perform differently on different channel images.

The magnetic lasso tool is convenient for selecting tissue pieces with high precision. The magic wand tool can be useful for brightfield images, to delete all white background before selecting and manipulating individual pieces; however, it relies on color information and cannot be used for fluorescent images because it will perform differently on different channel images.


When all areas to be edited have been isolated, they can be manipulated individually. To edit one of the isolated areas, select the layer representing it and do the desired changes.

Examples:
  • Move and rotate a layer with the Move tool (upper left menu bar)
  • Flip a layer horizontally and vertically by selecting Edit > Transform > Flip horizontal or Flip vertical
For fluorescent images only: Create a new background layer by selecting Layer > New Fill Layer > Solid color. Press OK in the dialogue box, and set the color to black (RGB 0,0,0) in the next dialogue box. Press OK. The layer will be added to the top of all layers. Move it to the background by dragging it down in the Layers panel.
Flatten the image by right clicking any layer in the Layers panel and selecting "Flatten Image".
Stop recording by pressing the stop button in the lower right menu of the Actions panel.
Validation: If you are planning to run a batch of Actions on fluorescent images of different channels, it might be useful to validate that the action is working as intended on one channel first. This means completing step 3.1 for images of one channel (a different one than that which the Actions were made on).
Apply action to other images
Apply action to other images
1h
1h
The Action can now be applied to other images. This can be done either directly to one image at a time through the Photoshop interface (described in step 3.1) or in batch through Python (described in step 3.2).
Applying an Action in the Photoshop interface.

Open the image to which the Action is to be applied. Navigate to the applicable Action in the Actions panel, select it, and press the play button in the lower right menu bar.

Applying Actions in batch through Python (works with versions of Photoshop up to 2023).

Preparations:
  • Make sure that all the images to be photoshopped are placed in a single folder and that they are named with the same unique subject and section IDs as the images on which the actions were made.
  • Make a separate path for the output images.

Running:
  • Use the python script named "photoshop_scripting.py" available from https://github.com/ingvildeb/brain_section_scripts
  • Make sure the path in the parameter "tif_path" corresponds to the folder with the images that you want to run in Photoshop and the "out_path" corresponds to the folder where you want the photoshopped images to be saved.
  • Run the script.
  • Once the script is finished, all the images will saved to the out path, but they will still be open in Photoshop. This allows you to quickly browse through them to see that the Action performed as expected on all images.

Note
The photoshop_scripting.py script assumes the following from your file names:
- That the ID for the animal that is identical to the one used to name the Actions folder in Photoshop (see step 2), and that it is separated from the rest of the file name by underscores. If it is not the first part of the file name, change the parameter called "underscores_to_ID".
- That the section number for the image follows the convention "sXXX"

Examples of compatible file names:
- mouse11_P120_CV_F_s039.tif
- mouse449_P35_F_s031_DAPI.tif

If your file names do not adhere to this, the script will not work and you must either rename your files or modify the script.


Note
If the Photoshop script crashes with the message that scratch discs are full, close all images and start over again. Alternatively, navigate to Edit > Purge > All to clear the scratch disk.

Tip: If the scratch disk fills up very quickly, you can increase available space in the Preferences. Navigate to Edit > Preferences > Scratch Disks and add another or an additional location with more space.

Note: If you are re-starting the script after a crash, note that you have to remove the images that have been finished from the tif_path folder. Otherwise, they will be processed again.

1h
Computational step