Sep 19, 2010 ... Doing the Stuff in Python. Demo(s). Q and A. Introduction to Image Processing
with SciPy and NumPy. Anil C R
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Introduction to Image Processing with SciPy and NumPy Anil C R
[email protected] Department of Electrical Engineering Indian Institute of Science
September 19, 2010
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Outline 1
Introduction Image Processing What are SciPy and NumPy?
2
Some Theory Filters The Fourier Transform
3
Doing the Stuff in Python
4
Demo(s)
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Image Processing SciPy and NumPy
Outline 1
Introduction Image Processing What are SciPy and NumPy?
2
Some Theory Filters The Fourier Transform
3
Doing the Stuff in Python
4
Demo(s)
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Image Processing SciPy and NumPy
What are Images? Continious domain, Continious range f : R2 → R(R3 ) Discrete domain, Continious range f : Z2 → R(R3 ) Discrete domain, Discrete range f : Z2 → Z(R3 ) Finite domain, Continious range f : Zm × Zn → R(R3 ) Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Image Processing SciPy and NumPy
What are Images? Continious domain, Continious range f : R2 → R(R3 ) Discrete domain, Continious range f : Z2 → R(R3 ) Discrete domain, Discrete range f : Z2 → Z(R3 ) Finite domain, Continious range f : Zm × Zn → R(R3 ) Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Image Processing SciPy and NumPy
Using Matrices to Represent Images f as an element of Rm×n (Rm×n×k ) ⇒ Linear Algebra ⇒ LAPACK, BLAS, etc ⇒ FORTRAN, C, etc ⇒ Super Hard ⇒ MATLAB ⇒ Super Expensive ⇒ SciPy + NumPy, GNU Octave, Scilab, etc PyCon 2010 ⇒ SciPy + NumPy Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Image Processing SciPy and NumPy
Outline 1
Introduction Image Processing What are SciPy and NumPy?
2
Some Theory Filters The Fourier Transform
3
Doing the Stuff in Python
4
Demo(s)
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Image Processing SciPy and NumPy
NumPy
Numerical Processing Started off as numecric written in 1995 by Jim Huguni et al. Numeric was slow for large arrays and was rewritten for large arrays as Numarray Travis Oliphant, in 2005 merged them both into NumPy
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Image Processing SciPy and NumPy
SciPy
Libraries for scientific computing Linear Algebra Statistics Signal and Image processing Optimization ODE Solvers
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Filters The Fourier Transform
Outline 1
Introduction Image Processing What are SciPy and NumPy?
2
Some Theory Filters The Fourier Transform
3
Doing the Stuff in Python
4
Demo(s)
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Filters The Fourier Transform
Filters
Keep what you want and throw away the rest Studying filters is the most important part in Image Processing Classified into linear and non-linear filters
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Filters The Fourier Transform
Linear Filters
Given images f1 , f2 , . . . , fn a filter H is called linear if H(α1 f1 + α2 f2 + · · · + αn fn ) = α1 H(f1 ) + α2 H(f2 ) + · · · + αn H(fn ) Linearity can be useful in fast computation
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Filters The Fourier Transform
Outline 1
Introduction Image Processing What are SciPy and NumPy?
2
Some Theory Filters The Fourier Transform
3
Doing the Stuff in Python
4
Demo(s)
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Filters The Fourier Transform
Time and Frequency Domains
⇓
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Filters The Fourier Transform
Fourier Transform
Continious FT F (ωx x, ωy y ) =
RR
R2
f (x, y )exp(−iωx x − iωy y )dxdy
Discrete FT F (ωx x, ωy y ) =
PM PN 0
0
x f (x, y )exp(−i{ 2πω M x −
Notation: F is the FT of f , also F = F{f }
Anil C R
Image Processing
2πωy N y })
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Filters The Fourier Transform
Convolution Continious (f ~ g)(x, y ) =
RR
R2
f (x 0 , y 0 )g(x − x 0 , y − y 0 )dxdy
Discrete PP 0 0 (f ~ g)(x, y ) = Z2 f (x, y )g(x − x , y − y ) Theorem (a) F{f ~ g} = FG (b) F{fg} = F ~ G Any linear filter can be written as a convolution. Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Filters The Fourier Transform
Fast Fourier Transform (FFT)
Computing the Discrete Fourier Transform takes O(n2 m2 ) for an m × n image FFT Computes the same in O(n log nm log m)
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Interactive Python
Install NumPy Install SciPy Install Matplotlib Install IPython Running IPython $ ipython -pylab
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Fast Fourier Transform (FFT)
FFT in NumPy In[1]: from scipy import lena In[2]: f = lena() In[3]: from numpy.fft import fft2 # unnecessary if you invoke ipython with -pylab In[4]: F = fft2(f) In[5]: imshow(real(F))
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Fast Fourier Transform (FFT)
FFT in NumPy In[1]: from scipy import lena In[2]: f = lena() In[3]: from numpy.fft import fft2 # unnecessary if you invoke ipython with -pylab In[4]: F = fft2(f) In[5]: imshow(real(F))
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Fast Fourier Transform (FFT)
FFT in NumPy In[1]: from scipy import lena In[2]: f = lena() In[3]: from numpy.fft import fft2 # unnecessary if you invoke ipython with -pylab In[4]: F = fft2(f) In[5]: imshow(real(F))
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Fast Fourier Transform (FFT)
FFT in NumPy In[1]: from scipy import lena In[2]: f = lena() In[3]: from numpy.fft import fft2 # unnecessary if you invoke ipython with -pylab In[4]: F = fft2(f) In[5]: imshow(real(F))
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Fast Fourier Transform (FFT)
FFT in NumPy In[1]: from scipy import lena In[2]: f = lena() In[3]: from numpy.fft import fft2 # unnecessary if you invoke ipython with -pylab In[4]: F = fft2(f) In[5]: imshow(real(F))
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells
Input Image Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells
Output Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells Procedure
Consider the image:
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells Procedure Cont’d
Find the variance of the neighborhood of each pixel, store them as a 2D array
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells Procedure Cont’d
Find the variance of the neighborhood of each pixel, store them as a 2D array
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells Procedure Cont’d
Find the variance of the neighborhood of each pixel, store them as a 2D array
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells Procedure Cont’d
Variance map (V ) V > E{V }
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells Procedure Cont’d
Variance map (V ) V > E{V }
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Demo: Cells Procedure Cont’d
Algorithm on the cell image:
Anil C R
Image Processing
Introduction Some Theory Doing the Stuff in Python Demo(s) Q and A
Q and A
Anil C R
Image Processing