unravel.image_io.convert_img module#
Use io_convert_img
(conv
) from UNRAVEL to load a 3D image and save as a different format.
- Input image types:
.czi
.nii.gz
.ome.tif or .tif series (provide a path to the dir containing the .tif files or to a single .tif file)
.zarr
.h5
- Output image types:
.nii.gz
.tif series (provide a path to the dir where the .tif files will be saved)
.zarr
.h5
Note
Provide -x and -z for .tif inputs to set the xy and z resolution in micrometers.
Usage to convert a .czi file to .nii.gz:#
conv -i ‘sample.czi’ -c 1 -s .nii.gz
Usage to convert a single .tif series to .nii.gz:#
conv -i ‘sample*/tifs/’ -x 3.5 -z 6 -s .nii.gz
Usage to recursively convert all dirs with tif files to .zarr:#
conv -i ‘**/*.tif’ -x 3.5 -z 6 –save_as .zarr
- unravel.image_io.convert_img.convert_img(img_file, save_as=None, output=None, force=False, channel=0, xy_res=None, z_res=None, dtype=None, reference=None, verbose=False)[source]#
Load a 3D image and save it in a different format. Supports .czi, .nii.gz, .tif series, .zarr, and .h5 formats.
Parameters:#
- img_filestr
Path to the input image file (e.g., .czi, .nii.gz, .tif series, .zarr, .h5).
- save_asstr
Desired output format (e.g., ‘.nii.gz’, ‘.tif’, ‘.zarr’, ‘.h5’).
- outputstr
Directory path where the output file will be saved. If None, saves in the same directory as the input file.
- forcebool
If True, overwrites existing output files. Default is False.
- channelint
Channel number to extract from .czi files. Default is 0.
- xy_resfloat, optional
xy resolution in micrometers. Required for .tif, .zarr, and .h5 files.
- z_resfloat, optional
z resolution in micrometers.
- dtypestr, optional
Data type for the output .nii.gz file. Options include ‘np.uint8’, ‘np.uint16’, ‘np.float32’. If None, uses the original data type.
- referencestr, optional
Path to a reference image for .nii.gz metadata. If None, the metadata will not be set.
- verbosebool
If True, prints detailed information about the image being processed. Default is False.