• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
phyitbos

Quantifying Difference Between Two Images

5 posts in this topic

Hi,

I am learning about genetic algorithms and my goal is to make a replica (similar at any rate) to the one shown in this YouTube video:

[media]http://www.youtube.com/watch?v=dO05XcXLxGs[/media]

I need to be able to rate the "fitness" of my generated images. To do this, I need to compare them to a supplied picture, and was wondering what algorithm I should use to quantify the similarity (distance?) between the two images. I'm not familiar with algorithms in this category, so any insight would be very helpful! One that is simple to implement would be best, considering the goal of my project is the genetic algorithm and not comparing images, although a little learning never hurts [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Thanks in advance!
0

Share this post


Link to post
Share on other sites
The simplest way would be to
[code]
int weight = 0;

for each (testPixel)
{
weight += abs(originalPixel.r - testPixel.r); // assuming each channel [0,255];
weight += abs(originalPixel.g - testPixel.g);
weight += abs(originalPixel.b - testPixel.b);
}
[/code]

The lower the weight the better the match. Edited by turch
1

Share this post


Link to post
Share on other sites
You might find the ImageMagick 'compare' tool useful. It has a number of metrics which you can use when comparing images: http://www.imagemagick.org/script/command-line-options.php#metric
0

Share this post


Link to post
Share on other sites
You need at least some idea, what kind of similarity you want to use as the basis:[list]
[*]The easiest is simply sum color differences of individual pixels (like turch suggested)
[*]Another is to find euclidean distance between MxN vectors (like Alvaro suggested)
[*]Now you may want to punish big differences proportionally more - in that case you may want to square the absolute differences before before adding them
[*]If you want to give less weight to high frequencies you should downsample images before comparing
[*]If you are interested in human percievable difference, you should transform your image to YUV or similar colorspace
[*]If you want to add more importance to shapes you may want to apply some edge-detection
[/list]
And so on [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]
1

Share this post


Link to post
Share on other sites
[quote name='turch' timestamp='1349267638' post='4986358']
The simplest way would be to
[code]int weight = 0;

for each (testPixel)
{
weight += abs(originalPixel.r - testPixel.r); // assuming each channel [0,255];
weight += abs(originalPixel.g - testPixel.g);
weight += abs(originalPixel.b - testPixel.b);
}
[/code]

The lower the weight the better the match.
[/quote]
This is not the way to go and can in fact be very hurtful to the actual result.


What you want is to use MSE ([url="http://en.wikipedia.org/wiki/Mean_squared_error"]mean squared error[/url]) if your goal is simply to compare qualities between different images, or PSNR ([url="http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio"]peak signal-to-noise-ratio[/url]) if you want to discretely quantify the differences between your images (in other words, calculating the MSE is part of determining the PSNR, and a higher MSE always results in a lower dB (the measurement for PSNR), so if your goal is simply to compare images to determine which is closer to the original than another, MSE is all that is needed, whereas if you want to quantify exactly how close using dB, you should continue on and calculate the PSNR, although even still this part is optional).

For MSE (all you probably really need), the pseudo code would be:[CODE]
error = 0
for ( all Y ) {
for ( all X ) {
error += (src(X, Y) - copy(X, Y)) * (src(X, Y) - copy(X, Y))
}
}
error /= (width * height)[/CODE]

This is applied to each channel separately, so you would have one error value for R, one for G, and one for B.

Then you apply perceptual weights to these error values based on how humans perceive light.

Common weights are:
(0.299f, 0.587f, 0.114f)
(0.212656f, 0.715158f, 0.072186f)
(0.3086f, 0.6094f, 0.082f)

Notice how they all add up to 1, and also how green is always weighted much higher than the rest. This is also why the 565 16-bit color format exists, because green is the most important color perceptually. For example, if it was instead red that was most important to us humans, the 16-bit color format would instead have been 655.


Your final total perceptually adjusted error would be (assuming weights of (0.212656f, 0.715158f, 0.072186f)):
[CODE]redError * 0.212656f + greenError * 0.715158f + blueError * 0.072186f[/CODE]


This gets you a properly weighted perceptually adjusted error metric that allows you to determine how close you are to the original, and is simple to implement.


L. Spiro Edited by L. Spiro
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0