Sampling Techniques by James Bigler

Home ~ Back to cs6650 ~ Back to Code Pit ~ Class Web Site


Assignment

In graphics it is important to be able to estimate the value of the greatest of all functions: THE RENDERING EQUATION! This equation states how the light goes from the light sources, interacts with the scene, and ends up in our little camera.

To actually evaluate the function exactly is entirely too computationally expensive, so we generally turn to estimation techniques. I have implemented three general approaches. The first is Monte-Carlo integration. This is basically an average of the function everywhere. Take enough samples and BLAMMO you converge to the the solution. The main disadvantage to this is that the magic BLAMMO number is *really* *really* high for most images. Some of the numerical noise can be reduced by stratifying your samples, as in jittering or n-rooks (see some other sampling patters here).

Alternatively you could use a density estimation approach, where you try and collect samples where the value of the function is higher. The image is a direct result of the number of samples that ended up in a particular area (pixel in this case). The density function should be proportional to the function you are trying to estimate, or all bets are off.

The last method I've implemented in Metropolis. This is similar to density estimation where you count the number of samples in a given pixel, but you distribute the samples differently. Where in density estimation you evaluate directly the pixel location from the integral of the function, in metropolis you move the samples around. You start off with a set of nicely distributed samples and then selectively move them to another random location in the image with a probability proportional to the value of the function (if f(p1) > f(p2), accept transition of point p1 to p2 with probability f(p2)/f(p1), otherwise move). This seemed to work well, but there was no way of knowing if the image converged or not looking at it yourself.

Check out my images below

Analytic solution

analytic solution

MC Integration, 16 random samples

Random 16 samples

MC Integration, 16 stratified samples

stratified 16 samples

MC Integration, 100 random samples

Random 100 samples

MC Integration, 100 stratified samples

stratified 100 samples

MC Inegration, 100 random samples, bspline filter

bspline 100 samples

Density Estimation, 100 random samples per pixel on average

Density estimation
100 random samples

Density Estimation, 100 stratified samples per pixel on average

Density estimation
100 stratified samples

Metropolis, 100 random samples per pixel on average

Metropolis 100
random samples

Create several images of the following function:

double f(double x, double y, double kx, double ky, int nx, int ny) {
    return  0.5*(x/nx)*(1+cos( kx* x*x))*(y/ny)*(1+cos(ky*y*y));
}

where the image has nx by ny pixels and
on the coordinate system where (x,y) \in [0,nx] x [0,ny]

For all items except for number 5, use a box filter, i.e.,
color = INTEGRAL INTEGRAL f(x,y) dy dx

where the limits are (i,i+1) x (j,j+1)

create 9 images with (nx,ny) = (512,384) and kx=0.004 and ky=0.006:
0. Analytic solution
1. MC Integration, 16 random samples
2. MC Integration, 16 stratified samples
3. MC Integration, 100 random samples
4. MC Integration, 100 stratified samples
5. MC Inegration, 100 random samples, bspline filter
6. Density Estimation, 100 random samples per pixel on average
7. Density Estimation, 100 stratified samples per pixel on average
8. Metropolis, 100 random samples per pixel on average

For number 5, generate a random sample location as follows:
    x = i + 0.5
    y = j + 0.5
    for k = 0; k < 4; k++ 
         x += drand48()-0.5
         y += drand48()-0.5