Axis of symmetry of a binary image I want to calculate the axis of symmetry of a binary image. 
In other words I have an image that has a black irregular shaped object with a white background. I want to find the best approximation of the axis of symmetry that will divide the black part in such a way that if you fold it on that axis that it will have the least non overlap.
I read an article that used moments, but I could not make out how they did this.
I also thought about maybe treating it as a optimization problem, but it also has its drawbacks. (Using a particle swarm for example will require me to test the overlap repeatedly and that would be dead slow)
Edit: it does not have to be the fastest option, but I will be running this on 500 or so images.
 A: This would be how I would go about it.
The axis of symmetry in your image would be given by two parameters, an angle $\theta$ and an offset $k$. You need to search this parameter space for a solution that minimises some objective function.
You have some choice about the objective function, should you line up the edges, should you get the largest fraction of matches between the two sides etc.
In any case, you need to specify an objective function, for the absolute difference in values take a function of the form
$$f(\theta, k) = \sum_{X\times Y}|J(x,y) - J(x',y')|$$
Where J is your image, and $(x',y')$ is the reflection of the point $(x,y)$ in the axis of symmetry.
You can speed up your calculation by coarse graining your image (and perhaps using greyscale levels) or by randomly sampling $(x,y)$ coordinates.
Then you use your favorite optimisation method to search, I think a particle swarm method would be overkill. For accuracy, just use a single particle on a lowered resolution image until it converges a bit, increase the resolution, optimise more, and so on. I don't think you need to worry to much about the momentum of the particles either. Pick a point, mutate it, test whether it is better, it wont be super-fast, but it will be acceptable for batch processing 500 images. Better that than spending far longer making a complicated algorithm that might not be any better!
Choose your starting point wisely too. Perhaps using the centre of mass would be a good hint.
A: I presume that your image isn't just a lot of individual points, otherwise it's hard to efficiently determine where the symmetry line should be even if you know the angle. This will be made precise below where I will state the assumption where I need it.
For any angle $a$:
  Require the symmetry line to have angle $a$
  Assume that if you sweep the symmetry line across from one side to the other, the amount of overlap as a function of position would be roughly composed of an increasing function followed by a decreasing function
  Binary search to find the optimal symmetry line based on this assumption
  This should find a reasonably good 'central' symmetry line efficiently
We can make the same kind of assumption about the angle, that the optimal overlap as a function of angle forms a single peak and single trough in each cycle of $180^\circ$, but this is far less likely for typical images, so we can instead assume that adjacent peaks and troughs are separated by at least a certain threshold $d^\circ$, say $d=3$
We then test each slice of $d^\circ$, which has at most one peak, and use a binary search to find the peak within that slice
I think this should do reasonably well, but it would be up to you to fine-tune the parameters for your data set, and you may also want to use the more general assumption of multiple peaks when finding the optimal symmetry line for a particular angle.
A: I wrote a brute force algorithm for this many years ago. It was slow, so you might not be interested. And full disclosure, I am not a programmer! But FWIW, it worked like this. (Apart from being slow, it did work well.)
Let $S$ be the set of integer $(x, y)$ points belonging to the image.
Because my images had fairly high symmetry about a single axis, with a nearly vertical axis, I parametrized the symmetry axis as $x + by = c$, where $b$ and $c$ are real parameters ($b$ likely small in my application).
Form the set $T$ (which depends on $b$ and $c$) by reflecting each point $(x_0, y_0)$ in $S$ across the line $x + by = c$. The equations for this are
$$x_{\rm new} = (2c-2by_0-(1-b^2)x_0)/(1+b^2)$$
$$y_{\rm new} = (2bc-2bx_0+(1-b^2)y_0/(1+b^2).$$
The reflected coordinates are to be rounded to the nearest integer.
Define the quality function $0 \leq Q \leq 1$ by
$$Q(b,c) = \frac{|S\cap T|}{|S|}.$$
Find the parameter values $\tilde{b}$ and $\tilde{c}$ that maximize $Q$. Then the approximate symmetry axis of the image is $x + \tilde{b}y = \tilde{c}$, and the maximum value of $Q$ is a measure of the symmetry of the image.
