VOOZH about

URL: https://www.geeksforgeeks.org/python/build-gui-application-pencil-sketch-from-photo-in-python/

⇱ Build GUI Application Pencil Sketch from Photo in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Build GUI Application Pencil Sketch from Photo in Python

Last Updated : 23 Jul, 2025

In this article, we will cover how to convert images to watercolor sketches and pencil sketch Linux.

Sketching and painting are used by artists of many disciplines to preserve ideas, recollections, and thoughts. Experiencing art from painting and sculpting to visiting an art museumβ€”provides a variety of well-being advantages, including reduced stress and improved critical thinking abilities. Drawing, sketching, and painting in particular, have been linked to increased creativity, memory, and stress alleviation, and are utilized in art therapy.

Through this article, we can now build a web application to directly convert an image to a sketch using a python framework Streamlit. The user can upload an image to convert it to either a watercolor sketch or a pencil sketch. The user can further download the converted image, before that let us understand some of the definitions that we will use in this article.

  • Streamlit - Streamlit is a popular open-source web application framework among Python developers. It is interoperable and compatible with a wide range of frequently used libraries, including Keras, Sklearn, Numpy, and pandas.
  • PIL - PIL stands for Python Imaging Library. It is a package for image processing in the Python programming language. It includes lightweight image processing tools that help with picture editing, creation, and storing. 
  • Numpy - Numpy is a widely used Python programming library utilized for high-level mathematical computations. 
  • cv2 - This library is utilized for solving computer vision problems

Package required

pip install streamlit
pip install opencv-python
pip install numpy
pip install Pillow

Stepwise Implementation

Step 1: Install Streamlit

πŸ‘ Image
 

Similarly, we will install PIL, Numpy, and cv2.

Step 2: Test that the installation worked

streamlit hello
πŸ‘ Image
 

Step 3: Now run the streamlit web application. We need to type the following command

streamlit run app.py
πŸ‘ Image
 

Step 4: Now the web application has been launched successfully. You can access the web application through the local URL or the Network URL.

πŸ‘ Image
 

Step 5: Create a new folder named - Web Application to convert images to sketches.

Step 6: Paste the code of the web application in the file 'app.py' and save the file.

Initially in the code, we import all the required frameworks, packages, libraries, and modules that we will utilize to build the web application. Further, we have to use user-defined functions utilized to convert an image to a watercolor sketch and to convert an image to a pencil sketch. There is also a function to load an image utilizing the PIL library. The main function has the code for the web application. Initially, we have some headings and subheadings to guide the user to upload an image. For uploading the image we have utilized streamlit's file uploader. We are also providing a drop-down menu for the user to choose between producing a watercolor sketch / producing a pencil sketch and then based on their choice, we render the results. Both the original image and the image after applying the filter are rendered side by side such that the user can compare both images to see the results. Finally, the user can also download the image to their local machine. This is done by utilizing the streamlit's download button.

Complete Code

Output:

πŸ‘ Image
 
πŸ‘ Image
 
πŸ‘ Image
 
πŸ‘ Image
 
πŸ‘ Image
 
πŸ‘ Image
 
Comment
Article Tags: