Using Objective-C, is there any way to compare two images and get a % difference value returned?

后端 未结 4 694
别那么骄傲
别那么骄傲 2021-01-15 11:31

Using Objective-C, is there any way to compare two images and get a % difference value returned?

For example, one image will have and X in it. Another image will ha

4条回答
  •  攒了一身酷
    2021-01-15 11:51

    You are going to have to think quite carefully about what kind of differences you care about.

    Doing a pixel-by-pixel comparison of identically sized images won't be too hard. Assign an error value to each pixel, and then somehow combine the differences to produce a single figure.

    Scaling one or other image if they start off different sizes but the same aspect ratio is also fairly simple.

    However, the edge cases get tricky very quickly. For example, what happens if your two X characters are displaced, so one is on the left of the image, and the other on the right? Should these be detected as "similar" somehow?

    Also, when comparing H to X, you want a high score - but how then would you rank an X against a colour picture of a butterfly? Even higher, presumably, but how much higher?

    Some kind of learning neural network might help you, where you work out what values you would assign yourself to some sample comparisons, then train the network to return those values for your sample images. But that isn't trivial to code.

    If your comparison requirements are simpler - for example, you are doing some kind of OCR equivalent, and you know that your inputs are likely to be monochromatic characters, then there are other tricks you can use - but the appropriate ones will depend on what you are trying to achieve.

提交回复
热议问题