Image enhance

2025-09-02 Thread amrodi9999--- via Python-list
I'm new to Python.
Operating System - Windows XP SP3
Python 2.7 installed.

I got a script that tries to improve the image?
I created a bat file using the command line.

C:\python27\python.exe d:\temp\teste.py

But even though it runs, it displays an error:

"... no encoding declare..."

Can anyone help?

My sincere thanks in advance.
-- 
https://mail.python.org/mailman3//lists/python-list.python.org


Re: Image enhance

2025-09-02 Thread amrodi9999--- via Python-list
My code

from PIL import Image, ImageEnhance
import matplotlib.pyplot as plt
import numpy as np
import cv2

# Original image path
image_path = "D:\temp\STC.jpg"  # Altere se estiver em outro local
original_image = Image.open(image_path)

# Convert to OpenCV to apply enhancements
cv_image = cv2.cvtColor(np.array(original_image), cv2.COLOR_RGB2BGR)

# Sharpen and reduce noise
denoised = cv2.fastNlMeansDenoisingColored(cv_image, None, 10, 10, 7, 21)

# Convert back to PIL
enhanced_image = Image.fromarray(cv2.cvtColor(denoised, cv2.COLOR_BGR2RGB))

# Improving contrast and sharpness with PIL
contrast = ImageEnhance.Contrast(enhanced_image).enhance(1.4)
sharp = ImageEnhance.Sharpness(contrast).enhance(2.5)

# Display enhanced image
plt.figure(figsize=(10, 10))
plt.imshow(sharp)
plt.axis("off")
plt.title("Imagem Restaurada (Pre-colorizacao)")
plt.show()

# Save restored image
sharp.save("STC_restaurada.jpg")
-- 
https://mail.python.org/mailman3//lists/python-list.python.org