Currently I am trying to convolve an image with a Gaussian function and am getting a white screen.

8 visualizaciones (últimos 30 días)
When I am trying to get the convolution I am getting blank screen. The code I have for this is given by:
p = imread('barphantom.png');
gp = rgb2gray(p)
figure, imshow(p) %shows the image
n = 1132;
m = 755;
sigma = 5
h = zeros(n,m);
for x=1:n
for y=1:m
h(x,y) = exp(-((x-n/2)^2+(y-m/2)^2)/(2*sigma^2));
end
end
figure, imshow(h) % shows the gaussian figure
k = conv2(gp, h,'same')
figure, imshow(k)

Respuesta aceptada

DGM
DGM el 15 de Feb. de 2022
Editada: DGM el 15 de Feb. de 2022
Sum-normalize the filter kernel
gp = imread('cameraman.tif');
n = 1132;
m = 755;
sigma = 5;
h = zeros(n,m);
for x=1:n
for y=1:m
h(x,y) = exp(-((x-n/2)^2+(y-m/2)^2)/(2*sigma^2));
end
end
h = h/sum(h(:)); % normalize the filter
%imshow(h) % shows the gaussian figure
k = conv2(im2double(gp), h,'same');
imshow(k)
Your filter also is wayyyy bigger than it needs to be. That only slows down the convolution. Depending on how much support you want, you can make it quite small. For comparison, imgaussfilt() creates the filter such that its width and height are 2*ceil(2*sigma)+1. You might want more support, so pick 2*ceil(3*sigma)+1 or 2*ceil(4*sigma)+1.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by