120 likes | 268 Views
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 . Relational Operators.
E N D
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.
Relational Operators • 4 < 5 true (1) • 4 <= 5 true (1) • 4 == 5 false (0) • 4 ~= 5 • 4 > 5 false (0) • 4 >= 4 • ‘A’ < ‘B’ (a) true (1) (b) false (0) (c) other/error (a) true (1) (b) false (0) (c) other/error (a) true (1) (b) false (0) (c) other/error
Why would we want to test “<“ between a number and a matrix? >> im = imread(‘rainbow.jpg’); >> g = im(:,:,2); >> result = g > 200; • What type of variable will result be after the assignment? What does this code do, conceptually? • Increases the amount of green in the image • Identifies pixels with high green value • Removes green layer from the image • None/more than one/MATLAB error
Why would we want to test “<“ between a number and a matrix? >> im = imread(‘rainbow.jpg’); >> result = im(:,:,1) > 200 & im(:,:,2) > 200 & im(:,:,3) > 200; • First, take each part by itself and figure out what it does; then combine the parts. What does this code do, conceptually? • Identifies pixels that have high red, or high blue, or high green value(s) • Identifies pixels that are close to black • Identifies pixels that are close to white • Error
Can you write code for the other answer choices? >> im = imread(‘rainbow.jpg’); >> result = im(:,:,1) > 200 & im(:,:,2) > 200 & im(:,:,3) > 200; • Identifies pixels that have high red, or high blue, or high green value(s) • Identifies pixels that are close to black
“Green screen” special effects • Actors or other objects are filmed in front of a screen with a very specific shade of green • Later, a computer program checks the color of each pixel of the movie • Pixels matching that specific shade of green are replaced with pixels from another image/movie • Pixels not matching that specific shade of green are left alone
“Green screen” special effects • Actors can wear green and be invisible in the final movie • The two men on the left are moving a puppet • The man on the right, if he doesn’t put his green shirt back on, will appear to be a floating torso