Skip to content

Commit

Permalink
Support no-compression method in converter
Browse files Browse the repository at this point in the history
If you want to use no compression method for your converted file,
you can set the compression method to None in the converter.

In CLI, you can use `--compression` option and set it to any string
except `jpeg`.

E.g,

  cucim convert --tile-size 512 --overlap 0 --num-workers 12 \
      --output-filename resize.tiff --compression RAW \
      notebooks/input/TUPAC-TR-467.svs

The converter will then convert the file without any compression.

Signed-off-by: Gigon Bae <gbae@nvidia.com>
  • Loading branch information
gigony committed Nov 17, 2022
1 parent f54b560 commit 4a0a684
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 3 additions & 2 deletions python/cucim/src/cucim/clara/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 14 additions & 3 deletions python/cucim/src/cucim/clara/converter/tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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"},
Expand All @@ -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.")
Expand Down

0 comments on commit 4a0a684

Please sign in to comment.