SchapiroLabor / Background_subtraction

Background subtraction for COMET platform
MIT License
6 stars 3 forks source link

Background_subtraction

Pixel-by-pixel channel subtraction scaled by exposure times, primarily developed for images produced by the COMET platform and to work within the MCMICRO pipeline. Main usecase is autuofluorescence subtraction for multichannel and multicycle images for visualization of images from tissues with high autofluroescence (FFPE), improved segmentation, and quantification (if the previous two usecases aren't necessary, downstream subtraction of autofluorescent signal is encouraged as the script is memory inefficent).

Introduction

If there are background (autofluorescence) channels present in a .tif image, background subtraction should be performed so as not to skew the quantification counts of markers. The most precise way of subtracting background would be on a pixel-to-pixel basis. An alternative would be on a cell basis by just subtracting the background measurements from the marker measurements for each cell, however, for visual inspection of images, as well as future use of images as figures in published work, it is preferred to use this.

Background subtraction is performed using the following formula:

Markercorrected = Markerraw - Background / ExposureBackground ExposureMarker*

Usage

The markers.csv file which gives details about the channels needs to contain the following columns: "marker_name", "background" and "exposure". An exemplary markers.csv file is given. The "marker_name" column should indicate the marker for the acquired channel and all values should be unique. The "background" column should indicate the marker name of the channel which needs to be subtracted. This value must match the "marker_name" value of the background channel. The "exposure" column should contain the exposure time used for channel acquisition, and the measure unit should be consistent across the column. Exposure time is used for scaling the value of the background to be comparable to the processed channel. The "remove" column should contain logical TRUE values for channels which should be exluded in the output image.

Versions v0.4.1 and newer:

The script has been rewritten to perform channel subtraction in a RAM-efficient manner - updating is highly recommended. If the output file is much bigger than expected, adjust the --tile-size parameter to a smaller value (e.g 512). Changing the --chunk-size parameter may affect performance (lower values increase execution time, higher values increase RAM usage).

Versions v0.2.0 and older:

The markers.csv file which gives details about the channels needs to contain the following columns: "Filter", "background" and "exposure". An exemplary markers_old.csv file is given. The "Filter" column should specify the Filter used when acquiring images. If different stains are aquired with the same filter, the exact same value needs to be written (including background) as it is used for determining which background channel should be subtracted. The "background" column should contain logical TRUE values for channels which represent autofluorescence. The "exposure" column should contain the exposure time used for channel acquisition, and the measure unit should be consistent across the column. Exposure time is used for scaling the value of the background to be comparable to the processed channel.

CLI

The script requires four inputs:

Output

The output image file will be a pyramidal ome.tif file containing the processed channels. The channels tagged for removal will be excluded from the final image. The output markers file will be a csv file containing the following columns: "marker_name", "background", "exposure". The "marker_name" column will contain the marker names of the processed channels. The "background" column will contain the marker names of the channels used for subtraction. The "exposure" column will contain the exposure times of the processed channels.

Docker usage

If you want to run the background subtraction directly from a pre-configured container with all the required packages, you can either build the docker container yourself or pull it from the Github container registry.

To build the container run:

git clone https://github.com/SchapiroLabor/Background_subtraction.git
docker build -t background_subtraction:latest .
docker run background_subtraction:latest python background_sub.py

To pull the container from the Github container registry (ghcr.io):

## Login to ghcr.io
docker login ghcr.io

## Pull container
docker pull ghcr.io/schapirolabor/background_subtraction:latest