distance between an image and a sliding window

1 回表示 (過去 30 日間)
Julien Renoult
Julien Renoult 2017 年 12 月 1 日
回答済み: Image Analyst 2017 年 12 月 2 日
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().

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by