Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at www.peerinstruction4cs.org.
Which image results from the following code segment: >> im = imread('rainbow.jpg'); >> part = im(1:floor(end/2),1:end,:); >> imshow(part) a) c) C **Be sure to explain what”floor” means—this is likely first time they’ve seen it (a)(b) misc. distractors (c) Correct. Top half of the rows, all the columns. Emphasize that while there is a lot more text now in the three index locations (row,col,layer), we break it down by separating with the *commas* (d) Confuses row/col index b) d) e) None/other/error
Which image results from the following code segment: >> im = imread('rainbow.jpg'); >> part = im(1:floor(end/2),floor(end/2)+1:end,:); >> imshow(part) a) c) A Correct – Top half of the rows and right half of the columns. Students will wonder what the +1 is for—this is just so that 1:floor(end/2) and floor(end/2)+1:end select non-overlapping sets of rows or columns, as the case may be. This doesn’t matter so much for this question, but we did a homework assignment where it mattered. Confuses row/col index (d) arbitrary distractors b) d) e) None/other/error
Which image results from the following code segment: RGB color reference Which image results from the following code segment: >> im = imread('rainbow.jpg'); >> im(1:floor(end/2),1:floor(end/2),1) = 0; >> imshow(im) a) c) D Correct color, wrong location. Correct location, wrong color. Incorrect Correct. Notice in the reference that blue and green maxed out, with no red, gives teal—so the white areas of the image are turned teal with the removal of red. Also notice that the red stripe as gone completely black, while the blue stripe and green stripe are intact. The purple stripe lost its red so it is now blue. All these are clues that the red was removed, as it says in the code. b) d) e) None/other/error
Which code segment takes the image on the left and transforms it to the image on the right? >> im = imread('rainbow.jpg'); >> z = zeros(size(im(:,:,1))); >> cat(3,z,im(:,:,2),z); >> imshow(ans) >> cat(3,z,z,im(:,:,3)); >> im = imread('rainbow.jpg'); >> z = zeros(size(im(:,:,1))); >> cat(3,im(:,:,1),z,z); >> imshow(ans) b) B Use as an opportunity to introduce functions zeros and cat (used them on homework). This preserves the green layer (2nd layer) and zeros out the 1st and 3rd. Correct This preserves the red layer and zeros out the 2nd and 3rd. d) None/other/error RGB color reference