Skip to content

Commit

Permalink
Merge pull request #25 from dbouget/dynamic_plane_export
Browse files Browse the repository at this point in the history
Dynamic plane export
  • Loading branch information
andreped authored Sep 11, 2024
2 parents de92c1f + d35e683 commit 444fe6e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
35 changes: 33 additions & 2 deletions vsi2tif/src/process.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging
import os
import shutil
import traceback

from tqdm import tqdm

Expand All @@ -18,7 +21,35 @@ def cellsens2tif_single(
max_mem: int = 32,
verbose: int = 1,
) -> None:
cellsens2tif(input_path, output_path, bfconvert, compression, tz, plane, quality, max_mem, verbose)

if int(plane) == -1:
image_folder = os.path.join(os.path.dirname(output_path), os.path.basename(output_path).replace(".tif", ""))
for s in range(50):
try:
curr_output_path = os.path.join(image_folder, "plane_" + str(s) + "_" + os.path.basename(output_path))
cellsens2tif(input_path, curr_output_path, bfconvert, compression, tz, s, quality, max_mem, verbose)
except Exception:
logging.info("End of planes with value {}".format(s))
break

try:
largest_size = 0
largest_file = None
for _, _, files in os.walk(image_folder):
for f in files:
fp = os.path.join(image_folder, f)
fs = os.path.getsize(fp)
if fs > largest_size:
largest_size = fs
largest_file = fp
shutil.copyfile(largest_file, output_path)
if os.path.exists(image_folder):
shutil.rmtree(image_folder)
except Exception:
logging.error("Issue cleaning up after all planes conversion.")
logging.error(traceback.format_exc())
else:
cellsens2tif(input_path, output_path, bfconvert, compression, tz, plane, quality, max_mem, verbose)


@benchmark
Expand Down Expand Up @@ -57,7 +88,7 @@ def cellsens2tif_batch(
curr_output_path = (output_path + "/" + curr_input_path.split(input_path)[-1]).replace(".vsi", ".tif")

try:
cellsens2tif(
cellsens2tif_single(
curr_input_path, curr_output_path, bfconvert, compression, tz, plane, quality, max_mem, verbose
)
except Exception:
Expand Down
8 changes: 7 additions & 1 deletion vsi2tif/vsi2tif.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ def main():
parser.add_argument("-b", "--bfconvert", help="path to bfconvert tool", required=True)
parser.add_argument("-c", "--compression", help="compression technique for final image", default="jpeg")
parser.add_argument("-s", "--tilesize", help="tile size to use during both conversion steps", default=1024)
parser.add_argument("-p", "--plane", help="which image plane to convert image from", default=0)
parser.add_argument(
"-p",
"--plane",
help="which image plane to convert image from. If set to -1, all planes are converted and the largest is kept",
default=0,
type=int,
)
parser.add_argument("-q", "--quality", help="compression quality used with JPEG compression", default=85)
parser.add_argument("-m", "--max-mem", help="set maximum memory in the java vm", default=32)
parser.add_argument("-v", "--verbose", help="set verbosity level", default=1, type=int)
Expand Down

0 comments on commit 444fe6e

Please sign in to comment.