Spaces:
Running
Running
File size: 1,488 Bytes
0e6ebc7 eab7c24 0e6ebc7 eab7c24 0e6ebc7 eab7c24 0e6ebc7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | import argparse
from pathlib import Path
import cv2
from cleaning import (
clean_display_image_and_mask,
cleaned_image_name,
read_image_rgb_and_preview,
write_image_rgb,
)
def main(
image_paths: list[str],
output_dir: str | Path = "out",
) -> None:
output_dir = Path(output_dir)
cleaned_dir = output_dir / "cleaned"
masks_dir = output_dir / "masks"
cleaned_dir.mkdir(parents=True, exist_ok=True)
masks_dir.mkdir(parents=True, exist_ok=True)
for image_path_string in image_paths:
image_path = Path(image_path_string)
image_rgb, display_rgb = read_image_rgb_and_preview(image_path)
cleaned_rgb, debris_mask = clean_display_image_and_mask(
image_rgb,
display_rgb,
)
cv2.imwrite(str(masks_dir / f"{image_path.stem}_mask.png"), debris_mask)
cleaned_path = cleaned_dir / cleaned_image_name(image_path)
write_image_rgb(cleaned_path, cleaned_rgb)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Clean debris from IHC images.")
parser.add_argument(
"images",
nargs="+",
help="Paths to one or more input images.",
)
parser.add_argument(
"--output-dir",
default="out",
help="Directory for cleaned images and masks (default: out).",
)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
main(args.images, args.output_dir)
|