Hacker News new | past | comments | ask | show | jobs | submit login

An image diff is pretty simple. If you represent an image as a vector of values, diffing just means subtracting two vectors abs(A-B) and writing out the result into a new image.

    template<typename T>
    T diff(const T& a, const T& b)
    {
        auto sz = std::min(a.size(), b.size());
        T img(sz, 1);
        for (auto i = 0; i < sz; ++i) {
            img[i] = std::fabs(a[i] - b[i]);
        }
        return img;
    }
    // usage
    vector<float> a, b;
    a.emplace_back(1.0); b.emplace_back(0.5);
    a.emplace_back(1.0); b.emplace_back(0.0);
    a.emplace_back(0.5); b.emplace_back(0.5);

    auto img = diff(a, b);
    write_exr("filename.exr", img);
The resulting image ends up with 0.0 black in pixels that are identical and non-zero values in the pixels that differ. When you look at it in an image viewer only the portions that differ will be visible.

You often need to crank up the gain when the differences are small.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: