Making image manipulations thru one class
This commit is contained in:
@@ -10,7 +10,6 @@ from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
import yaml
|
||||
from PIL import Image as PILImage
|
||||
from PySide6.QtCore import Qt, QThread, Signal
|
||||
from PySide6.QtWidgets import (
|
||||
QWidget,
|
||||
@@ -1293,8 +1292,8 @@ class TrainingTab(QWidget):
|
||||
if not sample_image:
|
||||
return False
|
||||
try:
|
||||
with PILImage.open(sample_image) as img:
|
||||
return img.mode.upper() != "RGB"
|
||||
img = Image(sample_image)
|
||||
return img.pil_image.mode.upper() != "RGB"
|
||||
except Exception as exc:
|
||||
logger.warning(f"Failed to inspect image {sample_image}: {exc}")
|
||||
return False
|
||||
@@ -1354,11 +1353,12 @@ class TrainingTab(QWidget):
|
||||
dst = dst_dir / relative
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
with PILImage.open(src) as img:
|
||||
if len(img.getbands()) == 1:
|
||||
rgb_img = convert_grayscale_to_rgb_preserve_range(img)
|
||||
img_obj = Image(src)
|
||||
pil_img = img_obj.pil_image
|
||||
if len(pil_img.getbands()) == 1:
|
||||
rgb_img = convert_grayscale_to_rgb_preserve_range(pil_img)
|
||||
else:
|
||||
rgb_img = img.convert("RGB")
|
||||
rgb_img = pil_img.convert("RGB")
|
||||
rgb_img.save(dst)
|
||||
except Exception as exc:
|
||||
logger.warning(f"Failed to convert {src} to RGB: {exc}")
|
||||
|
||||
@@ -5,12 +5,12 @@ Handles detection inference and result storage.
|
||||
|
||||
from typing import List, Dict, Optional, Callable
|
||||
from pathlib import Path
|
||||
from PIL import Image
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from src.model.yolo_wrapper import YOLOWrapper
|
||||
from src.database.db_manager import DatabaseManager
|
||||
from src.utils.image import Image
|
||||
from src.utils.logger import get_logger
|
||||
from src.utils.file_utils import get_relative_path
|
||||
|
||||
@@ -64,9 +64,9 @@ class InferenceEngine:
|
||||
stored_relative_path = str(Path(image_path).resolve())
|
||||
|
||||
# Get image dimensions
|
||||
img = Image.open(image_path)
|
||||
width, height = img.size
|
||||
img.close()
|
||||
img = Image(image_path)
|
||||
width = img.width
|
||||
height = img.height
|
||||
|
||||
# Perform detection
|
||||
detections = self.yolo.predict(image_path, conf=conf)
|
||||
|
||||
@@ -7,10 +7,9 @@ from ultralytics import YOLO
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, Dict, Callable, Any
|
||||
import torch
|
||||
from PIL import Image
|
||||
import tempfile
|
||||
import os
|
||||
from src.utils.image import convert_grayscale_to_rgb_preserve_range
|
||||
from src.utils.image import Image, convert_grayscale_to_rgb_preserve_range
|
||||
from src.utils.logger import get_logger
|
||||
|
||||
|
||||
@@ -232,11 +231,12 @@ class YOLOWrapper:
|
||||
source_path = Path(source)
|
||||
if source_path.is_file():
|
||||
try:
|
||||
with Image.open(source_path) as img:
|
||||
if len(img.getbands()) == 1:
|
||||
rgb_img = convert_grayscale_to_rgb_preserve_range(img)
|
||||
img_obj = Image(source_path)
|
||||
pil_img = img_obj.pil_image
|
||||
if len(pil_img.getbands()) == 1:
|
||||
rgb_img = convert_grayscale_to_rgb_preserve_range(pil_img)
|
||||
else:
|
||||
rgb_img = img.convert("RGB")
|
||||
rgb_img = pil_img.convert("RGB")
|
||||
|
||||
suffix = source_path.suffix or ".png"
|
||||
tmp = tempfile.NamedTemporaryFile(suffix=suffix, delete=False)
|
||||
|
||||
Reference in New Issue
Block a user