Michael Timbrook
Michael Timbrook

Reputation: 63

locating a change between two images

I have two images that are similar, but one has a additional change on it. What I need to be able to do is locate the change between the two images. Both images have white backgrounds and the change is a line being draw. I don't need anything as complex as openCV I'm looking for a "simple" solution in c or c++.

Upvotes: 1

Views: 185

Answers (3)

DanielHsH
DanielHsH

Reputation: 4453

You can use memcmp() (Ansi C function to compare 2 memory blocks, much like strcmp()). Just activate it on the Arrays of pixels and it returns whether they are identical or not. You can add a little tweak that you get as result the pointer to the memory block where the first change occurred. This will give you a pointer to the first pixel. You can than just go along its neighbors to find all the non white pixels (representing your line).

bool AreImagesDifferent(const char*Im1, const char* Im2, const int size){
    return memcmp(Im1,Im2,size);
}

const char* getFirstDifferentPixel(const char*Im1, const char* Im2, const int size){
    const char* Im1end = Im1+size;
    for (;Im1<Im1end; Im1++, Im2++){
        if ((*Im1)!=(*Im2))
            return Im1;
    }
}

Upvotes: 0

Diego Catalano
Diego Catalano

Reputation: 689

If you just want to show the differences, so you can use the code below.

FastBitmap original = new FastBitmap(bitmap);
FastBitmap overlay = new FastBitmap(processedBitmap);

//Subtract the original with overlay and just see the differences.
Subtract sub = new Subtract(overlay);
sub.applyInPlace(original);

// Show the results
JOptionPane.showMessageDialog(null, original.toIcon());

For compare two images, you can use ObjectiveFideliy class in Catalano Framework. Catalano Framework is in Java, so you can port this class in another LGPL project.

https://code.google.com/p/catalano-framework/

FastBitmap original = new FastBitmap(bitmap);
FastBitmap reconstructed = new FastBitmap(processedBitmap);

ObjectiveFidelity of = new ObjectiveFidelity(original, reconstructed);

int error = of.getTotalError();
double errorRMS = of.getErrorRMS();
double snr = of.getSignalToNoiseRatioRMS();

//Show the results

Disclaimer: I am the author of this framework, but I thought this would help.

Upvotes: 2

Drew Noakes
Drew Noakes

Reputation: 311315

Your description leaves me with a few unanswered questions. It would be good to see some example before/after images.

However at the face of it, assuming you just want to find the parameters of the added line, it may be enough to convert the frames to grey-scale, subtract them from one another, segment the result to black & white and then perform line segment detection.

If the resulting image only contains one straight line segment, then it might be enough to find the bounding box around the remaining pixels, with a simple check to determine which of the two possible line segments you have.

However it would probably be simpler to use one of the Hough Transform methods provided by OpenCV.

Upvotes: 0

Related Questions