diff --git a/python/cucim/src/cucim/clara/cli.py b/python/cucim/src/cucim/clara/cli.py index c4faceebc..4251e835a 100644 --- a/python/cucim/src/cucim/clara/cli.py +++ b/python/cucim/src/cucim/clara/cli.py @@ -49,12 +49,13 @@ def main(): @click.option('--tile-size', type=int, default=256) @click.option('--overlap', type=int, default=0) @click.option('--num-workers', type=int, default=os.cpu_count()) +@click.option('--compression', type=str, default='jpeg') @click.option('--output-filename', type=str, default='image.tif') def convert(src_file, dest_folder, tile_size, overlap, num_workers, - output_filename): + compression, output_filename): """Convert file format""" from .converter import tiff logging.basicConfig(level=logging.INFO) tiff.svs2tif(src_file, Path(dest_folder), tile_size, overlap, num_workers, - output_filename) + compression, output_filename) diff --git a/python/cucim/src/cucim/clara/converter/tiff.py b/python/cucim/src/cucim/clara/converter/tiff.py index d3cfcddbb..feb6012a5 100644 --- a/python/cucim/src/cucim/clara/converter/tiff.py +++ b/python/cucim/src/cucim/clara/converter/tiff.py @@ -56,7 +56,8 @@ def filter_tile( def svs2tif(input_file, output_folder, tile_size, overlap, - num_workers=os.cpu_count(), output_filename="image.tif"): + num_workers=os.cpu_count(), compression="jpeg", + output_filename="image.tif"): output_folder = str(output_folder) logger.info("Parameters") @@ -65,8 +66,18 @@ def svs2tif(input_file, output_folder, tile_size, overlap, logger.info(" tile size: %d", tile_size) logger.info(" overlap: %d", overlap) logger.info(" num_workers: %d", num_workers) + logger.info(" compression: %s", compression) logger.info(" output filename: %s", output_filename) + if compression is not None: + # handles only jpeg or None (no compression) + if compression.lower() == "jpeg": + compression = ("jpeg", 95) + else: + raise ValueError( + f"Unsupported compression: {compression}." + + " Should be 'jpeg' or None.") + with OpenSlide(input_file) as slide: properties = slide.properties slide_dimensions = slide.dimensions @@ -162,7 +173,7 @@ def svs2tif(input_file, output_folder, tile_size, overlap, else: subfiletype = SUBFILETYPE_NONE - tif.save( + tif.write( src_arr, software="Glencoe/Faas pyramid", metadata={"axes": "YXC"}, @@ -174,7 +185,7 @@ def svs2tif(input_file, output_folder, tile_size, overlap, y_resolution // 2 ** level, resolution_unit, ), - compress=("jpeg", 95), # requires imagecodecs + compression=compression, # requires imagecodecs subfiletype=subfiletype, ) logger.info("Done.")