This commit is contained in:
2026-01-05 08:59:36 +02:00
parent e98d287b8a
commit 395d263900
4 changed files with 30 additions and 29 deletions

View File

@@ -54,7 +54,7 @@ class ConfigManager:
"models_directory": "data/models", "models_directory": "data/models",
"base_model_choices": [ "base_model_choices": [
"yolov8s-seg.pt", "yolov8s-seg.pt",
"yolov11s-seg.pt", "yolo11s-seg.pt",
], ],
}, },
"training": { "training": {
@@ -225,6 +225,4 @@ class ConfigManager:
def get_allowed_extensions(self) -> list: def get_allowed_extensions(self) -> list:
"""Get list of allowed image file extensions.""" """Get list of allowed image file extensions."""
return self.get( return self.get("image_repository.allowed_extensions", Image.SUPPORTED_EXTENSIONS)
"image_repository.allowed_extensions", Image.SUPPORTED_EXTENSIONS
)

View File

@@ -46,9 +46,9 @@ def get_pseudo_rgb(arr: np.ndarray, gamma: float = 0.3) -> np.ndarray:
a3[a3 > p9999] = p9999 a3[a3 > p9999] = p9999
a3 /= a3.max() a3 /= a3.max()
# return np.stack([a1, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0) return np.stack([a1, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0)
return np.stack([a2, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0) return np.stack([a2, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0)
return np.stack([a1, a2, a3], axis=0) # return np.stack([a1, a2, a3], axis=0)
class ImageLoadError(Exception): class ImageLoadError(Exception):
@@ -114,8 +114,7 @@ class Image:
if not is_image_file(str(self.path), self.SUPPORTED_EXTENSIONS): if not is_image_file(str(self.path), self.SUPPORTED_EXTENSIONS):
ext = self.path.suffix.lower() ext = self.path.suffix.lower()
raise ImageLoadError( raise ImageLoadError(
f"Unsupported image format: {ext}. " f"Unsupported image format: {ext}. " f"Supported formats: {', '.join(self.SUPPORTED_EXTENSIONS)}"
f"Supported formats: {', '.join(self.SUPPORTED_EXTENSIONS)}"
) )
try: try:

View File

@@ -18,7 +18,13 @@ class UT:
self.rois = None self.rois = None
if no_labels: if no_labels:
self.rois = ImagejRoi.fromfile(self.roifile_fn) self.rois = ImagejRoi.fromfile(self.roifile_fn)
print(self.roifile_fn.stem)
print(self.roifile_fn.parent.parts[-1])
if "Roi-" in self.roifile_fn.stem:
self.stem = self.roifile_fn.stem.split("Roi-")[1] self.stem = self.roifile_fn.stem.split("Roi-")[1]
else:
self.stem = self.roifile_fn.parent.parts[-1]
else: else:
self.roifile_fn = roifile_fn / roifile_fn.parts[-1] self.roifile_fn = roifile_fn / roifile_fn.parts[-1]
self.stem = self.roifile_fn.stem self.stem = self.roifile_fn.stem
@@ -95,9 +101,7 @@ class UT:
for i, roi in enumerate(self.rois): for i, roi in enumerate(self.rois):
rc = roi.subpixel_coordinates rc = roi.subpixel_coordinates
if rc is None: if rc is None:
print( print(f"No coordinates: {self.roifile_fn}, element {i}, out of {len(self.rois)}")
f"No coordinates: {self.roifile_fn}, element {i}, out of {len(self.rois)}"
)
continue continue
xmn, ymn = rc.min(axis=0) xmn, ymn = rc.min(axis=0)
xmx, ymx = rc.max(axis=0) xmx, ymx = rc.max(axis=0)
@@ -143,6 +147,9 @@ if __name__ == "__main__":
) )
args = parser.parse_args() args = parser.parse_args()
# print(args)
# aa
for path in args.input: for path in args.input:
print("Path:", path) print("Path:", path)
if not args.no_labels: if not args.no_labels:
@@ -152,6 +159,7 @@ if __name__ == "__main__":
else: else:
for rfn in Path(path).glob("*.zip"): for rfn in Path(path).glob("*.zip"):
# if Path(path).suffix == ".zip":
print("Roi FN:", rfn) print("Roi FN:", rfn)
ut = UT(rfn, args.no_labels) ut = UT(rfn, args.no_labels)
ut.export_rois(args.output, class_index=0) ut.export_rois(args.output, class_index=0)

View File

@@ -56,9 +56,7 @@ def yolo_bbox_to_xyxy(coords, img_w, img_h):
def poly_to_pts(coords, img_w, img_h): def poly_to_pts(coords, img_w, img_h):
# coords: [x1 y1 x2 y2 ...] either normalized or absolute # coords: [x1 y1 x2 y2 ...] either normalized or absolute
if coords_are_normalized(coords[4:]): if coords_are_normalized(coords[4:]):
coords = [ coords = [coords[i] * (img_w if i % 2 == 0 else img_h) for i in range(len(coords))]
coords[i] * (img_w if i % 2 == 0 else img_h) for i in range(len(coords))
]
pts = np.array(coords, dtype=np.int32).reshape(-1, 2) pts = np.array(coords, dtype=np.int32).reshape(-1, 2)
return pts return pts
@@ -154,21 +152,21 @@ def load_labels_file(label_path):
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(description="Show YOLO segmentation / polygon annotations")
description="Show YOLO segmentation / polygon annotations"
)
parser.add_argument("image", type=str, help="Path to image file") parser.add_argument("image", type=str, help="Path to image file")
parser.add_argument("labels", type=str, help="Path to YOLO label file (polygons)") parser.add_argument("--labels", type=str, help="Path to YOLO label file (polygons)")
parser.add_argument( parser.add_argument("--alpha", type=float, default=0.4, help="Polygon fill alpha (0..1)")
"--alpha", type=float, default=0.4, help="Polygon fill alpha (0..1)" parser.add_argument("--no-bbox", action="store_true", help="Don't draw bounding boxes for polygons")
)
parser.add_argument(
"--no-bbox", action="store_true", help="Don't draw bounding boxes for polygons"
)
args = parser.parse_args() args = parser.parse_args()
print(args)
img_path = Path(args.image) img_path = Path(args.image)
if args.labels:
lbl_path = Path(args.labels) lbl_path = Path(args.labels)
else:
lbl_path = img_path.with_suffix(".txt")
lbl_path = Path(str(lbl_path).replace("images", "labels"))
if not img_path.exists(): if not img_path.exists():
print("Image not found:", img_path) print("Image not found:", img_path)
@@ -188,9 +186,7 @@ def main():
if not labels: if not labels:
print("No labels parsed from", lbl_path) print("No labels parsed from", lbl_path)
# continue and just show image # continue and just show image
out = draw_annotations( out = draw_annotations(img.copy(), labels, alpha=args.alpha, draw_bbox_for_poly=(not args.no_bbox))
img.copy(), labels, alpha=args.alpha, draw_bbox_for_poly=(not args.no_bbox)
)
# Convert BGR -> RGB for matplotlib display # Convert BGR -> RGB for matplotlib display
out_rgb = cv2.cvtColor(out, cv2.COLOR_BGR2RGB) out_rgb = cv2.cvtColor(out, cv2.COLOR_BGR2RGB)