Subtract Reference Channel
Subtract Reference Channel removes a signal from the image with the help of a second channel that shows only that signal: the reference. A typical case is a spot channel in which filaments, debris or the autofluorescence of the tissue bleed through. A second channel shows that structure alone. The step scales that channel to how bright the structure is in the spot channel, shifts it onto the spot channel and subtracts it. What is left is the spots.
is the image to correct (the target), the reference, a scale factor, an offset and the shift between the two channels. You can set , and by hand, or let the step estimate them from each image.
A typical spot pipeline:
Subtract Reference Channel → Threshold or Wavelet Spots → Connected Components
It is a preprocessing step, usually the first of the pipeline: its result replaces the image for the steps after it. It also measures per image what it estimated, like a measurement step (see Measurements). This is linear unmixing (Zimmermann 2005) with the factor fitted on every image, as in the subtraction of an autofluorescence image (van de Lest et al. 1995). In a project file it is SUBTRACT_REFERENCE_CHANNEL.
When to use
Section titled “When to use”- A signal you don’t want lies on top of the signal you measure, and a second channel shows the unwanted signal alone: filaments, debris or autofluorescence in a spot channel, bleed-through of a bright dye into a weak one.
- The two channels may differ in brightness, and may be shifted against each other by a few pixels (chromatic shift, a second camera).
For a background without a reference channel, use Median Subtract or Rolling Ball. For a known shift alone, use Translate Image.
Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
| ID | Names the step’s measurements in the results (e.g. reference_01). |
| Target | The image to correct. Current Image (default): the pipeline’s image at this step. Channel: an image channel as it was read. |
| Reference Channel | The channel that shows only the signal to remove. Default channel 1. |
| Camera Offset | (advanced) The camera’s black level, subtracted from both channels first. None (default) or Manual, with one offset for the Target and one for the Reference (default 100 each). |
| Saturation | (advanced) The level from which a pixel counts as saturated. Auto (default): the image’s largest value (255 for 8 bit, 65535 for 16 bit). Manual: a Level. Off: no pixel counts as saturated. Saturated pixels are left out of all estimates, see Saturated pixels. |
| Background | The slowly varying background, removed from both channels. Median (default): the median over a circle of Radius px (default 30), as Median Subtract. Rolling Ball: a ball of Radius px, as Rolling Ball. None. The radius should be a little larger than the structures. |
| Alignment | How the reference is shifted onto the target, see Alignment. Auto (default), Fixed or None. |
| Interpolation | (advanced) How the shifted reference is interpolated. Cubic (default): Keys’ bicubic. Linear: bilinear, a little smoother. |
| Target Extra Sigma | (advanced) An extra Gaussian blur (σ, px) of the target, when it is sharper than the reference. Default 0 (off), 0-20. |
| Reference Extra Sigma | (advanced) An extra Gaussian blur (σ, px) of the reference, when it is sharper than the target. Default 0 (off), 0-20. |
| Smoothing Sigma | The Gaussian blur (σ, px) of both channels, the same for both. It keeps noise from biasing the factor low. Default 1, 0-20 (0 = off). |
| Factor | How the scale factor is set, see Factor. Robust Fit (default), Fixed or Exposure Ratio. |
| Factor Scale | Multiplies after it is set, for fine tuning. Default 1 (unchanged), 0-100. |
| Estimation Scope | (advanced) The area the shift and the factor are estimated over. Image (default) or Tile. See Tiles and volumes. |
| Edge Tolerance | (advanced) The reference’s local maximum over this radius (px) is subtracted instead of the reference. It tolerates a small leftover shift or a width mismatch. Default 0 (off), 0-10. |
| Only Brighter Reference | Subtract only where the reference is brighter than its background. Dark cracks or holes in the reference then subtract nothing, instead of brightening the result. Default on. It needs a Background: without one the reference is never below 0. |
| Clip Negative | Set negative values of the result to 0. Default on. |
| Output | What the step puts out. Residual (default): the target without the reference’s signal. Scaled Reference: , what was subtracted, to inspect the estimate. Significance: the residual in units of its local noise, see Significance. |
Alignment
Section titled “Alignment”| Mode | Settings |
|---|---|
| Auto | The shift is estimated on every image by phase correlation. Max Shift (default 5 px): a larger estimated shift is not believed. Min Quality (default 0.3, 0-1): below this alignment quality the estimate is not believed. Fallback Dx, Fallback Dy (default 0): the shift used when the estimate is not believed. |
| Fixed | A fixed shift of the reference: Dx to the right (+) or left (−), Dy down (+) or up (−), in px with fractions, -100 to 100. |
| None | The reference is not shifted. |
Factor
Section titled “Factor”| Mode | Settings |
|---|---|
| Robust Fit | Fitted on every image: a robust line through the pixels where the reference shows structure, with the spots (bright in the target only) left out. Noise Factor (default 4): fit pixels have a reference above its median + this × its noise. Min Percentile (default 50): they are also above this percentile of the reference. Outlier K (default 3): pixels this many times the noise above the line are left out. Fit Offset (default on): fit too, otherwise the line goes through 0. Min R2 (default 0.5): below this R² the fallback is used. Fallback (default 1): the factor used when the fit fails. Min Value, Max Value (default 0 and 100): a fitted factor outside this range uses the fallback. |
| Fixed | A fixed Factor , e.g. measured on single-stain controls. . |
| Exposure Ratio | From the exposure times: , with Calibration the factor at equal exposure times and Exposure Target Ms, Exposure Reference Ms the exposure times in ms. . The signal of a camera grows linearly with the exposure time. |
How it works
Section titled “How it works”The order of the steps is fixed: every step changes what the next one sees.
- Camera offset subtracted from both channels.
- Background removed from both channels.
- Alignment: the shift is estimated, and the reference is shifted onto the target.
- Sharpness matching: the extra blur of the sharper channel.
- Smoothing: the same Gaussian on both channels.
- Factor: and are set or fitted, then is multiplied by Factor Scale.
- Subtraction, and with Output Significance the division by the local noise.
The steps run on each image plane on its own. In the formulas below, and always mean the target and the reference as the steps before have left them.
The model
Section titled “The model”Assume the target holds the spots plus some of the reference’s structure, linearly, and that the reference is shifted by :
Once , and are known, subtracting leaves . All the steps serve to make this model hold: the camera offset and the background make “no light” 0 in both channels, the alignment makes lie on , the blurs make the structure equally wide in both, and the smoothing reduces the noise that would bias .
1-2. Camera offset and background
Section titled “1-2. Camera offset and background”The camera offset is subtracted: , . Then the background is removed from each channel: , .
With Median, is the median over a circle of radius . From px on, it is computed on a reduced image, because a slowly varying background doesn’t need every pixel: the plane is reduced to the medians of blocks of px with , the median is taken there with radius , and the result is scaled back to every pixel bilinearly. That is about times less work and stays within 2 % of the full median on the tests. With Rolling Ball, is the ball’s surface (ball, no pre-smoothing).
After this step a pixel of the background is about 0 in both channels, so only has to absorb what is left.
3. Alignment
Section titled “3. Alignment”The shift comes before the fit. If the reference is off by even one pixel, the subtraction leaves the difference of two shifted profiles, : the derivative of the structure, bright on one side and dark on the other. It looks like a relief. The fit then also compensates by lowering .
Auto estimates by phase correlation (Kuglin & Hines 1975), to a fraction of a pixel (as Guizar-Sicairos et al. 2008, with a Gaussian peak instead of an upsampled DFT).
Preparing the channels. Each channel is prepared the same way, on its central 1024 × 1024 px at most:
- A band-pass in the frequency domain, , with the Gaussian’s frequency response ( in cycles per pixel). It removes a background of σ = 20 px and smooths with σ = 1 px.
- Clipped to its 1st to 99.5th percentile, so a few bright beads or spots don’t dominate.
- Its mean subtracted, and multiplied by a 2D Hann window per axis, so the image’s borders don’t make a false peak at shift 0.
The cross-power spectrum. A shift in space is a phase ramp in frequency: if , then . With the Fourier transforms and of the prepared channels, the normalized cross-power spectrum keeps only the phase difference. The step weights it with a Gaussian of σ = 1.5 px:
Transformed back, a pure phase ramp is a single spike at . With the weight, it becomes a sampled Gaussian of σ = 1.5 px, centred exactly at , even when lies between pixels. Its shape is known, so its centre can be found exactly.
The sub-pixel peak. Let be the correlation at the highest pixel and its two neighbours along one axis, and . The logarithm of a Gaussian is a parabola, so the parabola through the three finds the centre:
and the shift along that axis is the highest pixel’s position plus (wrapped to ). If one of the samples is not positive, the parabola goes through the values themselves. On the tests the error is below 0.02 px.
Alignment quality. The parabolas also give the height of the Gaussian’s top, with per axis. The quality is that height as a part of the highest one possible, which is reached when every frequency is exactly in phase:
It is 1 for identical images and near 0 for unrelated ones. The estimate is used when Min Quality and Max Shift. Otherwise, and on a tile smaller than 16 px, the fallback shift is used and Fallback used is set.
Sign. is the shift to apply to the reference so it lies on the target, in the convention of Translate Image: , positive moves the content down, positive to the right. Fixed uses the same convention.
Shifting. The reference is shifted with Keys’ cubic convolution (Keys 1981), (Catmull-Rom), or bilinearly with Interpolation Linear:
The shift is the same for every pixel, so are the weights: each axis needs one kernel of 4 taps, applied first along the rows, then along the columns. The strip the shift empties at the border repeats the edge pixel.
4. Sharpness matching
Section titled “4. Sharpness matching”If the reference shows the structure wider than the target does (a different focus, a different wavelength), the scaled reference is too low in the structure’s centre and too high on its flanks. The residual then has a bright centre line with dark sides. An extra blur of the sharper channel fixes it. Blurs add in quadrature: a structure of width blurred with is wide. For a target of and a reference of , Target Extra Sigma matches them.
5. Smoothing both: regression dilution
Section titled “5. Smoothing both: regression dilution”A least-squares slope of over is biased toward 0 when is noisy (regression dilution). With the spread of the reference’s true values and noise of variance on :
A Gaussian of σ px divides the variance of white noise by about , about 12.6 for σ = 1, while structures a few pixels wide hardly change. Both channels get the same smoothing, so their structures stay equally wide.
All the blurs use the discrete Gaussian (Lindeberg 1990), exact also below 1 px.
6. The factor
Section titled “6. The factor”Fixed and Exposure Ratio set directly, with . Robust Fit fits and in three parts.
Which pixels are fitted. Only pixels where the reference clearly shows structure say anything about . A pixel is a fit pixel when its reference value lies above the structure level and above 0:
with = Noise Factor and the Min Percentile. is the median absolute deviation; estimates the noise σ of normal noise, even with structure in the image.
The start. The median ratio , and with Fit Offset , over the fit pixels.
Iteratively reweighted least squares (a Huber M-estimate, Huber 1964). Each iteration:
- The residuals and their robust scale .
- Spots out: pixels with , = Outlier K, are left out of this iteration. Only the positive side counts: a spot is bright in the target but not in the reference.
- Huber weights for the rest, with :
1.345 gives 95 % of least squares’ efficiency for normal noise, while a single far-off pixel can’t pull the line.
- The weighted line, from the 2 × 2 normal equations (sums over the kept pixels):
so and . Without Fit Offset: and .
The loop stops when and change by less than (relative), after 20 iterations at most. Then, over the pixels within of the line:
When the fit is not believed. With fewer than 1000 pixels in the fit, Min R2, or outside Min Value to Max Value, the step uses the Fallback factor with and sets Fallback used. A reference without structure ends up here, not in an error.
In every mode, is then multiplied by Factor Scale.
Saturated pixels and the border
Section titled “Saturated pixels and the border”A saturated pixel (at or above the Saturation level in the target or the reference, before any step) doesn’t show how bright it really is, so it would bend the line. It is left out of the fit, and so are its neighbours as far as the blurs and the shift spread its value: px, with . A shifted reference has a border strip that only repeats its edge pixels; the strip px wide is left out too.
7. Subtraction
Section titled “7. Subtraction”With Edge Tolerance , the reference is first replaced by its local maximum over a circle of radius : . That widens the structure by on each side, so a fringe left by a small leftover shift is subtracted too, at the cost of subtracting a little too much at the structure’s edges.
Then:
The is Only Brighter Reference. After the background is removed, a reference below 0 is a dark crack or hole, not light that bled through. Subtracting it would add light, and dark cracks would become bright lines. Without it, . The outer is Clip Negative.
Note that and are the channels after the background removal and the blurs: the residual is background-free and smoothed like them.
Output Scaled Reference puts out .
Significance
Section titled “Significance”Where target and reference don’t see the structure the same way (e.g. focused differently), one factor can’t remove it everywhere: small leftovers stay on the structure. Bright regions also have more photon noise. To a cut-off for the whole image, both look like spots. Output Significance divides the residual by its local noise, so a cut-off means the same everywhere:
- : the residual’s robust noise, over the usable pixels (the residual is not clipped for this).
- The local baseline : the residual’s median over a circle of radius 10 px. Spots, being small, don’t move a median. The deviation is .
- The local noise, from the negative deviations only, over a 21 × 21 px window :
Noise is symmetric, so for noise alone , hence the factor 2. Spots only add light, so they don’t raise their own noise. The photon noise of a bright region and the relief of a leftover (dark on one side) do.
- The significance:
set to 0 where negative with Clip Negative.
means five times the noise right there: on the structure, on a bright region and on dark background alike. Beside the structure the values spread by about 1. A Threshold at 5 (Manual, Absolute) or Wavelet Spots then detects the spots with one cut-off.
The window, 21 × 21 px, is about 3.4 µm at 160 nm per pixel: enough pixels for a steady estimate, small enough to follow the brightness and the edges of the structure. The median is computed on the residual quantized to 65536 levels, exact to , a small part of the noise.
Reading the residual
Section titled “Reading the residual”Set Output to Residual or Scaled Reference and look at the structure:
| What you see | Cause | Fix |
|---|---|---|
| A relief: bright on one side of the structure, dark on the other | The shift is off | Alignment Auto, or a Fixed shift; check Alignment quality |
| A bright centre line with dark sides | The reference shows the structure wider than the target | Raise Target Extra Sigma |
| A dark centre line with bright sides | The target shows the structure wider than the reference | Raise Reference Extra Sigma |
| The whole structure left over, or dark | The factor is too low or too high | Factor Scale; check R² and Fallback used |
| Bright lines where the reference has dark cracks | Only Brighter Reference is off | Turn it on |
| A thin fringe along the structure after aligning | A leftover shift below a pixel | Edge Tolerance 1 |
Measurements
Section titled “Measurements”The step measures per image what it corrected with, named after its ID (e.g. reference_01 · Factor). Exclude Image can use them, e.g. to leave out images where Fallback used is above 0.5.
| Measurement | Meaning |
|---|---|
| Factor | , after Factor Scale. |
| Offset | (intensity). |
| Shift X, Shift Y | , in px. |
| Alignment quality | of the phase correlation; only with Alignment Auto. |
| R² | Of the robust fit; only with Factor Robust Fit. |
| Fit pixel fraction | The part of the image’s pixels in the final fit. |
| Saturated fraction | The part of the pixels that are saturated. |
| Fallback used | 1 if the shift or the factor fell back on a plane, else 0. |
| Residual noise | The median local noise ; only with Output Significance. |
A value that doesn’t apply (no quality without Auto alignment) is empty. On a volume each value is the median over the planes; on an image split into tiles, the median over the tiles. Fallback used is 1 if any plane fell back.
Tiles and volumes
Section titled “Tiles and volumes”- Volumes are corrected plane by plane, each plane with its own shift and factor.
- The step runs per tile. Up to 4096 px a tile is the whole image, so the estimates are for the whole image. On a larger image each tile has its own estimates for now: Estimation Scope Image logs a warning that it estimates per tile. The shift fills the tile’s borders with their edge pixels, without the neighbouring tiles.
- The phase correlation uses the central 1024 × 1024 px of a larger tile: the shift is one for the whole tile.
In a project file
Section titled “In a project file”Spots in the current image, the structure to remove in channel 4, everything else at its default:
{ "type": "SUBTRACT_REFERENCE_CHANNEL", "id": "reference", "referenceChannel": 4 }A fixed factor from single-stain controls and a fixed shift:
{ "type": "SUBTRACT_REFERENCE_CHANNEL", "id": "reference", "referenceChannel": 4, "alignment": { "type": "FIXED", "dx": -0.8, "dy": 1.3 }, "factor": { "type": "FIXED", "factor": 0.37 }}The other settings are target ({"type": "CURRENT_IMAGE"} or {"type": "CHANNEL", "channel": 2}), cameraOffset, saturation, background ({"type": "MEDIAN", "radius": 30}), interpolation, targetExtraSigma, referenceExtraSigma, smoothingSigma, factorScale, estimationScope, edgeTolerance, onlyBrighterReference, clipNegative and output ("RESIDUAL", "SCALED_REFERENCE", "SIGNIFICANCE"). See the project file schema.
Limitations
Section titled “Limitations”- Grey images only: label images and colour images are refused with an error.
- The target and the reference must have the same size and number of planes.
- The model is linear: one factor and one offset per image (per tile on large images). A bleed-through that varies across the image leaves leftovers; Output Significance keeps them from counting as spots.
- A shift as large as the tile stops the step with an error.
References
Section titled “References”- van de Lest C. H. A., Versteeg E. M. M., Veerkamp J. H. & van Kuppevelt T. H., “Elimination of autofluorescence in immunofluorescence microscopy with digital image processing,” Journal of Histochemistry & Cytochemistry, vol. 43, pp. 727-730, 1995. doi:10.1177/43.7.7608528
- Zimmermann T., “Spectral imaging and linear unmixing in light microscopy,” Advances in Biochemical Engineering/Biotechnology, vol. 95, pp. 245-265, 2005.
- Kuglin C. D. & Hines D. C., “The phase correlation image alignment method,” Proc. IEEE Int. Conf. on Cybernetics and Society, pp. 163-165, 1975.
- Guizar-Sicairos M., Thurman S. T. & Fienup J. R., “Efficient subpixel image registration algorithms,” Optics Letters, vol. 33, pp. 156-158, 2008. doi:10.1364/OL.33.000156
- Keys R., “Cubic convolution interpolation for digital image processing,” IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 29, pp. 1153-1160, 1981. doi:10.1109/TASSP.1981.1163711
- Huber P. J., “Robust estimation of a location parameter,” The Annals of Mathematical Statistics, vol. 35, pp. 73-101, 1964. doi:10.1214/aoms/1177703732
- Lindeberg T., “Scale-space for discrete signals,” IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 12, pp. 234-254, 1990.
The step cites van de Lest, Zimmermann, and - depending on its settings - Guizar-Sicairos (Alignment Auto), Keys (a shift with Cubic) and Huber (Robust Fit); see Citation for exporting the citations of a project.