CMPT 120 Lecture 24 – Unit 4 – Computer Vision

Slides:



Advertisements
Similar presentations
How SAS implements structured programming constructs
Advertisements

This Week More Types boolean string Modules print statement Writing programs if statement Type boolean.
CS 102 Computers In Context (Multimedia)‏ 02 / 02 / 2009 Instructor: Michael Eckmann.
Structure of program You must start with a module import# You must then encapsulate any while loop in a main function at the start of the program Then.
Path Testing + Coverage Chapter 9 Assigned reading from Binder.
TABLES AND VALUES Section 1.5. Open Sentence Equation.
Announcements Course evaluation Your opinion matters! Attendance grades Will be posted prior to the final Project 5 grades Will be posted prior to the.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
A Level Computing#BristolMet Session Objectives#U2 S3 MUST use/read programme flow charts accurately SHOULD adapt the calculator programme to include a.
BIT116: Scripting Lecture 05
Control Flow (Python) Dr. José M. Reyes Álamo.
Topic: Python Lists – Part 1
CMPT 120 Topic: Python’s building blocks -> More Statements
Topic: Recursion – Part 2
Pseudocode Key Revision Points.
Topic: Iterative Statements – Part 1 -> for loop
Topic: Conditional Statements – Part 1
Topic: Conditional Statements – Part 2
What to do when a test fails
Matlab Training Session 4: Control, Flow and Functions
Intro to Python Programming – Part II
CMPT 120 Topic: Searching – Part 1
CMPT 120 Topic: Functions – Part 4
Printing Lines of Asterisks
Topic: Functions – Part 2
Scripts & Functions Scripts and functions are contained in .m-files
Ruth Anderson UW CSE 160 Winter 2017
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Georgia Institute of Technology
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
Introduction to Computer Programming
Pixels.
Ruth Anderson UW CSE 140 Winter 2014
Practice with loops! What is the output of each function below?
Control flow : if statements
Faculty of Computer Science & Information System
EECS 110: Lec 4: Functions and Recursion
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Python programming exercise
Let’s all Repeat Together
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Programming Languages
SSEA Computer Science: Track A
CS 177 Week 3 Recitation Slides
February , 2009 CSE 113 B.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Data Structures & Algorithms
Introduction to Flowcharting
Loops CGS3416 Spring 2019 Lecture 7.
The Python interpreter
The Python interpreter
CMPT 120 Lecture 16 – Unit 3 – Graphics and Animation
James Wei Professor Peck 9/20/2013
Lecture 7 – Unit 1 – Chatbots Python – For loops + Robustness
CMPT 120 Lecture 29 – Unit 5 – Internet and Big Data
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Lecture 23 – Practice Exercises 5
Lecture 5 – Unit 1 – Chatbots Python – More on Conditional statements
Lecture 17 – Practice Exercises 3
CMPT 120 Lecture 18 – Unit 3 – Graphics and Animation
CMPT 120 Lecture 22 – Unit 4 – Computer Vision
Lecture 8 – Practice Exam
CMPT 120 Machine that can see! Lecture 21 – Unit 4 – Computer Vision
Lecture 20 – Practice Exercises 4
Lecture 23 – Practice Exercises 5
Lecture 17 – Practice Exercise 3 SOLUTIONS
CMPT 120 Lecture 26 – Unit 5 – Internet and Big Data
Presentation transcript:

CMPT 120 Lecture 24 – Unit 4 – Computer Vision Python – Creating Modules and Introducing Lists of Lists

Last Lecture, we got into trouble! https://repl.it/repls/CookedInconsequentialClient

… creating an output image We fixed it by … … creating an output image We did this by calling open() (without chaining a call to load() afterward)

open( ) versus load( ) open() gives you access to metadata information about the image such as its width, height, etc. load() can be run once open() has been executed load() gives you access to the pixel values

Last Lecture, we also saw … How to go through each pixel of A? Nested loops are useful for traversing 2D tables -> for loops

A Word about Comments! Consider the Python code fragment below, which comment would be the most helpful Comment A or Comment B (assuming imageKidGreen is A)? Comment A: Comment B:

Last Lecture, we had a homework! Write a Python statement to discover if a pixel is green Various ways of doing this: if g == 255 : if g > 230 and g <= 255 : if r < 180 and r >= 0 and g > 230 and g <= 255 and b < 120 and b >= 0 : How do we figure this out?

How to find the corresponding pixel in B?

Fruitful Functions Problem Statement: Write a function that returns True when a pixel is green and False otherwise How would we generalize this function i.e., given a colour, the function returns True if the given pixel has this colour

Let’s give this function a try! … Can you complete this function?

Let’s make our own Module! A module’s name is its filename with the .py removed Create a new file Paste your function definitions in here, and remove them from your main program

Let’s use our own Module! In the main program … Let’s use our own Module! Import the module … Use the module’s name when calling its functions

Let’s have another look at lists

Lists – so far We saw that a list can contain elements of various data types prices = [1.20, 0.75, 4.50] names = ["Mike", "Xinghua", "Lise"] somePrimes = [1, 3, 5, 7, 11, 13] underTheBed = [3, "old socks"] What if a list contains lists? stdInfo = ["Mike", [112, "B Street"], "YVR"] stdGrades = [ [3,4.5,4], [3.5,5,"-"] ]

Creating lists Here are ways of creating lists:

Another way of creating a list List comprehension Example 1: max = 5 list1 = ["*" for number in range(max)] Example 2: length = 4 list2 = [number for number in range(length)] Example 3: operandList = ["4", "5"] operandList = [int(operandList[i]) for i in range(len(operandList))]

Another 2D Data Structure: Lists of Lists Question: What if a problem statement ask us to manipulate a matrix? Answer: In our solution, we could use a list of lists to represent a matrix the Python code representing the above data would look like: myMatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Access elements in a list of lists myMatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Modify elements in a list of lists myMatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Slicing a list of lists myMatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

What else could a list of lists represent in our programs?

Next Lecture Practice Exam 6 Bring your laptop! 