distance between an image and a sliding window

1 次查看(过去 30 天)
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 个评论
Rik
Rik 2017-12-1
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
Julien Renoult 2017-12-1
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

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2017-12-2
Convolve I with F first using convn(). Then use immse().

Community Treasure Hunt

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

Start Hunting!

Translated by