We will start off with an easy-to-follow example, so that all the theory described previously is demonstrated. For our purposes, we will be using one of the images from the previous chapters. In this example, we will also introduce some new MATLAB functions, to facilitate your understanding. Let's start:
First, we load our image, which is
holiday_image2.bmp
:>> img = imread('holiday_image2.bmp');
Then, we generate our convolution kernel, using function
fspecial
and then rotate it 180 degrees:>> kernel = fspecial('average',3); >> kernel = rot90(kernel,2)
The output of the code will be as follows:
kernel = 0.1111 0.1111 0.1111 0.1111 0.1111 0.1111 0.1111 0.1111 0.1111
Now, it is time to use the three different ways of convolving our image:
>> con1 = conv2(img,kernel); % Default usage ('full') >> con2 = conv2(img,kernel,'same'); % convolution using 'same' >> con3 =...