vectorizing image mean absolute error loops

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)

What are you trying to do? Are you trying to do this: http://en.wikipedia.org/wiki/Mean_absolute_deviation

3 Comments

Why not just do
absDiff = abs(double(I1) - double(I2));
mae = mean(absDiff(:));
I never did understand why you didn't have i and j go to the edge of the image. Any reason why you did that? And why is B a subimage of I2? Aren't I1 and I2 the same size? If not, then just use B instead of I2 in my above solution.
absDiff = abs(double(I1) - double(B));
mae = mean(absDiff(:));
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...
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.

Asked:

on 27 Apr 2014

Commented:

on 28 Apr 2014

Community Treasure Hunt

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

Start Hunting!