Assignment 1, Part 2: Optics bootcamp

From Course Wiki
Jump to: navigation, search
20.309: Biological Instrumentation and Measurement

ImageBar 774.jpg


This is Part 2 of Assignment 1.

Lab orientation

Welcome to the '309 Lab. Before you get started, take a little time to learn your way around.

The 20.309 lab contains more than 15,000 optical, mechanical, and electronic components that you will use for your lab work throughout the semester. To the untrained eye, they all look pretty much alike. (For the final exam, you will be required to identify various components while blindfolded.)

You can waste a lot of time looking for things, so it's important to learn your way around. The floor plan below shows the layout of rooms 16-352 and 16-336. When you get to the lab, take a walk around, especially to the center cabinet, west cabinet, and west drawers. Go everywhere and check things out for a few minutes. Read the time machine poster between the cable rake and the Nikon microscope. Discover the stunning Studley tool chest poster near the east parts cabinet.

Map of the 20.309 lab.

Note that Station 11 is now the "Instructor Station," and the previously labeled instructor station is now "Station 5" and available for your use. There is also a cool STORM microscope that some 20.345 students built located at Station 3.

See! Wasn't that a worthwhile journey?


Exercise 1: measure focal length of lenses

Make your way to the lens measuring station. Measure the focal length of the four lenses marked A, B, C, and D located nearby.

Pencil.png Report the focal length you measured for each lens A through D.


Exercise 2: imaging with a lens

Imaging apparatus with illuminator, object, lens, and CCD camera mounted with cage rods and optical posts.

Make your way to the pre-assembled lens setup that looks like the thing on the right. You will be using similar parts to build your microscope, so take some time to look at the construction of the apparatus. Try to identify the illuminator, the object (a glass slide with a precision micro ruler pattern on it), the imaging lens (that has a 35mm focal length), and the camera (where the image will be captured). All of the components are mounted in an optical cage made out of cage rods and cage plates. The cage plates are held up by optical posts inserted into post holders that are mounted on an optical table. You will be able to adjust the positions of the object and lens by sliding them along the cage rods.

In this part of the lab, you are going to use this simple imaging system with one lens to compare measurements of the object distance $ S_o $, image distance $ S_i $, and magnification $ M $ with the values predicted by the lens makers' formula:

$ {1 \over S_o} + {1 \over S_i} = {1 \over f} $
$ M = {h_i \over h_o} = {S_i \over S_o} $

Measure stuff

  • Start with the lens at about 2$ f $ = 70 mm from the camera and the object.
  • If the LED is not already on, check that the power supply current is set to a number below 0.5 A, and press the OUTPUT button. You should see red light coming from the LED
  • Launch MATLAB
  • In the command window, start the image acquisition tool by running the following two lines of code:
foo = UsefulImageAcquisition;
foo.Initialize
  • After the Image Acquisition window appears, click the Start Preview button.
  • Set the exposure time
    • In the lower right side of the window, edit Exposure to obtain a well-exposed image. The units are in microseconds.
    • You can keep the default values for the Gain, Frame Rate, and Number of Frames for now.
    • You may also need to adjust the current in your LED. DO NOT EXCEED 0.5 A.
  • Move the lens and the object to produce a focused image.
Figure 1: Side view of the Matna G-032 camera. The detector is recessed inside the body of the camera, 17.5 mm from the end of the housing. The detector comprises an array of 656x492 square pixels, 7.4 μm on a side. The active area of the detector is 4.85 mm (H) × 3.64 mm with a diagonal measurement of 6 mm. The manual for the camera is available online here.
  • When everything is set, measure the distance $ S_o $ from the target object to the lens and the distance $ S_i $ from the lens to the camera detector.
    • Figure 1 shows the location of the detector inside of the camera.
  • In the image acquisition window, press Acquire (lower right).
  • Save your image to the MATLAB workspace
    • Your image is saved in foo.ImageData but it will be overwritten next time you acquire an image. You will need to copy the image into a new variable before continuing.
    • Choose a descriptive variable name such as Image1 and save your data to it:
Image1 = foo.ImageData;
  • Compute the magnification.
    • In the MATLAB Command Window, display your image by typing figure; imagesc( Image1 ); colormap gray;
    • Go back to the command window (by pressing ALT-TAB on the keyboard or selecting it from the task bar) and type imdistline.
    • Use the line to measure a feature of known size on the micro ruler
      • The small tick marks are 10 μm apart
      • The large tick marks are 100 μm apart
      • The whole pattern is 1 mm long
      • The pixel size is 7.4 μm
  • Record $ S_o, S_i, h_o, h_i, $, and calculate the magnification M.
  • Repeat the procedure for at least 4 image and object distances. Do an equal number with the target placed at less than and greater than 2$ f $ from the lens.
  • Using MATLAB, or your other favorite plotting software, make a plot of $ {1 \over S_i} $ as a function of $ {1 \over f} - {1 \over S_o} $, and $ {h_i \over h_o} $ as a function of $ {S_i \over S_o} $


Pencil.png # In a table, report the values you measured for $ S_o, S_i, h_o, h_i, $ and $ M $.
  1. Plot $ {1 \over S_i} $ as a function of $ {1 \over f} - {1 \over S_o} $
  2. Plot $ {h_i \over h_o} $ as a function of $ {S_i \over S_o} $
  3. Do the relationships between $ M $, $ S_o $, and $ S_i $ match the theory?
  4. List the sources of error affected your measurements?


Exercise 3: noise in images

Almost all measurements of the physical world suffer from some kind of noise. Capturing an image involves measuring light intensity at numerous locations in space. The Manta G-032 CCD cameras in the lab measure about 320,000 unique locations for each image. Every one of those measurements is subject to noise. In this part of the lab, you will quantify the random noise in images made with the Manta cameras, which are the same ones that you will use in the microscopy lab.

Figure 2: Noise measurement experiment. The cameras in the lab produce images with 656 horizontal by 492 vertical picture elements, or pixels. At regular intervals, the camera measures the intensity of light falling on each pixel and returns an array of pixel values $ P_{x,y}[t] $. The pixel values are in units of analog-digital units (ADU).

So what is noise in an image? Imagine that you pointed a camera at a perfectly static scene — nothing at all is changing. Then you made a movie of, say, 100 frames without moving the camera or anything in the scene or changing the lighting at all. In this ideal scenario, you might expect that every frame of the movie would be exactly the same as all the others. Figure 2 depicts a dataset generated by this thought experiment as a mathematical function $ P_{x,y}[t] $. If there is no noise at all, the numerical value of each pixel in all 100 of the images would be the same in every frame:

$ P_{x,y}[t]=P_{x,y}[0] $,

where $ P_{x,y}[t] $ is the the pixel value reported by the camera of at pixel $ x,y $ in the frame that was captured at time $ t $. The square braces indicated that $ P_{x,y} $ is a discrete-time function. It is only defined at certain values of time $ t=n\tau $, where $ n $ is the frame number and $ \tau $ is the interval between frame captures. $ \tau $ is equal to the inverse of the frame rate, which is the frequency at which the images were captured.

You probably can guess that IRL, the frames will not be perfectly identical. We will talk in class about why this is so. For now, let's just measure the phenomenon and see what we get. A good way to make the measurement is to go ahead and actually do our thought experiment: make a 100-frame movie of a static scene and then see how much each pixel varies over the course of the movie. Any variation in a particular pixel's value over time must be caused by random noise of one kind or another. Simple enough.

(An alternate way to do this experiment would be to simultaneously capture the same image in 100 identical, parallel universes. This will obviously reduce the time needed to acquire the data. You are welcome to use this alternative approach in the lab.)

Figure 3: Pixel variance versus mean mystery plot. Can you stand the suspense?

We need a quantitative measure of noise. Variance is a good, simple metric that specifies exactly how unsteady a quantity is, so let's use that. In case it's been a while, variance is defined as $ \operatorname{Var}(P)=\langle(P-\bar{P})^2\rangle $.

So here's the plan:

  • Point your camera at a static scene that has a range of light intensities from bright to dark.
  • Make a movie.
  • Compute the variance of each pixel over time.
  • Make a scatter plot of each pixel's variance on the vertical axis versus its mean value on the horizontal axis, as shown in Figure 3.

Plotting the data this way will reveal whether or not the quantity of noise depends on intensity. With zero noise, the plot would be a horizontal line on the axis. But you know that's not going to happen. How do you think the plot will look?

Set up the scene and adjust the exposure time

The first step is to set up a scene with a large range of intensities. It's also important to measure roughly the same number of pixels for each intensity value. How can we diagnose the intensity range and number of pixels at each intensity? Enter the histogram. This useful plot will tell you the distribution of pixel intensities in your image. In our case, we will use a histogram to help us maximize the range and even out the number of pixels at each intensity.

For this part of the lab, you will change your experimental set up to obtain an image with an approximately uniform intensity histogram. Lucky for you, the UsefulImageAcquisition tool displays the intensity histogram of your image in the top right corner of the Image Acquisition window.

Figure 4: Example intensity histogram with approximately uniform distribution of pixel values over the range 10-2000 ADU.
  1. In the Image Acquisition window, click Start Preview.
  2. Set the Exposure property to 100.
  3. Adjust your experiment until your histogram is a roughly uniform distribution of pixel values. Figure 4 shows a reasonably nice histogram.
    • A convenient way to get a uniform distribution of pixel values is to slide the object and imaging lens up close to the camera, then slide the illuminator lens forward until you see a bright circle on a dark background.
    • Try to get a broad range of pixel values between about 10 and 2000. Try not to have any pixels that are over-exposed (i.e. your max pixel value is 4095 and you see a red 'x' on the preview histogram)
    • You may need to adjust the exposure time and LED current (but remember not to exceed 0.5 A!).

If you ever want to plot your own histogram from a saved image, here is some example MATLAB code to do just that:

[ counts, bins ] = hist( double( squeeze( exposureTest(:) ) ), 100);
semilogy( bins, counts, 'LineWidth', 3 )
xlabel( 'Intensity (ADU)' )
ylabel( 'Counts' )
title( 'Image Intensity Histogram' )

If you're curious, the hist MATLAB function takes in the intensities you measured in the image exposureTest, divides the maximum range of intensities into a given number of equally spaced intervals or 'bins' (100 in this case), then counts the number of pixels which fall into each bin.

Acquire movie and plot results

Once you are set up correctly, make a movie and plot the results using the procedure below:

  1. Capture a 100 frame movie.
    • Go to the Image Acquisition window and change the Number of Frames property from 1 to 100.
    • Press Acquire.
    • Switch to the MATLAB console window. (Press alt-tab until the console appears.)
    • Save the movie to a variable called noiseMovie by typing: noiseMovie = foo.ImageData;
  2. Plot pixel variance versus mean.
    • Use the code below to make your plot.
pixelMean = mean( double( squeeze( noiseMovie) ), 3 );
pixelVariance = var( double( squeeze( noiseMovie) ), 0, 3 );
[counts, binValues, binIndexes ] = histcounts( pixelMean(:), 250 );
binnedVariances = accumarray( binIndexes(:), pixelVariance(:), [], @mean );
binnedMeans = accumarray( binIndexes(:), pixelMean(:), [], @mean );
figure
loglog( pixelMean(:), pixelVariance(:), 'x' );
hold on
loglog( binnedMeans, binnedVariances, 'LineWidth', 3 )
xlabel( 'Mean (ADU)' )
ylabel( 'Variance (ADU^2)')
title( 'Image Noise Versus Intensity' )

(Need a refresher on loglog plots? Click here.)

Save your plot as a .png (on the plot, click on File -> Save As ->)


Pencil.png Turn in
  • Plot pixel variance vs. mean.
  • How does noise vary as a function of light intensity?
  • Did the plot look the way you expected?


When you're done, please slide the object and lenses back to where you found them at the start of the lab exercise. Make sure you have all the relevant plots and/or data saved, then clear the MATLAB workspace for the next group using the command clear all.

Navigation

Back to 20.309 Main Page