A C++ to show image contrast (power law 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];
float gamma=0;
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);
cout<<“enter the value for power factor: “;
cin>>gamma;
while(!in.eof())
{
in.read((char*) (&pixel),sizeof(pixel));
out1<<“ORIGINAL : “<<(int)pixel.r<<” , “<<(int)pixel.g<<” , “<<(int)pixel.b<<endl;
pixel.r=L*pow(pixel.r,gamma);
pixel.g=L*pow(pixel.g,gamma);
pixel.b=L*pow(pixel.b,gamma);
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();
}