Re: Finding similar images
From: Bob Richardson (bobr_at_whidbey.com)
Date: Thu, 22 Jan 2004 10:21:28 -0800
> > A "border" is present if there is a "line" at the outer edges of the
> > made up of 1 color only.
> > - Starting from the outer pixel, move inwards until color changes
> > - Then, check if the entire image edge has the same color.
> > (the borders may be of somewhat different widths, and you need to handle
> > corners, where borders meet)
> > Do the border test first, compare images afterwards (taking image
> > into account).
> Border detection makes perfect sense and should be a simple enough
On some of my digital photos, I really like to put "wooden" frames. There
are free downloads that can be used with PhotoShop which allow you to choose
among 20 or more different wood types (pine, oak, etc.), and of course there
are different styles. Thus, the test for a border is much more difficult,
since a "solid" color isn't involved...the digital wood has a nice grain
Concerning height/width ratios, one of the most obvious fixes to a photo is
to crop it, which change the ratio almost every time.
You also have to consider that two photos might be identical/similar, but
just rotated 90 or 180 degrees, and certainly a grayscale conversion of a
colored pic would be "similar," or perhaps one pic slightly darkened, or
If you've played with PhotoShop or any graphics program, you know that a
photo can be manipulated in a bazillion different ways.
Given all that, here's my first attempt at a process:
1. convert both pics to grayscale
2. find several, non-contiguous, major transition points in each photo.
3. if most angles between these transition points are equal, I would next
try to superimpose one picture on the other, shrinking the larger photo if
necessary. Consider ALL possible rotations-not just 90,180,270 degrees. (I
take many photos with the sea as a backdrop - and I often rotate my pics 1
or 2 degrees to level out the horizon).
4.At this point, any frame would be "hanging out" - and thus you would lop
it off. (If both pics had frames, just the larger frame would have some of
it trimmed away).
5. Remove any remaining, frame-like, border (so it won't skew your
6. I would probably shrink both photos to a fairly small size (100 X 100 or
smaller) to make sure I'm looking at the forest, not the trees.
7. Next normalize both pics to the same brightness and contrast scale.
8. Then do a pixel by pixel comparison, testing the change in darkness
rather than the absolute level of darkness. Go left-right, up-down, and on a
In other words, my approach would be to dumb down both pictures so that only
the essence remains, then compare. Reducing the pics to 100 X 100 black and
whites will make the task manageable.
The hardest part will be defining transition points - from light to dark,
while not getting confused by additions to the photo. For example, two Mona
Lisa's, but one has a black tape over her lips. There will be several
"transition points" created by the tape in one pic, but not the other.
Another "fraud" might be Mona Lisa in a snow storm, or behind a chain linked
It would nice (for testing and debugging purposes) if your initial program
(while you're developing your algorithms) showed the two pics, side by side,
as the photos gradually got rotated, sized, and trimmed.