vectorizing image mean absolute error loops

2 views (last 30 days)
Hi
I have a couple of loops for calculating MAE of an image and was wondering if these could be optimized through vectorization? Here is my code:
im1=imread('image_1.jpg');
im2=imread('image_2.jpg');
I1=double(im1);
I2=double(im2);
[m n]=size(I1);
B1=I2(65:96,81:112);
[a b]=size(B1);
mae_x=flintmax;
x=1;
y=1;
for i = 1:(m-a)
for j = 1:(n-b)
mae=sum(sum( abs(B1-I1(i:i+(a-1),j:j+(b-1))) ))/(a*b);
if(mae < mae_x)
mae_x = mae;
x=i;
y=j;
end
end
end
Thanks...
edit1: I am trying to determine this, just in an optimized manner: http://en.wikipedia.org/wiki/Mean_absolute_error

Answers (1)

Image Analyst
Image Analyst on 27 Apr 2014
What are you trying to do? Are you trying to do this: http://en.wikipedia.org/wiki/Mean_absolute_deviation
  3 Comments
Mike Sousa
Mike Sousa on 27 Apr 2014
Thanks Image Analyst for the inputs, The reason for the sub image is my loops are performing a comparison for optical flow in a series of images, Where MEA is minimized is where it is assumed the images match the most. It is slow though and I was hoping to optimize it.
Thanks...
Image Analyst
Image Analyst on 28 Apr 2014
Well I can't quite comprehend the operation - what pixel is being subtracted from what pixel - so I can't really make a suggestion. Maybe if you can explain that better...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!