Lab2 Notes
-
Upload
jose-segura -
Category
Documents
-
view
265 -
download
4
description
Transcript of Lab2 Notes
-
MATLAB
-
2Image Processing
Filtering
Linear Filtering(using Convolution and Correlation)
Image Noise
Edge detection
-
Is a technique for modifying or enhancing an image;
Is a neighbourhood operation;
Linear filtering is filtering in which the value of an output pixel, is a linear combination of the values of the pixels in the input pixels neighbourhood.
3Image Processing
-
Linear filtering of an Image is achieved through an operation called convolution.
In convolution the value of an output pixel is computed as a weighted sum of neighbouring pixels.
The matrix of weights is called the convolution kernel(filter).
The convolution kernel is rotated 180 about its centre element.
4Image Processing
-
Similar to convolution;
The value of the output pixel is computed as a weighted sum of neighbouring pixels;
The correlation Kernel is not rotated during the computation.
5Image Processing
-
In Matlab filtering of images either by correlation or convolution can be performed using imfilter toolbox function.
It uses correlation by default imfilter(A,h)
For using convolution imfilter(A,h,conv)
6Image Processing
-
Example 1 :
imfilter, does not convert input images to the output.
>>h=ones(5,5)/25; I1=imfilter(I,h);
(I is original image andh is an averaging filter)
7Image Processing
-
Example 2 :
imfilter, does not convert input images to the output.
>>h=ones(5,5)/25; >>I1=imfilter(I,h,conv); >> imshow(I),figure,
imshow(I1);
8Image Processing
-
Zero padding imfilter function(notice the black border in the filtered image)
To avoid this, pass the optional argument replicate
>>imfilter(I,h,replicate);
9Image Processing
-
o fspecial,createspredefined2Dlinearspatialfilters:
>>h=fspecial(type,parameters)(typeisthefiltertypeandparametersdefinethespecifiedfilter)
o After creating a filter with fspecial we can apply directly to your image using imfilter
10Image Processing
-
Example 2 :
>>I=imread(elarco.jpg); >> h=fspecial('unsharp'); >> I1=imfilter(I,h); >>imshow(I),figure, imshow(I1);
11Image Processing
-
filter2, performs two dimensional correlation; converts the input to double:
conv2, performs two dimensional convolution;
Convn, performs multidimensional convolution
(see help menu in matlab)
12Image Processing
-
Devise a 3x3 mask which causes no change in the image.
Apply larger and larger averaging filters to this image. What happens?
Read through the help page of the fspecialfunction, and apply some of the other filters to an image.
13Image Processing
-
Degradation in the image signal
Matlab function for adding noise
J =imnoise (I,type)
Where I represents the image and type one of the following:
14Image Processing
-
>>J=imnoise(B,'gaussian');
>>imshow(B),title('Originalimage'),
>>figure,imshow(J),title('gaussiannoise');
Examples:
-
>> K=imnoise(G,'salt & pepper');
>> imshow(G),title('Original image'),
>> figure, imshow(K),title('salt&pepper noise')
16Image Processing
Examples:
-
The aim of image smoothing is to diminish the effects of camera noise, spurious pixel values, missing pixel values etc.
In the frequency domain, this process refers to the suppression of high frequencies.
Techniques for image smoothing: neighbourhood averaging, edge-preserving smoothing.
17Image Processing
-
Example:
>>h= fspecial('average');
>> Y=imfilter(G,h);
>> imshow(G)
>> figure,imshow(Y)
Mean filtero replaces each pixel value in an image with the mean
(`average') value of its neighbours, including itself.
18Image Processing
>>h=fspecial(average)>>B=imfilter(I,h)
(filtered image I using h filter)
-
Median filter(medfilt2), is a nonlinear operation, replaces the pixel value with the median of neighbouring pixel values.
>>B = medfilt2(A, [m n]),(Where A is the image and [m n] the neighbourhood)
Example:
>>YY=medfilt2(G,[33]);>>imshow(G)>>figure,imshow(YY)
19Image Processing
-
Gaussian smoothing operator the Gaussian smoothing operator is a 2-Dconvolution
operator that is used to `blur' images and remove detail
and noise
20Image Processing
-
Use imnoise function to add salt&pepper noise to an image.
Now apply median and mean filter to the obtained image.
Which one is better? Why?
21Image Processing
-
We can only do edge tracing for gray images
Edges contain some of the most useful information in an image.
We may use edges to measure the size of objects in an image; to isolate particular objects from their background; to recognize or classify objects.
22Image Processing
-
Matlab function (edge ) syntax edge(image,'method',parameters. . . )
Finds edges in greyscale image.
edge supports the following detectors: sobel prewitt Roberts Laplacian of Gaussian Canny zerocross
23Image Processing
-
Example : Sobel operator - Canny Operator
>>Im=imread(BomJesus.jpeg);
>> figure, imshow(Im)
>> BW1 = edge(Im,'sobel'); >>BW2 = edge(Im,'canny');
>> figure, imshow(BW1)
>> figure, imshow(BW2)
24Image Processing
-
Original image Sobel operator Canny operator
25Image Processing
-
Look in help Matlab for edge function and experiment all the operators
Try the effect of LoG filters using different width Gaussians
What is the general effect of increasing the Gaussian width? Notice particularly the effect on features of different sizes and thicknesses.
Compare the result of applying the Roberts Cross operator with the one of using the Sobel operator
Under what situations might you choose to use the Roberts Cross rather than the Sobel? And under what conditions would you avoid it?
26Image Processing