Compare commits
6 Commits
4d1b97f196
...
f47e3925f3
| Author | SHA1 | Date |
|---|---|---|
|
|
f47e3925f3 | |
|
|
d49cd08c23 | |
|
|
91df0b8ddd | |
|
|
e3c3fc7254 | |
|
|
0bf947b0c2 | |
|
|
91cc96a631 |
|
|
@ -1,6 +1,7 @@
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
__pycache__
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
|
||||||
|
|
|
||||||
141
README.md
141
README.md
|
|
@ -1,118 +1,63 @@
|
||||||
# ColorCalc – Interactive Colour Range Analyzer
|
# ICRS (Interactive Color Range Analyzer)
|
||||||
|
|
||||||
ColorCalc is a desktop app for Windows/macOS/Linux that helps you identify and highlight colours in images. It is built with Python, Tkinter, and Pillow and is tuned for full‑HD screens. Instead of focusing on a single hue (like purple), you can target any colour range, tweak saturation/value thresholds, and export overlays in seconds.
|
ICRS is a small Tkinter tool for analysing colour ranges in images. You load a picture, pick or click a reference colour, adjust hue/saturation/value sliders, and the app marks matching pixels while showing quick stats.
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
- Two synced previews (original + overlay)
|
||||||
|
- Hue/Sat/Value sliders with presets and image colour picker
|
||||||
|
- Exclusion rectangles to ignore regions
|
||||||
|
- Theme toggle (light/dark) with rounded toolbar buttons
|
||||||
|
- Folder support with previous/next navigation
|
||||||
|
- Quick overlay export (PNG) and optional defaults via `config.toml`
|
||||||
|
|
||||||
- 🎯 **Configurable hue detection** – adjust hue, saturation, and value windows or pick colours directly from the image/preset swatches.
|
## Requirements
|
||||||
- 🪟 **Responsive dual-preview UI** – original image on the left, processed overlay on the right, sized for 1080p.
|
- Python 3.11+ (3.10 works with `tomli`)
|
||||||
- 🖱️ **Interactive masks** – draw exclusion rectangles to ignore specific regions when calculating results.
|
- [uv](https://github.com/astral-sh/uv) for dependency management
|
||||||
- 🌗 **Light & dark mode** – rounded toolbar buttons adapt to the current theme; toggle any time.
|
- Tkinter (install separately on some Linux distros)
|
||||||
- 🟨 **Real‑time stats** – centre-aligned labels show match ratios with/without exclusions plus filenames and dimensions.
|
|
||||||
- 💾 **Overlay export** – save PNG overlays blended with the source image for reporting or further editing.
|
|
||||||
- ⚙️ **Config file defaults** – populate `config.toml` to ship different starting values across machines.
|
|
||||||
- 🎨 **Preset palette** – one-click access to common colours (red, cyan, grey, black, …).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
### Requirements
|
|
||||||
|
|
||||||
- Python 3.11+ (includes the standard `tomllib`; for 3.10 install `tomli`)
|
|
||||||
- Tkinter (ships with most Python distributions; on Linux install `python3-tk`)
|
|
||||||
- Pillow (`pip install pillow`)
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
|
## Setup with uv
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/<your-org>/ColorCalc.git
|
git clone https://github.com/<your-org>/ICRS.git
|
||||||
cd ColorCalc
|
cd ICRS
|
||||||
python3 -m venv .venv
|
uv venv
|
||||||
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
||||||
pip install -r requirements.txt # or pip install pillow
|
uv pip sync # installs Pillow + optional deps from pyproject
|
||||||
|
uv run icrs # launches the GUI
|
||||||
```
|
```
|
||||||
|
To include the optional ttkbootstrap theme pack:
|
||||||
### Launch
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 main.py
|
uv pip install '.[ui]'
|
||||||
```
|
```
|
||||||
|
|
||||||
The window opens maximized; load an image, tweak sliders, and watch the overlay update in real time.
|
## Workflow
|
||||||
|
1. Load an image (`📂`) or a folder (`📁`).
|
||||||
---
|
2. Pick a colour (`🎨` dialog, `🖱️` image click, or preset swatch).
|
||||||
|
3. Fine‑tune sliders; watch the overlay update on the right.
|
||||||
## Usage Tips
|
4. Move through folder images with `⬅️` / `➡️`.
|
||||||
|
5. Draw exclusions with right drag; reset or save when ready.
|
||||||
- **Pick colours quickly:** use the 🎨 button to open a colour chooser or click directly inside the left preview (enable 🖱️ first).
|
|
||||||
- **Fine-tune defaults:** edit `config.toml` and set keys under `[defaults]`. Restart the app to apply changes.
|
|
||||||
- **Reset & compare:** `🔄 Slider zurücksetzen` reverts to defaults and clears the status message.
|
|
||||||
- **Exclude areas:** right-drag on the original preview to mark rectangles; use `↩️` to undo or `🧹` to clear all.
|
|
||||||
- **Copy stats:** right-click the filename or ratio labels to copy.
|
|
||||||
- **Export overlay:** `💾` saves a PNG with your overlay merged onto the source image.
|
|
||||||
- **Theme switch:** `🌓` toggles between light/dark; button palettes update instantly.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Project Structure
|
|
||||||
|
|
||||||
```
|
|
||||||
ColorCalc/
|
|
||||||
├── app/
|
|
||||||
│ ├── app.py # ColorCalcApp composition root
|
|
||||||
│ ├── __init__.py # Package exports
|
|
||||||
│ ├── gui/
|
|
||||||
│ │ ├── color_picker.py # Colour selection & presets
|
|
||||||
│ │ ├── exclusions.py # Exclusion rectangle handlers
|
|
||||||
│ │ ├── theme.py # Theme detection & style updates
|
|
||||||
│ │ └── ui.py # Tkinter layout and custom widgets
|
|
||||||
│ └── logic/
|
|
||||||
│ ├── constants.py # Config defaults & preview sizing
|
|
||||||
│ ├── image_processing.py # Loading, overlay creation, stats
|
|
||||||
│ └── reset.py # Slider reset mixin
|
|
||||||
├── config.toml # Default HSV/alpha overrides
|
|
||||||
├── images/ # Optional sample inputs
|
|
||||||
└── main.py # CLI entry point (`python3 main.py`)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Configuration (`config.toml`)
|
|
||||||
|
|
||||||
|
## Config Defaults
|
||||||
|
Optional `config.toml`:
|
||||||
```toml
|
```toml
|
||||||
[defaults]
|
[defaults]
|
||||||
hue_min = 250.0 # 0..360°
|
hue_min = 250.0
|
||||||
hue_max = 310.0
|
hue_max = 310.0
|
||||||
sat_min = 15.0 # percentage 0..100
|
sat_min = 15.0
|
||||||
val_min = 15.0
|
val_min = 15.0
|
||||||
val_max = 100.0
|
val_max = 100.0
|
||||||
alpha = 120 # overlay opacity 0..255
|
alpha = 120
|
||||||
```
|
```
|
||||||
|
|
||||||
All values are optional; omit them to fall back to built-in defaults. Hue min/max support wrap-around (e.g. 350 to 20).
|
## Project Layout
|
||||||
|
```
|
||||||
|
app/
|
||||||
|
app.py # main app assembly
|
||||||
|
gui/ # UI, theme, picker mixins
|
||||||
|
logic/ # image ops, defaults, reset
|
||||||
|
config.toml # optional defaults
|
||||||
|
main.py # entry point
|
||||||
|
```
|
||||||
|
|
||||||
---
|
## Development
|
||||||
|
- Quick check: `uv run python -m compileall app main.py`
|
||||||
## Development Workflow
|
- Contributions welcome; include screenshots for UI tweaks.
|
||||||
|
|
||||||
- Format: project sticks to standard Python style; no formatter enforced.
|
|
||||||
- Testing: primary quick check is compilation via `python3 -m compileall app main.py`.
|
|
||||||
- Platform quirks: some theme detection uses Windows registry; errors are swallowed when unavailable.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
1. Fork + clone.
|
|
||||||
2. Create a feature branch.
|
|
||||||
3. Make changes and run `python3 -m compileall app main.py`.
|
|
||||||
4. Submit a PR with a clear description and screenshots if UI changes are visible.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT License © 2024 ColorCalc contributors. See `LICENSE` (add one if missing) for details.
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
"""Application package."""
|
"""Application package."""
|
||||||
|
|
||||||
from .app import ColorCalcApp, start_app
|
from .app import ICRSApp, start_app
|
||||||
|
|
||||||
__all__ = ["ColorCalcApp", "start_app"]
|
__all__ = ["ICRSApp", "start_app"]
|
||||||
|
|
|
||||||
10
app/app.py
10
app/app.py
|
|
@ -8,7 +8,7 @@ from .gui import ColorPickerMixin, ExclusionMixin, ThemeMixin, UIBuilderMixin
|
||||||
from .logic import DEFAULTS, ImageProcessingMixin, ResetMixin
|
from .logic import DEFAULTS, ImageProcessingMixin, ResetMixin
|
||||||
|
|
||||||
|
|
||||||
class ColorCalcApp(
|
class ICRSApp(
|
||||||
ThemeMixin,
|
ThemeMixin,
|
||||||
UIBuilderMixin,
|
UIBuilderMixin,
|
||||||
ImageProcessingMixin,
|
ImageProcessingMixin,
|
||||||
|
|
@ -20,7 +20,7 @@ class ColorCalcApp(
|
||||||
|
|
||||||
def __init__(self, root: tk.Tk):
|
def __init__(self, root: tk.Tk):
|
||||||
self.root = root
|
self.root = root
|
||||||
self.root.title("ColorCalc — Bild + Overlay")
|
self.root.title("ICRS — Interactive Color Range Analyzer")
|
||||||
try:
|
try:
|
||||||
self.root.state("zoomed")
|
self.root.state("zoomed")
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
@ -56,6 +56,8 @@ class ColorCalcApp(
|
||||||
self.preview_img = None
|
self.preview_img = None
|
||||||
self.preview_tk = None
|
self.preview_tk = None
|
||||||
self.overlay_tk = None
|
self.overlay_tk = None
|
||||||
|
self.image_paths = []
|
||||||
|
self.current_image_index = -1
|
||||||
|
|
||||||
# Build UI
|
# Build UI
|
||||||
self.setup_ui()
|
self.setup_ui()
|
||||||
|
|
@ -66,8 +68,8 @@ class ColorCalcApp(
|
||||||
def start_app() -> None:
|
def start_app() -> None:
|
||||||
"""Entry point used by the CLI script."""
|
"""Entry point used by the CLI script."""
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
app = ColorCalcApp(root)
|
app = ICRSApp(root)
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["ColorCalcApp", "start_app"]
|
__all__ = ["ICRSApp", "start_app"]
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ class UIBuilderMixin:
|
||||||
toolbar.pack(fill=tk.X, padx=12, pady=8)
|
toolbar.pack(fill=tk.X, padx=12, pady=8)
|
||||||
buttons = [
|
buttons = [
|
||||||
("📂 Bild laden", self.load_image),
|
("📂 Bild laden", self.load_image),
|
||||||
|
("📁 Ordner laden", self.load_folder),
|
||||||
|
("⬅️ Bild zurück", self.show_previous_image),
|
||||||
|
("➡️ Nächstes Bild", self.show_next_image),
|
||||||
("🎨 Farbe wählen", self.choose_color),
|
("🎨 Farbe wählen", self.choose_color),
|
||||||
("🖱️Farbe aus Bild klicken", self.enable_pick_mode),
|
("🖱️Farbe aus Bild klicken", self.enable_pick_mode),
|
||||||
("💾 Overlay speichern", self.save_overlay),
|
("💾 Overlay speichern", self.save_overlay),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""Logic utilities and mixins for processing and configuration."""
|
"""Logic utilities and mixins for processing and configuration."""
|
||||||
|
|
||||||
from .constants import BASE_DIR, DEFAULTS, IMAGES_DIR, PREVIEW_MAX_SIZE
|
from .constants import BASE_DIR, DEFAULTS, IMAGES_DIR, PREVIEW_MAX_SIZE, SUPPORTED_IMAGE_EXTENSIONS
|
||||||
from .image_processing import ImageProcessingMixin
|
from .image_processing import ImageProcessingMixin
|
||||||
from .reset import ResetMixin
|
from .reset import ResetMixin
|
||||||
|
|
||||||
|
|
@ -9,6 +9,7 @@ __all__ = [
|
||||||
"DEFAULTS",
|
"DEFAULTS",
|
||||||
"IMAGES_DIR",
|
"IMAGES_DIR",
|
||||||
"PREVIEW_MAX_SIZE",
|
"PREVIEW_MAX_SIZE",
|
||||||
|
"SUPPORTED_IMAGE_EXTENSIONS",
|
||||||
"ImageProcessingMixin",
|
"ImageProcessingMixin",
|
||||||
"ResetMixin",
|
"ResetMixin",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ _DEFAULTS_BASE = {
|
||||||
"alpha": 120,
|
"alpha": 120,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SUPPORTED_IMAGE_EXTENSIONS = (".webp", ".png", ".jpg", ".jpeg", ".bmp")
|
||||||
|
|
||||||
_DEFAULT_TYPES: dict[str, Callable[[Any], Any]] = {
|
_DEFAULT_TYPES: dict[str, Callable[[Any], Any]] = {
|
||||||
"hue_min": float,
|
"hue_min": float,
|
||||||
"hue_max": float,
|
"hue_max": float,
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ from __future__ import annotations
|
||||||
|
|
||||||
import colorsys
|
import colorsys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterable, Tuple
|
from typing import Iterable, Sequence, Tuple
|
||||||
|
|
||||||
from tkinter import filedialog, messagebox
|
from tkinter import filedialog, messagebox
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageTk
|
from PIL import Image, ImageDraw, ImageTk
|
||||||
|
|
||||||
from .constants import IMAGES_DIR, PREVIEW_MAX_SIZE
|
from .constants import IMAGES_DIR, PREVIEW_MAX_SIZE, SUPPORTED_IMAGE_EXTENSIONS
|
||||||
|
|
||||||
|
|
||||||
class ImageProcessingMixin:
|
class ImageProcessingMixin:
|
||||||
|
|
@ -22,6 +22,9 @@ class ImageProcessingMixin:
|
||||||
preview_tk: ImageTk.PhotoImage | None
|
preview_tk: ImageTk.PhotoImage | None
|
||||||
overlay_tk: ImageTk.PhotoImage | None
|
overlay_tk: ImageTk.PhotoImage | None
|
||||||
|
|
||||||
|
image_paths: list[Path]
|
||||||
|
current_image_index: int
|
||||||
|
|
||||||
def load_image(self) -> None:
|
def load_image(self) -> None:
|
||||||
default_dir = IMAGES_DIR if IMAGES_DIR.exists() else Path.cwd()
|
default_dir = IMAGES_DIR if IMAGES_DIR.exists() else Path.cwd()
|
||||||
path = filedialog.askopenfilename(
|
path = filedialog.askopenfilename(
|
||||||
|
|
@ -31,21 +34,88 @@ class ImageProcessingMixin:
|
||||||
)
|
)
|
||||||
if not path:
|
if not path:
|
||||||
return
|
return
|
||||||
self.image_path = Path(path)
|
self._set_image_collection([Path(path)], 0)
|
||||||
|
|
||||||
|
def load_folder(self) -> None:
|
||||||
|
default_dir = IMAGES_DIR if IMAGES_DIR.exists() else Path.cwd()
|
||||||
|
directory = filedialog.askdirectory(
|
||||||
|
title="Ordner mit Bildern wählen",
|
||||||
|
initialdir=str(default_dir),
|
||||||
|
)
|
||||||
|
if not directory:
|
||||||
|
return
|
||||||
|
folder = Path(directory)
|
||||||
|
if not folder.exists():
|
||||||
|
messagebox.showerror("Fehler", "Der Ordner wurde nicht gefunden.")
|
||||||
|
return
|
||||||
|
image_files = sorted(
|
||||||
|
(
|
||||||
|
path
|
||||||
|
for path in folder.iterdir()
|
||||||
|
if path.suffix.lower() in SUPPORTED_IMAGE_EXTENSIONS and path.is_file()
|
||||||
|
),
|
||||||
|
key=lambda item: item.name.lower(),
|
||||||
|
)
|
||||||
|
if not image_files:
|
||||||
|
messagebox.showinfo("Info", "Keine unterstützten Bilder im Ordner gefunden.")
|
||||||
|
return
|
||||||
|
self._set_image_collection(image_files, 0)
|
||||||
|
|
||||||
|
def show_next_image(self, event=None) -> None:
|
||||||
|
if not getattr(self, "image_paths", None):
|
||||||
|
return
|
||||||
|
next_index = getattr(self, "current_image_index", -1) + 1
|
||||||
|
if next_index < len(self.image_paths):
|
||||||
|
self._display_image_by_index(next_index)
|
||||||
|
|
||||||
|
def show_previous_image(self, event=None) -> None:
|
||||||
|
if not getattr(self, "image_paths", None):
|
||||||
|
return
|
||||||
|
prev_index = getattr(self, "current_image_index", -1) - 1
|
||||||
|
if prev_index >= 0:
|
||||||
|
self._display_image_by_index(prev_index)
|
||||||
|
|
||||||
|
def _set_image_collection(self, paths: Sequence[Path], start_index: int) -> None:
|
||||||
|
self.image_paths = list(paths)
|
||||||
|
if not self.image_paths:
|
||||||
|
return
|
||||||
|
self.current_image_index = -1
|
||||||
|
self._display_image_by_index(max(0, start_index))
|
||||||
|
|
||||||
|
def _display_image_by_index(self, index: int) -> None:
|
||||||
|
if not self.image_paths:
|
||||||
|
return
|
||||||
|
if index < 0 or index >= len(self.image_paths):
|
||||||
|
return
|
||||||
|
path = self.image_paths[index]
|
||||||
|
if not path.exists():
|
||||||
|
messagebox.showerror("Fehler", f"Datei nicht gefunden: {path}")
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
image = Image.open(path).convert("RGBA")
|
image = Image.open(path).convert("RGBA")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
messagebox.showerror("Fehler", f"Bild konnte nicht geladen werden: {exc}")
|
messagebox.showerror("Fehler", f"Bild konnte nicht geladen werden: {exc}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.image_path = path
|
||||||
self.orig_img = image
|
self.orig_img = image
|
||||||
|
self.exclude_rects = []
|
||||||
|
self._rubber_start = None
|
||||||
|
self._rubber_id = None
|
||||||
|
self.pick_mode = False
|
||||||
|
|
||||||
self.prepare_preview()
|
self.prepare_preview()
|
||||||
self.update_preview()
|
self.update_preview()
|
||||||
|
|
||||||
dimensions = f"{self.orig_img.width}x{self.orig_img.height}"
|
dimensions = f"{self.orig_img.width}x{self.orig_img.height}"
|
||||||
status_text = f"Geladen: {self.image_path.name} — {dimensions}"
|
suffix = f" [{index + 1}/{len(self.image_paths)}]" if len(self.image_paths) > 1 else ""
|
||||||
|
status_text = f"Geladen: {path.name} — {dimensions}{suffix}"
|
||||||
self.status.config(text=status_text)
|
self.status.config(text=status_text)
|
||||||
self.status_default_text = status_text
|
self.status_default_text = status_text
|
||||||
if hasattr(self, "filename_label"):
|
if hasattr(self, "filename_label"):
|
||||||
self.filename_label.config(text=f"{self.image_path.name} — {dimensions}")
|
self.filename_label.config(text=f"{path.name} — {dimensions}{suffix}")
|
||||||
|
|
||||||
|
self.current_image_index = index
|
||||||
|
|
||||||
def save_overlay(self) -> None:
|
def save_overlay(self) -> None:
|
||||||
if self.orig_img is None:
|
if self.orig_img is None:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
[project]
|
||||||
|
name = "icrs"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Interactive Color Range Analyzer (ICRS) for Tkinter"
|
||||||
|
readme = "README.md"
|
||||||
|
authors = [{ name = "ICRS contributors" }]
|
||||||
|
license = { text = "MIT" }
|
||||||
|
requires-python = ">=3.10"
|
||||||
|
dependencies = [
|
||||||
|
"pillow>=10.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
ui = ["ttkbootstrap>=1.10.0"]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
icrs = "app.app:start_app"
|
||||||
|
|
||||||
|
[tool.uv]
|
||||||
|
package = false
|
||||||
Loading…
Reference in New Issue