I have to remove raindrops from a scene , and I am using python with opencv. But I am not able to maintain the quality. any suggestion?

I am trying to remove raindrops from an image using OpenCV in Python. The image is a cartoon-style outdoor scene with trees, clouds, a pond, and a green landscape. Raindrops are drawn across the scene in white streaks. After applying an inpainting algorithm, the quality of the image decreases, and the pond in the center of the image appears to split into two parts.

I attempted to remove raindrops in my code, but I’m struggling to maintain the quality. I’m seeking help to improve the code and would appreciate assistance with refining it.

import cv2 as cv
import numpy as np

# Load the image
image_path = "C:/Users/kavit/Downloads/RAIN.png"  # Update this path to your image file
image = cv.imread(image_path)

# Check if the image is loaded correctly
if image is None:
    raise Exception("Error: Could not load the image.")

# Convert the image to grayscale
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)

# Apply a Gaussian blur to reduce noise and minor raindrop streaks
blurred = cv.GaussianBlur(gray, (5, 5), 0)

# Use adaptive thresholding to detect raindrops with more sensitivity
mask = cv.adaptiveThreshold(blurred, 255, cv.ADAPTIVE_THRESH_MEAN_C, 
                            cv.THRESH_BINARY_INV, 11, 2)

# Combine with Canny edge detection to capture more details of raindrops
edges = cv.Canny(blurred, threshold1=20, threshold2=60)
combined_mask = cv.bitwise_or(mask, edges)

# Apply stronger morphological operations to clean the mask more thoroughly
kernel = np.ones((5, 5), np.uint8)  # Increase kernel size
mask_cleaned = cv.dilate(combined_mask, kernel, iterations=5)  # More dilation
mask_cleaned = cv.erode(mask_cleaned, kernel, iterations=4)  # More erosion

# Use inpainting with a larger radius to cover remaining rain streaks
inpainted_image_ns = cv.inpaint(image, mask_cleaned, 10, cv.INPAINT_NS)
inpainted_image_telea = cv.inpaint(image, mask_cleaned, 15, cv.INPAINT_TELEA)

# Blend the two inpainted results for more comprehensive raindrop removal
inpainted_image = cv.addWeighted(inpainted_image_ns, 0.5, inpainted_image_telea, 0.5, 0)

# Apply selective sharpening to restore some of the lost quality
sharpen_kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]])
sharpened_image = cv.filter2D(inpainted_image, -1, sharpen_kernel)

# Display the results
cv.imshow('Original Image with Raindrops', image)
cv.imshow('Refined Raindrop Mask', mask_cleaned)
cv.imshow('Final Image without Raindrops', sharpened_image)

# Wait until a key is pressed to close the windows
cv.waitKey(0)
cv.destroyAllWindows()

# Save the result to your desired path
cv.imwrite("C:/Users/kavit/Downloads/raindrop_removed_final_improved_v2.png", sharpened_image)

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật