32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
|
|
import cv2
|
|
import numpy as np
|
|
from PIL import Image
|
|
import os
|
|
from Image_Process.image_enhancement import remove_glare_and_bubbles
|
|
|
|
def test_glare_removal():
|
|
image_path = "a282.jpg"
|
|
if not os.path.exists(image_path):
|
|
print(f"Image {image_path} not found. Creating a dummy one.")
|
|
# Create a dummy image with a bright spot
|
|
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
|
img[:] = (100, 50, 50) # Background
|
|
cv2.circle(img, (50, 50), 10, (255, 255, 255), -1) # Bright spot (glare)
|
|
cv2.circle(img, (20, 20), 5, (255, 255, 255), -1) # Another glare
|
|
image = Image.fromarray(img)
|
|
image.save(image_path)
|
|
else:
|
|
image = Image.open(image_path).convert("RGB")
|
|
|
|
print("Processing image...")
|
|
# Apply the removal function
|
|
result = remove_glare_and_bubbles(image, threshold=200, saturation_threshold=50)
|
|
|
|
output_path = "test_glare_removed.png"
|
|
result.save(output_path)
|
|
print(f"Result saved to {output_path}")
|
|
|
|
if __name__ == "__main__":
|
|
test_glare_removal()
|