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');
double
are expected to have values ranging from0
to1
. YourfilteredImage
is probably exceeding that. – beakerfilteredImage
? In your edited code, I'd be willing to bet they're between0
and4
. – beakerdouble(ones(3,3))/9
. – beaker