CMPT 120 Machine that can see! Lecture 21 – Unit 4 – Computer Vision

Slides:



Advertisements
Similar presentations
This Week More Types boolean string Modules print statement Writing programs if statement Type boolean.
Advertisements

Visual Attention Jeremy Wyatt. Where to look? Many visual processes are expensive Humans don’t process the whole visual field How do we decide what to.
Guide to Programming with Python
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
IMAGE PROCESSING LIBRARY (PIL) This is a package that you can import into python and it has quite a few methods that you can process image files with.
Hello World 2 What does all that mean?.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Data Collections: Dictionaries CSC 161: The Art of Programming Prof. Henry Kautz 11/4/2009.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 6 Value-Returning.
This Week The string type Modules print statement Writing programs if statements (time permitting) The boolean type (time permitting)
Python – May 11 Briefing Course overview Introduction to the language Lab.
Last Week if statement print statement input builtin function strings and methods for loop.
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:
A Python Tour: Just a Brief Introduction "The only way to learn a new programming language is by writing programs in it." -- B. Kernighan and D. Ritchie.
Quiz Week 8 Topical. Topical Quiz (Section 2) What is the difference between Computer Vision and Computer Graphics What is the difference between Computer.
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
Turtle Graphics Let’s see what we can draw on Python!
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Review: A Computational View Programming language common concepts: 1. sequence of instructions -> order of operations important 2. conditional structures.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Image Processing Intro2CS – week 6 1. Image Processing Many devices now have cameras on them Lots of image data recorded for computers to process. But.
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
Machine Language Computer languages cannot be directly interpreted by the computer – they are not in binary. All commands need to be translated into binary.
Lecture 3 Translation.
Introduction to Scratch
CSC 222: Object-Oriented Programming
David Meredith Aalborg University
A Python Tour: Just a Brief Introduction
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Classwork: Examine and enhance falling drop(s) or make your own.
Two Dimensional Array Mr. Jacobs.
Two-Dimension Arrays Computer Programming 2.
Introduction to R.
Functions CIS 40 – Introduction to Programming in Python
Corpus Linguistics I ENG 617
JavaScript: Functions.
Data Analysis using Python-I
PH2150 Scientific Computing Skills
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Review for Test1.
CS190/295 Programming in Python for Life Sciences: Lecture 6
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
WICS - Flappy Anteater Python Tutorial
Practice with loops! What is the output of each function below?
Design and Implementation
CSC1018F: Intermediate Python
ARRAYS 2 GCSE COMPUTER SCIENCE.
February , 2009 CSE 113 B.
Introduction to Computer Science
CMPT 120 Lecture 2 - Introduction to Computing Science – Problem Solving, Algorithm and Programming.
CMPT 120 Lecture 3 - Introduction to Computing Science – Programming language, Variables, Strings, Lists and Modules.
More Basics of Python Common types of data we will work with
CMPT 120 Lecture 15 – Unit 3 – Graphics and Animation
CMPT 120 Lecture 4 – Unit 1 – Chatbots
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 22 – Unit 4 – Computer Vision
Lecture 20 – Practice Exercises 4
COS 151 Bootcamp – Week 4 Department of Computer Science
CMPT 120 Lecture 24 – Unit 4 – Computer Vision
Lecture 20 – Practice Exercises 4
Lecture 23 – Practice Exercises 5
Lecture 17 – Practice Exercise 3 SOLUTIONS
Selamat Datang di “Programming Essentials in Python”
Python – May 25 Quiz Python’s imaging library Lab
Using Modules.
Presentation transcript:

CMPT 120 Machine that can see! Lecture 21 – Unit 4 – Computer Vision Python – Files, Nested Loops and Tuples

Unit 4 - Computer Vision We can make machines understand our world visually Facebook’s automatic photo captions for the blind iPhone X recognizes faces Instagram filters Medical imaging Gesture recognition New Visual Computing M.Sc.

Unit 4 - Computer Vision APPLICATIONS In this unit, we’ll learn about the computing science field of computer vision, that allows machines to process images and understand them ALGORITHMS We’ll learn about more advanced functions, nested (embedded) loops, etc… Python We’ll learn about tuples, file input/output (I/O), etc…

Puzzle 1 What would the Python code fragment below output? import random def random_animal(animals): default = "cat" animal = random.choice(animals) return animal # Main part of program print(default) print(random_animal(["dog", "bird"]))

Puzzle 2 What would the Python code fragment below output? def special(numbers): for num1 in numbers: for num2 in numbers: if num1 < num2: return num1 + num2 # Main part of program print(special([3,1,2]))

Image Processing

Combining Images

This week, we shall … … make a program that can merge a green screen image with another background, using the following concepts: Importing a package module using from … import Looking up and understanding module documentation Pixel representations of images in 2D arrays, e.g. image[x,y] Colours in RGB space -> we already know this!  Review functions that return values (e.g. boolean and string)

Let’s get started! Problem Statement: Write a program that combines two images ----------------------------------------------------------------------- Let’s get started by downloading these two files: kid-green.jpg from https://goo.gl/cju79e beach.jpg from https://goo.gl/nCgxdQ

Working with images in Repl.It Upload image files to Repl.it here

For the sake of simplicity, let’s use the same sized image here x <--- 450 pixels --> <--- 450 pixels --> y For the sake of simplicity, let’s use the same sized image here

module inside the Python Imaging Let’s get started! Image is a module inside the Python Imaging Library (PIL) package, which is a collection of modules. The Image module contains pre-built functions that will help us do image processing. https://repl.it/repls/CookedInconsequentialClient

to find out how to load images Opening Image Files 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

Accessing each pixel This is a 2-dimensional (2D) table containing our image (in other programming languages, sometimes it is called a 2D array) Accessing each pixel You can access the value of this 2D table element (pixel) similar to list access: my_image[c, r] E.g. image_green[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

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 all pixels of A? How to know if a pixel is green? How to find the corresponding pixel in B?

How to go through all pixels of A?

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

How to find the corresponding pixel in B?

Next Lecture Let’s have an other look at our program! Can we improve it?