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 Dr Ben Leong NUS School of Computing 28 Nov 2012

Embed Size (px)

Citation preview

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

What are stereograms?What are stereograms?

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

How do stereograms work?How do stereograms work?

Image plane

A BC D

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

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

Generation of stereogramsGeneration of stereograms

Image plane

Generation of stereogramsGeneration of stereograms

Image plane

Generation of stereogramsGeneration of stereograms

Image plane

How far?

Generation of stereogramsGeneration of stereograms

Image plane

AD

-z

E

s

zD

E

z

s

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

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

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

Primitive building blocksPrimitive building blocks

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

Primitive building blocksPrimitive building blocks

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

Primitive building blocksPrimitive building blocks

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

Primitive building blocksPrimitive building blocks

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

Primitive building blocksPrimitive building blocks

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

Primitive building blocksPrimitive building blocks

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

Primitive building blocksPrimitive building blocks

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

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))

Derived Operation:Derived Operation:Rotating Upside DownRotating Upside Down

(clear)(clear)

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

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))

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))

Means of Combination:Means of Combination:StackingStacking

(clear)(clear)

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

Multiple StackingMultiple Stacking

(clear)(clear)

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

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

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))

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

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)

Repeating the patternRepeating the pattern

(clear)(clear)

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

Repeating multiple timesRepeating multiple times

(clear)(clear)

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

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)))

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))

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)))))

Another regular patternAnother regular pattern

(clear)(clear)

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

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

Creating 3D objectsCreating 3D objects

means

Overlay OperationOverlay Operation

(clear)(clear)

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

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))

ScalingScaling

(clear)(clear)

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

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))

Your First StereogramYour First Stereogram

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>)

What if you What if you cannot see cannot see

stereograms? stereograms?

Think DifferentThink Different

Image plane

Think DifferentThink Different

Image plane

Think DifferentThink Different

Image plane

3D Anaglyphs3D Anaglyphs

Image plane

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

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

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

Simulating 3D Effect with AnimationSimulating 3D Effect with Animation

Image plane

QUESTIONSQUESTIONS

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

basics of basics of programming! programming!

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

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

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?