Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114

Slides:



Advertisements
Similar presentations
Lecture 2 Concepts, Terms and Definitions. Display Devices They are divided into a lot of small squares called pixels (“PICture ELements”). Each pixel.
Advertisements

Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Polygons and the convex hull Prof. Noah Snavely CS1114
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
CSSE463: Image Recognition Day 6 Yesterday: Yesterday: Local, global, and point operators all operate on entire image, changing one pixel at a time!! Local,
CS 61C L02 Number Representation (1)Harvey / Wawrzynek Fall 2003 © UCB 8/27/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
Interpolation Prof. Noah Snavely CS1114
General Computer Science for Engineers CISC 106 Lecture 22 Dr. John Cavazos Computer and Information Sciences 04/13/2009.
CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.
Robustness and speed Prof. Noah Snavely CS1114
Finding Red Pixels – Part 1 Prof. Noah Snavely CS1114
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
Polygons and the convex hull Prof. Noah Snavely CS1114
Linked lists and memory allocation Prof. Noah Snavely CS1114
Matlab Tutorial Continued Files, functions and images.
Clustering and greedy algorithms Prof. Noah Snavely CS1114
Lecture 10: Robust fitting CS4670: Computer Vision Noah Snavely.
Math 010 online work that was due today at the start of class:
PLEASE HELP US OUT WITH THIS: When you go to the open lab next door in 203, please make sure you sign in on the log sheet and enter your instructor’s.
Robust fitting Prof. Noah Snavely CS1114
Interpolation, extrapolation, etc. Prof. Ramin Zabih
© GCSE Computing Candidates should be able to:  explain the representation of an image as a series of pixels represented in binary  explain the need.
Voronoi diagrams and applications Prof. Ramin Zabih
Geometry 13.5 The Midpoint Formula. The Midpoint Formula The midpoint of the segment that joins points (x 1,y 1 ) and (x 2,y 2 ) is the point (-4,2) (6,8)
Image segmentation Prof. Noah Snavely CS1114
CS 1699: Intro to Computer Vision Matlab Tutorial Prof. Adriana Kovashka University of Pittsburgh September 3, 2015.
Interpolation Prof. Noah Snavely CS1114
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
C++ crash course Class 8 statements, sort, flight times program.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Finding Red Pixels Prof. Ramin Zabih
Medians and blobs Prof. Ramin Zabih
What to expect or Now that I have gotten used to Prof. Fitzpatrick, here is this new guy with his weird foreign accent…
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.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
Finding Red Pixels – Part 1 Prof. Noah Snavely CS1114
Clustering Prof. Ramin Zabih
Introduction to Image Processing Our first look at image processing will be through the use of Paint Shop Pro, a bitmap editing program available as shareware.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
1 Computer Science 631 Multimedia Systems Prof. Ramin Zabih Computer Science Department CORNELL UNIVERSITY.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
June 14, ‘99 COLORS IN MATLAB.
CSSE463: Image Recognition Day 6 Yesterday: Local, global, and point operators use different context, but all Yesterday: Local, global, and point operators.
CS 180 Problem Solving and Object Oriented Programming Fall 2011 Notes for Week 14: Nov 21-25, 2011 Aditya Mathur Department of Computer Science Purdue.
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
Math 010 online work that was due today at the start of class: Section 1.3A Online Homework.
CSSE463: Image Recognition Day 9 Lab 3 (edges) due Weds, 3:25 pm Lab 3 (edges) due Weds, 3:25 pm Take home quiz due Friday, 4:00 pm. Take home quiz due.
1. PLEASE HELP US OUT WITH THIS: When you go to the open lab next door in 203, please make sure you sign in on the log sheet and enter your instructor’s.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
CS 1114: Finding things Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Recognizing objects Prof. Noah Snavely CS1114
AP CSP: Pixelation – B&W/Color Images
Pixels, Colors and Shapes
Lab 9 Intro to Robots.
DIP 9 65 Original 210 Eye Zoomed.
Garbage collection; lightstick orientation
Each column represents another power of the base
EE/CSE 576 HW 1 Notes.
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Numbers and their bases
EE/CSE 576 HW 1 Notes.
Quickselect Prof. Noah Snavely CS1114
CS 1114: Introduction to Computing Using MATLAB and Robotics
Bounding Boxes, Algorithm Speed
Working with images and scenes
ECE/CSE 576 HW 1 Notes.
Sorting and selection Prof. Noah Snavely CS1114
Presentation transcript:

Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114

Administrivia  You should all have access to the Upson 317 lab, CSUG accounts –If not, please let me know  Your card should now unlock Upson 319 2

Administrivia  Assignment 1 posted, due next Friday by 5pm –You should have all gotten from me announcing the assignment  Quiz 1 on Thursday  No evening lecture tonight 3

4 Administrivia  Office hours are posted on the website

Correction from last time  “Vectorized” code  Usually much faster than loops  But please use for loops for assignment 1 5 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; D = D + 20; D = [ ]

Why 256 intensity values? 6 8-bit intensity (2^8 = 256) 5-bit intensity (2^5 = 32) 5-bit intensity with noise

Why 256 intensity values? 7 4-color CGA display Today’s (typical) displays: 256 * 256 * 256 = 16,777,216 colors

How many black pixels? 8 nzeros = 0; [nrows,ncols] = size(D); for row = 1:nrows for col = 1:ncols if D(row,col) == 0 nzeros = nzeros + 1; end What if we need to execute this code many times?

Turning this into a function 9 function [ nzeros ] = count_zeros(D) % Counts the number of zeros in a matrix nzeros = 0; [nrows,ncols] = size(D); for row = 1:nrows for col = 1:ncols if D(row,col) == 0 nzeros = nzeros + 1; end Save in a file named count_zeros.m count_zeros([ ])

What about red pixels? 10 = + + RGB red(1,1) == 255, green(1,1) == blue(1,1) == 0

11 How many red pixels? img = imread(‘wand1.bmp’); [red, green, blue] = image_rgb(img); nreds = 0; [nrows,ncols] = image_size(img); for row = 1:nrows for col = 1:ncols if red(row,col) == 255 nreds = nreds + 1; end

12  We’ve counted the red pixels in Matlab –Can anything go wrong? for row = 1:nrows for col = 1:ncols if red(row,col) == 255 nreds = nreds + 1; end

Are we done?  Assignment 1: come up with a thresholding function 13

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

15 Finding the rightmost red pixel  We can always process the red pixels as we find them: right = 0; for row = 1:nrows for col = 1:ncols if red(row,col) == 255 right = max(right,col); end

16 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”, I really mean “rectangle aligned with the X,Y axes”

Finding the bounding box  Each red pixel we find is basically a point –It has an X and Y coordinate –Column and row Note that Matlab reverses the order 17

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) 18 Aspect ratio: 2.05/1.08 = " 2.05"

19 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?

Computing a bounding box  Lots of CS involves trying to find something that is both useful and efficient –To do this well, you need a lot of clever ways to efficiently compute things (i.e., algorithms) –We’re going to learn a lot of these in CS

21 Beyond the bounding box  Computing a bounding box isn’t hard –Hint: the right edge is computed by the code we showed a few slides ago –You’ll write this and play with it in A2  Does it work?

22 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

23 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 24 img thresh Your thresholding function [X,Y] = find(thresh); X = % x-coords of nonzero points Y = % y-coords of nonzero points

25 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

26 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? 27

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, … } 28 Default for images

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: 29 doubleuint8uint16 uint8(200) + uint8(200) % Result = ?

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 30

For next time  Attend section tomorrow in the lab  Reminder: Quiz on Thursday, beginning of class 31