CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified...
-
date post
21-Dec-2015 -
Category
Documents
-
view
229 -
download
5
Transcript of CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified...
![Page 1: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/1.jpg)
CS 1114: Introduction to Computing Using MATLAB and Robotics
Prof. Graeme Bailey
http://cs1114.cs.cornell.edu
(notes modified from Noah Snavely, Spring 2009)
![Page 2: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/2.jpg)
2
Overview
What is CS 1114?– An honors-level intro to CS using
camera-controlled robots (Rovio, Sony Aibo, iRobot Create)
– An alternative to CS1112 or CS1132, to fulfill your Matlab computing requirement
– Formerly known as CS100R
![Page 3: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/3.jpg)
Goals of CS1114
Give you an intuition about computation problem solving
Teach you useful (and interesting) computer science
Give you fluency in the Matlab programming environment
Have fun with robots
3
![Page 4: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/4.jpg)
Requirements
Exposure to programming (in any language)
Some interest in math– Computer science is about much more than
programming, and so is this course
4
![Page 5: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/5.jpg)
Java or Matlab?
Both CS1110 and CS111[2,4] teach fundamental problem solving skills and computer science techniques
The destination is the same…
… but the vehicle is different
5
(inspired by Charlie Van Loan)
![Page 6: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/6.jpg)
Robots: 2029
6
![Page 7: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/7.jpg)
7
Robots: cute but dumb
What do they know about the world around them?– Without your help, very little– Can’t even notice a bright red lightstick
Your mission: make them smarter Lots of interesting math and computer
science, some computer programming– Lots of experience with programming, even
with robots, won’t give you a leg up in 1114
![Page 8: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/8.jpg)
8
CS1114 Logistics
Lectures: Tue Thu 11:15–12:05, PHL 307 Sections:
– Wed 1:25 - 2:15, Upson 317– Wed 2:30 - 3:20, Upson 317– Wed 3:35 - 4:25, Upson 317– Please go to same section for the entire course
Occasional evening lectures (optional)– First lecture will be in next week (TBA)
![Page 9: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/9.jpg)
CS1114 Logistics
CS1114 lab: Upson 317 You will soon have access to the lab and
passwords for the computers Office hours will generally be held in the
lab (hours to be announced soon)
9
![Page 10: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/10.jpg)
10
Assignments
Several mini-quizes– In class, usually at start of lecture
• Corollary: be on time, or write fast…
5-6 robot programming assignments with multiple parts– You will demo each part to the lab TA’s
2-3 prelims Free-form final project (required)
![Page 11: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/11.jpg)
What can we do with computer vision?
11
![Page 12: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/12.jpg)
Human vision
12
Question: How many people are in this image?
Source: “80 million tiny images” by Torralba, et al.
![Page 13: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/13.jpg)
Interpreting images
13
Q: Can a computer (or robot) understand this image? A: Yes and no (mostly no)
![Page 14: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/14.jpg)
Human vision has its shortcomings…
14
Sinha and Poggio, Nature, 1996
Credit: Steve Seitz
![Page 15: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/15.jpg)
Human vision has its shortcomings…
15
by Ted Adelson, slide credit Steve Seitz
![Page 16: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/16.jpg)
16
![Page 17: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/17.jpg)
Interpreting images
17
Q: Can a computer (or robot) find the lightstick?A: With your help, yes!*
(300, 100)
![Page 18: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/18.jpg)
What is an image?
18
“lightstick1.jpg”
![Page 19: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/19.jpg)
19
Major CS1114 Projects
From a camera, figure out the position of a bright red lightstick– Use this to guide a robot around
What we see What the robot sees
![Page 20: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/20.jpg)
What is an image? A grid of numbers (intensity values)
Intensity values range between 0 (black) and 255 (white)
20
x
y…
…snoop
3D view
![Page 21: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/21.jpg)
What is an image?
A grid of numbers (intensity values) In Matlab, a matrix
21
[ 10 30 40 106 123 … ; 8 49 58 112 145 … ; 16 53 86 123 152 … ; … ]
{{
100
120
120 x 100 matrix
![Page 22: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/22.jpg)
Matrices in Matlab
1D matrix is often called a vector– Similar to arrays in other languages
22
A = [ 10 30 40 106 123 ]
Row vector(or 1 x 5 matrix)
B = [ 10 ; 30 ; 40 ; 106 ; 123 ]
Column vector
(or 5 x 1 matrix)
A(1) == 10A(4) == 106
![Page 23: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/23.jpg)
Matrices in Matlab
23
C = [ 10 30 40 106 123 ; 8 49 58 112 145 ; 16 53 86 123 152 ]
3 x 5 matrix
C(1,1) == ?
C(2,4) == ?
10
112
can also assign to a matrix entries
C(1,1) = C(1,1) + 1
![Page 24: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/24.jpg)
Image processing
We often want to modify an image by “doing something” to each pixel:
24
BlurBrighten
![Page 25: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/25.jpg)
Brightening an image
25
Q: What does this mean in terms of matrix entries?
[ 10 30 40 106 123 ; 8 49 58 112 145 ; 16 53 86 123 152 ]
A: Increase each element by some amount(say, 20)
![Page 26: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/26.jpg)
Brightening an image (Take 1)
26
D = [ 10 30 40 106 123 8 49 58 112 145 16 53 ]
D(1) = D(1) + 20;D(2) = D(2) + 20;D(3) = D(3) + 20;D(4) = D(4) + 20;D(5) = D(5) + 20;D(6) = D(6) + 20;D(7) = D(7) + 20;D(8) = D(8) + 20;D(9) = D(8) + 20;D(10) = D(10) + 20;D(11) = D(11) + 20;D(12) = D(12) + 20;D(13) = D(13) + 20;D(14) = D(14) + 20;D(15) = D(15) + 20;x
![Page 27: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/27.jpg)
27
Avoiding duplicate code
Programming languages are designed to make this easy– It’s a huge theme in language design– Many new programming techniques are
justified by this• Object-oriented programming, higher-order
procedures, functional programming, etc.
![Page 28: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/28.jpg)
Why is it a bad idea to duplicate code?
28
Hard to write Hard to modify Hard to get right Hard to generalize Programmer’s “inten
t” is obscured
D(1) = D(1) + 20;D(2) = D(2) + 20;D(3) = D(3) + 20;D(4) = D(4) + 20;D(5) = D(5) + 20;D(6) = D(6) + 20;D(7) = D(7) + 20;D(8) = D(8) + 20;D(9) = D(8) + 20;D(10) = D(10) + 20;D(11) = D(11) + 20;D(12) = D(12) + 20;
![Page 29: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/29.jpg)
29
Brightening an image (Take 2) Using iteration
for i = 1:12 D(i) = D(i) + 20; end
D(1) = D(1) + 20;D(2) = D(2) + 20;D(3) = D(3) + 20;D(4) = D(4) + 20;D(5) = D(5) + 20;D(6) = D(6) + 20;D(7) = D(7) + 20;D(8) = D(8) + 20;D(9) = D(9) + 20;D(10) = D(10) + 20;D(11) = D(11) + 20;D(12) = D(12) + 20;
Much easier to understand and modify the code Better expresses programmer’s “intent”
D = D + 20; • “Vectorized” code• Usually much faster than loops
![Page 30: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/30.jpg)
Many advantages to iteration
Can do things with iteration that you can’t do by just writing lots of statements
Example: increment every vector cell– Without knowing the length of the vector!
len = length(D); % New Matlab function
for i = 1:len
D(i) = D(i) + 20;
end
30
![Page 31: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/31.jpg)
31
Introducing iteration into code
Programming often involves “clichés”– Patterns of code rewriting– I will loosely call these “design patterns”
Iteration is our first example
![Page 32: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/32.jpg)
Brightening 2D images
32
C = [ 10 30 40 106 123 ; 8 49 58 112 145 ; 16 53 86 123 152 ]
3 x 5 matrix
for row = 1:3 for col = 1:5 C(row,col) = C(row,col) + 20; endend
Called a “nested” for loop
![Page 33: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/33.jpg)
Brightening 2D images
33
for row = 1:3 for col = 1:5 C(row,col) = C(row,col) + 20 endend
What if it’s not a 3x5 matrix?
[nrows,ncols] = size(C) % New Matlab function for row = 1:nrows for col = 1:ncols C(row,col) = C(row,col) + 20 endend
![Page 34: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/34.jpg)
What about red pixels?
A grayscale image is a 2D array– Brightest = 255, darkest = 0
34
![Page 35: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/35.jpg)
What about red pixels?
A color image is 3 different 2D arrays– For red/green/blue values (RGB)– We provide a way to create these 3 arrays Why are there 3?
35
=
![Page 36: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/36.jpg)
What about red pixels?
Example colors:
red(1,1) == 255, green(1,1) == blue(1,1) == 0
red(2,1) == 100 == green(2,1) == blue(2,1)
red(3,1) == 0 == green(3,1) == blue(3,1)
red(3,1) == 255 == green(3,1), blue(3,1) == 0
36
![Page 37: CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.](https://reader036.fdocuments.in/reader036/viewer/2022062320/56649d5e5503460f94a3e0e9/html5/thumbnails/37.jpg)
For next time
……….. Wait* and see** ……… !!!***
______________* Assuming you know how to ‘wait’
** assuming you know how to ‘see’*** assuming you know why waiting helps seeing
37