The required data file, mer_img.mat, located in the data directory of lab data archive, has a single variable (mer_img) which contains a set of six 720 x 720 images taken at different focus positions (the distance from the target ranges from 6.4 cm to 4.9 cm). All these images are aligned/co-registered to within a pixel. Your goal is to produce a "super focused" image (Fig. 1). This is done using variance calculations - where the image is in focus, the variance is large and where it is blurry and out of focus, the variance is low. As before, you can find the mer_img.mat in the data directory of the lab archive.
Fig. 1 - An example of a "Super focused" image
The lab report (lab3_soln.txt), which you will turn in, can be found in the REPORT direcory of the lab data archive. As with all other labs, please remember to turn in your Matlab workbook as well. Put the copies of both into the LAB9 directory of your area on datafarm: datafarm.astro.cornell.edu:/data/Courses/A3310/FA15/netid/LAB9. Remember that you get credit only for the files that you put in that directory. Each question in the lab is explained in more detail below.
1. Display the individual images within the data cub and scale/stretch them using the techinques described in the MATLAB Image Tutorial. You can create 2D variables from the 3D array by using the command img = mer_img(:,:,i) , where i refers to backplanes 1 through 6.2. Derive some statistics like mean and standard deviation on selected areas within the images first using loops in IDL and calculating the statistics "the hard way" (for example, sum all the pixels in a box using a loop and then divide the sum by the number of pixels to get the mean), and only after knowing how to do it the hard way then using canned routines like moment.pro to do it "the easy way" in IDL.
Select two areas of arbitrary size within the images, and call them area1 and area2. Show the areas on the image of byte_mer_img[*,*,1] using the plots and xyouts commands (Fig. 2). Calculate the mean and standard deviation for each area using "the hard way." Using canned routines like moment.pro, find again the mean and standard deviation for comparison.
3. Test that the image with the highest variance is the best focused. Pick any 40 x40 pixel box and calculate the variances. Does the image you feel most focus have the largest variance? The following is an example you can use for display purposes:IDL> area3 = mer_img[320:359, 320:359, *]4. Calculate the variance of a 40 x 40 pixel box at a time across the entire image (see Fig. 3) and select the subregion with the highest variance from each 40 x 40 box. Then, put all these subregions together into a new image that is a combination of the best focused parts of all the input images. This process is called focal sectioning and this "super focused image" should look much nicer than any of the individual images because the surface has 3-D topography with some parts in better focus than others for any single image. This is essentially what the MER team does with MI data coming back from Mars. Please save your "super focused image" in a TIFF file called "my_superimage.tiff" and save the Matlab variable you created to store the indices of highest variances in file calld findex.mat.
IDL> byte_area3 = byte_mer_img[320:359, 320:359, *]
IDL> window, /free, xs=200*6, ys=200
IDL> for n=0, 5 do tv, congrid(byte_area3[*,*,n], 200, 200), n*200, 0
IDL> ; Now calculate the variance and see if you agree that the best
IDL> ; focused image has the highest variance value.