From: Walter Roberson on
James wrote:

> Thank you very much, Nathan. But that's probably not what i am looking for.
> The reason i wanted to overlay two images is because i want see if there
> is any difference between the two images, and if there is, i want to
> pinpoint exactly where it occurs and how much difference there is
> between the two images.

im1 = image(ImageMatrix1);
im2 = image(get(im1,'XData'), get(im1,'YData'), ImageMatrix2);

Image 2 will now be overlayed exactly on top of Image 1.

That's what you asked for, but it won't do you any good, because Image 2
will not be at all transparent, and so will completely hide what is
underneath it in Image 1.

If the two images are the same size, then if you want to see differences
between them, with greatest relative difference mapped to the last color
in the colormap (and the place they are the same mapped to the first
color), then (assuming the two images are the same data class)

imagesc(cast(abs(double(ImageMatrix1)-double(ImageMatrix2)),class(ImageMatrix1)));

If you want an absolute scaling rather than a relative scaling, then
provide the scaling parameters in the imagesc() call.

Note: the above assumes the images are grayscale or pseudo-color (one
value per pixel) rather than true color (Red, Green, and Blue values per
pixel.) If your images are true color, then it becomes more difficult to
define what is meant by "how much difference" there is between images.

For example, if you had an all-black (RGB - 0,0,0) image, and an
all-blue image (RGB = 0, 0, 255) then abs() of [0., 0., 0.] - [0., 0.,
255.] would be [0., 0., 255.], which the cast() would then convert back
to uint8, [0, 0, 255]. Which, naturally, would be exactly the same as
the all-blue image... which would probably be confusing. Anyhow, the
"total difference" between the pixels would be 255. You would get a
greater "total difference" comparing a medium gray image to the black
image, if the medium gray was (86, 86, 86), as the total difference
would be 258. Most people would tend to think that going from black to
bright blue would be a bigger difference than going from black to gray
-- but when computing the "difference" between two color images, you
have to -somehow- include measures of the differences in all three color
channels.

Some people consider pixels to be most different if they have the
greatest difference in luminance. If you have two RGB images, then


if isinteger(ImageMatrix1)
tim1 = double(ImageMatrix1) ./ double(intmax(class(ImageMatrix1)));
else
tim1 = ImageMatrix1;
end
if isinteger(ImageMatrix2)
tim2 = double(ImageMatrix2) ./ double(intmax(class(ImageMatrix2)));
else
tim2 = ImageMatrix2;
end
gdiff = abs(rgb2gray(tim1) - rgb2gray(tim2));

image(gdiff);
colormap(gray);

This code does not assume that the images are the same data class.


You may wish to experiment with something like:

surf(gdiff, 'CData', tim1, 'FaceColor', 'texturemap');

This will show a surface in which the image is the same as the first
image, but "bumpy", with the greatest height being at the place of
greatest luminance differences between the two images.
From: Parker on
On Mar 24, 1:01 am, "James " <cche5...(a)uni.sydney.edu.au> wrote:
> Nathan <ngrec...(a)gmail.com> wrote in message <90166712-6e95-4290-aa00-c8e23a74a...(a)g28g2000prb.googlegroups.com>...
> > On Mar 23, 5:37 pm, "James " <cche5...(a)uni.sydney.edu.au> wrote:
> > > ImageAnalyst <imageanal...(a)mailinator.com> wrote in message <afa2d5e2-7a85-4543-9734-f15acf97e...(a)j21g2000yqh.googlegroups.com>...
> > > > Why don't you just display the average of the two images?
>
> > > Sorry, i am kind of new to matlab so i don't really know the best way to overlay two images. What does taking the average of the two images do?
>
> > Why would ImageAnalyst suggest displaying the average of the two
> > images if it did not do what you were asking?...
>
> > The average of two images is essentially the two images overlaid
> > equally. (One image is not shown more than another image)
> > This is true (only?) if the two images have the same dimensions.
>
> > The average of two images can be found as such (assuming they have the
> > same dimensions)
>
> > avgimg = (img1 + img2)./2
>
> > I hope that helps
>
> > -Nathan
>
> Thank you very much, Nathan. But that's probably not what i am looking for.
> The reason i wanted to overlay two images is because i want see if there is any difference between the two images, and if there is, i want to pinpoint exactly where it occurs and how much difference there is between the two images.  

the difference could be computed by

>>diff = image1-image2;
>>imshow(diff);
From: Oliver Woodford on
"James" wrote:
> Thank you very much, Nathan. But that's probably not what i am looking for.
> The reason i wanted to overlay two images is because i want see if there is any difference between the two images, and if there is, i want to pinpoint exactly where it occurs and how much difference there is between the two images.

A good way to visualize the difference between two images, I1 and I2, is this:

sc(double(I1)-double(I2), '-diff');
colorbar;

where the function sc can be downloaded from:
http://www.mathworks.com/matlabcentral/fileexchange/16233-sc-powerful-image-rendering

HTH.
Oliver
From: Walter Roberson on
Parker wrote:

> the difference could be computed by
>
>>> diff = image1-image2;
>>> imshow(diff);

If the images are data class uint8, then any value that would come out
negative on the subtraction would be clamped at 0. If the images are
true color floating point, then imshow() has no provision for showing
any negative data.

That's why in previous postings, people were careful to double() the
images before subtraction, and why I was careful to rescale the image to
[0,1] if it was an integer type.