Now that we know the steps of the process, we can write a function that performs it. The function will have some similarities to the spatiotemporal deinterlacing function implemented in the previous example. It will take as input a grayscale video in a matrix variable (if it is not grayscale it will convert each frame to grayscale) and the filtering neighborhood, and will produce as output a matrix containing the filtered video:
function [vid] = SpatioTemporalAveraging(vid,nhood) % Function for de-interlacing a video using Field Merging % Inputs: % vid – Input video matrix (we assume grayscale video) % nhood - Dimensions of filtering neighborhood % Output: % vidOut - Output video matrix (filtered) vid = single(vid); % Convert matrix to single to perform averaging vidOut = zeros(size(vid)); % Create a zero-valued matrix to hold the result % For all frames except the ones that fall off...