# image comparison

someone knows how to compare two images pixel per pixel? i want to know which parts of it are different.

I want to be able to produce a map that i can apply to GL_QUADS. on GL_QUADS a texture is applied with the different regions to be transparent.

The two images to compare and the GL_QUADS are all of the same width and height.

so the comparison of the 2 images determines the transparency sections of GL_QUADS.

Any ideas?

impossible?

Its certainly NOT impossible - however I am new to C programming, and even newer to OpenGL so I do not know exactly how. I have written a procedure to do exactly this for Delphi/Pascal, and it’s not that hard. Do just like you say - compare pixel by pixel. I think you can ignore the GL_QUADS element of this problem - after all, once you’ve compared and created the texture it doesn’t matter a fig what you texture with it.

I can post the Pascal code for this if it’s required, but I can’t imagine it’ll help other than serve as pseudo-code.

Peace,
Rawlyn

Hi,

I do something similar, but I’m interested in the difference between two images (but that’s effectively the case when a-b=0). I use fragment programmes, though.

One way off the top of my head would involve rendering A to the frame buffer and then render B with the subtract blend equation. You’d then copy the result to a texture and define a fragment program that computed its alpha as ceil(r+g+b). That way you’d get alpha==0 everywhere r=g=b=0 and 1 otherwise.

cheers,
John

john, problem with your technique is that 0 - 1 = 0 in the framebuffer as range is clamped to [0,1]

that is indeed true.

perhaps it can only be peformed, then, within the shader using two two textures rather writing the intermediate result to the framebuffer

cheers

or you could scale the colour space so

x’ = x*0.5+0.5

(where x is a colour channel) and then subtract the two images in the frame-buffer. You loose precision, though.

Another solution would be to invert the colour space of the first image and add the second, thus test for

(1-x’) + x = 1

(where x’ and x are the channel from the first and second image). This is true when x’=x for all x,x’ \in [0, 1]

cheers
John

Hi,

if I understand you correctly, you want to know which pixels are different in 2 images.

A quite nice solution for this problem is the usage with a fragment shader:
You just render a full-screen quad with texture coordinates (orthogonal projection) and use a fragemtnshader to do a lookup into both textures and to compare them - if you use the fragmentshader you can decide how to compare the images. For example just Out = ImgA - ImgB, or something else.

If you are not interested in the difference value, but you - for example - just want to see all diferent pixels black on a white background you could just write something like:

if((ImgA-ImgB)!=0.0)
Out = 0.0;
else
Out = 1.0;

Another funny thing is the usage of occlusion queries if you want to know the number of different pixels: therefore you send an occlusion query before drawing the quad and you write a fragment shader with the “discard” (Cg) or “kill” (that´s the GLSL command I think) command - something like:

if((ImgA-ImgB)!=0.0)
Out = 0.0;
else