def main(args=sys.argv[1:]): args = parse_args(args) if args.output is None: get_tiff_dims(input_glob_or_list=args.input, print_out=True) else: if args.x_pixels or args.y_pixels or args.z_pixels: x_dim, y_dim, z_dim = get_tiff_dims(args.input, print_out=False) crop_xyz = parse_crop_dims_str(args.crop_x, args.crop_y, args.crop_z) crop_x, crop_y, crop_z = validate_tiff_crop_dims(x_dim, y_dim, z_dim, *crop_xyz) if args.x_pixels: args.scale_x = float(args.x_pixels) / (crop_x[1] - crop_x[0] + 1) if args.y_pixels: args.scale_y = float(args.y_pixels) / (crop_y[1] - crop_y[0] + 1) if args.z_pixels: args.scale_z = float(args.z_pixels) / (crop_z[1] - crop_z[0] + 1) transform_tiff(input_glob_or_list=args.input, output_path=args.output, crop_x=args.crop_x, crop_y=args.crop_y, crop_z=args.crop_z, flip_x=args.flip_x, flip_y=args.flip_y, flip_z=args.flip_z, scale_x=args.scale_x, scale_y=args.scale_y, scale_z=args.scale_z, split_output=args.split_output, start_num=args.start_num, num_digits=args.num_digits)
def main(args=sys.argv[1:]): args = parse_args(args) if args.output is None: num_tuples = get_num_coords(input_path=args.input) print("JSON file at {} has {} coordinate tuples".format( args.input, num_tuples)) else: if args.x_pixels or args.y_pixels or args.z_pixels: x_dim, y_dim, z_dim = get_tiff_dims(args.original_tiff, print_out=False) crop_xyz = parse_crop_dims_str(args.crop_x, args.crop_y, args.crop_z) crop_x, crop_y, crop_z = validate_tiff_crop_dims( x_dim, y_dim, z_dim, *crop_xyz) if args.x_pixels: args.scale_x = float( args.x_pixels) / (crop_x[1] - crop_x[0] + 1) if args.y_pixels: args.scale_y = float( args.y_pixels) / (crop_y[1] - crop_y[0] + 1) if args.z_pixels: args.scale_z = float( args.z_pixels) / (crop_z[1] - crop_z[0] + 1) transform_json(input_path=args.input, output_path=args.output, crop_x=args.crop_x, crop_y=args.crop_y, crop_z=args.crop_z, flip_x=args.flip_x, flip_y=args.flip_y, flip_z=args.flip_z, scale_x=args.scale_x, scale_y=args.scale_y, scale_z=args.scale_z, original_tiff=args.original_tiff)
def transform_tiff(input_glob_or_list: Union[str, List[str]], output_path: str, crop_x: Union[str, List[int], Tuple[int, int]] = None, crop_y: Union[str, List[int], Tuple[int, int]] = None, crop_z: Union[str, List[int], Tuple[int, int]] = None, flip_x: bool = False, flip_y: bool = False, flip_z: bool = False, scale_x: float = 1, scale_y: float = 1, scale_z: float = 1, split_output: bool = False, start_num: int = 0, num_digits: int = None) -> None: """Main function for cropping tiffs Note: progress bars not particularly accurate for inputs with very large tiff files due to IO-limited multiprocessing and how the jobs are queued Parameters ---------- input_glob_or_list : Union[str, List[str]] String containing input glob or list of file paths to individual tiffs output_path : str Output file path, should either be a directory or tiff file, depending on the value of split_output crop_x : Union[str, List[int], Tuple[int, int]] String in format "[x_min,x_max]" or Sequence of ints in format [x_min, x_max] specifying the minimum and maximum x-values (inclusive) to include in the outputted cropped tiff crop_y : Union[str, List[int], Tuple[int, int]] String in format "[y_min,y_max]" or Sequence of ints in format [y_min, y_max] specifying the minimum and maximum y-values (inclusive) to include in the outputted cropped tiff crop_z : Union[str, List[int], Tuple[int, int]] String in format "[z_min,z_max]" or Sequence of ints in format [z_min, z_max] specifying the minimum and maximum x-values (inclusive) to include in the outputted cropped tiff flip_x : bool Specify whether or not the output image should have its x-axis reversed after cropping flip_y : bool Specify whether or not the output image should have its y-axis reversed after cropping flip_z : bool Specify whether or not the output image should have its z-axis reversed after cropping scale_x : float Specify the scaling factor along the x-axis after cropping scale_y : float Specify the scaling factor along the y-axis after cropping scale_z : float Specify the scaling factor along the z-axis after cropping split_output : bool True if output should be a directory of 2D tiffs, False if output should be single multi-page tiff file start_num : int Number from which to start outputting in output TIFF stack num_digits : int Number of digits in output TIFF stack file names Returns ------- None """ tiff_paths = glob_to_list(input_glob_or_list) # Ensures TIFF stack is outputted into a directory if split_output: if platform.system() == "Windows": if output_path[-1] != "\\": output_path += "\\" elif platform.system() == "Linux" or platform.system == "Darwin": if output_path[-1] != "/": output_path += "/" x_dim, y_dim, z_dim = get_tiff_dims(input_glob_or_list) crop_x, crop_y, crop_z = parse_crop_dims_str(crop_x, crop_y, crop_z) crop_x, crop_y, crop_z = validate_tiff_crop_dims(x_dim, y_dim, z_dim, crop_x, crop_y, crop_z) if num_digits is None: num_digits = int(np.floor(np.log10(crop_z[1] - crop_z[0] + 1)) + 1) if len(tiff_paths) == 1: tiff_ndarray_reshape = reshape_single_tiff(tiff_paths[0]) transform_single_tiff(tiff_ndarray_reshape, output_filepath=output_path, output_tiff_stack=split_output, crop_x=crop_x, crop_y=crop_y, crop_z=crop_z, flip_x=flip_x, flip_y=flip_y, flip_z=flip_z, scale_x=scale_x, scale_y=scale_y, scale_z=scale_z, start_num=start_num, num_digits=num_digits) else: transform_multi_tiff(tiff_paths, output_filepath=output_path, output_tiff_stack=split_output, crop_x=crop_x, crop_y=crop_y, crop_z=crop_z, flip_x=flip_x, flip_y=flip_y, flip_z=flip_z, scale_x=scale_x, scale_y=scale_y, scale_z=scale_z, start_num=start_num, num_digits=num_digits)