upate
This commit is contained in:
@@ -9,7 +9,7 @@ from typing import Optional, List, Dict, Callable, Any
|
|||||||
import torch
|
import torch
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
from src.utils.image import Image, convert_grayscale_to_rgb_preserve_range
|
from src.utils.image import Image
|
||||||
from src.utils.logger import get_logger
|
from src.utils.logger import get_logger
|
||||||
|
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ class YOLOWrapper:
|
|||||||
img_obj = Image(source_path)
|
img_obj = Image(source_path)
|
||||||
pil_img = img_obj.pil_image
|
pil_img = img_obj.pil_image
|
||||||
if len(pil_img.getbands()) == 1:
|
if len(pil_img.getbands()) == 1:
|
||||||
rgb_img = convert_grayscale_to_rgb_preserve_range(pil_img)
|
rgb_img = img_obj.convert_grayscale_to_rgb_preserve_range()
|
||||||
else:
|
else:
|
||||||
rgb_img = pil_img.convert("RGB")
|
rgb_img = pil_img.convert("RGB")
|
||||||
|
|
||||||
|
|||||||
@@ -12,18 +12,27 @@ class UT:
|
|||||||
Operetta files along with rois drawn in ImageJ
|
Operetta files along with rois drawn in ImageJ
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, roifile_fn: Path):
|
def __init__(self, roifile_fn: Path, no_labels: bool):
|
||||||
self.roifile_fn = roifile_fn
|
self.roifile_fn = roifile_fn
|
||||||
print("is file", self.roifile_fn.is_file())
|
print("is file", self.roifile_fn.is_file())
|
||||||
self.rois = ImagejRoi.fromfile(self.roifile_fn)
|
self.rois = None
|
||||||
self.stem = self.roifile_fn.stem.split("Roi-")[1]
|
if no_labels:
|
||||||
|
self.rois = ImagejRoi.fromfile(self.roifile_fn)
|
||||||
|
self.stem = self.roifile_fn.stem.split("Roi-")[1]
|
||||||
|
else:
|
||||||
|
self.roifile_fn = roifile_fn / roifile_fn.parts[-1]
|
||||||
|
self.stem = self.roifile_fn.stem
|
||||||
|
|
||||||
|
print(self.roifile_fn)
|
||||||
|
|
||||||
|
print(self.stem)
|
||||||
self.image, self.image_props = self._load_images()
|
self.image, self.image_props = self._load_images()
|
||||||
|
|
||||||
def _load_images(self):
|
def _load_images(self):
|
||||||
"""Loading sequence of tif files
|
"""Loading sequence of tif files
|
||||||
array sequence is CZYX
|
array sequence is CZYX
|
||||||
"""
|
"""
|
||||||
print(self.roifile_fn.parent, self.stem)
|
print("Loading images:", self.roifile_fn.parent, self.stem)
|
||||||
fns = list(self.roifile_fn.parent.glob(f"{self.stem.lower()}*.tif*"))
|
fns = list(self.roifile_fn.parent.glob(f"{self.stem.lower()}*.tif*"))
|
||||||
stems = [fn.stem.split(self.stem)[-1] for fn in fns]
|
stems = [fn.stem.split(self.stem)[-1] for fn in fns]
|
||||||
n_ch = len(set([stem.split("-ch")[-1].split("t")[0] for stem in stems]))
|
n_ch = len(set([stem.split("-ch")[-1].split("t")[0] for stem in stems]))
|
||||||
@@ -116,6 +125,7 @@ class UT:
|
|||||||
self.image = np.max(self.image[channel], axis=0)
|
self.image = np.max(self.image[channel], axis=0)
|
||||||
print(self.image.shape)
|
print(self.image.shape)
|
||||||
|
|
||||||
|
print(path / subfolder / f"{self.stem}.tif")
|
||||||
with TiffWriter(path / subfolder / f"{self.stem}.tif") as tif:
|
with TiffWriter(path / subfolder / f"{self.stem}.tif") as tif:
|
||||||
tif.write(self.image)
|
tif.write(self.image)
|
||||||
|
|
||||||
@@ -126,14 +136,25 @@ if __name__ == "__main__":
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-i", "--input", nargs="*", type=Path)
|
parser.add_argument("-i", "--input", nargs="*", type=Path)
|
||||||
parser.add_argument("-o", "--output", type=Path)
|
parser.add_argument("-o", "--output", type=Path)
|
||||||
|
parser.add_argument(
|
||||||
|
"--no-labels",
|
||||||
|
action="store_false",
|
||||||
|
help="Source does not have labels, export only images",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
for path in args.input:
|
for path in args.input:
|
||||||
print("Path:", path)
|
print("Path:", path)
|
||||||
for rfn in Path(path).glob("*.zip"):
|
if not args.no_labels:
|
||||||
print("Roi FN:", rfn)
|
print("No labels")
|
||||||
ut = UT(rfn)
|
ut = UT(path, args.no_labels)
|
||||||
ut.export_rois(args.output, class_index=0)
|
|
||||||
ut.export_image(args.output, plane_mode="max projection", channel=0)
|
ut.export_image(args.output, plane_mode="max projection", channel=0)
|
||||||
|
|
||||||
|
else:
|
||||||
|
for rfn in Path(path).glob("*.zip"):
|
||||||
|
print("Roi FN:", rfn)
|
||||||
|
ut = UT(rfn, args.no_labels)
|
||||||
|
ut.export_rois(args.output, class_index=0)
|
||||||
|
ut.export_image(args.output, plane_mode="max projection", channel=0)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|||||||
Reference in New Issue
Block a user