© Copyright 2021 Surface Concept GmbH
Memo - intensity calibration / scTDC library
(library version 1.3004.3)
(document version 2021-01-13)
Contents
- Description
- Reference Image - Requirements
- Automatic normalization
- Effect of the intensity calibration feature
- Recommended preparation of the reference image
- Query the calibration data
- Library versions
Description
The scTDC library has an optional feature to deliver 2D and
3D histograms where the intensity has been corrected to eliminate intensity
patterns of the detector. The feature is automatically active as soon as a file
named cal_i.tif
is found in the current working directory at the
moment where the first 2D or 3D histogram is created. The cal_i.tif
file should contain an image of the homogeneously illuminated detector (denoted
as reference image in the following). The library then uses one of two
approaches to fill the histograms to the same effect as if they were divided by
the reference image - thus removing intensity patterns that arise from the
position-dependent sensitivity of the detector.
Reference Image - Requirements
The expected file format of the cal_i.tif
file
is TIFF (Tagged Image File Format). TIFF defines a large variety of possible
data formats for pixel values. The subset supported by the scTDC library when
reading the cal_i.tif
, is restricted to single channel (gray scale,
no RGB) values with either unsigned integers of bitsize 8, 16, 32 or
floating-point with bitsize 32.
If the pixel format is integer values, the scTDC library normalizes the
reference image. In case of floating point values, the scTDC library assumes
that the reference image is already normalized to 1. Correct normalization
is required to receive the same average count of recorded events both with and
without active intensity calibration.
Many generic image viewers or image editors do not support pixel formats other than 8 bit integer. One of the more scientific image processing tools is the freely available ImageJ software. If TIFF files are written by ImageJ, the 8-bit and 16-bit types are unsigned integer, whereas the 32-bit type is floating-point.
Automatic normalization
Automatic normalization is provided to make it easier to use detector images
recorded with standard DLD software as reference images without further editing
(even though better results may be achieved with some manual editing). Automatic
normalization is only active when the image contains integer pixel values rather
than floating point. This distinction can be overridden: Adding a line
CalIntensNormalize = 1
to the ini file inside the
[DLD]
section forces auto normalization even when
cal_i.tif
is in floating-point pixel format.
The normalization procedure is designed to adapt to simple non-circular shapes
such as elliptical or rectangular detector areas. At first, the center-of-mass
of the image is evaluated. Centered on this point, the image is divided into
sectors of 15 degrees angle. For each sector, a radius is evaluated that
contains two thirds of the total intensity of that sector. The intensity within
the radii of each sector is averaged and represents the average intensity of the
detector area. The limitation to the 66 percentile radius is used to exclude the
border areas of the detector area.
Effect of the intensity calibration feature
The intensity calibration is only effective for some of the histogram pipes
provided by the scTDC library. Interfaces that provide the individual events
(USER_CALLBACKS pipe, legacy event streams) do not currently provide
intensity-calibrated data. However, the scTDC library can deliver the
calibration image buffer, such that the intensity value of each event can be
looked up. This reduces redundancy compared to transmission of the intensity
values with every event.
The pipe types that support intensity calibration are:
- DLD_IMAGE_XY
- DLD_IMAGE_XT
- DLD_IMAGE_YT
- DLD_IMAGE_3D
depth
parameter of type enum bitsize_t
, specifying the data format
of the intensity values in the histogram. Among these are four unsigned integer
types of varying bitwidth (BS8, BS16, BS32, BS64
) and two
floating-point types (F32, F64
) corresponding to the
float
and the double
data types in the C programming
language, respectively.Histograms with integer-valued data format are using a different approach when processing intensity-calibrated events than the floating-point histograms.
Floating-point valued histograms
Each event is processed by adding an intensity value equal to 1 divided by the intensity in the normalized calibration image at detector position (x,y) to the respective pixel / histogram bin. (In the non-intensity-calibrated mode, each event is processed by adding 1.0 to a histogram bin). If the corresponding pixel in thecal_i.tif
file is zero, the event
is added with intensity 1.
Integer valued histograms
The intensity weight for the event is calculated similarly to the floating-point variant. If this weight is, e.g.1.27
, a random number is generated
and used to add the value 1 with a probability of 73% and the value 2 with the
remaining 27%. The expectancy value of the histogram bin after n
events in the same spot is then n×1.27
, yielding the corrected
intensity similar to the floating-point mode after a sufficient number of events.
Rationale
Prior to library version 1.3000.0, only the unsigned integer variants of
histograms were existent and most software developed on top of the scTDC library
is still using them exclusively. However, it is not possible to insert
intensity-weighted events into histograms that can only count integer number of
events. Users expect that the histogram delivers a correct total count of events.
In that case, the intensity weights of detector events according to the intensity
calibration must be floating point values in the vicinity of 1.0. Such numbers
cannot be accurately stored in a matrix where each cell has an integer data type.
This is only possible in the more recent histogram types with depth
set to F32
or F64
. Migrating software to these newer
histogram types also requires the subsequent processing of the histogram data
to be adapted (for example code that draws the histograms to the screen).
Offering the randomized intensity weight scheme for the integer-valued
histograms enables existing software to benefit from the intensity calibration
without adaptation. The randomized scheme often raises the concern, that
individual events can be dropped entirely such that data is lost. However, the
individual event registered by a counting detector is rarely of any significance,
anyways. Only by assembling a large number of detector events, data can be
produced that delivers information about the system from where the detected
particles originated (imagine a source emitting homogeneously in all directions
but you stop the experiment after the first detected event and draw the
conclusion that the source emits a collimated beam in only one direction).
An actual disadvantage of using random numbers is the loss of reproducibility
when using simulation data files instead of a real detector.
Preparation of a new reference image
Due to aging of detector components (e.g. microchannel plates) it may be necessary to replace the calibration image. This can be done by recording an image of a homogeneously illuminated detector.Image statistics
It is important to reach a
sufficient average count N
of events per pixel within the detector
area. The noise/signal ratio is 1/sqrt(N
). For example, with an
event count of 10000 per pixel, the relative noise level is 1%. When the
intensity calibration is used, this relative noise level is always added to the
recorded data. That means the noise level of measurements using the intensity
calibration is always limited by the noise level of the reference image —
measurements cannot reach a better (lower) noise level than the calibration
image, no matter how long they are recorded!
Clearing inactive areas
After recording the detector image, it is recommended to clear the area outside the detector area, by setting it to zero using a suitable scientific image editor (e.g. ImageJ). Most often, there are a few stray events outside the detector area with very low counts compared to the active detector area. When using such an image as the calibration image, an event that hits these spots will be overemphasized by the calibration algorithm, leading to very bright pixels outside the detector area which often breaks the automatic intensity scaling in software that displays the image data. This is prevented by clearing everything outside the active detector area in the calibration image. Events that hit a spot which is zero in the calibration image are added with intensity 1.
Using ImageJ, this can be done by selecting the region of interest according
to the detector area, then invoking the menu entry
Edit → Selection → Make Inverse
.
Now, everything outside the detector area should be selected. Proceed by
using the menu entry
Process → Math → Set...
.
Enter the value zero and confirm.
Manual image normalization
Bypassing the automatic normalization of the scTDC library requires that
the reference image is converted to 32-bit IEEE754 floating-point pixel format.
This can be done by opening the TIFF file in ImageJ, selecting menu entry
Image → Type → 32-bit
, then saving
the file. (Secondly, the ini file must not contain the parameter
CalIntensNormalize
with value greater than zero which forces
automatic normalization).
To normalize the image, the average intensity within the active detector area
must be one. In ImageJ, this can be achieved by first selecting the region
of interest according to the detector area, then pressing the key m
.
A window should open that displays the average intensity of the region of interest
in a column labelled 'Mean' (if the column is missing, right-click into the
table and select 'Set Measurements', then put a check-mark before 'Mean gray
value' and repeat the measurement). Afterwards the region of interest should
be deselected. Via menu entry
Process → Math → Divide...
the whole image can be divided by the previously evaluated mean intensity.
Query the calibration data
The calibration data can be collected as a 2D array of floating-point
values via the API function sc_tdc_get_intens_cal_f
.
The function can be called the first time with a nullptr
for the
buf
argument, which will fill only the size_required
and width
variables such that the caller knows the required size
of the buffer. After calling the function a second time with the buffer pointer,
the buffer will be filled with the calibration data. The values written in this
buffer are already normalized and inverted so they can be used directly as the
weights of the events.
Library versions
1.3004.3
Zero pixels in thecal_i.tif
file are treated such that an event
in this position is added with value 1. In earlier versions it was treated as
if the pixel in the cal_i.tif
was 0 during the normalization stage
but 1 afterwards.
1.3004.2
Calibration images are auto-normalized only when they are in integer pixel
format (not in case of floating-point format). This distinction was not made
in earlier library versions. Auto-normalization can be forced for floating-point
images by setting CalIntensNormalize = 1
in the [DLD]
section of the ini file. This parameter did not exist in earlier versions.
1.3000.4
Calibration images is loaded at most three times during the time that the TDC stays initialized. The three times are possible if the calibration buffer is used in different data formats. E.g. if all open histogram pipes are in integer pixel value format, the calibration image is loaded only once. Previous versions were reloading the calibration image for every histogram.