Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support no-compression method in converter #443

Merged
merged 4 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 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,17 @@ 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)

gigony marked this conversation as resolved.
Show resolved Hide resolved
compression = compression.lower()
if compression in ['raw', 'none']:
compression = None

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