
Plt. To convert an image to grayscale, display it and then save it is very easy, just do the following: Import required library from PIL import Image Read an image & convert it to gray-scale image Image.open('statueofunity.jpg').convert('L') Display image image.show() Save image image.save('statueofunitygs. Im = cv2.imread('TajMahal.jpg',cv2.IMREAD_GRAYSCALE)Īnother way to write above program with a tick/line to mark the image. Showing image in grayscale #Import required library Below are some of the example program to demonstrate the use of much powerful library for image processing. We can use other library like open-cv, matplotlib & numpy for image processing. > TajMahal_gray = Image.open('TajMahal.jpg').convert('L')Ībove example is from the PIL library of python.

We can make the grayscale image from our original colored image.

We can change the size of image using thumbnail() method of pillow − > im.thumbnail ((300, 300))Ĭonverting to grayscale image − convert() Now if we see the folder, we have same image in two different formats. We can change the format of image from one form to another, like below − > im.save('TajMahal.png') We can retreive some information about the opened image − > im You can rotate the image while showing like below − #Import required libraryĪs the above variable im, is a pillow object. Image: Open() and show()įirst, open the file/image and show. That's it: now we can play with our image.
PYTHON IMAGE CONVERT L INSTALL
We can use pip to install the required library, like − $pip install pillow Our first step will be to install the required library, like openCV, pillow or other which we wants to use for image processing. In this section we are going to see some basics of image processing in python. Python Imaging Library (PIL) − To perform basic operations on images like create thumnails, resize, rotation, convert between different file formats etc. Sckikit − Provides lots of alogrithms for image processing. Numpy and Scipy libraries − For image manipuation and processing.

OpenCV − Image processing library mainly focused on real-time computer vision with application in wide-range of areas like 2D and 3D feature toolkits, facial & gesture recognition, Human-computer interaction, Mobile robotics, Object identification and others. Python provides lots of libraries for image processing, including −
