Convert Color Image to Sketch
Introduction:
In today’s digital age, the intersection of art and technology has led to remarkable advancements in image processing. One fascinating application is the ability to convert color images into sketches, mimicking the traditional art form. This not only unleashes creativity but also provides a unique perspective on visual content. In this tutorial, we’ll explore how to achieve this transformation using Python.
Sections
1- Packages installation
2-Read the image using imgaeio package’s
3-Make the image Black and White
4-Blur the image using gaussian filter
5-Create function to perform dogding
📚 Package installation
#Install imageio package
#The imageio package in Python is a versatile library for reading and writing a wide range of image file formats.
!pip install imageio
📚Read the image using imgaeio package’s
%matplotlib inline
import imageio
import requests
import matplotlib.pyplot as plt
import IPython.display as dp
#Display the image from the web using an URI.
img="https://raw.githubusercontent.com/hussain0048/Projects-/master/emo.jfif"
dp.Image(requests.get(img).content)
#Read the image using imgaeio package's imread method and URI from web using
source_img = imageio.imread(img)
📚Make the image Black and White
# Make the image Black and White using the formula Y= 0.299*R + 0.587*G + 0.114*B i.e. applying greyscale
import numpy as np
def grayscaleimg(rgb):
return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
gryscl_img = grayscaleimg(source_img)
#Invert the image by subtracting it from 255
inv_img = (255 - gryscl_img)
plt.imshow(inv_img)
📚Blur the image using gaussian filter
#Blur the image using gaussian filter
import scipy.ndimage
blurred_img = scipy.ndimage.filters.gaussian_filter(inv_img, sigma=5)
plt.imshow(blurred_img)
📚Create function to perform dogding
#Create function to perform dogding(belnding together greyscale and blurred image)
def dodging(blur_img, gryscl_img):
resultant_dodge=blur_img*255/(255-gryscl_img)
resultant_dodge[resultant_dodge>255]=255
resultant_dodge[gryscl_img==255]=255
return resultant_dodge.astype('uint8')
#Generate the target image by applying the dodge
target_img= dodging(blurred_img, gryscl_img)
#Display the target image
%matplotlib inline
import matplotlib.pyplot as plt
plt.imshow(target_img, cmap="gray")
Conclusion:
Converting color images into sketches using Python opens up a world of creative possibilities. Whether you’re an artist looking for inspiration or a developer exploring image processing techniques, this tutorial provides a solid foundation to get started. Experiment with different parameters, explore additional techniques, and unleash your imagination to create stunning sketches from ordinary photographs. Happy sketching!
Github
Here you can find the complete code of project.
Github Link
Please Follow and 👏 Clap for the story courses teach to see latest updates on this story
🚀 Elevate Your Data Skills with Coursesteach! 🚀
Ready to dive into Python, Machine Learning, Data Science, Statistics, Linear Algebra, Computer Vision, and Research? Coursesteach has you covered!
🔍 Python, 🤖 ML, 📊 Stats, ➕ Linear Algebra, 👁️🗨️ Computer Vision, 🔬 Research — all in one place!
Don’t Miss Out on This Exclusive Opportunity to Enhance Your Skill Set! Enroll Today 🌟 at
Machine Learning projects course
🔍 Explore Free world top University computer Vision ,NLP, Machine Learning , Deep Learning , Time Series and Python Projects, access insightful slides and source code, and tap into a wealth of free online websites, github repository related Machine Learning Projects. Connect with like-minded individuals on Reddit, Facebook, and beyond, and stay updated with our YouTube channel and GitHub repository. Don’t wait — enroll now and unleash your Machine Learning projects potential!”
Stay tuned for our upcoming articles because we reach end to end ,where we will explore specific topics related to Deep Learning in more detail!
Remember, learning is a continuous process. So keep learning and keep creating and Sharing with others!💻✌️
Ready to dive into data science and AI but unsure how to start? I’m here to help! Offering personalized research supervision and long-term mentoring. Let’s chat on Skype: themushtaq48 or email me at mushtaqmsit@gmail.com. Let’s kickstart your journey together!
Contribution: We would love your help in making coursesteach community even better! If you want to contribute in some courses , or if you have any suggestions for improvement in any coursesteach content, feel free to contact and follow.
Together, let’s make this the best AI learning Community! 🚀