0
votes

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.

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.

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');

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.

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');
1
Images of type double are expected to have values ranging from 0 to 1. Your filteredImage is probably exceeding that.beaker
@beaker Yes it was exceeding that, but I have converted it to double first using "im2double", but it is too white instead of getting blurredOuissal Benameur
Okay, now you're reached the second problem. What is the range of values in filteredImage? In your edited code, I'd be willing to bet they're between 0 and 4.beaker
@beaker Yes they're between 0 and 3Ouissal Benameur
Try dividing your kernel by its size instead: double(ones(3,3))/9.beaker

1 Answers

0
votes

The following solution has fixed the range issue, the other solutions that were given were about a specific type of low-pass filters which is an averaging filte :

Img1 = imread('cameraman.tif');
Im=im2double(Img1);
filteredImage = conv2(Im, ones(3,3));
figure; subplot(1,2,1); imshow(filteredImage, []);title('filtered');
subplot(1,2,2); imshow(Im); title('original');

Instead of dividing by the kernel, I've used imshow(filteredImage, []).