Homework 1 Due Friday, Sept. 29 at 9 a.m. Part I: Basic Matlab Write a script called part1.m the performs and displays the results of the following: 1.) Make a 10x10 matrix and fill in with the numbers 1-100 column-wise (without the use of for loops!). I.E. the first column is 1,2,3,4... the second is 11,12,13,14 .... and so on. 2.) Do the same as question 1 now row-wise. 3.) Using the matrix from question 1, create a new matrix half the size of the original containing the odd columns and the even rows. 4.) Using the matrix from question 1 create a Boolean matrix (0,1) indicating the elements greater than 50. 5.) Solve this system: X + Y + Z = 2; 2*X + Y = 3; Y + Z = 5; This should be done in one short line using matrixes and built-in operators. Part II: Basic Image manipulations Write a script called part2.m that performs and displays the results of the following: For 1 through 4 use the built-in image "peppers.png" to test. 1.) Flip an image upside-down. 2.) Take a color image and make it grayscale using equal weights of R, G, and B. 3.) Swap the R and B color channels of an RGB image such that R is now B and vise versa. 4.) Rotate an image 90 degrees counter-clockwise. 5.) Create a 10 by 10 by 3 "image" using the matrix from part 1 question 1. Now, look at the "reshape" function in matlab using the help command. Use reshape to a) convert this matrix to a 100 by 3 matrix. b) convert the 100 by 3 matrix back to the original 10 by 10 by 3 structure. Part III: Image Processing Here are three more involved problems, one written and two programming. The written problem should be handed in in class. The programming problems should be developed as specified. For each you must submit a script that executes the specified functions on the specified data. *DO NOT SUBMIT THE SOURCE IMAGES WITH YOUR ASSIGNMENT*. These scripts should be called problem2.m and problem3.m and problem4.m. 1. (Written) For a given Sony camera, the transformation from YCbCr format to RGB format is given as R = 1.4022Cr + Y G = Y - 0.7144Cr - 0.3457Cb B = 1.7710Cb + Y The data coming from the camera is in YUV form which differs only in that Cb = U-0.5 and Cr = V-0.5 (here I have assumed the images have been converted to the range of 0 to 1). a) What is the transformation from RGB to YCbCr? b) What is the transformation from RGB to YUV? c) What is the YUV equivalent of a gray image where R=G=B=x for some x in [0,1]? c) What are the minimum and maximum YUV values, assuming RGB values range in the unit cube? d) What are minimum and maximum RGB values given that YUV ranges within the unit cube? e) Given this, is it a good idea to convert YUV to RGB before processing? Suggest what sort of problems might arise. 2. Create a simple image segmentation method using color. The idea is as follows. 1. Choose a sample region in an RGB image that has the color of interest (e.g. bricks on a building or skin tone). 2. Convert it to YUV format using the transformation you developed above (do *not* use the pre-defined matlab functions!). 3. Compute the range of U and V (which carry the color information) in the patch of interest. A simple way to do this is to find the minimum and maximum values of U and V. Another (generally better) way is to compute the mean and standard deviation, and create an interval that is about 2 standard deviations about the mean. 4. Now, given a new image, a) convert it to YUV b) create a new image where every matching pixel (i.e. a pixel with U and V in the interval computed above) is assigned a 1, and every other pixel is 0. Write two functions to do this: [uInterval,vInterval] = LearnUV(RGBPatchIn); matchimage = SegmentYUV(RGBImageIn, uInterval, vInterval); For grading purposes, apply these functions to the built-in image "peppers.png" with the goal of getting the red pepper in the foreground. Show the resulting segmentation using imshow. Extra Credit (5 pts): Perform multiple segmentations of the different peppers and show the results as one image where each segmented region is assigned a constant color (e.g. red peppers are light red, chile peppers are dark red, etc.) 3. You are to implement a simple renderer using infinite point light sources and a given BRDF. Your function should operate as follows. It should accept a 2-dimensional array of surface normals (as an n by m by 3 matlab matrix), the direction of the light source, and a integer indicating what type of BRDF to use. It should return an image that shows the shaded surface. More specifically, write: imOut = Shade(normalsIn, lightSourceDir, BRDFType) where normalsIn is an n by m by 3 array of normals lightSourceDir is a 3 by 1 unit vector BRDFType is an integer with: 0 indicates a mirror surface 1 indicates a Lambertian surface 2 indicates Phong's model using cosine to the 4th power 3 indicates the Lambertian plus Phong's model, each contributing equally We will supply two files of test normals as "testnormal1.mat" and "testnormal2.mat" Use the light source direction (.2,.1,.975). Your submission should include a script that executes and displays the results of the function above on both test cases using all four types of shading. EXTRA CREDIT: You can get extra credit (5 pts) by allowing multiple light sources and superimposing the results. CS 461 ONLY 4. Implement a image resampling algorithm that reduces the size of an RGB image by 2. The algorithm should: 1. Convolve each band of the images using a 5x5 Gaussian filter with a sigma of 1. 2. Sample every other pixel in the resulting image (in both rows and columns) producing a 1/2 size image. Your functional form should be: newImage = Resample(inputImage); Call this function on "peppers.png" and display the result.