Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Hands-On Image Processing with Python
Hands-On Image Processing with Python

Hands-On Image Processing with Python: Expert techniques for advanced image analysis and effective interpretation of image data

Arrow left icon
Profile Icon Sandipan Dey
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (5 Ratings)
Paperback Nov 2018 492 pages 1st Edition
eBook
€28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Sandipan Dey
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (5 Ratings)
Paperback Nov 2018 492 pages 1st Edition
eBook
€28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Hands-On Image Processing with Python

Chapter 2. Sampling, Fourier Transform, and Convolution

In this chapter, we'll discuss 2D signals in the time and frequency domains. We'll first talk about spatial sampling, an important concept that is used in resizing an image, and about the challenges in sampling. We'll try solving these problems using the functions in the Python library. We'll also introduce intensity quantization in an image; intensity quantizing means how many bits will be used to store a pixel in an image and what impact it will have on the quality of the image. You will surely want to know about the Discrete Fourier Transform (DFT) that can be used to transform an image from the spatial (time) domain into the frequency domain. You'll learn to implement DFT with the Fast Fourier Transform (FFT) algorithm using numpy and scipy functions and will be able to apply this implementation on an image!

You will also be interested in knowing about 2D convolutions that increase the speed of convolution. We'll also understand...

Image formation – sampling and quantization


In this section, we'll describe two important concepts for image formation, namely, sampling and quantization, and see how we can resize an image with sampling and colors quantized with PIL and scikit-image libraries. We'll use a hands-on approach here and we'll define the concepts while seeing them in action. Ready?

Let's start by importing all of the required packages:

% matplotlib inline # for inline image display inside notebook
from PIL import Image
from skimage.io import imread, imshow, show
import scipy.fftpack as fp
from scipy import ndimage, misc, signal
from scipy.stats import signaltonoise
from skimage import data, img_as_float
from skimage.color import rgb2gray
from skimage.transform import rescale
import matplotlib.pylab as pylab
import numpy as np
import numpy.fft
import timeit

Sampling

Sampling refers to the selection/rejection of image pixels, which means that it is a spatial operation. We can use sampling to increase or reduce the...

Discrete Fourier Transform


The Fourier transform method has a long mathematical history and we are not going to discuss it here (it can be found in any digital signal processing or digital image processing theory book). As far as image processing is concerned, we shall focus only on 2D Discrete Fourier Transform (DFT). The basic idea behind the Fourier transform method is that an image can be thought of as a 2D function, f, that can be expressed as a weighted sum of sines and cosines (Fourier basic functions) along two dimensions.

We can transition from a set of grayscale pixel values in the image (spatial/time domain) to a set of Fourier coefficients (frequency domain) using the DFT, and it is discrete since the spatial and the transform variables to be used can only take a set of discrete consecutive integer values (typically the locations of a 2D array representing the image).

In a similar way, the frequency domain 2D array of Fourier coefficients can be converted back into the spatial...

Understanding convolution


Convolution is an operation that operates on two images, one being an input image and the other one being a mask (also called the kernel) as a filter on the input image, producing an output image. 

Convolution filtering is used to modify the spatial frequency characteristics of an image. It works by determining the value of a central pixel by adding the weighted values of all of its neighbors together to compute the new value of the pixel in the output image. The pixel values in the output image are computed by traversing the kernel window through the input image, as shown in the next screenshot (for convolution with the valid mode; we'll see convolution modes later in this chapter):

As you can see, the kernel window, marked by an arrow in the input image, traverses through the image and obtains values that are mapped on the output image after convolving.

Why convolve an image?

Convolution applies a general-purpose filter effect on the input image. This is done in order...

Summary


We discussed a few important concepts primarily related to 2D DFT and its related applications in image processing, such as filtering in the frequency domain, and we worked on quite a few examples using scikit-image numpy.fft, scipy.fftpack, signal, and ndimage modules.

Hopefully, you are now clear on sampling and quantization, the two important image formation techniques. We have seen 2D DFT, Python implementations of FFT algorithms, and applications such as image denoising and restoration, correlation and convolution of the DFT in image processing, and application of convolution with an appropriate kernel in filter design and the application of correlation in template matching.

You should now be able to write Python code to do sampling and quantization using PIL/SciPy/sckit-image libraries and to perform 2D FT/IFT in Python using the FFT algorithm. We saw how easy it was to do basic 2D convolutions on images with some kernels.

In the next chapter, we'll discuss more on convolution...

Questions


The following are the questions:

  1. Implement down-sampling with anti-aliasing using the Gaussian LPF (hint: reduce the house grayscale image four times, first by applying a Gaussian filter and then by filtering every other row and column. Compare the output images with and without pre-processing with LPF before down-sampling). 
  2. Use the FFT to up-sample an image: first double the size of the lena grayscale image by padding zero rows/columns at every alternate positions, then use the FFT followed by an LPF and then by the IFFT to get the output image. Why does it work?
  3. Try to apply the Fourier transform and image reconstruction with a color (RGB) image. (Hint: apply the FFT for each channel separately).
  4. Show (mathematically and with a 2D kernel example) that the Fourier transform of a Gaussian kernel is another Gaussian kernel.
  1. Use the lena image and the asymmetric ripple kernel to generate images with correlation and convolution. Show that output images are different. Now, flip the kernel...

Further reading


The following are the various references from various sources:

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Practical coverage of every image processing task with popular Python libraries
  • Includes topics such as pseudo-coloring, noise smoothing, computing image descriptors
  • Covers popular machine learning and deep learning techniques for complex image processing tasks

Description

Image processing plays an important role in our daily lives with various applications such as in social media (face detection), medical imaging (X-ray, CT-scan), security (fingerprint recognition) to robotics & space. This book will touch the core of image processing, from concepts to code using Python. The book will start from the classical image processing techniques and explore the evolution of image processing algorithms up to the recent advances in image processing or computer vision with deep learning. We will learn how to use image processing libraries such as PIL, scikit-mage, and scipy ndimage in Python. This book will enable us to write code snippets in Python 3 and quickly implement complex image processing algorithms such as image enhancement, filtering, segmentation, object detection, and classification. We will be able to use machine learning models using the scikit-learn library and later explore deep CNN, such as VGG-19 with Keras, and we will also use an end-to-end deep learning model called YOLO for object detection. We will also cover a few advanced problems, such as image inpainting, gradient blending, variational denoising, seam carving, quilting, and morphing. By the end of this book, we will have learned to implement various algorithms for efficient image processing.

Who is this book for?

This book is for Computer Vision Engineers, and machine learning developers who are good with Python programming and want to explore details and complexities of image processing. No prior knowledge of the image processing techniques is expected.

What you will learn

  • Perform basic data pre-processing tasks such as image denoising and spatial filtering in Python
  • Implement Fast Fourier Transform (FFT) and Frequency domain filters (e.g., Weiner) in Python
  • Do morphological image processing and segment images with different algorithms
  • Learn techniques to extract features from images and match images
  • Write Python code to implement supervised / unsupervised machine learning algorithms for image processing
  • Use deep learning models for image classification, segmentation, object detection and style transfer

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 30, 2018
Length: 492 pages
Edition : 1st
Language : English
ISBN-13 : 9781789343731
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 30, 2018
Length: 492 pages
Edition : 1st
Language : English
ISBN-13 : 9781789343731
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 112.97
Hands-On Image Processing with Python
€37.99
Hands-On Machine Learning for Algorithmic Trading
€49.99
Artificial Intelligence and Machine Learning Fundamentals
€24.99
Total 112.97 Stars icon

Table of Contents

12 Chapters
Getting Started with Image Processing Chevron down icon Chevron up icon
Sampling, Fourier Transform, and Convolution Chevron down icon Chevron up icon
Convolution and Frequency Domain Filtering Chevron down icon Chevron up icon
Image Enhancement Chevron down icon Chevron up icon
Image Enhancement Using Derivatives Chevron down icon Chevron up icon
Morphological Image Processing Chevron down icon Chevron up icon
Extracting Image Features and Descriptors Chevron down icon Chevron up icon
Image Segmentation Chevron down icon Chevron up icon
Classical Machine Learning Methods in Image Processing Chevron down icon Chevron up icon
Deep Learning in Image Processing - Image Classification Chevron down icon Chevron up icon
Deep Learning in Image Processing - Object Detection, and more Chevron down icon Chevron up icon
Additional Problems in Image Processing Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(5 Ratings)
5 star 20%
4 star 0%
3 star 60%
2 star 0%
1 star 20%
S.C.N.T Jan 15, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Das Buch liefert als Hands-On Handbuch, die Möglichkeit, die im Buch beschriebenen Beispiele mit vergleichsweise wenig Aufwand selbst nachzuvollziehen. Faktisch auf dem eigenen Laptop Python zu installieren, die relevanten Pakete runterzuladen und dann anhand der Download-baren Skripte und Bilder von Packt.com die angegebenen Beispiele auf dem eigenen Laptop durchzurechnen. Damit ist für mich die Anforderung an ein Hands-On Handbuch absolut erfüllt. Ich habe vorher noch nie mit Python gearbeitet, habe aber umfangreiche Programmiererfahrung mit Matlab und C++. Das erfolgreiche Ausführen eines der Beispiele zum Inpainting in Kapitel 12 Seiten 450 bis 452 hat etwa 3 Stunden gedauert (inkl. der gesamten Installation der notwendigen SW).
Amazon Verified review Amazon
fengsien Aug 16, 2021
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Since 2020 I've purchased 2 computer tech books written by Indian author. Both of their contents have problems. This is the 2nd one. Like another commenter said, its content seems like to be copied from the author's blog articles.From these two book's impression to me, you should be wary of Indian authors of computer tech books. And I've also purchased an Iranian author's computer tech book, I'm also disappointed.So be wary of Indian & Iranian authors!
Amazon Verified review Amazon
Michael Sprayberry May 11, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Again Packt publishing is letting me down. This book offers little more than what can be found online in blog posts. Save your dollars this is just nickel and dime offerings.
Amazon Verified review Amazon
see-rose Feb 03, 2020
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I bought this book to learn basic tools and techniques of image (pre)processing, and at the same time learning to do it with Python.First: the book delivers both, an overview over the basic techniques using for image processing, enhancement and manipulation; and a lot of code blocks to do this.BUT: it's probably not worth spending money on that book. Rather find relevant code in the internet, and most probably even better code examples and by far better documented and explained.This book in most parts is no more than a printout of collected Python code. And even not the best one, using partly deprecated functions.Moreover, the code blocks (delivered in jupyter notebooks) are inconsistently written, so some errors have to be found and corrected by the user (as an excersise?). Most of all, the code is very very poorly explained and commented, the author leaves it to the reader to find out what is going on. So for the more complicated tasks / programming examples the marooned reader may decide by himself if it's worth the effort to understand the idea of the code or to skip it.But the critics is not the bad and poorly commented code but the sparse and missing explanations of what is done for image processing, and why. Presenting a technique (a filter, a function, ...) by showing just an example is in no way an explanation of how image processing should be done, or even what the tool itself really does. Besides the general explanation and discussion (! there are a lot of sentences "... as will be discussed in a later section", but there simply is no discussion) I missed detailed explanations of the code - e.g. why the parameters where chosen as they were implemented in the code, what the purpose and effect of these parameters is, some mathematical background, and I absolutely missed the discussion of when the presented tool should be used outsided the classroom. Instead, the author leaves it to the reader to find out which tool fits to her own usecase and how to tune the parameters in a useful way. That's not a textbook to learn and understand the basics and make the reader ready to apply the newly gained knowlegde to the real world.All in all I got the impression of a sloppy collection of sometimes confusing, not stringent Python code with almost no code explanations. Poorly edited text connects the code blocks with meaningless comments. Besides having chapters and chapter numbers the text is completely unstructured and text blocks are not always ordered in a logical way. Poor review, but eventually a nice and well done layout makes the book nice to look at, at least (that would be worth two stars). Third star is just a half one for a quite comprehensive collection of Python code for image processing, that at least can give the reader some starting point to look for real explanations and useful disucssions in the internet.
Amazon Verified review Amazon
Shivam Mittal May 23, 2023
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
The whole book was supposed to be colorful as it is an Image processing book. Instead, it's like the whole book is just photo copied and even the page quality is really bad
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.