distance between an image and a sliding window

2 views (last 30 days)
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 Comments
Rik
Rik on 1 Dec 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
Julien Renoult on 1 Dec 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

Sign in to comment.

Answers (1)

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

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!