50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
"""
|
|
Wrapper over bftools
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
def convert(input_path, output_path, tile_x=None, tile_y=None,
|
|
channel=0, series=0, crop_indices = None, bigtiff=False):
|
|
|
|
"""
|
|
Convert an input image in ZEISS LSM or CZI format to an OME TIFF.
|
|
Slice spacing information is lost in this operation for some reason.
|
|
"""
|
|
|
|
# Set up the command for bfconvert
|
|
bf_tools_dir = os.getenv('BFTOOLS_DIR', os.getcwd()) + "/"
|
|
command = bf_tools_dir + "/bfconvert "
|
|
if not os.path.exists(output_path):
|
|
os.makedirs(output_path)
|
|
output_path += "/" + os.path.splitext(input_path)[0] + "_T%t"
|
|
|
|
# Only one channel at a time
|
|
command += " -channel " + str(channel) + " "
|
|
output_path += "_C%c"
|
|
# Only one series at a time
|
|
command += " -series " + str(series) + " "
|
|
output_path += "_S%s"
|
|
|
|
# Set up tiles
|
|
if tile_x is not None and tile_y is not None:
|
|
command += " -tilex " + str(tile_x) + " -tiley " + str(tile_y) + " "
|
|
output_path += "_tile_X%x_Y%y_ID_%m"
|
|
|
|
|
|
# bigtiff
|
|
if bigtiff:
|
|
command += " -bigtiff "
|
|
|
|
# crop
|
|
if crop_indices is not None:
|
|
command += " -crop " + str(int(crop_indices[4])) + "," + str(int(crop_indices[5]))
|
|
command += "," + str(int(crop_indices[6])) + "," + str(int(crop_indices[7])) + " "
|
|
global_index = crop_indices[0] + crop_indices[1]*crop_indices[2]
|
|
output_path += "_x_"+ str(int(crop_indices[0])) + "_y_" + str(int(crop_indices[1])) + "_m_" + str(int(global_index))
|
|
command += input_path + " " + output_path + ".tiff"
|
|
|
|
# Do the conversion
|
|
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
|
|
p.wait()
|