Finding pixels that make an image unique within a list, can you improve on brute force?

前端 未结 3 1842
暗喜
暗喜 2021-02-06 11:05

Suppose I have a list of strings where each string is

  • exactly 4 characters long and
  • unique within the list.

For each of these strings I wan

3条回答
  •  难免孤独
    2021-02-06 11:34

    If your goal is to identify images later, you could create a very fast hash of the image by picking predefined points to serve as identity pixels.

    for example, you could have a structure (class, struct, doesn't matter what language) as follows:

    structure ImageHash {
        int x_pixels, y_pixels;
        u_long hash;
        void createHash(Image img) {
            x_pixels = img.x_pixels;
            y_pixels = img.y_pixels;
            for(int i = 1; i < 5; i++) {
                int x = x_pixels / i;
                for(int j = 1; j < 5; j++) {
                    int y = y_pixels / j;
                    int r = img.getPixelRed(x,y);
                    int g = img.getPixelGreen(x,y);
                    int b = img.getPixelBlue(x,y);
                    hash = (hash * 31) ^ (r^g^b);
                }
            }
        }
    }
    

    This sort of "incomplete hash" will allow you identify possible identities, and then you can do the expensive, full comparison sparingly as required.

    Expand the incomplete hash as necessary.

提交回复
热议问题