Open Spacha opened 1 year ago
I found that there is a new repo for further developments and I moved this issue there.
Hi Spacha, Thanks for letting me know about the new repo. I feel like your algo is interesting. If I wanted, I could use your algo to quickly check uniqueness before doing a longer check. Unfortunately, I don't think it's perfect. As the size of the grid increases, the number of solution grows something like 2^(n^2) while the number of combos in your algo seems to only grow at this kind of rate: (2^10)*n^2. For large n, 2^(n^2) will win, but I still like it!
Yes, this one was a miss unfortunately. As pointed out in the other repo, this has another issue which makes this useless. I've been trying to find a better way of encoding the relative positions but it gets difficult for n > 5.
I still feel like there is a way of representing all of the rotations by a single hash but it isn't easy.
My attempt to represent the shapes in a rotation invariant way is inspired by Local Binary Patterns (LBP).
LBP is used in machine vision to extract descriptors from an image. It is quite simple in principle (if you are not familiar with it, maybe read the article first!).
How does it work?
Say we have a shape like the one in the image (green blocks):
1. Add zero padding for calculation
We then add 2 levels of zero padding around the shape, which looks like this:
2. Calculate the cell values using modified LBP
Then we can start calculating the feature matrix. We start from the second cell of the second row (cell
(1, 1)
, see the figure below) so that there are not edges next to it. The cell value for cell(1, 1)
is calculated based on its 8-neighboring values as well as its own value. Each cell value is a 9-bit integer (0-512).Here the cell
(1, 1)
is highlighted in orange:Now we have a 9-bit cell value for the first cell:
00001_0000
, which is16
in decimal. We can then move to the next cell. This is repeated for all cells except cells that are on the edge (so skipping the first and last columns as well as the first and last rows).Here are all the cell values for the example shape:
Then, the feature vector of this shape is:
3. Calculate the sum of the matrix values
Finally, we sum all the cell values in the feature matrix to get the fingerprint of that shape. This fingerprint is the same for all rotations of the same shape.
Comparing the variants
Here are all the variants of the example shape, along with their feature matrices and their sums (the fingerprints).
As you see, all variants have the same fingerprint 3577!
Final words
I have tested this with maybe tens of various 2-D shapes. So far so good. Check my Notebook for all the tests.
I have not yet proven nor disproven that this will work. However, I am planning to do that later.