Created
May 13, 2025 05:13
-
-
Save me-suzy/e46573e5f4e047bea3e16cccd559c600 to your computer and use it in GitHub Desktop.
Photoscape X Pro - schimba carte imagini mai clare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from PIL import Image, ImageEnhance, ImageOps | |
from pathlib import Path | |
import numpy as np | |
def apply_custom_curve(img): | |
"""Aplică o curbă similară cu cea din PhotoScape X Pro""" | |
# Convertește în numpy array | |
img_array = np.array(img) | |
# Creează lookup table pentru curbă | |
# Curba din PhotoScape: 0,0,191,83,255,255 | |
# Aceasta întunecă tonurile medii drastic | |
curve = np.zeros(256) | |
# Puncte de control pentru curbă | |
points = [(0, 0), (191, 83), (255, 255)] | |
# Construiește curba cu interpolație | |
for i in range(len(points) - 1): | |
x0, y0 = points[i] | |
x1, y1 = points[i + 1] | |
for x in range(x0, x1 + 1): | |
if x1 != x0: | |
t = (x - x0) / (x1 - x0) | |
y = y0 + t * (y1 - y0) | |
curve[x] = int(y) | |
# Aplică curba la imagine | |
result = img_array.copy() | |
# Aplică pe fiecare canal de culoare | |
for i in range(3): | |
result[:,:,i] = np.vectorize(lambda x: curve[int(x)])(img_array[:,:,i]) | |
return Image.fromarray(result.astype('uint8')) | |
def photoscape_style_effect(image_path, output_path): | |
"""Aplică stilul PhotoScape X Pro cu fundal gălbui și text foarte negru""" | |
try: | |
# Deschide imaginea | |
img = Image.open(image_path) | |
# Convertește la RGB | |
if img.mode != 'RGB': | |
img = img.convert('RGB') | |
# Pasul 1: Aplică curba custom pentru contrast dramatic | |
img_curved = apply_custom_curve(img) | |
# Pasul 2: Crește contrastul general | |
contrast = ImageEnhance.Contrast(img_curved) | |
img_contrast = contrast.enhance(1.5) | |
# Pasul 3: Crește luminozitatea doar pentru fundal | |
img_array = np.array(img_contrast) | |
# Detectează și modifică fundalul | |
for i in range(img_array.shape[0]): | |
for j in range(img_array.shape[1]): | |
r, g, b = img_array[i, j] | |
# Pentru pixeli deschiși (fundal) | |
if r > 200 and g > 200 and b > 200: | |
# Aplică culoarea gălbuie | |
img_array[i, j] = [252, 248, 230] | |
# Pentru pixeli gri deschiși | |
elif r > 180 and g > 180 and b > 180: | |
# Fă-i mai gălbui | |
img_array[i, j] = [248, 244, 220] | |
# Pentru text (pixeli întunecați) | |
elif r < 100 and g < 100 and b < 100: | |
# Fă-i complet negri | |
img_array[i, j] = [0, 0, 0] | |
# Pentru tonuri medii | |
else: | |
# Întunecă dramatic | |
factor = 0.4 | |
img_array[i, j] = [ | |
int(r * factor), | |
int(g * factor), | |
int(b * factor) | |
] | |
# Convertește înapoi | |
result = Image.fromarray(img_array) | |
# Pasul 4: Film grain effect (similar cu PhotoScape) | |
# Adaugă un pic de zgomot pentru efect de film | |
noise = np.random.normal(0, 3, img_array.shape) | |
img_with_grain = np.clip(img_array + noise, 0, 255) | |
result = Image.fromarray(img_with_grain.astype('uint8')) | |
# Pasul 5: Ajustări finale | |
# Crește ușor claritatea | |
sharpness = ImageEnhance.Sharpness(result) | |
result = sharpness.enhance(1.2) | |
# Salvează cu calitate maximă | |
result.save(output_path, quality=100, subsampling=0) | |
return True | |
except Exception as e: | |
print(f"Eroare: {e}") | |
return False | |
def process_all_photoscape_style(input_folder): | |
"""Procesează toate imaginile cu stilul PhotoScape X Pro""" | |
input_path = Path(input_folder) | |
output_path = input_path / "photoscape_style" | |
output_path.mkdir(exist_ok=True) | |
image_extensions = ['.jpg', '.jpeg', '.png', '.tiff', '.tif', '.bmp'] | |
print(f"Procesez imaginile din: {input_folder}") | |
print(f"Salvez în: {output_path}") | |
print("Aplic stilul PhotoScape X Pro (fundal gălbui + text foarte negru)") | |
print("-" * 60) | |
processed = 0 | |
for file_path in input_path.iterdir(): | |
if file_path.is_file() and file_path.suffix.lower() in image_extensions: | |
output_file = output_path / file_path.name | |
print(f"Procesez: {file_path.name}") | |
if photoscape_style_effect(file_path, output_file): | |
processed += 1 | |
print(f" ✓ Salvat cu stil PhotoScape: {output_file.name}") | |
else: | |
print(f" ✗ Eroare") | |
print("-" * 60) | |
print(f"Gata! Am procesat {processed} imagini.") | |
if __name__ == "__main__": | |
process_all_photoscape_style(r"d:\77") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment