Fastest way to process image patches?

조회 수: 3 (최근 30일)
JohnDapper
JohnDapper 2016년 1월 27일
댓글: JohnDapper 2016년 2월 2일
Hi all,
My matlab script is almost entirely a big loop that searches through small patches of an image and computes sum-of-square-differences with a "target patch", like this:
for i = 1:num_pixels_in_image
patch = image(i-5:i+5,j-5:j+5);
ssd(i) = sum(patch(:) - target(:)).^2;
end
Naturally, this process is very slow when the number of pixels grows large. I'm wondering what the absolutely most efficient way to implement this is. Problems such as this, it seems, don't lend themselves easily to vectorization. Cheers!

답변 (1개)

Image Analyst
Image Analyst 2016년 1월 28일
Not sure why you're doing that but I'm not sure you should do it that way. I think you maybe should use normalized cross correlation instead. There is a function that does that called normxcorr2(). I attach a demo. Basically it will give a high signal when the image patch is like the target patch and a low signal when the target patch is not like the image patch. Why do you want to do it the way you said? What is the overall goal of that algorithm? To determine where in the image is like the patch? That's what normxcorr2() is for.
  댓글 수: 4
JohnDapper
JohnDapper 2016년 1월 28일
Good point. The parantheses is misplaced. For the sum of squared differences, you suggest nlfilter? I'll take a look at that, thanks.
JohnDapper
JohnDapper 2016년 2월 2일
For anyone who may be interested, C++ mex is the way to go here.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by