A C++ to show image brightness (log transformation function)


#include<iostream>
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<math.h>
using namespace std;
struct pix {
unsigned char b,g,r; }pixel;
int L=255;//L is set to highest intensity per byte
char Header[54];
ifstream in;
ofstream out,out1;
int main() {
char infile[]=”d:\\bf.bmp”;
char outfile[]=”d:\\bf-mod.bmp”;
char imdata[]=”d:\\imdata.dat”;
in.open(infile,ios::in|ios::binary);
in.read((char*)(&Header),sizeof(Header));
out.open(outfile,ios::out|ios::binary);
out.write((char*)(&Header),sizeof(Header));
out1.open(imdata,ios::out);
while(!in.eof()) {
in.read((char*) (&pixel),sizeof(pixel));
out1<<“ORIGINAL : “<<(int)pixel.r<<” , “<<(int)pixel.g<<” , “<<(int)pixel.b<<endl;
pixel.r=L*log(pixel.r+1);
pixel.g=L*log(pixel.g+1);
pixel.b=L*log(pixel.b+1);
out.write((char*) (&pixel),sizeof(pixel));
out1<<“MODIFIED : “<<(int)pixel.r<<” “<<(int)pixel.g<<” “<<(int)pixel.b<<endl;}
in.close();
out.close();
out1.close();
getch(); }