MATLAB: How to convolve an image with a 2D function and plot the result

bar phantomconv2fft2filterhomeworkimage processingimaging

Hi, I have a bar phantom image attached that I want to convolve with the 2d function h1(x,y)=e^(-5x^2-5y^2). I'm not very familiar with Matlab or similar programs so bear with me.
I have created and plotted the function h1 using the following code:
x = [-1: .01: 1];
y = [-1: .01: 1];
[x_,y_] = meshgrid(x,y);
h1_ = exp((-5.*x_.^2)-(5.*y_.^2));
surf(x_,y_,h1_)
I then inserted the bar phantom image into Matlab using:
I = imread('bar phantom1.png');
From here I'm stuck and I've tried a number of things unsuccessfully. I've tried:
H1_ = abs(fft2(h1_));
I1 = abs(fft2(I));
g = ifft2(H1_.*I1);
And get the error: Array dimensions must match for binary array op.
I tried changing the dimensions of my x and y variables to match the dimensions of my image but the result g is a blank white image.
I also played tried to avoid using fft2 using imfilter, double, and conv2 but only got all white or black resulting images. Any help would be greatly appreciated.

Best Answer

Try this:
kernel = h1_ / sum(h1_(:));
filteredImage = conv2(double(I), kernel, 'same');
imshow(filteredImage, []);