A C++ to show Image Subtraction


#include<iostream>
#include<conio.h>
#include<math.h>
#include<fstream>
using namespace std;
struct pix{
unsigned char r,g,b;}pixel,pixel1,pixel2;
intbi,L=255;
char Header[54];
inttmp;
ifstream in;
ofstream out1,out2,out;
int main(){
char infile1[]=”d:\\lena.bmp”;
char infile2[]=”d:\\bf.bmp”;
char outfile1[]=”d:\\lena2.bmp”;
char outfile2[]=”d:\\bf2.bmp”;
char imdata1[]=”d:\\imdata1.dat”;
char imdata2[]=”d:\\imdata2.dat”;
in.open(infile1,ios::in|ios::binary);
in.read((char*)(&Header),sizeof(Header));
out.open(outfile1,ios::out|ios::binary);
out.write((char*)(&Header),sizeof(Header));
in.open(infile2,ios::in|ios::binary);
in.read((char*)(&Header),sizeof(Header));
out.open(outfile2,ios::out|ios::binary);
out.write((char*)(&Header),sizeof(Header));
out1.open(imdata1,ios::out);
out2.open(imdata2,ios::out);
while(!in.eof())
{
pixel1.r=pixel1.r-pixel2.r;
pixel1.g=pixel1.g-pixel2.g;
pixel1.b=pixel1.b-pixel2.b;
out.write((char*)(&pixel1),sizeof(pixel1));
}
in.close();
out.close();
out1.close();
getch();
}