Top Banner
Image Processing Toolbox (1) • Grayscale Image (row x col) • Binary Image (row x col) = Grayscale with 2 levels
21

Image filtering

Jan 27, 2016

Download

Documents

Andrei Chih

Many basic image processing techniques are based on convolution.
In a convolution, a convolution filter is applied to every pixel to create a filtered image
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Image filtering

Image Processing Toolbox (1)

• Grayscale Image(row x col)

• Binary Image (row x col)= Grayscale with 2 levels

Page 2: Image filtering

Image Processing Toolbox (2)

• RGB Image(row X col X 3)

Page 3: Image filtering

Image Processing Toolbox (3)

• Indexed Image (2 matrices – colormap and index)

Page 4: Image filtering

Image Processing Toolbox (4)• Reading an Image and storing it in matrix I:

– I = imread(‘pout.tif’);

– [I,map] = imread(‘pout.tif’); For indexed images

• Deals with many formats– JPEG, TIFF, GIF, BMP, PNG, PCX, … more can be added

from Mathworks Central File Exchange• http://www.mathworks.com/matlabcentral/fileexchan

ge

Page 5: Image filtering

Image Processing Toolbox (5)

• After an image has been read we can convert from one type to another:– ind2gray, gray2ind, rgb2gray, gray2rgb, rgb2ind, ind2rgb

• Images are read into uint8 data type. To manipulate the pixel values, they have to be first converted to double type using the double(I) function.

Page 6: Image filtering

Image Processing Toolbox (6)

• Pixel values are accessed as matrix elements.– 2D Image with intensity values: I(row,col)– 2D RGB images I(row,col,color)

• Color : Red = 1; Green = 2 ; Blue = 3

• Displaying images– >>figure, imshow(I)

• Displaying pixel position and intensity information– pixval on

Page 7: Image filtering

Image Processing Toolbox (7)

• All arithmetic operations performed on matrices may be performed on images

• After processing, an image matrix can be written to an output image file with the imwrite function– imwrite(I,map,’filename’,’fmt’)

• Without the map argument, the image data is supposed to be grayscale or RGB.

• The format ‘fmt’ needs to support the particular type of image

Page 8: Image filtering

Let’s move on to…

Image Filtering

Page 9: Image filtering

Image Filtering

• Many basic image processing techniques are based on convolution.

• In a convolution, a convolution filter is applied to every pixel to create a filtered image I*(x, y):

u v

yvxuWvuIyxWyxIyxI ),(),(),(*),(),(*

Page 10: Image filtering

xx

yy

Image Filtering• Example: Averaging filter:

u v

yvxuWvuIyxWyxIyxI ),(),(),(*),(),(*

0 0 0 0 0

0 1/9 1/9 1/9 0

0 1/9 1/9 1/9 0

0 1/9 1/9 1/9 0

0 0 0 0 0

Page 11: Image filtering

Image Filtering• Image:

u v

yvxuWvuIyxWyxIyxI ),(),(),(*),(),(*

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

• Filter:

•New value:

•6/9 + 9/9 + 7/9 + 0/9 + 2/9 + 8/9 +2/9 + 9/9 + 10/9 = 5.889

Page 12: Image filtering

Image Filtering

• Grayscale Image:

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

• Averaging Filter:

Page 13: Image filtering

Image Filtering• Original Image:

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

• Filtered Image:

0 0 0 0 0

0 0

0 0

0 0

0 0 0 0 0

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

• value = 11/9 + 61/9 + 31/9 + 21/9 + 111/9 + 31/9 + 51/9 + 101/9 + 61/9 = 47/9 = 5.222

55

Page 14: Image filtering

Image Filtering• Original Image:

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

• Filtered Image:

0 0 0 0 0

0 0

0 0

0 0

0 0 0 0 0

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

• value = 61/9 + 31/9 + 21/9 + 111/9 + 31/9 + 101/9 + 101/9 + 61/9 + 91/9 = 60/9 = 6.667

55 77

Page 15: Image filtering

Image Filtering• Original Image:

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

• Filtered Image:

0 0 0 0 0

0 0

0 0

0 0

0 0 0 0 0

55 77 55

55

55

55 66

6644

•Now you can see the averaging (smoothing) effect of the 33 filter that we applied.

Page 16: Image filtering

Image Filtering• More common: Gaussian Filters

2

22

222

1),(),(

yx

eyxGyxW

•1•4•7•4•1

•4•16•26•16•4

•7•26•41•26•7

•4•16•26•16•4

•1•4•7•4•1

• Discrete version: 1/273

• implement decreasing influence by more distant pixels

Page 17: Image filtering

Image Filtering

originaloriginal 3333 9999 15151515

• Effect of Gaussian smoothing:

Page 18: Image filtering

Different Types of Filters• Smoothing can reduce noise in the image.• This can be useful, for example, if you want to find regions of

similar color or texture in an image.

• However, there are different types of noise.• For so-called “salt-and-pepper” noise, for example, a median

filter can be more effective.

Page 19: Image filtering

Median Filter• Use, for example, a 33 filter and move it across the image like

we did before.• For each position, compute the median of the brightness values

of the nine pixels in question.

– To compute the median, sort the nine values in ascending order.

– The value in the center of the list (the fifth value) is the median.

• Use the median as the new value for the center pixel.

Page 20: Image filtering

Median Filter

• Advantage of the median filter: Capable of eliminating outliers such as the extreme brightness values in salt-and-pepper noise.

• Disadvantage: The median filter may change the contours of objects in the image.

Page 21: Image filtering

Median Filter

• original image • 33 median • 77 median