In order to see how the averaging filter is implemented, we will use the same example as before. We will follow these steps:
First off, we load our video and convert it to grayscale, using the first two steps of the previous example:
>> obj = VideoReader('inter.avi'); >> vid = read(obj); >> grayVid = uint8(zeros(size(vid,1), size(vid,2), size(vid,4))); >> for i = 1:size(vid,4), grayVid(:,:,i) = rgb2gray(vid(:,:,:,i)); end
Now, we must generate a three-dimensional filter to use for the averaging process. Its dimensions can be the same as the neighborhood we used before. To perform averaging, it must have all its values equal to 1/n, where n are the number of elements in the filter. Let's create it:
>> avFilt = ones(3,3,3); % Make a 3x3x3 matrix full of ones >> avFilt = avFilt/numel(avFilt); % Make all elements equal to 1/n
All we have to do now is to apply convolution between
grayVid
and...