Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Figure F exists on a regular square grid.

T transforms F by any combination of horizontal or vertical reflection as well as rotation by 90 or 180 degrees.

A larger background grid of X by Y contains noise, where each square has a 50% chance of being 0 or 1.

I am trying to produce a score for the probability that F will match the background grid.

For a match, F or one of its transformations (T) must be able to be compared to the background grid at some location such that the squares that are part of F match the 1s on the background grid but none of the 0s.

The score does not need to be in any particular unit, but must be comparable to other scores.

For example:



Background (X = 7, Y = 4)


A match occured. I have replaced the units that match with .s, they matched because they were all 1s and formed one of Fs transformations.


I'm currently using (64 / 2 ^ f_squares) + (c - 1) * 2 where c is the transformational symmetry of F, f_squares is the number of squares in F and ^ is "to the power of". I'm looking for a more accurate approximation.

64 / 2 ^ f_squares represents the decreasing probability of a match the more squares that F contains, with (c - 1) * 2 for the additional chance of a match if Fs transformations are different from each other.

share|cite|improve this question
You probably meant "horizontal or vertical reflection" instead of "horizontal or vertical rotation"? – joriki Aug 2 '12 at 12:39
Thanks, well spotted. – alan2here Aug 2 '12 at 13:30
Just a thought, but I wonder if you could apply the Hough transform here, and consider the votes as a sum of iid Bernoulli rvs. – Emily Aug 2 '12 at 13:35
@EdGorcenski Is there an answer in this idea involving Bernoulli. Otherwise I may mark jorikis answer as correct soon after I have tested it, if it works. – alan2here Aug 2 '12 at 14:58
@alan2here I don't know. It was just a fleeting comment. I'm sure you could do such a thing; I don't know that it would be any easier -- or practical at all. – Emily Aug 2 '12 at 15:01
up vote 1 down vote accepted

The probability of getting at least one match is hard to compute, but since you only want a score, you could consider using the expected number of matches, which is easy to compute. Let $G$ be the symmetry group of $F$, with $c=|G|$ (I presume this is what you mean by "the transformational symmetry of $F$"). Denote the width and height of $F$ by $w$ and $h$, respectively, and the number of squares in $F$ by $f$ (your "f_squares"). Then, assuming that the background is big enough to accommodate $F$ in both horizontal and vertical orientations, the expected number of matches is

$$\frac12((X-w+1)(Y-h+1)+(X-h+1)(Y-w+1))\frac c{2^f}\;.$$

This is just the chance of a match for a particular placement, $2^{-f}$, times the number of different placements, which is $c$ times the number of positions, which are averaged over horizontal and vertical orientations, of which there are half each.

share|cite|improve this answer
I've just tested this and it works very well, thanks. – alan2here Aug 2 '12 at 19:11
@alan2here: You're welcome! – joriki Aug 2 '12 at 19:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.