Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Processing Using Scilab
Shanmuganathan Raman
Vision and Image Processing Laboratory
Department of Electrical Engineering
Indian Institute of Technology Bombay
shanmuganathan@[Link]
[Link]/student/shanmuga
December 2, 2010
1 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Introduction to Digital Images
Images can be Grayscale or Color (RGB)
Specified as a matrix of size M N 3 (M N for
grayscale)
2 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Processing in Scilab
Toolboxes - SIP (Scilab Image Processing) , SIVP
(Scilab Image & Video Processing)
We focus on SIVP Toolbox
Installation in Ubuntu Linux - SIVP through atoms
(5.3beta onwards), SIP through CVS (Both tested on
Scilab 5.2.2)
Installation in Windows - SIVP through atoms
(5.3beta onwards), SIP (installed, not working yet)
3 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Grayscale and Color Images
(a) Gray Scale Image
(b) Color Image
4 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Read/Write/Show
1. Read Image - lena = imread(0 [Link] 0 )
2. Show Image - figure; imshow(lena)
3. Write Image - imwrite(lena,0 [Link] 0 )
5 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Datatype Conversions
im2int8
im2int16
im2int32
im2uint8
im2uint16
im2double
6 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Conversions
> babbon = imread(0 [Link] 0 );
RGB to Gray scale - rgb2gray
> babgray = rgb2gray(babbon);
RGB to Binary - im2bw
> lenabw = im2bw(lena, 0.5);
> imwrite(lenabw,0 [Link] 0 );
RGB to HSV format - rgb2hsv
HSV to RGB format - hsv2rgb
RGB to YCbCr - rgb2ycbcr
YCbCr to RGB - ycbcr2rgb
7 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Conversions - Results
(a) rgb2gray(babbon);
(b) im2bw(lena, 0.5);
8 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Basic Operations
Crop -
> lenacrop = imcrop(lena, [200, 200, 200, 200]);
Complement > lenacomp = imcomplement(lena);
Resize > lenaresize = imresize(lena, 2,0 bicubic 0 );
The last term can be nearest, bilinear, bicubic or
area
9 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Basic Operations - Complement
(a) Original
(b) Complement
10 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Basic Operations - Crop
(a) Original
(b) Cropped
11 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Basic Operations - Resize
(a) Original
(b) Resize by 2
12 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Add Noise
> lenaNgaussian = imnoise(lena,0 gaussian0 );
The noise can be one of these:
1. salt & Pepper - white/black noise (default probability
d=0.05)
2. speckle - multiplicative noise (uniform with mean 0
and variance v=0.04)
3. gaussian - additive noise (with mean 0 and variance
v=0.01)
13 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Add Noise - Results
(a) Original
(b) Salt & Pepper
(c) Speckle
(d) Gaussian
14 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
LTI Filter Kernels
Derivatives (High-Pass filter) using fspecial
sobel > fspecial(0 sobel 0 )
1 2 1
0 0 0
1 2 1
prewitt > fspecial(0 prewitt 0 )
1 1 1
0 0 0
1 1 1
laplacian > fspecial(0 laplacian0 )
0.1666667
0.6666667 0.1666667
0.6666667 3.3333333 0.6666667
0.1666667 0.6666667 0.1666667
15 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
LTI Filter Kernels Contd.
Blur (Low-Pass filter) using fspecial
gaussian > fspecial(0 gaussian0 )
0.0113437 0.0838195 0.0113437
0.0838195 0.6193470 0.0838195
0.0113437 0.0838195 0.0113437
log > fspecial(0 log 0 )
0.0447924
0.0468064
0.0564068
0.0468064
0.0447924
0.0468064
0.3167464
0.7146325
0.3167464
0.0468064
0.0564068
0.7146325
4.904764
0.7146325
0.0564068
0.0468064
0.3167464
0.7146325
0.3167464
0.0468064
0.0447924
0.0468064
0.0564068
0.0468064
0.0447924
average > fspecial(0 average0 )
0.1111111 0.1111111 0.1111111
0.1111111 0.1111111 0.1111111
0.1111111 0.1111111 0.1111111
16 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Spatial Domain Processing
FIR filters using fspecial > h = fspecial(0 sobel 0 );
Convolve 2D image with a 2D kernel imfilter/filter2
> lenaSobel = imfilter (lena, h);
Low-pass, High-pass filters realized
17 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Derivative Kernels - Results
(a) Original
(b) Sobel
(c) Prewitt
(d) Laplacian
18 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Blurring Kernels - Results
(a) Original
(b) Gaussian
(c) LoG
(d) Average
19 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Edge Detection
edge - High-pass filtering and thresholding
Sobel > lenaESobel = edge(lena,0 sobel 0 );
Prewitt > lenaEPrewitt = edge(lena,0 prewitt 0 );
LoG > lenaELog = edge(lena,0 log 0 );
Canny > lenaECanny = edge(lena,0 canny 0 );
20 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Edge Detection - Results
(a) Original
(b) Sobel
(d) LoG
(c) Prewitt
(e) Canny
21 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Miscellaneous
1. imhist - Histogram of the
image > [counts, bins] = imhist(lena);
2. imfinfo - Image Information > imfinfo(0 [Link] 0 )
22 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Gaussian Pyramid - Work Out
impyramid - Gaussian Smoothing and subsampling
> im0 = imread(0 [Link] 0 );
> im1 = impyramid(im0,0 reduce0 );
> im2 = impyramid(im1,0 reduce0 );
> im3 = impyramid(im2,0 reduce0 );
> imshow(im0);
> imshow(im1);
> imshow(im2);
> imshow(im3);
23 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Compression
Consider grayscale image as a matrix
Take SVD I = UV T
Drop lowest singular values from diagonal matrix
Reconstruct Image again
24 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Compression in Scilab
> A = imread(0 [Link] 0 );
> [u, s, v ] = svd(double(A));
> norm(u s v 0 A) // just to check that A = u*s*v
> vdash = v 0 ;
> svalues = diag(s); . // these are ordered increasing
to decreasing
> n = 100;// how many singular values of A we want
to KEEP.
> Alowerrank = u(:, [1 : n]) diag(svalues(1 :
n)) vdash([1 : n], :);
> imwrite(uint8(Alowerrank),0 [Link] 0 );
25 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Image Compression - Results
(a) Original
(b) Top 20
(c) Top 40
(d) Top 60
(e) Top 80
(f) Top 100
26 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Advanced Topics - To be Explored
FFT
Wavelets
Radon Transform
Hough Transform
27 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Recap
1.
2.
3.
4.
5.
6.
Read/Write/Show Image
Basic Operations
Noise and Blur
LTI Filtering
Image as a Matrix
Transform Domain Operations
28 / 29
Introduction
Image Degradation
Image Enhancement
Image as a Matrix
Conclusion
Thanks
Thank You
shanmuganathan@[Link]
29 / 29