CMPT 120 Lecture 22 – Unit 4 – Computer Vision

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 8 Fruitful Functions 05/02/09 Python Mini-Course: Day 2 - Lesson 8 1.
Advertisements

Final Project Web Design. Final Project Your robot will be placed in a room with the red cone. Your robot will need to find the cone in the room and run.
Decision Making George Mason University. Today’s topics 2 Review of Chapter 2: Decision Making Go over exercises Decision making in Python.
Digital Colour Theory. What is colour theory? It is the theory behind colour mixing and colour combination.
COMPSCI 101 Principles of Programming Lecture 27 - Using the Canvas widget to draw rows and columns of shapes.
CATHERINE AND ANNIE Python: Part 4. Strings  Strings are interesting creatures. Although words are strings, anything contained within a set of quotes.
While Loops CMSC 201. Overview Today we will learn about: Looping Structures While loops.
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:
CS1315: Introduction to Media Computation Color replacements and targeted color replacement (IF)
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Debugging and Printing George Mason University. Today’s topics Review of Chapter 3: Printing and Debugging Go over examples and questions debugging in.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Introduction to Programming Python Lab 6: Relational Operators and Boolean Variables 12 February PythonLab6 lecture slides.ppt Ping Brennan
String and Lists Dr. José M. Reyes Álamo.
Math operations 9/19/16.
Control Flow (Python) Dr. José M. Reyes Álamo.
Introduction to Programming
David Meredith Aalborg University
Topic: File Input/Output (I/O)
Pixels, Colors and Shapes
Topic: Recursion – Part 2
CSIS-110 Introduction to Computer Science
Tuples and Lists.
Image Processing & Perception
Topics Introduction to Repetition Structures
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
Intro to Computer Science CS1510 Dr. Sarah Diesburg
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Programming
Georgia Institute of Technology
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Practice with loops! What is the output of each function below?
Design and Implementation
CSC1018F: Intermediate Python
More Looping Structures
3. Decision Structures Rocky K. C. Chang 19 September 2018
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Programming Using Python PART 2
Lecture 13: Two-Dimensional Arrays
Python programming exercise
Programming Languages
Recursion Taken from notes by Dr. Neil Moore
February , 2009 CSE 113 B.
CS1315: Introduction to Media Computation
Programming In Lesson 4.
Introduction to Programming
More Looping Structures
The Python interpreter
CMPT 120 Lecture 16 – Unit 3 – Graphics and Animation
Lecture 9: Implementing Complex Logic
CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Lecture 23 – Practice Exercises 5
CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation
Lecture 5 – Unit 1 – Chatbots Python – More on Conditional statements
Lecture 17 – Practice Exercises 3
CMPT 120 Lecture 18 – Unit 3 – Graphics and Animation
Topic: Where to put functions in a program
Lecture 8 – Practice Exam
Lecture 20 – Practice Exercises 4
CMPT 120 Machine that can see! Lecture 21 – Unit 4 – Computer Vision
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
CMPT 120 Lecture 24 – Unit 4 – Computer Vision
Lecture 20 – Practice Exercises 4
Lecture 23 – Practice Exercises 5
Lecture 37 – Practice Exercises 9
Lecture 17 – Practice Exercise 3 SOLUTIONS
Lecture 37 – Practice Exercises 9
Python – May 25 Quiz Python’s imaging library Lab
Presentation transcript:

CMPT 120 Lecture 22 – Unit 4 – Computer Vision Python – Nested Loops, Tuples and Fruitful Functions

to find out how to load images Last Lecture, we did … Look at the PIL documentation to find out how to load images and access image pixels. Can you print the values of the pixels in your image? https://repl.it/repls/CookedInconsequentialClient

This is how I access this pixel: Last Lecture, we saw … 2D table called my_image This is how I access this pixel: my_image[10, 8]

Write the code that prints what is at Testing … Testing … What is at coordinates (0,0)? Write the code that prints what is at coordinates (0,0)

Tuples Like a list, but not. Tuples are like read-only lists.

Let’s have a closer look at … Tuples https://repl.it/repls/AutomaticAdventurousTheory

Back to our “combining images” problem … Let’s translate this comment into Python code! A few things to keep in mind: How to go through each pixel of A? How to know if a pixel is green? How to find the corresponding pixel in B?

How to go through each pixel of A? Nested loops are useful for traversing 2D tables

How to know if a pixel is green? 255 is maximum intensity

Two ways to access a pixel tuple's rgb values # Get aPixel at (0,0) aPixel = imageKidGreen[0,0] # Way 1 - Get this pixel’s r value r = aPixel[0] # Way 2 - Get this pixel’s g value g = imageKidGreen[0,0][1] # Way 2 - Get this pixel’s b value b = imageKidGreen[0,0][2]

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 pixel and a colour, the function returns True if the pixel has this colour

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

Can we improve our program? Tada!!! Hum… Can we improve our program?

Review How do you create or initialize a tuple? In an image contained in a table called awesome_image, how would you access the pixel located 5 pixels in, and 8 pixels down from the top left? What can nested loops be used for in the context of image processing? What are 2 differences between tuples and lists? What can computer vision be used for?

Next Lecture New practice exercises Bring your laptop! 