Making image manipulations thru one class

This commit is contained in:
2025-12-11 16:59:56 +02:00
parent 32a6a122bd
commit 9a221acb63
3 changed files with 30 additions and 30 deletions

View File

@@ -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,12 +1353,13 @@ 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)
else:
rgb_img = img.convert("RGB")
rgb_img.save(dst)
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 = pil_img.convert("RGB")
rgb_img.save(dst)
except Exception as exc:
logger.warning(f"Failed to convert {src} to RGB: {exc}")