image filtering
DESCRIPTION
Many basic image processing techniques are based on convolution.In a convolution, a convolution filter is applied to every pixel to create a filtered imageTRANSCRIPT
Image Processing Toolbox (1)
• Grayscale Image(row x col)
• Binary Image (row x col)= Grayscale with 2 levels
Image Processing Toolbox (2)
• RGB Image(row X col X 3)
Image Processing Toolbox (3)
• Indexed Image (2 matrices – colormap and index)
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
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.
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
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
Let’s move on to…
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 ),(),(),(*),(),(*
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
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
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:
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
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
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.
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
Image Filtering
originaloriginal 3333 9999 15151515
• Effect of Gaussian smoothing:
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.
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.
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.
Median Filter
• original image • 33 median • 77 median