Example for difference calculation of images: Takes two RGB input images and calculates the difference between them. Should be used for images that were taken from the same viewpoint with different aperture/exposure to visualize the difference in the two images. If the images are bigger than 1024x256 the difference for each channel will be visualized in a diagram as well.NOTE THAT the first image should be the brighter one! If you don't stick to this, the diff image might be black due to (prevented) underflows!
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/ImageUtils/ImageDraw.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[]) {
if (argc < 3) {
cout << "wrong parameter count!!" << endl << endl;
cout << "usage:" << endl;
cout << argv[0] << " " << "<brighter_image> <darker_image>" << endl;
return -1;
}
cout << "image 1 could not be loaded!" << endl;
return -1;
}
else {
cout << "image 1 loaded!" << endl;
}
cout << "image 2 could not be loaded!" << endl;
return -1;
}
else {
cout << "image 2 loaded!" << endl;
}
cout << "images loaded" << endl;
unsigned char *imDiffData = imDiff.GetImageData();
unsigned int offset = 0;
int diff = 0;
unsigned int gammaX, gammaY;
cout << "starting iteration..." << endl;
for (
unsigned int y = 0; y < im1.
GetHeight(); y++) {
for (
unsigned int x = 0; x < im1.
GetWidth(); x++) {
diff = (int)im1Data[offset] - (int)im2Data[offset]
+ (int)im1Data[offset+1] - (int)im2Data[offset+1]
+ (int)im1Data[offset+2] - (int)im2Data[offset+2];
diff /= 3;
diff = diff < 0 ? 0 : diff;
diff = diff > 255 ? 255 : diff;
imDiffData[offset] = (unsigned char)diff;
imDiffData[offset+1] = (unsigned char)diff;
imDiffData[offset+2] = (unsigned char)diff;
if (drawChannelDiffs) {
gammaX = (unsigned int)im1Data[offset];
gammaY = 256 - (unsigned int)im2Data[offset];
= 255;
gammaX = (unsigned int)im1Data[offset+1] + 256;
gammaY = 256 - (unsigned int)im2Data[offset+1];
= 255;
gammaX = (unsigned int)im1Data[offset+2] + 512;
gammaY = 256 - (unsigned int)im2Data[offset+2];
= 255;
gammaX = (unsigned int)im1Data[offset] + (unsigned int)im1Data[offset+1] + (unsigned int)im1Data[offset+2];
gammaX /= 3;
gammaX += 768;
gammaY = (unsigned int)im2Data[offset] + (unsigned int)im2Data[offset+1] + (unsigned int)im2Data[offset+2];
gammaY /= 3;
gammaY = 256 - gammaY;
imDiffData[offset] = 255;
imDiffData[offset + 1] = 255;
imDiffData[offset + 2] = 255;
}
}
}
cout << "done!" << endl;
return 0;
}