readCzi is an R package to read CZI image files (images from ZEISS microscopes), stack them if needed (projection), convert the files to tifs (also normalized and histogram equalized), and store the metadata a CSV files.
The R package readCzi has been checked with image data from
- ZEISS Apotome,
- ZEISS AxioImager,
- ZEISS laser scanning microscopes (1 to 3 channels, 1 to 3 tracks, 1 to n z layers). Please contact Kai for further information and sample data.
The following example (script and results) shows the capabilities of the package.
The script is found in inst/testscript.R
.
# Testscript for using the R package readCzi +++++++++++++++++++++++++++++++
# Author: Kai Budde-Sagert
# Created: 2021/04/08
# Last changed: 2024/01/17
# Delete everything in the environment
rm(list = ls())
# close all open plots in RStudio
graphics.off()
# Load packages ############################################################
groundhog.day <- "2023-01-01"
if(!any(grepl(pattern = "groundhog", x = installed.packages(), ignore.case = TRUE))){
install.packages("groundhog")
}
# Load packages
library(groundhog)
pkgs <- c("BiocManager", "devtools", "reticulate", "tibble", "xml2")
groundhog.library(pkgs, groundhog.day)
if(!("EBImage" %in% utils::installed.packages())){
print("Installing EBImage.")
BiocManager::install("EBImage")
}
require(EBImage)
# Install Python package for reading data of CZI files
# (Users will be asked to install miniconda when starting for the first time)
if(! "czifile" %in% reticulate::py_list_packages()$package){
reticulate::py_install("czifile")
}
# Install this R package for reading CZI images in R
if(!("readCzi" %in% installed.packages()[,"Package"])){
devtools::install_github("SFB-ELAINE/readCzi")
}
require(readCzi)
# Please adapt the following parameters ####################################
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Input file
input_file <- system.file("extdata", "LSM_threeChannels.czi",
package = "readCzi", mustWork = TRUE)
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
## 1. Read czi file and store as array -------------------------------------
image_data <- readCzi(input_file = input_file)
## 2. Read metadata of czi file and save as CSV ----------------------------
## (in German and English format)
df_metadata <- readCziMetadata(input_file = input_file,
save_metadata = TRUE)
file_path_de <- file.path(dirname(input_file), "output",
paste0(gsub("\\.czi", "", basename(input_file)),
"_df_metadata_de.csv"))
file_path_en <- file.path(dirname(input_file), "output",
paste0(gsub("\\.czi", "", basename(input_file)),
"_df_metadata_en.csv"))
dir.create(path = file.path(dirname(input_file), "output"),
showWarnings = FALSE)
readr::write_csv(x = df_metadata, file = file_path_en)
readr::write_csv2(x = df_metadata, file = file_path_de)
## 3. Convert czi file to tifs ---------------------------------------------
convertCziToTif(input_file = input_file,
convert_all_slices = TRUE)
The results are the following:
1. LSM_threeChannels.czi
-
Original images (z-stack layers + projection (maximum intensity method)):
- Layer 1:
- Layer 2:
- ...
- Layer 15:
- Layer 16:
- Layer 17:
- Layer 18:
- Layer 19:
- Layer 20:
- Layer 21:
- Layer 22:
- Layer 23:
- Layer 24:
- Layer 25:
- Z-stack projection (maximum intensity method):
- Histogram equalized z-stack projection (using the clahe method of the EBImage R package):
- Normalized histogram equalized z-stack projection (normalizing each channel separately):
(The jpgs were created with the R package 'magick'. Please see ´inst/testscript.R´ for details.)