When working with image processing tasks in Python, Pillow (PIL) and the scikit-image library are two powerful tools that can help you manipulate and analyze images. While PIL is widely used for basic image processing tasks, scikit-image offers a comprehensive set of functions for more advanced image analysis and manipulation. So, in some situations, it is necessary to convert PIL image to Scikit image. Thankfully, the conversion process is straightforward. This tutorial shows how to do that using Python.
Prepare environment
- Install the following packages using
pip
:
pip install scikit-image
pip install Pillow
Code
In the following code, the image is loaded using the PIL image module. The scikit-image library works with images stored as NumPy arrays. So, we convert a PIL image to the Scikit image using the np.array
function, the resulting image is represented as a NumPy array. This array can then be passed to various functions and algorithms provided by scikit-image for image analysis, manipulation, and processing.
from PIL import Image
import numpy as np
pilImg = Image.open('test.jpg')
skiImg = np.array(pilImg)
Leave a Comment
Cancel reply