introduction to computer science – chapter 9 csc 2010 spring 2011 marco valero

11
Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Upload: silvester-kelley

Post on 29-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Introduction to Computer Science – Chapter 9CSc 2010Spring 2011Marco Valero

Page 2: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Overview

• Review image basics

• Making pictures

• Image processing

• Shrinking and enlarging

• Blurring and sharpening

• Negative and embossing

• Robot vision

Page 3: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Image basics

• We used takePicture and show to

respectively take and show pictures already

• We’ve also seen savePicture as a means to

save a snapshot to disk

• makePicture(<filename>) will load a picture

from disk and return a picture object

▫myPic = makePicture(pickAFile())

Page 4: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Image basics

•Height and width can be retrieved from a

picture

▫getHeight(<pic>) and getWidth(<pic>)

•show(<pic>,<title>)

▫We can call show(myPic, ‘my title’) to

create a window with a title

Page 5: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Making pictures

• Rather than taking pictures, we can create our

own

▫width = height = 100

▫newPic = makePicture(width, height, black)

• RGB

▫Each is a byte, 0-255

• We can loop through each pixel just like a matrix

and change the value

Page 6: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Image processing

• We can think of the bitmap as a matrix then any

transformation from one picture to another is a

matrix transformation

• 500x500 pixel bitmap

▫250k pixels

▫ If 10 operations per transformation that’s 2.5 mil

ops!

• Image processing is intensive

Page 7: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Shrinking & enlarging

•If we wanted to shrink a given n x n image

by a factor of f

▫Result size is n/f x n/f

▫Bitmap[x*f, y*f] -> NewBitmap[x, y]

•Enlarging is the inverse

▫Result size is n*f x n*f

▫Bitmap[x/f, y/f] -> NewBitmap[x, y]

Page 8: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Blurring & sharpening

• Pixel transformation as a result of its local

neighbors’ values

• Blurring is done by setting a pixels value to the

averages of its neighbors

▫V = sum([getRed(up),getRed(left),…]) / 5

• Sharpening is done by subtracting the sum of its

neighbors

▫V = 5*getRed(self) – sum([neighborvalues])

Page 9: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Negative & embossing

•To create a negative of an image we

simply subtract 255 from the current

value

▫V = 255 – getRed(pixel)

•Creating an embossed effect is done by

subtracting a neighbors value from a pixel

▫V = getRed(pixel) – getRed(neighbor)

Page 10: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Robot vision

•Are computers good at recognizing

objects?

•Are _we_ good at recognizing objects?

•What would a simple tracking code look

like?

Page 11: Introduction to Computer Science – Chapter 9 CSc 2010 Spring 2011 Marco Valero

Robot vision

•What if we only focused on the object?

▫We can use high contrast filter

▫What are the issues with this?

•Blob filtering

▫takePicture(‘blob’)

▫Compare to older program