# 2d convolution returns empty result

7 visualizaciones (últimos 30 días)
xiaojuezi el 11 de Mayo de 2020
Editada: Ameer Hamza el 11 de Mayo de 2020
I have an image matrix of size 512x512x3, for each pixel I would like to compute its weight as the average of the neighbouring pixels like below:
weight(y,x,:) = 0.25 * (I(y+1,x,:) + I(y-1,x,:) + I(y,x+1,:) + I(y,x-1,:))
I used the matlab conv2 function to avoid for loops, i.e.
kernel = [0,1,0;
1,0,1;
0,1,0]
weight = conv2(kernel, I)
As matlab uses zero padding for the convolution result, I would get the result of size 514x514. But I only want the parts that don't use zero padding:
weight = conv(kernel, I, 'valid')
Unfortunately, this returns empty result. Does anyone know how to solve this problem?
Thank you very much.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Ameer Hamza el 11 de Mayo de 2020
Editada: Ameer Hamza el 11 de Mayo de 2020
For 'valid' option, reverse the order of I and kernel
I2 = conv2(I, kernel, 'valid');
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Logical en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by