MATLAB: Apply a low-pass filter to an image
<p>I am trying to implement a simple low-pass filter using "ones" function as a filter and "conv2" to compute the convolution of both matrices (the original image and the filter), which is the filtered image I want to get, but the result of imshow(filteredImage) is just an empty white image instead of a filtered image.</p>

<p>I have checked the matrice of the filtered image, it is a 256x256 double, but I don't know the reason why it isn't displayed properly.</p>

<pre><code>I = imread('cameraman.tif');

filteredImage = conv2(double(I), double(ones(3,3)), 'same');

figure; subplot(1,2,1); imshow(filteredImage);title('filtered');
    subplot(1,2,2); imshow(I); title('original');
</code></pre>

<p>EDIT:
I have also tried converting it to double first before calculating the convolution as it was exceeding 1, but it didn't give a low-pass filter effect, but the image's contrast got increased instead.</p>

<pre><code>I = imread('cameraman.tif');
I1 = im2double(I);
filteredImage = conv2(I1, ones(2,2), 'same');

figure; subplot(1,2,1); imshow(filteredImage);title('filtered');
    subplot(1,2,2); imshow(I1); title('original');
</code></pre>