sci lab talk

29
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 [email protected] www.ee.iitb.ac.in/student/ ˜ shanmuga December 2, 2010 1 / 29

Upload: jhon-jairo-lozano

Post on 12-Jul-2016

229 views

Category:

Documents


2 download

DESCRIPTION

tutorial

TRANSCRIPT

Page 1: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Image Processing Using Scilab

Shanmuganathan Raman

Vision and Image Processing LaboratoryDepartment of Electrical EngineeringIndian Institute of Technology Bombay

[email protected]/student/˜shanmuga

December 2, 2010

1 / 29

Page 2: Sci Lab Talk

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

Page 3: Sci Lab Talk

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 onScilab 5.2.2)

• Installation in Windows - SIVP through atoms(5.3beta onwards), SIP (installed, not working yet)

3 / 29

Page 4: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Grayscale and Color Images

(a) Gray Scale Image (b) Color Image

4 / 29

Page 5: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Image Read/Write/Show

1. Read Image - lena = imread(′lenagray .jpg′)2. Show Image - figure; imshow(lena)

3. Write Image - imwrite(lena,′ lena.png′)

5 / 29

Page 6: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Image Datatype Conversions

• im2int8• im2int16• im2int32• im2uint8• im2uint16• im2double

6 / 29

Page 7: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Image Conversions

−− > babbon = imread(′bab.png′);

• RGB to Gray scale - rgb2gray−− > babgray = rgb2gray(babbon);

• RGB to Binary - im2bw−− > lenabw = im2bw(lena,0.5);−− > imwrite(lenabw ,′ lenabw .png′);

• RGB to HSV format - rgb2hsv• HSV to RGB format - hsv2rgb• RGB to YCbCr - rgb2ycbcr• YCbCr to RGB - ycbcr2rgb

7 / 29

Page 8: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Image Conversions - Results

(a) rgb2gray(babbon); (b) im2bw(lena,0.5);

8 / 29

Page 9: Sci Lab Talk

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,′ bicubic′);

• The last term can be ’nearest’, ’bilinear’, ’bicubic’ or’area’

9 / 29

Page 10: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Basic Operations - Complement

(a) Original (b) Complement

10 / 29

Page 11: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Basic Operations - Crop

(a) Original (b) Cropped

11 / 29

Page 12: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Basic Operations - Resize

(a) Original (b) Resize by 2

12 / 29

Page 13: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Add Noise

−− > lenaNgaussian = imnoise(lena,′ gaussian′);The noise can be one of these:

1. salt & Pepper - white/black noise (default probabilityd=0.05)

2. speckle - multiplicative noise (uniform with mean 0and variance v=0.04)

3. gaussian - additive noise (with mean 0 and variancev=0.01)

13 / 29

Page 14: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Add Noise - Results

(a) Original (b) Salt & Pepper (c) Speckle

(d) Gaussian14 / 29

Page 15: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

LTI Filter KernelsDerivatives (High-Pass filter) using fspecial

• sobel −− > fspecial(′sobel ′)(1 2 10 0 0−1 −2 −1

)• prewitt −− > fspecial(′prewitt ′)(

1 1 10 0 0−1 −1 −1

)• laplacian −− > fspecial(′laplacian′)(

0.1666667 0.6666667 0.16666670.6666667 −3.3333333 0.66666670.1666667 0.6666667 0.1666667

)

15 / 29

Page 16: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

LTI Filter Kernels Contd.Blur (Low-Pass filter) using fspecial

• gaussian −− > fspecial(′gaussian′)(0.0113437 0.0838195 0.01134370.0838195 0.6193470 0.08381950.0113437 0.0838195 0.0113437

)• log −− > fspecial(′log′)(

0.0447924 0.0468064 0.0564068 0.0468064 0.04479240.0468064 0.3167464 0.7146325 0.3167464 0.04680640.0564068 0.7146325 −4.904764 0.7146325 0.05640680.0468064 0.3167464 0.7146325 0.3167464 0.04680640.0447924 0.0468064 0.0564068 0.0468064 0.0447924

)

• average −− > fspecial(′average′)(0.1111111 0.1111111 0.11111110.1111111 0.1111111 0.11111110.1111111 0.1111111 0.1111111

)16 / 29

Page 17: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Spatial Domain Processing

• FIR filters using fspecial −− > h = fspecial(′sobel ′);

• Convolve 2D image with a 2D kernel imfilter/filter2−− > lenaSobel = imfilter(lena,h);

• Low-pass, High-pass filters realized

17 / 29

Page 18: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Derivative Kernels - Results

(a) Original (b) Sobel (c) Prewitt

(d) Laplacian18 / 29

Page 19: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Blurring Kernels - Results

(a) Original (b) Gaussian (c) LoG

(d) Average19 / 29

Page 20: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Edge Detection

edge - High-pass filtering and thresholding• Sobel −− > lenaESobel = edge(lena,′ sobel ′);

• Prewitt −− > lenaEPrewitt = edge(lena,′ prewitt ′);

• LoG −− > lenaELog = edge(lena,′ log′);

• Canny −− > lenaECanny = edge(lena,′ canny ′);

20 / 29

Page 21: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Edge Detection - Results

(a) Original (b) Sobel (c) Prewitt

(d) LoG (e) Canny21 / 29

Page 22: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Miscellaneous

1. imhist - Histogram of theimage−− > [counts,bins] = imhist(lena);

2. imfinfo - Image Information −− > imfinfo(′lena.jpg′)

22 / 29

Page 23: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Gaussian Pyramid - Work Out

impyramid - Gaussian Smoothing and subsampling−− > im0 = imread(′lena.jpg′);−− > im1 = impyramid(im0,′ reduce′);−− > im2 = impyramid(im1,′ reduce′);−− > im3 = impyramid(im2,′ reduce′);−− > imshow(im0);−− > imshow(im1);−− > imshow(im2);−− > imshow(im3);

23 / 29

Page 24: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Image Compression

• Consider grayscale image as a matrix• Take SVD I = UΣV T

• Drop lowest singular values from diagonal matrix Σ

• Reconstruct Image again

24 / 29

Page 25: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Image Compression in Scilab

−− > A = imread(′lena.jpg′);−− > [u, s, v ] = svd(double(A));−− > norm(u ∗ s ∗ v ′ − A) // just to check that A = u*s*v’−− > vdash = v ′;−− > svalues = diag(s); . // these are ordered increasingto decreasing−− > n = 100;// how many singular values of A we wantto KEEP.−− > Alowerrank = u(:, [1 : n]) ∗ diag(svalues(1 :n)) ∗ vdash([1 : n], :);−− > imwrite(uint8(Alowerrank),′ lenaSVD100.png′);

25 / 29

Page 26: Sci Lab Talk

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 10026 / 29

Page 27: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Advanced Topics - To be Explored

• FFT• Wavelets• Radon Transform• Hough Transform

27 / 29

Page 28: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Recap

1. Read/Write/Show Image2. Basic Operations3. Noise and Blur4. LTI Filtering5. Image as a Matrix6. Transform Domain Operations

28 / 29

Page 29: Sci Lab Talk

Introduction Image Degradation Image Enhancement Image as a Matrix Conclusion

Thanks

Thank [email protected]

29 / 29