# distance between an image and a sliding window

1 visualización (últimos 30 días)
Julien Renoult el 1 de Dic. de 2017
Respondida: Image Analyst el 2 de Dic. de 2017
Hi ! I have an image I of size 300x300 pix, and a "filter" F of size 12x12 pix, and I would like to slide this patch everywhere on I and for each position, to extract the euclidean distance between F and the 12x12 local patch of I. Is there an efficient way to encode this ? In advance, Thanks !
##### 2 comentariosMostrar NingunoOcultar Ninguno
Rik el 1 de Dic. de 2017
Do you mean a convolution? If so, Matlab has a function to do that. I don't really understand what you mean with the distance between the sample and the filter. Could you provide a small example of how this should work?
Also, have a read here and here. It will greatly improve your chances of getting an answer.
Julien Renoult el 1 de Dic. de 2017
Hi. Thanks for your comment. A kind of convolution but I do not want the product of the filter and the patch, but the euclidean distance. Currently I have this peace of code. My problem is that it is really time-consuming (I repeat this on thousands of images) and I thus would like to avoid these two "for" loops.
F = rand(12,12,4); % I did not mentioned it before but in fact I have 3D filters and images
I = rand(70,100,4);
sz = size(F,1);
[dx2,dy2,~]=size(I);
for y=1:dy2-sz
for x=1:dx2-sz
P = I(x:x+sz-1,y:y+sz-1,:);
R = F - P;
R = R.^2;
R = sum(sum(sum(R)));
J(x,y) = R;
end
end

Iniciar sesión para comentar.

### Respuestas (1)

Image Analyst el 2 de Dic. de 2017
Convolve I with F first using convn(). Then use immse().
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Correlation and Convolution 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