Hands-On Image Processing with Python

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Sandipan Dey
Publisher: Packt Publishing
Year: 2018

Language: English

Cover
Title Page
Copyright and Credits
Dedication
About Packt
Contributors
Table of Contents
Preface
Chapter 1: Getting Started with Image Processing
What is image processing and some applications
What is an image and how it is stored on a computer
What is image processing?
Some applications of image processing
The image processing pipeline
Setting up different image processing libraries in Python
Installing pip
Installing some image processing libraries in Python
Installing the Anaconda distribution
Installing Jupyter Notebook
Image I/O and display with Python
Reading, saving, and displaying an image using PIL
Providing the correct path to the images on the disk
Reading, saving, and displaying an image using Matplotlib
Interpolating while displaying with Matplotlib imshow()
Reading, saving, and displaying an image using scikit-image
Using scikit-image's astronaut dataset
Reading and displaying multiple images at once
Reading, saving, and displaying an image using scipy misc
Using scipy.misc's face dataset
Dealing with different image types and file formats and performing basic image manipulations
Dealing with different image types and file formats
File formats
Converting from one file format to another
Image types (modes)
Converting from one image mode into another
Some color spaces (channels)
Converting from one color space into another
Data structures to store images
Converting image data structures
Basic image manipulations
Image manipulations with numpy array slicing 
Simple image morphing - α-blending of two images using cross-dissolving
Image manipulations with PIL
Cropping an image
Resizing an image
Negating an image
Converting an image into grayscale
Some gray-level transformations
Some geometric transformations
Changing pixel values of an image
Drawing on an image
Drawing text on an image
Creating a thumbnail
Computing the basic statistics of an image
Plotting the histograms of pixel values for the RGB channels of an image
Separating the RGB channels of an image 
Combining multiple channels of an image
α-blending two images
Superimposing two images
Adding two images
Computing the difference between two images
Subtracting two images and superimposing two image negatives
Image manipulations with scikit-image
Inverse warping and geometric transformation using the warp() function
Applying the swirl transform
Adding random Gaussian noise to images
Computing the cumulative distribution function of an image 
Image manipulation with Matplotlib
Drawing contour lines for an image
Image manipulation with the scipy.misc and scipy.ndimage modules
Summary
Questions
Further reading
Chapter 2: Sampling, Fourier Transform, and Convolution
Image formation – sampling and quantization
Sampling
Up-sampling
Up-sampling and interpolation 
Down-sampling
Down-sampling and anti-aliasing
Quantization
Quantizing with PIL
Discrete Fourier Transform
Why do we need the DFT?
The Fast Fourier Transform algorithm to compute the DFT
The FFT with the scipy.fftpack module
Plotting the frequency spectrum
The FFT with the numpy.fft module
Computing the magnitude and phase of a DFT
Understanding convolution
Why convolve an image?
Convolution with SciPy signal's convolve2d
Applying convolution to a grayscale image
Convolution modes, pad values, and boundary conditions
Applying convolution to a color (RGB) image
Convolution with SciPy ndimage.convolve
Correlation versus convolution
Template matching with cross-correlation between the image and template
Summary
Questions
Further reading
Chapter 3: Convolution and Frequency Domain Filtering
Convolution theorem and frequency domain Gaussian blur
Application of the convolution theorem
Frequency domain Gaussian blur filter with numpy fft
Gaussian kernel in the frequency domain
Frequency domain Gaussian blur filter with scipy signal.fftconvolve()
Comparing the runtimes of SciPy convolve() and fftconvolve() with the Gaussian blur kernel
Filtering in the frequency domain (HPF, LPF, BPF, and notch filters)
What is a filter?
High-Pass Filter (HPF)
How SNR changes with frequency cut-off
Low-pass filter (LPF)
LPF with scipy ndimage and numpy fft
LPF with fourier_gaussian
LPF with scipy fftpack
How SNR changes with frequency cutoff
Band-pass filter (BPF) with DoG
Band-stop (notch) filter
Using a notch filter to remove periodic noise from images
Image restoration
Deconvolution and inverse filtering with FFT
Image deconvolution with the Wiener filter
Image denoising with FFT
Filter in FFT
Reconstructing the final image
Summary
Questions
Further reading
Chapter 4: Image Enhancement
Point-wise intensity transformations – pixel transformation
Log transform
Power-law transform
Contrast stretching
Using PIL as a point operation
Using the PIL ImageEnhance module
Thresholding
With a fixed threshold
Half-toning
Floyd-Steinberg dithering with error diffusion
Histogram processing – histogram equalization and matching
Contrast stretching and histogram equalization with scikit-image
Histogram matching
Histogram matching for an RGB image
Linear noise smoothing
Smoothing with PIL
Smoothing with ImageFilter.BLUR
Smoothing by averaging with the box blur kernel
Smoothing with the Gaussian blur filter
Comparing smoothing with box and Gaussian kernels using SciPy ndimage
Nonlinear noise smoothing
Smoothing with PIL
Using the median filter
Using max and min filter
Smoothing (denoising) with scikit-image
Using the bilateral filter
Using non-local means
Smoothing with scipy ndimage
Summary
Questions
Further reading
Chapter 5: Image Enhancement Using Derivatives
Image derivatives – Gradient and Laplacian
Derivatives and gradients
Displaying the magnitude and the gradient on the same image
Laplacian
Some notes about the Laplacian
Effects of noise on gradient computation
Sharpening and unsharp masking
Sharpening with Laplacian
Unsharp masking
With the SciPy ndimage module
Edge detection using derivatives and filters (Sobel, Canny, and so on)
With gradient magnitude computed using the partial derivatives
The non-maximum suppression algorithm
Sobel edge detector with scikit-image
Different edge detectors with scikit-image – Prewitt, Roberts, Sobel, Scharr, and Laplace
The Canny edge detector with scikit-image
The LoG and DoG filters
The LoG filter with the SciPy ndimage module
Edge detection with the LoG filter
Edge detection with the Marr and Hildreth's algorithm using the zero-crossing computation
Finding and enhancing edges with PIL
Image pyramids (Gaussian and Laplacian) – blending images
A Gaussian pyramid with scikit-image transform pyramid module
A Laplacian pyramid with scikit-image transform's pyramid module
Constructing the Gaussian Pyramid
Reconstructing an image only from its Laplacian pyramid
Blending images with pyramids
Summary
Questions
Further reading
Chapter 6: Morphological Image Processing
The scikit-image morphology module
Binary operations
Erosion
Dilation
Opening and closing
Skeletonizing
Computing the convex hull
Removing small objects
White and black top-hats
Extracting the boundary 
Fingerprint cleaning with opening and closing
Grayscale operations
The scikit-image filter.rank module
Morphological contrast enhancement
Noise removal with the median filter
Computing the local entropy
The SciPy ndimage.morphology module
Filling holes in binary objects
Using opening and closing to remove noise
Computing the morphological Beucher gradient
Computing the morphological Laplace
Summary
Questions
Further reading
Chapter 7: Extracting Image Features and Descriptors
Feature detectors versus descriptors
Harris Corner Detector
With scikit-image
With sub-pixel accuracy
An application – image matching
Robust image matching using the RANSAC algorithm and Harris Corner features
Blob detectors with LoG, DoG, and DoH
Laplacian of Gaussian (LoG)
Difference of Gaussian (DoG)
Determinant of Hessian (DoH)
Histogram of Oriented Gradients
Algorithm to compute HOG descriptors
Compute HOG descriptors with scikit-image
Scale-invariant feature transform
Algorithm to compute SIFT descriptors
With opencv and opencv-contrib
Application – matching images with BRIEF, SIFT, and ORB
Matching images with BRIEF binary descriptors with scikit-image
Matching with ORB feature detector and binary descriptor using scikit-image
Matching with ORB features using brute-force matching with python-opencv
Brute-force matching with SIFT descriptors and ratio test with OpenCV
Haar-like features
Haar-like feature descriptor with scikit-image
Application – face detection with Haar-like features
Face/eye detection with OpenCV using pre-trained classifiers with Haar-cascade features
Summary
Questions
Further reading
Chapter 8: Image Segmentation
What is image segmentation?
Hough transform – detecting lines and circles
Thresholding and Otsu's segmentation
Edges-based/region-based segmentation
Edge-based segmentation
Region-based segmentation
Morphological watershed algorithm
Felzenszwalb, SLIC, QuickShift, and Compact Watershed algorithms 
Felzenszwalb's efficient graph-based image segmentation
SLIC
RAG merging
QuickShift
Compact Watershed
Region growing with SimpleITK 
Active contours, morphological snakes, and GrabCut algorithms
Active contours
Morphological snakes
GrabCut with OpenCV
Summary
Questions
Further reading
Chapter 9: Classical Machine Learning Methods in Image Processing
Supervised versus unsupervised learning
Unsupervised machine learning – clustering, PCA, and eigenfaces
K-means clustering for image segmentation with color quantization
Spectral clustering for image segmentation
PCA and eigenfaces 
Dimension reduction and visualization with PCA
2D projection and visualization
Eigenfaces with PCA
Eigenfaces
Reconstruction
Eigen decomposition
Supervised machine learning – image classification
Downloading the MNIST (handwritten digits) dataset
Visualizing the dataset
Training kNN, Gaussian Bayes, and SVM models to classify MNIST 
k-nearest neighbors (KNN) classifier
Squared Euclidean distance
Computing the nearest neighbors
Evaluating the performance of the classifier
Bayes classifier (Gaussian generative model)
Training the generative model – computing the MLE of the Gaussian parameters
Computing the posterior probabilities to make predictions on test data and model evaluation
SVM classifier
Supervised machine learning – object detection
Face detection with Haar-like features and cascade classifiers with AdaBoost – Viola-Jones
Face classification using the Haar-like feature descriptor
Finding the most important Haar-like features for face classification with the random forest ensemble classifier
Detecting objects with SVM using HOG features
HOG training
Classification with the SVM model
Computing BoundingBoxes with HOG-SVM
Non-max suppression
Summary
Questions
Further reading
Chapter 10: Deep Learning in Image Processing - Image Classification
Deep learning in image processing
What is deep learning?
Classical versus deep learning
Why deep learning?
CNNs
Conv or pooling or FC layers – CNN architecture and how it works
Convolutional layer
Pooling layer
Non-linearity – ReLU layer
FC layer
Dropout
Image classification with TensorFlow or Keras
Classification with TF
Classification with dense FC layers with Keras
Visualizing the network
Visualizing the weights in the intermediate layers 
CNN for classification with Keras
Classifying MNIST
Visualizing the intermediate layers 
Some popular deep CNNs
VGG-16/19
Classifying cat/dog images with VGG-16 in Keras
Training phase
Testing (prediction) phase
InceptionNet
ResNet
Summary
Questions
Further reading
Chapter 11: Deep Learning in Image Processing - Object Detection, and more
Introducing YOLO v2 
Classifying and localizing images and detecting objects
Proposing and detecting objects using CNNs
Using YOLO v2 
Using a pre-trained YOLO model for object detection
Deep semantic segmentation with DeepLab V3+
Semantic segmentation
DeepLab V3+
DeepLab v3 architecture
Steps you must follow to use DeepLab V3+ model for semantic segmentation
Transfer learning – what it is, and when to use it
Transfer learning with Keras
Neural style transfers with cv2 using a pre-trained torch model
Understanding the NST algorithm
Implementation of NST with transfer learning
Ensuring NST with content loss
Computing the style cost
Computing the overall loss
Neural style transfer with Python and OpenCV
Summary
Questions
Further reading
Chapter 12: Additional Problems in Image Processing
Seam carving
Content-aware image resizing with seam carving
Object removal with seam carving
Seamless cloning and Poisson image editing
Image inpainting
Variational image processing
Total Variation Denoising
Creating flat-texture cartoonish images with total variation denoising
Image quilting
Texture synthesis
Texture transfer
Face morphing
Summary
Questions
Further reading
Other Books You May Enjoy
Index