Skip to content

Assignment #1 – playing with color channels

September 23, 2010

This is the result of the assignment #1 for Dr. Ramesh Raskar’s Computational Photography Course at MIT. The goal is to take pictures of a subject by using different light sources and combining them programmatically. For this assignment, we were encouraged to use our own cameras and the programming platform of our choice.

Equipment and tools

I used a Nikon D3000, with the original 18mm-55mm (F3.5-F5.6) lens set attached, and manually controlling all camera parameters. For the programming part, I chose to use Processing, an open source language for media visualization and manipulation.

Experiment description and setup

All photographs were taken with a fixed camera mount, ISO 200 sensitivity, focal length of 28mm, F4 aperture and 1/30s shutter speed. The room was almost completely dark, so I ignored ambient light for the chosen aperture and shutter speed values (some controversy and more comments on this later).

I tried to reproduce the results obtained by Paul Haeberli, also using two separate light sources around the subject, and taking a picture with each one of them turned on respectively. Taking advantage of the linearity of light, the two photographs can be combined to achieve a result similar to that of the reference picture below, taken with both the lights turned on:

Two lights turned on (reference)

Now, these are the individual photographs for each light source:

Left light source turned on

Right light source turned on


To simulate the reference picture (both light sources turned on), I added the values for each color channel of both the input images. The image below shows the result of this operation:

Simulated full light (sum of source images)

The brightness of the simulated full light image is a bit higher than the desired result, probably because of some post exposure processing at the camera for the dynamic range. This may also be an effect of ambient light being added twice, but I took control pictures without any of the lights, and all pixels were absolutely black with the camera parameters used for the photos.

To avoid this in future experiments, I’ll take RAW photographs straight from the camera, without any post-processing. However, the achieved result is still quite convincing as natural lighting.

Another option is to use color masks for each original image, simulating the effect of light sources of different colors. By doing this, very interesting light effects can be achieved, such as those shown by the next images:

Blue channel from left and Red channel from right images

Full Red channel plus some Blue and Green from right image only

Interactive version of the experiment

By using Processing, I chose to make the combination of color channels an interactive application. It wasn’t possible to publish the resulting applet here because of some security restrictions of my hosting website, but I posted it at my other website:

The full source code for the application can also be downloaded from the above link. The following code snippet is the important part, where I combine the channels based on the position of the mouse, relative to the app window:

for(int i=0; i < out.pixels.length; i++) {

 // original colors from the original pictures
 color c1 = img1.pixels[i];
 color c2 = img2.pixels[i];

 // calculating the amount of each color channel to use from each image
 float rightR = red(c2)*rightIntensity;
 float rightG = green(c2)*normalizedY*rightIntensity;
 float rightB = blue(c2)*normalizedY*rightIntensity;

 float leftR = red(c1)*normalizedY*leftIntensity;
 float leftG = green(c1)*normalizedY*leftIntensity;
 float leftB = blue(c1)*leftIntensity;

 // filling the output by adding the calculated color channels from both sides
 out.pixels[i] = color( leftR+rightR , leftG+rightG, leftB+rightB, 255);

At line 17, one can see that after applying the color mask for each side, the resulting pixel color is just the channel-wise sum of the left and right pixels. The full source code contains comments that are useful to understand the implementation details, and the original images can be directly downloaded from this post for your own reproducibility check.

Other fun experiments with color channels

The assignment consisted of using our own camera and experimenting with exposure parameters and different light setups, and then using a software (for non-engineers) or programming language to play with the color channels of the images acquired.

The first experiment I did was taking two pictures with different apertures, and experimenting with the blending of color channels and try to create simple glow effects. The source images are shown bellow:

Large aperture: 35mm F1.8

Small aperture: 35mm F8.0

Some of the results are shown below:

Blue glow

Purple back, Green detail

The kernel source code for the result achieved above is this:

for(int i=0; i < out.pixels.length; i++) {

 // original pixels from the pictures
 color c1 = img1.pixels[i];
 color c2 = img2.pixels[i];

 // interpolation of the red and blue channels, based on mouse location
 float r = map(mouseX, 0, width, red(c1), red(c2));
 float b = map(mouseY, 0, height, blue(c1), blue(c2));
 float g = map(mouseY, 0, height, green(c1), green(c2));

 out.pixels[i] = color( g , (r+b)/2, g, 255);

Life on Mars

Finally, I also used a picture I found on the internet to play with its color channels. I liked the result of using the green channel from the picture of a forest as the red channel, and diminishing the others. The result is shown bellow:


(Plant) Life on Mars?

I’ll keep posting my assignments here at the blog, as long as they are not part of a research project.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: