Does anyone know how to detect image offset?

Hi, I have two images: http://mercurius.f-snet.com/offset1.png http://mercurius.f-snet.com/offset1.png http://mercurius.f-snet.com/offset2.png http://mercurius.f-snet.com/offset2.png They are the same in visually by eyes, but actually they are different because of margin. Does anyone know any algorithm or way to compare these two images but ignores the offset of images? (I mean, offset2.png can be treated like offset1.png + n pixels offset, it only moved, not changed.) If I do boost::gil::equal_pixels(offset1, offset2), I will get false because they are different. I need a way to compare offset1.png and offset2.png with moving detection. Any suggestion is welcome! Thanks. -- View this message in context: http://www.nabble.com/Does-anyone-know-how-to-detect-image-offset--tp2391331... Sent from the Boost - Users mailing list archive at Nabble.com.

Hi,
I have two images:
http://mercurius.f-snet.com/offset1.png http://mercurius.f-snet.com/offset1.png http://mercurius.f-snet.com/offset2.png http://mercurius.f-snet.com/offset2.png
They are the same in visually by eyes, but actually they are different because of margin.
Does anyone know any algorithm or way to compare these two images but ignores the offset of images? (I mean, offset2.png can be treated like offset1.png + n pixels offset, it only moved, not changed.)
If I do boost::gil::equal_pixels(offset1, offset2), I will get false because they are different. I need a way to compare offset1.png and offset2.png with moving detection.
Any suggestion is welcome!
Trim the first lines and rows from both images, which only contain pixels of white/transparent color. But thats surley expensive, as you have to look at a lot of pixels. regards, Jens Weller -- GMX FreeDSL mit DSL 6.000 Flatrate und Telefonanschluss nur 17,95 Euro/mtl.! http://dslspecial.gmx.de/freedsl-aktionspreis/?ac=OM.AD.PD003K11308T4569a

Jens Weller wrote:
Trim the first lines and rows from both images, which only contain pixels of white/transparent color. But thats surley expensive, as you have to look at a lot of pixels.
The performance issue is critical for my application. And image might offset to left, right, down. I need a way to detect the image moving. Thanks for your reply, do you have any suggestion for that? Thank you. -- View this message in context: http://www.nabble.com/Does-anyone-know-how-to-detect-image-offset--tp2391331... Sent from the Boost - Users mailing list archive at Nabble.com.

On Sun, Jun 7, 2009 at 9:56 PM, blp330
Jens Weller wrote:
Trim the first lines and rows from both images, which only contain pixels of white/transparent color. But thats surley expensive, as you have to look at a lot of pixels.
The performance issue is critical for my application. And image might offset to left, right, down. I need a way to detect the image moving.
Thanks for your reply, do you have any suggestion for that?
How about finding the first non-white pixel in each image? In the "baseline" picture that you're comparing against you can pre-compute this one time at the beginning. Suppose you find that for the reference image the first non-white pixel is at coordinates (r, s) To detect a move, calculate it for the image you're trying to verify and you find that the first non-white pixel is at coordinates (x, y). 1) It is the original image offset by some amount. In this case, it has been offset by exactly (x-r, y-s). 2) It is a totally different image than the original. If you can tolerate less than 100% confidence that the image is the same thing but just shifted, just do a memcmp of the first few lines starting from this point. You know to offset into the image by (x-r,y-s) when doing the memcmps so that the comparisons are based at the same reference. This should give you good confidence whether or not they are the same. If the image is stored in a large 2-dimensional array as I suspect it may be with only pixel color information and no other information embedded into the cells, then once you find the first non-white pixel in each cell, just do a memcmp against the entire rest of the buffer. As long as the rectangles are not different sizes, this should still work. For example, image 1 and image 2 are both 1280x1024. They are the same except image1 is in the rectangle {(3, 7), (12, 18)} and image2 is in the rectangle {(4, 8), (13,19)}. You find that the first non-white pixel is (3,7) in image 1 and (4,8) in image 2. The memory from (3,7) to (4,7) in image 1 (1024 pixels) should be the same as the memory from (4,8) to (5,8) in image 2. It's just that the margin has moved from one side to the other. It realy depends a lot on the requirements of your app how to make it faster, there are a bunch of possibilities depending on error tolerance, needs, etc.

Zachary Turner-2 wrote:
How about finding the first non-white pixel in each image? ...
Thanks for your reply. This way sounds good but I am very sorry I didn't mention that background color might not be white, it might be black, brown...etc, even a other pattern image. This is more complicated to solve this problem. Do you have any suggestion for that? Thank you very much. -- View this message in context: http://www.nabble.com/Does-anyone-know-how-to-detect-image-offset--tp2391331... Sent from the Boost - Users mailing list archive at Nabble.com.

blp330 wrote:
Thanks for your reply. This way sounds good but I am very sorry I didn't mention that background color might not be white, it might be black, brown...etc, even a other pattern image.
This is more complicated to solve this problem.
Do you have any suggestion for that? Thank you very much.
Here is a more complicated case. http://mercurius.f-snet.com/offset3.png http://mercurius.f-snet.com/offset3.png http://mercurius.f-snet.com/offset4.png http://mercurius.f-snet.com/offset4.png These two images are different by image comparison method, but you can't find what different in human eyes. The only different part is background pattern. I need a way to ignore the background and detect the image moving. Thanks. -- View this message in context: http://www.nabble.com/Does-anyone-know-how-to-detect-image-offset--tp2391331... Sent from the Boost - Users mailing list archive at Nabble.com.

Image difference will give 0 where pixels doesn't change. You may have to get some basic courses in image processing at some point.

joel-75 wrote:
Image difference will give 0 where pixels doesn't change.
You may have to get some basic courses in image processing at some point. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Image difference will give 0? You mean there are no pixels different between offset3.png and offset4.png? I use boost::gil::equal_pixels, it returns false to me. I also use some comparison application, it hits me that the only different part is background pattern. I will get some basic courses, I am sorry that my project requires me to solve this problem at this time. :( Thank you. -- View this message in context: http://www.nabble.com/Does-anyone-know-how-to-detect-image-offset--tp2391331... Sent from the Boost - Users mailing list archive at Nabble.com.

blp330 wrote:
Image difference will give 0? You mean there are no pixels different between offset3.png and offset4.png?
I use boost::gil::equal_pixels, it returns false to me. I also use some comparison application, it hits me that the only different part is background pattern Do a pixel-wise difference. Result(x,y) = input1(x,y) - input2(x,y)
the resulting matrix will contains zone where the pixel value will be 0 and some where it wont. It can be then thresholded so you get a mask. I assume gil::equal_pixels do a reduction on such thing by returning a single bool which is not what you want here -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

You need image processing and analysis functions for that, specifically
pattern recognition. GIL lacks these functions, in that sense it's a body
without arms and legs.
Have a look at www.ngi-central.org. The search sample explains how to search
for patterns in images, and from this you can calculate the offset. Once you
have the offset there are other algorithms which can give you a degree of
similarity of your images.
Peter
"blp330"
Hi,
I have two images:
http://mercurius.f-snet.com/offset1.png http://mercurius.f-snet.com/offset1.png http://mercurius.f-snet.com/offset2.png http://mercurius.f-snet.com/offset2.png
They are the same in visually by eyes, but actually they are different because of margin.
Does anyone know any algorithm or way to compare these two images but ignores the offset of images? (I mean, offset2.png can be treated like offset1.png + n pixels offset, it only moved, not changed.)
If I do boost::gil::equal_pixels(offset1, offset2), I will get false because they are different. I need a way to compare offset1.png and offset2.png with moving detection.
Any suggestion is welcome!
Thanks. -- View this message in context: http://www.nabble.com/Does-anyone-know-how-to-detect-image-offset--tp2391331... Sent from the Boost - Users mailing list archive at Nabble.com.

Peter Schregle wrote:
You need image processing and analysis functions for that, specifically pattern recognition. GIL lacks these functions, in that sense it's a body without arms and legs.
Have a look at www.ngi-central.org. The search sample explains how to search for patterns in images, and from this you can calculate the offset. Once you have the offset there are other algorithms which can give you a degree of similarity of your images.
Peter
Thank you!! I will look and try NGI. If I have any idea for that I will tell you! thank you very much. -- View this message in context: http://www.nabble.com/Does-anyone-know-how-to-detect-image-offset--tp2391331... Sent from the Boost - Users mailing list archive at Nabble.com.

You can find the offset with subpixel accuracy (useful when you have antialiased or interpolated images) by using Phase correlation. http://en.wikipedia.org/wiki/Phase_correlation You have to apply 3 FFTs, which makes it rather computationally expensive, but the method is very stable to noise. Greetings, Falco
participants (6)
-
blp330
-
Falco Hirschenberger
-
Jens Weller
-
joel
-
Peter
-
Zachary Turner