function convolution() % Read the image as a gray-scale matrix I = imread('rose.jpg'); subplot(3,2,1); imshow(I); title('Original image'); subplot(3,2,2); imshow(conv2(I, 1/9*ones(3), 'same'), []); title('3x3'); subplot(3,2,3); imshow(conv2(I, 1/49*ones(7), 'same'), []); title('7x7'); subplot(3,2,4); imshow(conv2(I, 1/121*ones(11), 'same'), []); title('11x11'); subplot(3,2,5); imshow(conv2(I, 1/7*ones(1,7), 'same'), []); title('1x7'); subplot(3,2,6); imshow(conv2(I, 1/7*ones(7,1), 'same'), []); title('7x1'); set(gcf, 'color', 'w'); % COMMENTS: % The larger the filter is, the more neighbors contribute to the current % pixel's value, and the more blurry the image becomes. In other words, % noise from some pixels is spread over their neighboring pixels. % Note that the bottom 2 images seem to be blurry horizontally and % vertically, respectively. That's because of the 1D filters applied. % COMPLEXITY: % Suppose that the image has size M x N and that the filter has size m x n. % To compute the final value of each image pixel, we have to perform mn % multiplications and mn-1 additions. Total complexity = O(MNmn). end
