function img = imdiff(img1,img2)
% IMDIFF

if length(size(img1))>2
    img1 = rgb2gray(img1);
end
if length(size(img2))>2
    img2 = rgbgray(img2);
end

% calculate difference

d = img2 - img1;
dmax = max(max(d));
dmin = min(min(d));

% determine where to color code
thres = 0.15*max(dmax,-dmin);
k1 = d < -thres;
k2 = d >  thres;

% mask to get final image
g = (img1.*not(k1)).*not(k2);
img = cat(3,g+double(k2),g,g+double(k1));
if nargout == 0
    imshow(img);
end