Teen Programmers Unite  


Return to forum top

Algorithm Help

Posted by DavidS [send private reply] at November 21, 2002, 03:54:56 PM

Given Image X, I want to find a single image in a set of unique images that is the most similar (in respect to hue and location) to X.

I tried taking the average pixel value of each image and compairing it to the average pixel value of X, but the resulting image was only the closest in respect to overall brightness rather than hue.

What would be the most accurate way of doing this on a per-pixel compairitive basis?

Posted by CDR700 [send private reply] at November 21, 2002, 04:03:36 PM

I'm probably not the man to explain (as in my lifetime i have'nt as yet fiddled with image) but there are many statisitcal similarity algorithms avalible for such matrixes as yours.I dont know how they are structured,but there are many things like this is mathematical computation programs or mathematical programming languages (IMSL).

Posted by taubz [send private reply] at November 21, 2002, 04:18:36 PM

If you search the slashdot archives you'll find a fairly recent news bit about research in this area, at my school no less. This is a pretty difficult thing... (s/pretty/extremely/)

You might want to think about what constitutes similarity. Overall brightness/hue won't do it. I'd guess we humans use shapes to compare images, but finding shapes -- don't even try. Maybe something less than shapes but more than comparing individual pixels -- edges? Or, compare small regions of the images with hue/brightness.

Again, this is a difficult problem.

- taubz

Posted by regretfuldaydreamer [send private reply] at November 21, 2002, 04:54:34 PM

As far as I know, this is probably one of the most researched problems within any intelligence/police organisaton in the world.

Why not try mapping gradients? (See if similar gradients of HSB appear in an image)

As taubz said, this is an extremly difficult problem.

Posted by CDR700 [send private reply] at November 21, 2002, 05:12:52 PM

Again its more than al algorthm,would you agree,it a whole philosophy.DavidS ,may I ask what technical knowledge you have on realising such an algortih or is it just the kick from getting the algorithm on paper? (no offense please)

Posted by DavidS [send private reply] at November 22, 2002, 09:21:10 AM

This is just a pet project of mine.

Basically, what I'm trying to do is make a "photo collage" program.

(Actually, The end result will be taking 2 movies and taking every frame of one movie and turning it into a photo collage using frames from the second movie)

For each section of Image 1, find an image in the set that resembles it more than any other.

So it's not like I'm trying to take a picture of a clown and find all images that resemble clowns.

I'm taking an abstract chunk out of one picture and replacing it with a non-abstract picture that looks similar to it.

Posted by DavidS [send private reply] at November 22, 2002, 09:45:59 AM

Finding the image with the closest matching gradient is exactly what i'm looking for. This will work perfectly.

Does anybody know of any good resources explaining how this is done?

Posted by regretfuldaydreamer [send private reply] at November 22, 2002, 10:49:56 AM

Nope, but I'm working on something sorta similar. If its a pet project does that mean you have a good amount of time to do it? If so, I'll PM you or email you if you leave your email in your proffile I'll email you.

Posted by DavidS [send private reply] at November 22, 2002, 11:53:17 AM


Take out the exclamation points.

Posted by DavidS [send private reply] at November 22, 2002, 12:55:42 PM

Original Image

Average: 3.5

Image Set
6543 1123
5432 1234
4321 2334

Average: 3.5,2.41

By doing overall image, the first #1 wins out, even though #2 probably looks more like it.

Could this be solved by getting the overall delta between each pixel and finding the lowest value?


#1 is

1135 = 28

#2 is
1122 = 13

Here, #2 wins out.

What do you think?

Posted by regretfuldaydreamer [send private reply] at November 22, 2002, 01:09:16 PM

One problem with checking if images are alike is that different methods can be used with different typess. Iff you have a set of shapes with each shape only 1 colour, then you can map those shapes out as a vector image, however with a photo, it is probably easier to try mapping colour gradients and see if similar gradients appear in images. I would think that this would probably be done better using RGB instead of HSB, because HSB the H is continuous (i.e. if it is represented as a value between 0 and 1 0=1 or if it is represented as an unsigned byte 0=255).And if you look for gradients its gonna take a good deal of math to work out the formula for the gradient and your gonna have to check the gradient around each pixel in a wheel fashion (Check the gradient straight above the pixel and then go round it checking the gradient at 5degrees, 10degrees and so on.

Posted by Psion [send private reply] at November 22, 2002, 01:13:34 PM

David, profiles already have e-mail addresses obfuscated by changing "@" to " at ". I would hope that's enough for you to be willing to help other people contact you.

Posted by DavidS [send private reply] at November 22, 2002, 01:36:20 PM

Okay. Email Address is now in my profile.

The application of this applies to smoothly blending sets of smaller images to look like one larger image.

It works pretty well using overall averages with a large and diverse set of images. I bet it will work alot better using per-pixel deltas.

I guess the question now is can you think of any better ways to accomplish this?

Posted by CodeRed [send private reply] at November 23, 2002, 12:48:43 PM

Image recognition technology is still far from perfect, trying to do stuff that the industry still cannot do is just asking for a headache

Posted by gian [send private reply] at November 23, 2002, 03:43:34 PM

Multiplying corresponding pixels in each image together and looking for a large output is a very common way of doing image comparison. From there, you could possibly emply this technique on each channel.

Posted by CodeRed [send private reply] at November 23, 2002, 04:03:47 PM

What I would do is divide the image into a few thousand square (or rectangular if the image is) sections, calculate the average value of each color channel for each square section, then compare the averages to the original image, anything above a certain percent accuracy is considered a match, anything below that percentage accuracy is not a match. This would work rather well on close up images of peoples faces and stuff like that

You must be logged in to post messages and see which you have already read.

Log on
Save for later automatic logon

Register as a new user
Copyright TPU 2002. See the Credits and About TPU for more information.