CS 1114: Finding things Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)

Slides:



Advertisements
Similar presentations
MS 101: Algorithms Instructor Neelima Gupta
Advertisements

Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Sorting and Selection, Part 1 Prof. Noah Snavely CS1114
Polygons and the convex hull Prof. Noah Snavely CS1114
CSC321: Neural Networks Lecture 3: Perceptrons
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 21 Instructor: Paul Beame.
CS 1114: Sorting and selection (part one) Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
1 Computer Science 631 Lecture 3: Morphing, Sampling Ramin Zabih Computer Science Department CORNELL UNIVERSITY.
CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.
Complexity (Running Time)
Lec 5 Feb 10 Goals: analysis of algorithms (continued) O notation summation formulas maximum subsequence sum problem (Chapter 2) three algorithms image.
Robustness and speed Prof. Noah Snavely CS1114
Finding Red Pixels – Part 1 Prof. Noah Snavely CS1114
Lecture 3a: Feature detection and matching CS6670: Computer Vision Noah Snavely.
28-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
Polygons and the convex hull Prof. Noah Snavely CS1114
Linked lists and memory allocation Prof. Noah Snavely CS1114
CS4670: Computer Vision Kavita Bala Lecture 7: Harris Corner Detection.
Search Lesson CS1313 Spring Search Lesson Outline 1.Searching Lesson Outline 2.How to Find a Value in an Array? 3.Linear Search 4.Linear Search.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Unit 1 (Chapter 5): Significant Figures
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
IT253: Computer Organization
CS 101: Numerical Computing Abhiram Ranade. Representing Integers “int x;” : reserves one cell in memory for x. One cell: “One word” has 32 capacitors.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
1 ITK Lecture 8 - Neighborhoods Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image.
Image segmentation Prof. Noah Snavely CS1114
C++ crash course Class 8 statements, sort, flight times program.
10/3/02 (c) 2002 University of Wisconsin, CS 559 Last Time 2D Coordinate systems and transformations.
Finding Red Pixels Prof. Ramin Zabih
Medians and blobs Prof. Ramin Zabih
Robustness and speed Prof. Noah Snavely CS1114
CSC508 Convolution Operators. CSC508 Convolution Arguably the most fundamental operation of computer vision It’s a neighborhood operator –Similar to the.
Finding Red Pixels – Part 1 Prof. Noah Snavely CS1114
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
CS 2601 Runtime Analysis Big O, Θ, some simple sums. (see section 1.2 for motivation) Notes, examples and code adapted from Data Structures and Other Objects.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Overview of c++ Objectives 1. Understanding the use of the following elements in a c++ program variables constants assignment input output 2. Writing a.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
D75P 34R - HNC Computer Architecture Week 4 Signed Integers © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen College unless otherwise.
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
Searching and Sorting Searching: Sequential, Binary Sorting: Selection, Insertion, Shell.
BIT115: Introduction to Programming
6.S093: Visual Recognition through Machine Learning Competition MATLAB tutorial.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Recognizing objects Prof. Noah Snavely CS1114
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
AP CSP: Pixelation – B&W/Color Images
List Algorithms Taken from notes by Dr. Neil Moore & Dr. Debby Keen
CSS Layouts: Grouping Elements
Week 13: Searching and Sorting
Lab 9 Intro to Robots.
Garbage collection; lightstick orientation
Big-Oh and Execution Time: A Review
CS 1114: Sorting and selection (part three)
List Algorithms Taken from notes by Dr. Neil Moore
So where is it anyway? Bounding box, median, centroids, and an introduction to algorithm analysis.
Quickselect Prof. Noah Snavely CS1114
CS 1114: Sorting and selection (part two)
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
CS 1114: Introduction to Computing Using MATLAB and Robotics
Bounding Boxes, Algorithm Speed
Working with images and scenes
Sorting and selection Prof. Noah Snavely CS1114
Presentation transcript:

CS 1114: Finding things Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)

2 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

3  We’ve counted the red pixels in Matlab –Can anything go wrong?  Question: devise a thresholding function

Finding the lightstick  We’ve answered the question: is there a red light stick?  But the robot needs to know where it is! 4

5 Finding the lightstick – Take 1  Compute the bounding box of the red points  The bounding box of a set of points is the smallest rectangle containing all the points –By “rectangle”, we really mean “rectangle aligned with the X,Y axes”

What does this tell us?  Bounding box gives us some information about the lightstick Midpoint  rough location Aspect ratio  rough orientation (aspect ratio = ratio of width to height) 6 Aspect ratio: 2.05/1.08 = " 2.05"

7 Computing a bounding box  Two related questions: –Is this a good idea? Will it tell us reliably where the light stick is located? –Can we compute it quickly?

8 Beyond the bounding box  Computing a bounding box isn’t hard –Hint: the right edge is computed by the code we showed in lecture 2.  Does it work?

9 Finding the lightstick – Take 2  How can we make the algorithm more robust? –New idea: compute the centroid  Centroid: (average x-coordinate, average y-coordinate) –If the points are scattered uniformly, this is the same as the midpoint of the bounding box –Average is sometimes called the mean –Centroid = center of mass

10 Computing the centroid?  We could do everything we want by simply iterating over the image as before –Testing each pixel to see if it is red, then doing something to it  It’s often easier to iterate over just the red pixels  To do this, we will use the Matlab function called find

The find function 11 img thresh Your thresholding function [X,Y] = find(thresh); X = % x-coords of nonzero points Y = % y-coords of nonzero points

12 Using find on images  We can get the x- and y- coordinates of every red pixel using find –Now all we need to do is to compute the average of these numbers –We will leave this as a homework exercise You might have done this in high school

13 Q: How well does this work?  A: Still not that well –One “bad” red point can mess up the mean  This is a well-known problem –What is the average weight of the people in this kindergarten class photo?

How well does this work? 14

Aside: What’s the difference between = and == ?  Answer: a lot  = : assignment x = 2;  == : test for equality if x == 2 y = 4; end ... very important not to get these mixed up 15

Aside: Logical operators  && -- logical “and”  || -- logical “or” if (x == 1 && y == 2) || z == 3 % do something interesting else % do something else end 16

Aside: Types in Matlab  Different types of numbers: –Integer (int) { 17, 42, -144, … } Signed Unsigned 8-bit (uint8) [0 : 255] 16-bit (uint16) [0 : 65,535] –Floating point (double) { 3.14, 0.01, -20.5, … } 17 Default for images

Aside: Converting between types  Most numbers in Matlab are double by default (images are an exception)  Various functions for converting numbers:  What happens when we do this: 18 doubleuint8uint16 uint8(200) + uint8(200) % Result = ?

Aside: Images in different formats  uint8 : intensities in range [0-255]  uint16 : intensities in range [ ]  double : intensities in range [ ]  imdouble(img) converts an image to double format  double(img) almost converts an image to double format 19

Finding the lightstick center  : two approaches  Both have problems… 20 Bounding boxCentroid

How can we do better?  What is the average weight of the people in this kindergarten class photo? kids, avg. weight= 40 lbs 1 Arnold, weight = 236 lbs Mean: (12 x ) / 13 = 55 lbs

How can we do better?  Idea: remove maximum value, compute average of the rest kids, avg. weight= 40 lbs 1 Arnold, weight = 236 lbs Mean: (12 * ) / 11 = 55 lbs Mean: 40lbs

How can we do better? 23  Trade deficit by country

24 How can we avoid this problem?  Consider a simple variant of the mean called the “trimmed mean” –Simply ignore the largest 5% and the smallest 5% of the values –Q: How do we find the largest 5% of the values? D.E. Knuth, The Art of Computer Programming Chapter 5, pages 1 – 391

25 Easy to find the min (or max) A = [ ]; m = -1; for i = 1:length(A) if (A(i) > m) m = A(i); end % Alternatively: m = max(m,A(i)); end % Why -1?

 First, we need to know how many cells we’re dealing with –Let’s say there are 100  remove top 5  How do we remove the biggest 5 numbers from an array? 26 How to get top 5%?

% A is a vector of length 100 for i = 1:5 % Find the maximum element of A % and remove it end 27 Removing the top 5% -- Take 1

28 How good is this algorithm?  Is it correct?  Is it fast?  Is it the fastest way? % A is a vector of length 100 for i = 1:5 % Find the maximum element of A % and remove it end

How do we define fast?  It’s fast when length(A) = 20  We can make it faster by upgrading our machine  So why do we care how fast it is?  What if length(A) = 6,706,993,152 ? 29

How do we define fast?  We want to think about this issue in a way that doesn’t depend on either: A. Getting really lucky input B. Happening to have really fast hardware 30

31 Where we are so far  Finding the lightstick –Attempt 1: Bounding box (not so great) –Attempt 2: Centroid isn’t much better –Attempt 3: Trimmed mean Seems promising But how do we compute it quickly? The obvious way doesn’t seem so great… But do we really know this?

Things to do  Think about how you might solve these issues of finding interesting regions in a static image (don’t just look it up, have fun thinking for yourself).  Homework 1 is due next Monday – work with each other, ask questions, have fun! 32