Project Report

Procedure

In this project, I first took 13 pictures with different explosion times. Then I developed a program in java to generate the g(Z) function for R, G, and B from the 13 photos, and then saved them as txt files. Then I developed a C++ program to read the g functions, and use the equation:

to recover the radiance for each pixel and save them as a hdr file. I wasted much time (at least 5 hours) on compiling the C++ file in VC8, but it failed all the time. I found even the given sample could not get passed. The line where got trouble is:

gil::write(result, "c:\\766\\result.hdr");

Finally, I used g++ compiler under mingw to generate the executable file succefully. The central parts to get the hdr file are mainly in the java file:

1. to get sample points (7*7=49) evenly from each image.

private int[][] getSamplePoints(){
int[][] rtn=new int[49][13];
int xstep=width/8;
int ystep=height/8;
for(int i=1;i<8;i++)
for(int j=1;j<8;j++)
for(int k=0;k<13;k++){
rtn[(i-1)*7+j-1][k]=z(i*xstep,j*ystep,k); //get the RGB value for the sample
//point[(i-1)*7+j-1]
}
return rtn;
}

2. The most important part of this project is to generate the function g(Z). In this program, to solve the AX=b, I imported a java package called Jama, which can be found by searching google.

private double[] g(int[][] samples){
double[][] A=new double[samples.length*samples[0].length+255][256+samples.length];
double[] ba=new double[samples.length*samples[0].length+255];
int k=0;
for(int i=0;i<samples.length;i++)
for(int j=0;j<samples[0].length;j++){
double wij=w(samples[i][j]+1);
A[k][samples[i][j]]=wij;
A[k][256+i]=-wij;
ba[k]=wij*b[j];
k++;
}
A[k][128]=1;
k++;

for(int i=0;i<254;i++){
A[k][i]=lamda*w(i+1);
A[k][i+1]=-2*A[k][i];
A[k][i+2]=A[k][i];
k++;
}
Matrix rightSide=new Matrix(ba,ba.length);
Matrix leftSide=new Matrix(A);
LUDecomposition sv=new LUDecomposition(leftSide);
Matrix result=sv.solve(rightSide);
double[] rtn=new double[256];
for(int i=0;i<256;i++){
rtn[i]=result.get(i,0);
}
return rtn;
}

3. With g(Z) for R,G, and B, I used following code to calculate the radiance for each pixel:

gil::FloatImage3 result(width, height);
result.fill(gil::Float3(0, 0, 0));
for(int i=0;i<640;i++){
for(int j=0;j<426;j++){
double tmp1[3]={0,0,0},tmp2[3]={0,0,0};
for(int k=0;k<13;k++){
tmp1[0]+=weight(bi[k](i,j)[0])*(gr[bi[k](i,j)[0]]-b[k]);
tmp2[0]+=weight(bi[k](i,j)[0]);

tmp1[1]+=weight(bi[k](i,j)[1])*(gg[bi[k](i,j)[1]]-b[k]);
tmp2[1]+=weight(bi[k](i,j)[1]);

tmp1[2]+=weight(bi[k](i,j)[2])*(gb[bi[k](i,j)[2]]-b[k]);
tmp2[2]+=weight(bi[k](i,j)[2]);
}

result(i,j)[0]=exp(tmp1[0]/tmp2[0]);
result(i,j)[1]=exp(tmp1[1]/tmp2[1]);
result(i,j)[2]=exp(tmp1[2]/tmp2[2]);
}
}
gil::write(result, "c:\\766\\result.hdr");
return 0;

After generating the “result.hdr” file, I imported it to HDRShop and used the plugin to created a toned map, “tone.jpg”.

The file check list:

1 to 13.jpg ------------ photos

Result.hdr ------------ radiance map

Tone.jpg -------------- toned image

HDR.java -------------- java source file to calculate g(Z) and save them to files.

r.txt, g.txt, b.txt ------- g(Z) files, the number on line I is g(i)

main.cpp ------------- use g(Z) to recover radiance for pixels and save them to .hdr file

main.exe ------------- executable file generated by g++ in mingwa

Results

High Explosion Photo

 

Low Explosion Photo

Toned HDR