Reproducting Image Perception in Zeiss Zen from Raw Data
TL; DR
I’ve created a package (czi-shader) to achieve what is mentioned in the title.
Introduction
Most of the lab’s slices are scanned using Zeiss microscopes. Previously, when working with CZI files outside Zen, you either had to export them within the software or directly convert them to pseudocolor using Python. But how are the appropriate colors assigned to different fluorescence channels when displaying the images?
Principles
After experimentation, the process of going from raw light to the final display can be divided into two steps: single-channel coloring and multi-channel merging.
Single-Channel Coloring
CTB488 is usually specified as fluorescence green, with RGB saturation values of (0, 255, 91), which translates to (141, 100%, 50%) in the HSL color space. Let the actual brightness obtained from scanning be denoted as $l_r$. The resulting color is calculated as follows:
$$
\begin{equation}
\begin{aligned}
H &= 141 \
S &= 100% \
L &= \frac{l_r - \text{low}}{\text{high} - l_r} * 50%
\end{aligned}
\end{equation}
$$
This process is applied to each channel, resulting in multiple (h, w, 3) matrices, where 3 represents the three components of the HSL color space.
Multi-Channel Merging
Zen’s merging is done in the RGB space. The HSL space images obtained above are converted to RGB and then summed and clipped. The equivalent numpy code is as follows:
1 | merged_image = np.clip( |
In practice, overflow needs to be considered.
Channel Information
Now that we have the calculation method, where can we find the raw data for the channels? Based on experiments, in the CZI metadata under .//DisplaySetting/Channels/
, a sample data entry looks like this:
1 | <Channel Id="Channel:2" Name="EGFP"> |
The data format is self-explanatory, but parsing this XML and converting it into appropriate data for coloring the raw light can be repetitive. Therefore, I have developed a Python package that allows you to perform these operations directly.
1 | import cv2 |
1 | CZIChannel(id=0, name='Cy5', bit_count_range=16, pixel_type='Gray16', dye_name='Cy5', short_name='Cy5', illumination_type='Fluorescence', dye_max_emission=673, dye_max_excitation=650, dye_id='McNamara-Boswell-0774', dye_database_id='66071726-cbd4-4c41-b371-0a6eee4ae9c5', color='#FFFF0014', original_color='#FFFF0014', color_mode=None, palette_name=None, gamma=None, low=0.0059662775616083005, high=0.03865110246433204, is_selected=None) |
The package contains only two important APIs, as shown above. To install it, run pip install czi-shader
.
Reproducting Image Perception in Zeiss Zen from Raw Data
https://myuan.fun/Reproducting-Image-Perception-in-Zeiss-Zen-from-Raw-Data/