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

eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
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 : 9781789341850
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 147.97
Hands-On Image Processing with Python
$48.99
Hands-On Machine Learning for Algorithmic Trading
$65.99
Artificial Intelligence and Machine Learning Fundamentals
$32.99
Total $ 147.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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.