63
NUS Computing Camp for NUS Computing Camp for Junior Colleges & High School Junior Colleges & High School Students Students Stereogram Stereogram Generation Generation Workshop Workshop Dr Ben Leong Dr Ben Leong NUS School of Computing NUS School of Computing 28 Nov 2012 28 Nov 2012

NUS Computing Camp for Junior Colleges & High School Students Stereogram Generation Workshop

Embed Size (px)

DESCRIPTION

NUS Computing Camp for Junior Colleges & High School Students Stereogram Generation Workshop. Dr Ben Leong NUS School of Computing 28 Nov 2012. What are stereograms?. How do stereograms work?. Because there is a small separation between our eyes, they perceive slightly different images - PowerPoint PPT Presentation

Citation preview

Page 1: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

NUS Computing Camp for NUS Computing Camp for Junior Colleges & High School Students Junior Colleges & High School Students

Stereogram Stereogram Generation WorkshopGeneration Workshop

Dr Ben LeongDr Ben LeongNUS School of ComputingNUS School of Computing

28 Nov 201228 Nov 2012

Page 2: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

What are stereograms?What are stereograms?

Page 3: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

How do stereograms work?How do stereograms work?

Because there is a small separation Because there is a small separation between our eyes, they perceive slightly between our eyes, they perceive slightly different imagesdifferent images

These differences allow us to perceive These differences allow us to perceive depth. depth.

Autostereograms work by repeating Autostereograms work by repeating patterns in such a way as to give us an patterns in such a way as to give us an illusionillusion of depth of depth

Page 4: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

How do stereograms work?How do stereograms work?

Image plane

A BC D

Page 5: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Generation of stereogramsGeneration of stereograms

Key idea: compute the sets of points Key idea: compute the sets of points that are constrained to be of the that are constrained to be of the same coloursame colour

Note that we can compute the Note that we can compute the required image one line at a timerequired image one line at a time

How do we compute these sets? How do we compute these sets? Use simple geometryUse simple geometry

Page 6: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Generation of stereogramsGeneration of stereograms

1.1. Create a 3-d model of the objectCreate a 3-d model of the object Use a function Use a function f(x,y)f(x,y) to define the depth of to define the depth of

an objectan object

2.2. Decide on some parametersDecide on some parameters Distance between eyes and imageDistance between eyes and image Position of object relative to image planePosition of object relative to image plane Distance between the two eyesDistance between the two eyes

3.3. Compute one line at a timeCompute one line at a time

Page 7: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Generation of stereogramsGeneration of stereograms

Image plane

Page 8: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Generation of stereogramsGeneration of stereograms

Image plane

Page 9: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Generation of stereogramsGeneration of stereograms

Image plane

How far?

Page 10: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Generation of stereogramsGeneration of stereograms

Image plane

AD

-z

E

s

zD

E

z

s

Page 11: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

How would YOU create a How would YOU create a stereogram? stereogram?

We have already written the program that We have already written the program that will automatically generate a stereogram will automatically generate a stereogram based on the method described.based on the method described.

What you need to do is to create a depth What you need to do is to create a depth map and feed it to the stereogram map and feed it to the stereogram generator:generator:

STEREOGRAM

GENERATOR

depth map

stereogram

Page 12: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

How would YOU create a How would YOU create a stereogram?stereogram?

Our stereogram generator is written in Our stereogram generator is written in SchemeScheme

You will learn how to manipulate You will learn how to manipulate some simple objects to build your some simple objects to build your own depth maps and create your own own depth maps and create your own stereogramsstereograms

Simple programming Simple programming

Page 13: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Plan for TodayPlan for TodayYou will get a worksheet that will You will get a worksheet that will

guide you through what we have guide you through what we have discusseddiscussed

My lab assistants will help youMy lab assistants will help youCreate Create cool stereogramscool stereograms and and

share with your friends and familyshare with your friends and family

Page 14: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Primitive building blocksPrimitive building blocks

(show rcross-bb)(show rcross-bb)

Page 15: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Primitive building blocksPrimitive building blocks

(show corner-bb)(show corner-bb)

Page 16: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Primitive building blocksPrimitive building blocks

(show sail-bb)(show sail-bb)

Page 17: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Primitive building blocksPrimitive building blocks

(show nova-bb)(show nova-bb)

Page 18: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Primitive building blocksPrimitive building blocks

(show heart-bb)(show heart-bb)

Page 19: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Primitive building blocksPrimitive building blocks

(show circle-bb)(show circle-bb)

Page 20: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Primitive building blocksPrimitive building blocks

(show spiral-bb)(show spiral-bb)

Page 21: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Primitive Operation:Primitive Operation:Rotating to the RightRotating to the Right

(clear)(clear)

(show (quarter-turn-right sail-bb))(show (quarter-turn-right sail-bb))

Page 22: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Derived Operation:Derived Operation:Rotating Upside DownRotating Upside Down

(clear)(clear)

(show (turn-upside-down sail-bb))(show (turn-upside-down sail-bb))

Page 23: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

How about How about Rotating to the Left?Rotating to the Left?

(clear)(clear)

(show (quarter-turn-left sail-bb))(show (quarter-turn-left sail-bb))

Page 24: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Flipping ObjectsFlipping Objects

(clear)(clear)

(show (flip-horiz nova-bb))(show (flip-horiz nova-bb))

(clear)(clear)

(show (flip-vert nova-bb))(show (flip-vert nova-bb))

Page 25: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Means of Combination:Means of Combination:StackingStacking

(clear)(clear)

(show (stack rcross-bb sail-bb))(show (stack rcross-bb sail-bb))

Page 26: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Multiple StackingMultiple Stacking

(clear)(clear)

(show (stack rcross-bb (show (stack rcross-bb

(stack rcross-bb sail-bb)))(stack rcross-bb sail-bb)))

Page 27: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Placing objects one beside Placing objects one beside the otherthe other

(clear)(clear)

(show (beside sail-bb rcross-bb))(show (beside sail-bb rcross-bb))

Page 28: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

A complex objectA complex object

(clear)(clear)

(show(show

(stack(stack

(beside (beside

(quarter-turn-right rcross-bb)(quarter-turn-right rcross-bb)

(turn-upside-down rcross-bb))(turn-upside-down rcross-bb))

(beside (beside

rcross-bbrcross-bb

(quarter-turn-left rcross-bb))))(quarter-turn-left rcross-bb))))

This operation is also known This operation is also known asas make-crossmake-cross

Page 29: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Naming your objects with defineNaming your objects with define

(clear)(clear)

(define myPic (define myPic

(make-cross sail-bb))(make-cross sail-bb))

(show myPic)(show myPic)

(define myPic2 (define myPic2

(make-cross nova-bb))(make-cross nova-bb))

(show myPic2)(show myPic2)

Page 30: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Repeating the patternRepeating the pattern

(clear)(clear)

(show (make-cross (make-cross nova-bb)))(show (make-cross (make-cross nova-bb)))

Page 31: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Repeating multiple timesRepeating multiple times

(clear)(clear)

(show (repeat-pattern 4 make-cross nova-bb))(show (repeat-pattern 4 make-cross nova-bb))

Page 32: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

What about 3 rows?What about 3 rows?

(clear)(clear)

(show (stack-frac 1/3 rcross-bb sail-bb))(show (stack-frac 1/3 rcross-bb sail-bb))

(clear)(clear)

(show (stack-frac 1/3 rcross-bb(show (stack-frac 1/3 rcross-bb

(stack rcross-bb rcross-bb)))(stack rcross-bb rcross-bb)))

Page 33: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Repeating n timesRepeating n times

(clear)(clear)

(show (stackn 3 nova-bb))(show (stackn 3 nova-bb))

(clear)(clear)

(show (stackn 5 nova-bb))(show (stackn 5 nova-bb))

Page 34: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

A rectangular repeated patternA rectangular repeated pattern

(clear)(clear)

(show (stackn 5 (quarter-turn-right (show (stackn 5 (quarter-turn-right

(stackn 5 (quarter-turn-left nova-(stackn 5 (quarter-turn-left nova-bb)))))bb)))))

Page 35: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Another regular patternAnother regular pattern

(clear)(clear)

(show (nxn 3 (make-cross rcross-bb)))(show (nxn 3 (make-cross rcross-bb)))

Page 36: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Creating 3D objects Creating 3D objects

We use greyscale to represent depthWe use greyscale to represent depthBlack is nearest to youBlack is nearest to youWhite is furthest awayWhite is furthest away

means

Page 37: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Creating 3D objectsCreating 3D objects

means

Page 38: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Overlay OperationOverlay Operation

(clear)(clear)

(show (overlay sail-bb rcross-bb))(show (overlay sail-bb rcross-bb))

Page 39: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Advanced Overlay OperationAdvanced Overlay Operation

(clear)(clear)

(show (overlay-frac 1/4 corner-bb heart-bb))(show (overlay-frac 1/4 corner-bb heart-bb))

Page 40: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

ScalingScaling

(clear)(clear)

(show (scale 1/2 heart-bb))(show (scale 1/2 heart-bb))

Page 41: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Wait, did we say we’re creating Wait, did we say we’re creating stereograms?stereograms?

Yeah, that’s the easy part!Yeah, that’s the easy part!Do: Do:

(stereogram <depth map>)(stereogram <depth map>)Example:Example:(show (overlay sail-bb rcross-bb))(show (overlay sail-bb rcross-bb))

(stereogram (stereogram

(overlay sail-bb rcross-bb))(overlay sail-bb rcross-bb))

Page 42: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Your First StereogramYour First Stereogram

Page 43: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Loading from/Saving to FileLoading from/Saving to File

You can also create a depth map using You can also create a depth map using some paint program and load using:some paint program and load using:

(load-map <filename>)(load-map <filename>)

You can save your work with:You can save your work with:

(save <filename>)(save <filename>)

Page 44: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

What if you What if you cannot see cannot see

stereograms? stereograms?

Page 45: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Think DifferentThink Different

Image plane

Page 46: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Think DifferentThink Different

Image plane

Page 47: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Think DifferentThink Different

Image plane

Page 48: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

3D Anaglyphs3D Anaglyphs

Image plane

Use filters to show one image to each eye!Use filters to show one image to each eye!

Page 49: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

What else can we What else can we do to create an do to create an illusion of 3D? illusion of 3D?

Page 50: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop
Page 51: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Page 52: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Page 53: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Page 54: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Page 55: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Page 56: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Page 57: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Page 58: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop
Page 59: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

QUESTIONSQUESTIONS

Page 60: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

What you have What you have seen are the seen are the

basics of basics of programming! programming!

Page 61: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

The World of Computer ScienceThe World of Computer Science

Programming

Database

Artificial IntelligenceLogic

Data Structures & Algorithms

Compilers

Graphics

Vision

Software EngineeringTheory

Human-Computer Interaction

Programming Languages

Architecture

Operating SystemsNetworks

Security

Page 62: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Words of AdviceWords of Advice

Consider Computer Science if:Consider Computer Science if:Like Maths (esp. ‘elegant’ Maths)Like Maths (esp. ‘elegant’ Maths)Like to ‘create’ or build thingsLike to ‘create’ or build thingsWant to make a difference to society in Want to make a difference to society in

the work you dothe work you doYou are impatient and you want to see You are impatient and you want to see

your work out there in the real world in a your work out there in the real world in a hurryhurry

Page 63: NUS Computing Camp for   Junior Colleges & High School Students Stereogram Generation Workshop

Words of AdviceWords of Advice

Follow your heart, Follow your heart, NOTNOT the market the marketFigure out what you like and what Figure out what you like and what

you’re good at – and keep doing ityou’re good at – and keep doing itTry and explore different thingsTry and explore different thingsAsk yourself: What do you want to Ask yourself: What do you want to

do with your life? WHY?do with your life? WHY?