vectorizing image mean absolute error loops
Show older comments
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
on 27 Apr 2014
0 votes
What are you trying to do? Are you trying to do this: http://en.wikipedia.org/wiki/Mean_absolute_deviation
3 Comments
Image Analyst
on 27 Apr 2014
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(:));
Mike Sousa
on 27 Apr 2014
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...
Categories
Find more on Image Filtering 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!