
Extract Taxa Images from MATLAB Classified Sample
Source:R/ifcb_extract_classified_images.R
ifcb_extract_classified_images.Rd
This function reads a MATLAB classified sample file (.mat) generated
by the start_classify_batch_user_training
function from the ifcb-analysis
repository (Sosik and Olson 2007),
extracts specified taxa images from the corresponding ROI files,
and saves each image in a specified directory.
Usage
ifcb_extract_classified_images(
sample,
classified_folder,
roi_folder,
out_folder,
taxa = "All",
threshold = "opt",
overwrite = FALSE,
scale_bar_um = NULL,
scale_micron_factor = 1/3.4,
scale_bar_position = "bottomright",
scale_bar_color = "black",
old_adc = FALSE,
gamma = 1,
use_python = FALSE,
verbose = TRUE
)
Arguments
- sample
A character string specifying the sample name.
- classified_folder
A character string specifying the directory containing the classified files.
- roi_folder
A character string specifying the directory containing the ROI files.
- out_folder
A character string specifying the directory to save the extracted images.
- taxa
A character string specifying the taxa to extract. Default is "All".
- threshold
A character string specifying the threshold to use ("none", "opt", "adhoc"). Default is "opt".
- overwrite
A logical value indicating whether to overwrite existing PNG files. Default is FALSE.
- scale_bar_um
An optional numeric value specifying the length of the scale bar in micrometers. If NULL, no scale bar is added.
- scale_micron_factor
A numeric value defining the conversion factor from micrometers to pixels. Defaults to 1/3.4.
- scale_bar_position
A character string specifying the position of the scale bar in the image. Options are
"topright"
,"topleft"
,"bottomright"
, or"bottomleft"
. Defaults to"bottomright"
.- scale_bar_color
A character string specifying the scale bar color. Options are
"black"
or"white"
. Defaults to"black"
.- old_adc
A logical value indicating whether the
adc
file is of the old format (samples from IFCB1-6, labeled "IFCBxxx_YYYY_DDD_HHMMSS"). Default is FALSE.- gamma
A numeric value for gamma correction applied to the image. Default is 1 (no correction). Values <1 increase contrast in dark regions, while values >1 decrease contrast.
- use_python
Logical. If
TRUE
, attempts to read the.mat
file using a Python-based method. Default isFALSE
.- verbose
A logical value indicating whether to print progress messages. Default is TRUE.
Details
If use_python = TRUE
, the function tries to read the .mat
file using ifcb_read_mat()
, which relies on SciPy
.
This approach may be faster than the default approach using R.matlab::readMat()
, especially for large .mat
files.
To enable this functionality, ensure Python is properly configured with the required dependencies.
You can initialize the Python environment and install necessary packages using ifcb_py_install()
.
If use_python = FALSE
or if SciPy
is not available, the function falls back to using R.matlab::readMat()
.
References
Sosik, H. M. and Olson, R. J. (2007), Automated taxonomic classification of phytoplankton sampled with imaging-in-flow cytometry. Limnol. Oceanogr: Methods 5, 204–216.
Examples
if (FALSE) { # \dontrun{
# Define the parameters
sample <- "D20230311T092911_IFCB135"
classified_folder <- "path/to/classified_folder"
roi_folder <- "path/to/roi_folder"
out_folder <- "path/to/outputdir"
taxa <- "All" # or specify a particular taxa
threshold <- "opt" # or specify another threshold
# Extract taxa images from the classified sample
ifcb_extract_classified_images(sample, classified_folder, roi_folder, out_folder, taxa, threshold)
} # }