Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Critique my SSD implementation: is it correct?

I have implemented sum of squared differences in C++. Is my code correct, can it be improved for 3 channel images?

Also I have one important question; what is the difference between the Sum of Squared Errors, Sum of Squared Differences and Mean Squared Error? Are they different names for the same thing or are they used for different applications?

Are there better algorithms that give me a measure of the difference between 2 images?

int calcSSD( Mat& img1,  Mat& img2) const {
    int sum = 0;
    int r, c;
    uchar* i1Ptr, *i2Ptr;

    for (r = 0; r < img1.rows; ++r) {
        i1Ptr = img1.ptr<uchar>(r);
        i2Ptr = img2.ptr<uchar>(r);

        for (c = 0; c < img1.cols; ++c) {
            int diff = i1Ptr[c] - i2Ptr[c];
            sum += diff * diff;
        }
    }

    return sum;
}

Critique my SSD implementation: is it correct?

I have implemented sum of squared differences in C++. Is my code correct, can it be improved for 3 channel images?

Also I have one important question; what is the difference between the Sum of Squared Errors, Sum of Squared Differences and Mean Squared Error? Are they different names for the same thing or are they used for different applications?

Are there better algorithms that give me a measure of the difference between 2 images?images? My understanding is there is Variance (std deviation squared) which can also measure the difference between 2 images however it is less better? than SSD. However SSD isn't that great either I hear.

int calcSSD( Mat& img1,  Mat& img2) const {
    int sum = 0;
    int r, c;
    uchar* i1Ptr, *i2Ptr;

    for (r = 0; r < img1.rows; ++r) {
        i1Ptr = img1.ptr<uchar>(r);
        i2Ptr = img2.ptr<uchar>(r);

        for (c = 0; c < img1.cols; ++c) {
            int diff = i1Ptr[c] - i2Ptr[c];
            sum += diff * diff;
        }
    }

    return sum;
}