Download presentation
Presentation is loading. Please wait.
Published byAudrey Walker Modified over 9 years ago
1
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.Dr. Cynthia Lee, UCSDCreative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported Licensewww.peerinstruction4cs.org 1
2
RELATIONAL OPERATORS 2
3
Relational Operators 4 < 5true (1) 4 <= 5true (1) 4 == 5false (0) 4 ~= 5 4 > 5false (0) 4 >= 4 ‘A’ < ‘B’ 3 (a) true (1) (b) false (0) (c) other/error
4
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? a)Increases the amount of green in the image b)Identifies pixels with high green value c)Removes green layer from the image d)None/more than one/MATLAB error 4
5
A new data type for variables! 5
6
LOGICAL OPERATORS 6
7
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? a)Identifies pixels that have high red, or high blue, or high green value(s) b)Identifies pixels that are close to black c)Identifies pixels that are close to white d)Error 7
8
8
9
>> im = imread(‘rainbow.jpg’); >> result = im(:,:,1) > 200 & im(:,:,2) > 200 & im(:,:,3) > 200; a)Identifies pixels that have high red, or high blue, or high green value(s) b)Identifies pixels that are close to black 9 Can you write code for the other answer choices?
10
“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 10
11
“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 11
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.