Win a copy of The Java Performance Companion this week in the Performance forum!

# Symmetry Calculator

jean yann
Greenhorn
Posts: 4
Hi there,

I'm a french graphic designer and am working on my diploma project.
The subject: Symmetry (more precisely bilateral symmetry).
I came up with the idea of a symmetry calculator, to determine a percentage of symmetry for a given image, so 0% would be total chaos and 100% would be a computer mirrored image (but the point would be that nothing in the real world ever reaches 0 or 100%).

The principle is quite simple:

For that, I found Rafael Santos's code sample to calculate the similarity between two images.
I had absolutely no knowledge of Java or any programming language (except a little HTML/CSS), so I downloaded EclipseIDE and read a few Java lessons online.
I managed to create my little program (which is still very austere), by finding samples of code here and there and adapt it to my purpose.

Now, my problem is that the program works great for symmetrical images, but not quite good for asymmetrical images... See for yourself:

Rafael's code splits the images in 25 chunks and compares them to each other using their RGB values and other stuff that I can't really understand... I just know it's not thorough enough (he himself calls his program "NaiveSimilarityFinder").
He suggests other ways to precise the comparer, like descriptors for shapes, areas, general color, texture, position, etc. because right now, the program compares colors above all, and I need it to recognize shapes, more or less...

Does anybody know where I can find some examples of great image comparers? The ones I found don't seem really better that Rafael's...
(I checked pHash.org, the Windows software ImageComparer....)

Thank you very much. Here is a little PDF of the symmetry results I had with my program for those who're interested (to find out how it prefers colors over shapes, etc.):
SymResults.pdf

Winston Gutkowski
Bartender
Posts: 10422
63
jean yann wrote:Now, my problem is that the program works great for symmetrical images, but not quite good for asymmetrical images...

I hate to say, but this is NOT simple stuff. I've certainly never tackled anything like it; indeed, I'm not even sure that Java is the best vehicle for it, since it's graphics is, of necessity, generalized (although there are probably libraries out there for all sorts of things).

Does anybody know where I can find some examples of great image comparers?

At the risk of getting my knuckles rapped (because this is not an advertisement site): I use this one, which I find very useful. However, it's not free; and I doubt whether it has any hooks to Java (unless you can negotiate it with the owners).

There are also a ton of comparison packages and libraries out there, including lots of freeware ones; but how good they are, or how well they dovetail with Java, I have no idea.

My advice: try Googling "image comparison".

In the meantime, unless anyone has a better suggestion, I'm moving this thread to the 'Java in General' forum.

Winston

Greenhorn
Posts: 28
its a hard one, but i think you can start picking some distinguish pixel in the image, and comparing them you can use 2 images, 1 the orignial , and the second one the mirrowed copy of the first one. sum the value of the same pixel in the both images, and check if the result is the same as the double of the value of the pixel in the 1st image..

you can count the total pixels in the image, and make and average on how many are simetrical and how many are not.

http://www.prg.unicamp.br/hotsites/profisic/php/projetos/96-projeto_reconhecimento_placas2.pdf

this is a study of a car plate recognition software, take a look at the references, last page, it might help you on how to read the images and better undestand on pixel reading

jean yann
Greenhorn
Posts: 4
Winston Gutkowski wrote:I'm not even sure that Java is the best vehicle for it

Yep, I wasn't too, and in terms of graphic design I've heard more about Processing (which is a kind of java). But it seems that Processing is really about graphic forms & colors, lines, squares, circles... for generative purposes.
Plus, I remain a humble graphic designer and have not decided to learn all programming languages for my diploma so I'll try my best with Java and, hopefully, manage to have some results...

Rafael Prado Oliveira wrote:its a hard one, but i think you can start picking some distinguish pixel in the image, and comparing them you can use 2 images, 1 the orignial , and the second one the mirrowed copy of the first one. sum the value of the same pixel in the both images, and check if the result is the same as the double of the value of the pixel in the 1st image..

you can count the total pixels in the image, and make and average on how many are simetrical and how many are not.

That's a nice way of doing it too, but I think comparing only the halves of the image may return less difference (and may be quicker).
I checked your PDF --> I'm not so good with portuguese yet
But I was very interested in the part where they put the image in Black&White: that may be a great way to compare shapes, shade areas, textures etc. in addition to the colors I already had compared, wouldn't it?

I'll continue my researches, but if anyone thinks of anything that might help it will be most welcome!

Y.

Ulf Dittmer
Rancher
Posts: 42968
73
Check out the ImageJ app and library. IMO, it's the premier package for doing any kind of image processing in Java. Ask this question on their mailing list, where a variety of majorly knowledgeable folks regarding image processing hang out.

jean yann
Greenhorn
Posts: 4
Thanks! I'll have a look.
Anyone familiar with OpenCV? Looks like it's good for image processing.

Do you guys think one or several of those techniques could solve my problem?
They look like pretty hardcore stuff so if I can avoid time wasting...

Image Features (edges, corners and blobs)
--> Points of interest in image (for further comparison?)

Sobel Derivatives
--> From a B&W image, it detects what they call "the edges" of the image

Hough Line transform
--> Detects lines in an image. Maybe of handy (if the image contains lines) and works also for circles...

Thank you!

Joe Areeda
Ranch Hand
Posts: 331
2
• 1
Hi Jean,

If it were my project, I'd go with the features approach and probably add textures and some kind of classifiers for the blobs.

Sobel derivatives are much much easier to generate but they tend to be very noisy, not as bad as a straight gradient but still takes some insight to work with.

Hough transforms always seemed like magic to me and I never had the right mystic incantation to get them to do anything useful, but don't let me discourage you from trying them.

I think what we perceive as symmetry has much more to do with shapes and textures than it has to do with colors and shading. We don't miss the symmetry if there's a shadow in a photo.

Extracting and comparing shapes and textures is not a simple problem as people have already said. Be prepared for some real work to figure it out.

Good luck,
Joe

jean yann
Greenhorn
Posts: 4
All right thanks!
I'll go with features then, and check ImageJ too.
I'll keep you posted.