Snap.swift icon indicating copy to clipboard operation
Snap.swift copied to clipboard

Custom threshold

Open skyweb07 opened this issue 7 years ago • 4 comments
trafficstars

Allow passing a custom error threshold

skyweb07 avatar Nov 30 '17 12:11 skyweb07

Take a look into this https://en.wikipedia.org/wiki/Binary_space_partitioning , http://game-ai.gatech.edu/sites/default/files/documents/assignments/bsp.html

skyweb07 avatar Jan 18 '18 09:01 skyweb07

Also having this issue, CoreGraphics seems to render non-deterministic when it comes to anti aliasing, at least I get pixel values off +/- 1 or 2 with the exact same code.

Currently I use a custom compare operation via CIImage that might be a starting point, although it doesn't seem to be particularly fast: https://gist.github.com/ralfebert/4c69b264cd374c91d28ba6b54ab1062f

ralfebert avatar Feb 26 '18 21:02 ralfebert

mmm thanks for the code @ralfebert, I'll take a deeper look into this, seems that it's a little slow but I think we can speed it up a little, I'll try to hack something and come back with the results, thanks again!!

skyweb07 avatar Feb 27 '18 22:02 skyweb07

The quickest way seems to be just to compare the bytes manually:

    let d1 = referenceImageContext.data!
    let d2 = imageContext.data!
    for i in 0..<referenceImageSizeBytes {
        let b1 = d1.load(fromByteOffset: i, as: UInt8.self)
        let b2 = d2.load(fromByteOffset: i, as: UInt8.self)
        if b1 != b2 {
            let diff = abs(Int(b1) - Int(b2))
            if diff > tolerance {
                throw CompareError.notEquals
            }
        }
    }

Doesn't seem to be particularly slow...

ralfebert avatar Mar 02 '18 12:03 ralfebert