Re: Image enhance

amrodi9999--- via Python-list <[email protected]>
Newsgroups gmane.comp.python.general
Message-ID <[email protected]>
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")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.