I N F O A R Y A N

Computer Vision Project | PHOTO to WATER COLOR ART using OPENCV-PYTHON with CODE | Explanation

In the enchanting realm of computer vision, we embark on a creative odyssey to turn ordinary photos into mesmerizing watercolor art using OpenCV and Python. Our journey begins with a captivating algorithm, where we harness the power of image processing to infuse life into images, mimicking the delicate strokes of a watercolor masterpiece.

Flow of Article :

  1. Understanding the algorithm
  2. Writing functions 
  3. Coding them in phases

 

Video Explanation :

 

Understanding the algorithm:

  1. Load the Image:

    • Utilize OpenCV to load the input photo, the canvas of our artistic endeavor.
  2. Convert to Grayscale:

    • Transform the colorful palette into grayscale, laying the foundation for artistic interpretation.
  3. Apply Bilateral Filter:

    • Employ OpenCV’s bilateral filter to smoothen the image while preserving edges, imparting a watercolor-like texture.
  4. Generate Pencil Sketch:

    • Employ OpenCV’s pencil sketch algorithm to create a pencil-style outline, adding artistic depth to the image.
  5. Combine Bilateral Filter and Pencil Sketch:

    • Merge the effects of the bilateral filter and pencil sketch, capturing the essence of both texture and structure.
  6. Add Color Tint:

    • Introduce subtle color tints to infuse vibrancy into the grayscale canvas, emulating the characteristic hues of watercolor paintings.
  7. Display the Watercolor Art:

    • Showcase the transformed image, now a breathtaking watercolor rendition of the original photo.

Phase 1: Reading and Resizing

# Read the image
image = cv2.imread(‘test2.webp’)

# Resize the image with cubic interpolation
image_resized = cv2.resize(image, None, fx=0.5, fy=0.5)

cv2.imread: This function reads an image from a file.

cv2.resize: Resizes the image to a specified size using cubic interpolation. 

Phase 2: Clearing Impurities and Edge Preservation

# Remove impurities using median blur
image_cleared = cv2.medianBlur(image_resized, 3)
image_cleared = cv2.medianBlur(image_cleared, 3)
image_cleared = cv2.medianBlur(image_cleared, 3)

# Preserve edges using edge-preserving filter
image_cleared = cv2.edgePreservingFilter(image_cleared, sigma_s=5)

cv2.medianBlur: Applies a median filter for noise reduction.

cv2.edgePreservingFilter: Applies an edge-preserving filter to enhance edges while smoothing the image.

Phase 3: Bilateral Filtering

# Apply bilateral filtering for detail enhancement
image_filtered = cv2.bilateralFilter(image_cleared, 3, 10, 5)

# Iterative bilateral filtering for additional refinement
for i in range(2):
image_filtered = cv2.bilateralFilter(image_filtered, 3, 20, 10)

for i in range(3):
image_filtered = cv2.bilateralFilter(image_filtered, 5, 30, 10)

cv2.bilateralFilter: Applies a bilateral filter for smoothing while preserving edges.

Phase 4: Sharpening with Gaussian Blur

# Sharpen the image using addWeighted
gaussian_mask = cv2.GaussianBlur(image_filtered, (7,7), 2)
image_sharp = cv2.addWeighted(image_filtered, 1.5, gaussian_mask, -0.5, 0)
image_sharp = cv2.addWeighted(image_sharp, 1.4, gaussian_mask, -0.2, 10)

cv2.GaussianBlur: Applies a Gaussian blur to the image.

cv2.addWeighted: Blends two images together with specified weights. 

 

The Code can be found here.

 

Conclusion 

In conclusion, this computer vision project employing OpenCV and Python showcases the transformative potential within image processing. By seamlessly blending functions like `cv2.medianBlur`, `cv2.edgePreservingFilter`, and `cv2.bilateralFilter`, we embark on a visual journey, reshaping ordinary images into extraordinary masterpieces. The orchestrated dance of resizing, impurity clearing, and detail enhancement breathes life into the digital canvas. The final touch, executed through `cv2.GaussianBlur` and `cv2.addWeighted`, sharpens the image, revealing intricate details reminiscent of watercolor strokes. This project, teeming with techniques for image enhancement, invites exploration and experimentation. Elevate your Python and OpenCV endeavors with these transformative processes, and let your projects resonate with the harmonious blend of art and technology. Dive into the world of Python image processing and OpenCV tutorials to further expand your horizons. Happy coding and envisioning!