Image Feature Extraction Using Scikit Image – A Hands-On Guide

Image Feature Extraction Using Scikit Image - A hands on tutorial on handling and analyzing images using skimage in Python
Image Feature Extraction using SKIMAGE

Features are the basic attributes or aspects which clearly help us identify the particular object, image, or anything. Features are the marked properties which are unique. While working on an image dataset we need to extract the features of different images which will help us segregate the images based on certain features or aspects. 

There is no exact definition of the features of an image but things like the shape, size, orientation, etc. constitute the feature of the image. Extracting these features can be done using different techniques using python.


Sign up for your weekly dose of what's up in emerging technology.

Scikit-Image is an open-source image processing library for Python. It includes algorithms for segmentation, geometric transformations, color space manipulation, analysis, filtering, morphology, feature detection, and more. We will use scikit-image for feature extraction.

In this article we will discuss:

  1. Loading and Visualizing an Image
  2. Analyze image properties
  3. Image Feature Extraction using Scikit-Image

We will start by analyzing the image and then basic feature extraction using python followed by feature extraction using Scikit-Image. We can use any local image we have on our system, I will use an image saved on my system for which I will try and extract features.  

a. Importing the required libraries

We will look at all the aspects of the image so we need to import different libraries including NumPy, pandas, etc.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from import imread, imshow

b. Loading the image

You can use any image from your system. I have an image named’elephant.jpg’ for which I will be performing feature extraction.

image1 = imread('C:/Users/Lenovo/Downloads/elephant.jpg')

image2 = imread('elephant.jpg', as_gray=True)
Image Feature Extraction using Scikit Image

c. Analyzing both the images

#Shape of images

Here we can see that the colored image contains rows, columns, and channels as it is a colored image there are three channels RGB while grayscale pictures have only one channel. So we can clearly identify the colored and grayscale images by their shapes.

Let’s look at the size of the images.


Image size is the product of the rows, columns, and channels. Despite being the same images grayscale is smaller in size because it has only 1 channel. 

d. Feature Extraction

i. Pixel Features

The number of pixels in an image is the same as the size of the image for grayscale images we can find the pixel features by reshaping the shape of the image and returning the array form of the image.

pixel_feat1 = np.reshape(image2, (1080 * 1920)

Similarly, we can find the pixel feature for the colored image.

pixel_feat2 = np.reshape(image1, (1080 * 1920 * 3)

ii. Edge Features

Edges in an image are the corners where the pixel change drastically, as the images are stored in array form we can visualize different values and see where the change in pixel value is higher but doing it manually takes time, Scikit-Image provides functions for image edge features extraction namely:

  • Prewitt Kernel:

It is an edge detection kernel that works separately for both horizontal and vertical axis.

  • Sobel Kernel:

It works on creating images with emphasis on edges 

  • Canny Algorithm

Canny Algorithm is an edge detection technique that uses a multi-stage algorithm to detect a wide range of edges in images. 

Using these three algorithms for edge feature extraction.

from skimage import filters

# prewitt kernel
pre_hor = prewitt_h(image2)
pre_ver = prewitt_v(image2)

# Sobel Kernel
ed_sobel = filters.sobel(image2)

#canny algorithm
can = feature.canny(image2)

imshow(pre_ver, cmap='gray');
Image Feature Extraction using Scikit Image

imshow(pre_hor, cmap='gray');
Image Feature Extraction using Scikit Image

imshow(ed_sobel, cmap='gray');

imshow(can, cmap=’gray);
Image Feature Extraction using Scikit Image

There are many other kernels for edge feature extraction but these three are the most used ones. 

  • Region-Based Segmentation

We use this segment object from a background. We will use our image and try region-based segmentation on it. 

from skimage.exposure import histogram
hist, hist_centers = histogram(image2)

#Plotting the Image and the Histogram of gray values
fig, axes = plt.subplots(1, 2, figsize=(8, 3))
axes[1].plot(hist_centers, hist, lw=2)
axes[1].set_title('histogram of gray values')

This image clearly depicts the feature we have tried to extract i.e segmentation of object from the background. 

These are some of the main image features which can be extracted using python and Scikit-Image. 


In this article, we successfully discovered:

  1. How to analyze an image?
  2. Extracting feature using basic python.
  3. Extracting advanced image features using Scikit-Image.

More Great AIM Stories

Himanshu Sharma
An aspiring Data Scientist currently Pursuing MBA in Applied Data Science, with an Interest in the financial markets. I have experience in Data Analytics, Data Visualization, Machine Learning, Creating Dashboards and Writing articles related to Data Science.

Our Upcoming Events

Conference, in-person (Bangalore)
Machine Learning Developers Summit (MLDS) 2023
19-20th Jan, 2023

Conference, in-person (Bangalore)
Rising 2023 | Women in Tech Conference
16-17th Mar, 2023

Conference, in-person (Bangalore)
Data Engineering Summit (DES) 2023
27-28th Apr, 2023

Conference, in-person (Bangalore)
MachineCon 2023
23rd Jun, 2023

3 Ways to Join our Community

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Telegram Channel

Discover special offers, top stories, upcoming events, and more.

Subscribe to our newsletter

Get the latest updates from AIM