I am working on image processing. I want to add the difference of pixels of two images.
Suppose I have two images A, and B. I pick the first pixel of both images and store the difference value. I want to add this difference value to next pixel-difference. I try using this code, but it is not working. How can I do it?
A = imread('sub2.jpg');
B = imread('sub1.jpg');
tic
[rows cols] = size(A);
diff1 = 0;
for x = 1:rows
for y = 1:cols
diff = A(x,y)-B(x,y);
diff1 = diff1+diff;
end
end
disp(diff1);
toc
Looks okay though, but you’re better off with:
or if
Bis larger thanA:This gives just one value (as your code does), I’m not sure if that really is what you want..