Twelve painting with procedures. Overview Making shaded images with procedures Making a more elegant language Making textures with noise functions.

Slides:



Advertisements
Similar presentations
RAPTOR Syntax and Semantics By Lt Col Schorsch
Advertisements

Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Image Data Representations and Standards
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
CS 551 / CS 645 Antialiasing. What is a pixel? A pixel is not… –A box –A disk –A teeny tiny little light A pixel is a point –It has no dimension –It occupies.
December 5, 2013Computer Vision Lecture 20: Hidden Markov Models/Depth 1 Stereo Vision Due to the limited resolution of images, increasing the baseline.
Lecture 4 Linear Filters and Convolution
Six compound procedures and higher-order procedures.
Twenty high-level operations on pictures. Recap: vector graphics constructors [box width height] Creates a picture with a box [group pictures …] Makes.
Eleven colors and rasters. Color objects [color name] Returns color with the specified name [color red green blue] Returns color with the specified amounts.
Connecting with Computer Science, 2e
Fifteen high-level operations on pictures. Recap: vector graphics constructors [box width height] Creates a picture with a box [group pictures …] Makes.
Fourteen lists and compound data. Some primitive data types Integers (whole numbers) 1, 2, 3, -1, 0, , etc. “Floating-point” numbers ,
Eleven colors and rasters. Color objects Meta represents colors with color objects You can create a color by saying: [color r g b] r: amount of red (0-255)
Lec 5 Feb 10 Goals: analysis of algorithms (continued) O notation summation formulas maximum subsequence sum problem (Chapter 2) three algorithms image.
2D Fourier Theory for Image Analysis Mani Thomas CISC 489/689.
Eighteen painting with procedures. Review [bitmap-from-procedure procedure width height] Returns a bitmap width pixels by height pixels Obtains colors.
Image Analysis Preprocessing Arithmetic and Logic Operations Spatial Filters Image Quantization.
Professor Jennifer Rexford COS 217
Eleven colors and rasters. Color objects Meta represents colors with color objects You can create a color by saying: [color r g b] r: amount of red (0-255)
lecture 2, linear imaging systems Linear Imaging Systems Example: The Pinhole camera Outline  General goals, definitions  Linear Imaging Systems.
Post-rendering Cel Shading & Bloom Effect
What to do when you are done. PRINTING WITH PHOTOSHOP.
Principles of the Global Positioning System Lecture 11 Prof. Thomas Herring Room A;
Procedural Textures.
Gaussian process modelling
COMP 175: Computer Graphics March 24, 2015
Image Synthesis Rabie A. Ramadan, PhD 3. 2 Our Problem.
Color Correct and Remove Keystoning A minimalist approach to photographing your art By Paul Marley.
IT253: Computer Organization
Copyright © 2010 Pearson Education, Inc. Chapter 6 The Standard Deviation as a Ruler and the Normal Model.
Shading CMSC 435/634. RenderMan Light Displacement Surface Volume Imager.
Image Synthesis Rabie A. Ramadan, PhD D Images.
December 4, 2014Computer Vision Lecture 22: Depth 1 Stereo Vision Comparing the similar triangles PMC l and p l LC l, we get: Similarly, for PNC r and.
September 5, 2013Computer Vision Lecture 2: Digital Images 1 Computer Vision A simple two-stage model of computer vision: Image processing Scene analysis.
Shading CMSC 435/634.
Week 6 - Wednesday.  What did we talk about last time?  Light  Material  Sensors.
EE663 Image Processing Dr. Samir H. Abdul-Jauwad Electrical Engineering Department King Fahd University of Petroleum & Minerals.
Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T Computer Vision Tahun: 2010.
Copyright 2004 Ken Greenebaum Introduction to Interactive Sound Synthesis Lecture 18:Noise Ken Greenebaum.
Design Studies 20 ‘Show Off’ Project How to make a computer monitor In Google Sketchup By: Liam Jack.
CSC508 Convolution Operators. CSC508 Convolution Arguably the most fundamental operation of computer vision It’s a neighborhood operator –Similar to the.
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities Prof. Charlene Tsai.
Creating a Silhouette in Illustrator. Go File>Place and place the photo on the artboard. Select the photo and click Live Trace (its on the tool bar right.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
02/05/2002 (C) University of Wisconsin 2002, CS 559 Last Time Color Quantization Mach Banding –Humans exaggerate sharp boundaries, but not fuzzy ones.
Sampling Pixel is an area!! – Square, Rectangular, or Circular? How do we approximate the area? – Why bother? Color of one pixel Image Plane Areas represented.
Data Representation. What is data? Data is information that has been translated into a form that is more convenient to process As information take different.
October 16, 2014Computer Vision Lecture 12: Image Segmentation II 1 Hough Transform The Hough transform is a very general technique for feature detection.
(c) 2002 University of Wisconsin, CS 559
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities May 2, 2005 Prof. Charlene Tsai.
Computer Graphics & Image Processing Chapter # 4 Image Enhancement in Frequency Domain 2/26/20161.
Instructor: Mircea Nicolescu Lecture 5 CS 485 / 685 Computer Vision.
COSC 1P02 Introduction to Computer Science 5.1 Cosc 1P02 Week 5 Lecture slides Psychiatrist to patient "You have nothing to worry about - anyone who can.
The accuracy of averages We learned how to make inference from the sample to the population: Counting the percentages. Here we begin to learn how to make.
Filters– Chapter 6. Filter Difference between a Filter and a Point Operation is that a Filter utilizes a neighborhood of pixels from the input image to.
IS502:M ULTIMEDIA D ESIGN FOR I NFORMATION S YSTEM D IGITAL S TILL I MAGES Presenter Name: Mahmood A.Moneim Supervised By: Prof. Hesham A.Hefny Winter.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Some Maths David Meredith Aalborg University.
Week 7 - Monday CS361.
high-level operations on pictures
Digital Image Processing Lecture 16: Segmentation: Detection of Discontinuities Prof. Charlene Tsai.
painting with procedures
Fitting Curve Models to Edges
Histogram Histogram is a graph that shows frequency of anything. Histograms usually have bars that represent frequency of occuring of data. Histogram has.
Ch2: Data Representation

Multimedia Summer Camp
Presentation transcript:

twelve painting with procedures

Overview Making shaded images with procedures Making a more elegant language Making textures with noise functions

Making bitmaps [bitmap-from-procedure procedure width height] Returns a bitmap width pixels by height pixels Obtains colors for pixels by calling procedure Passes procedure a point (vector) object with the coordinates Procedure returns a color object (color image) or a single number (grayscale image)

Making a grayscale ramp We can use dot products to make a grayscale ramp The dot-product of two vectors is a single number It increases as The first vector grows in the direction of the second, or alternatively, The second grows in the direction of the first i.e. it’s symmetrical Each vector gets bigger By manipulating the direction of the vector in the dot- product, we can get different directions for the ramp [bitmap-from-procedure [p → [dot p [vector ]]] ]

Changing the vector direction [bitmap-from-procedure [p → [dot p [vector 1 0]]] ] [bitmap-from-procedure [p → [dot p [vector 0 1]]] ]

Clipping Why is this one different? The display only has the ability to produce amounts of light in the range [bitmap-from-procedure [p → [dot p [vector 1 1]]] ]

Constructive laziness It’s bad to keep typing the same arguments over and over again Slows you down Frustrates you Leads to errors So make a new procedure that Just takes the parameter we care about and Fills in the rest for us [define show [procedure → [bitmap-from-procedure procedure ]]] Now we can just say: [show [p → [dot p [vector 1 1]]]]

Making it (slightly) more efficient This version calls the vector procedure for each pixel Wasteful Arguments are always the same Same vector is always returned (more or less) We only need to call it once So we can call it once and save it in a local variable [show [p → [dot p [vector 1 1]]]] [show [with vec = [vector 1 1] [p → [dot p vec]]]

Making another pattern The magnitude procedure gives the length of the vector passed to it So using it as the painting function for a bitmap gives us A radial pattern That’s black at (0,0) And grows white farther away Like a grayscale ramp, but circular [show magnitude]

Question What’s the difference between: magnitude and: [p → [magnitude p]] Nothing; they behave the same Both take a vector as input And return its magnitude as output [show magnitude] [show [p → [magnitude p]]]

Shifting it over How do we shift it so that the black part is in the center of the image? We shift the vector we’re taking the magnitude of We use − to shift vectors What vector do we subtract off? It’s a 256×256 image So the center is (128, 128) [show [p → [magnitude [− p [vector ]]]]]

Making it brighter Now it’s too dark How do we fix it? Brighten by multiplying Multiplying by 2 Doubles the brightness Although now it clips [show [p → [× 2 [magnitude [− p [vector ]]]]]]

White on black Okay, but what if we want it to be white in the center and black on the outside? How do we fix it? Just subtract The brightness computed brightness From 255 (the maximum brightness) [show [p → [− 255 [× 2 [magnitude [− p [vector ]]]]]]]

Overview Making shaded images with procedures Making a more elegant language Making textures with noise functions

Thinking about it differently We started with a simple pattern (magnitude) We shifted it over We brightened it We inverted it But the code doesn’t make that clear Can we make the code reflect our intentions more clearly? [show [p → [− 255 [× 2 [magnitude [− p [vector ]]]]]]]

Making the code clearer We’d like to be able to write the code like this Take the magnitude image Shift it by [vector ] Brighten it And invert it Can we make Meta work this way? [show [invert [brighten 2 [shift [vector ] magnitude]]]]

Procedures that operate on whole patterns Let’s call A pattern a procedure that takes a point and returns a brightness A pattern operator a procedure that takes a pattern and returns a new pattern If we had pattern operators For shifting, brightening, and inverting We could write the code much more clearly [shift vector pattern] Makes a new pattern that’s pattern shifted over by vector [brighten level pattern] Makes a new pattern that’s like pattern but with its brightness multiplied by level [invert pattern] Makes a new pattern that’s the same as pattern, but with black exchanged for white

Programming with pattern operators Now we can take the magnitude pattern Since magnitude takes a point as input And returns a number So we can use it as a pattern [show magnitude]

Programming with pattern operators Now we can take the magnitude pattern Shift it [show [shift [vector ] magnitude]]

Programming with pattern operators Now we can take the magnitude pattern Shift it Brighten it [show [brighten 2 [shift [vector ] magnitude]]]

Programming with pattern operators Now we can take the magnitude pattern Shift it Brighten it And invert it Now we don’t even need to know that patterns are really procedures [show [invert [brighten 2 [shift [vector ] magnitude]]]]

Writing brighten Okay, now let’s write brighten Remember we want to be able to say something like: [brighten 2 [p → [magnitude p]]] And get back something that behaves like: [p → [× 2 [magnitude p]]] ► [define brighten ???]

Writing brighten Okay, now let’s write brighten Brighten must Take a brightness level and a pattern as arguments ► [define brighten [level pattern → ???]]

Writing brighten Okay, now let’s write brighten Brighten must Take a brightness level and a pattern as arguments Return a new procedure that Takes a point as an argument ► [define brighten [level pattern → [p → ???]]]

Writing brighten Okay, now let’s write brighten Brighten must Take a brightness level and a pattern as arguments Return a new procedure that Takes a point as an argument And computes the correct brightness ► [define brighten [level pattern → [p → [× level [pattern p]]]]]

Higher-order procedures Brighten is called a “higher-order” procedure It takes a procedure as input And returns a new procedure as a result Procedures that make new procedures are perfectly acceptable And very useful [define brighten [level pattern → [p → [× level [pattern p]]]]] [brighten 2 magnitude] = [p → [× 2 [magnitude p]]] [brighten 3 magntidue] = [p → [× 3 [magnitude p]]] [brighten 3 [brighten 2 magnitude]] = [p → [× 3 [ [p → [× 2 [magnitude p]]] p]] ≈ [p → [× 3 [× 2 [magnitude p]]]]

Writing invert Okay, now let’s write invert► [define invert ???]

Writing invert Okay, now let’s write invert Invert must Take a a pattern ► [define invert [pattern → ???]]

Writing invert Okay, now let’s write invert Invert must Take a a pattern Return a new procedure that Takes a point as an argument ► [define invert [pattern → [p → ???]]]

Writing invert Okay, now let’s write invert Invert must Take a a pattern Return a new procedure that Takes a point as an argument And computes the correct brightness ► [define invert [pattern → [p → [− 255 [pattern p]]]]]

Writing shift Patterns are procedures So shift is a higher order procedure It takes a procedure as an argument And returns a new procedure as its result ► [define shift ???]

Writing shift Patterns are procedures So shift is a higher order procedure It takes a procedure as an argument And returns a new procedure as its result Shift must Take an offset and a pattern as arguments ► [define shift [offset pattern → ???]]

Writing shift Patterns are procedures So shift is a higher order procedure It takes a procedure as an argument And returns a new procedure as its result Shift must Take an offset and a pattern as arguments Return a new procedure that Takes a point as an argument ► [define shift [offset pattern → [p → ???]]]

Writing shift Patterns are procedures So shift is a higher order procedure It takes a procedure as an argument And returns a new procedure as its result Shift must Take an offset and a pattern as arguments Return a new procedure that Takes a point as an argument And computes the correct brightness ► [define shift [offset pattern → [p → [pattern [− p offset]]]]]

Repeated patterns [mod a b] For positive numbers, returns the remainder when dividing a by b When a is negative, returns b minus the remainder This turns out to be just the right thing to make a repeated texture [define replicate [width height pattern → [p → [pattern [point [mod p.X width] [mod p.Y height]]]] ]] [show [replicate magnitude]]

Repeated patterns [brighten 8 [replicate [shift [point 32 32] magnitude]]]] [replicate [invert magnitude]]

And now, in color … [define colorize [r-pattern g-pattern b-pattern → [p → [color [r-pattern p] [g-pattern p] [b-pattern p]]]]] Takes three grayscale patterns and combines them into a single color pattern

Groovy, man [colorize [brighten 8 [replicate [shift [point 32 32] magnitude]]] [replicate [invert magnitude]] [p → 50]]]

Groovy, man [colorize [brighten 8 [replicate [shift [point 32 32] magnitude]]] [replicate [p → [dot p [point 1 1]]]] [p → 50]]]

Overview Making shaded images with procedures Making a more elegant language Making textures with noise functions

Spatial frequencies Pictures can be thought of as having harmonic structure Like sound Picture can be thought of as many different frequencies combined We won’t go into this in any detail, but … Frequency corresponds roughly to size Fine detail is high frequency Bigger structures are lower frequeny

White noise White noise is a random signal Every pixel (sample) computed using a random number generator Called “white” because it contains equal amounts of all frequencies Not very interesting as a texture ► [show [p → [random-integer 0 255]]]

Bandpass noise But now suppose we zoom in between the randomly chosen pixel values And smoothly interpolate between them The result is still a random texture, but it’s missing the very high and very low frequencies [noise point] Interpolated noise Gaussian distribution Result is between -0.7 and 0.7 [show [p → [+ 128 [× 128 [noise [ ⁄ p 30]]]]]]

Bandpass noise at different frequences [show [p → [+ 128 [× 128 [noise [ ⁄ p 10]]]]]] [show [p → [+ 128 [× 128 [noise [ ⁄ p 80]]]]]]

Summing bandpass noise You can get interesting effects by summing bandpass noise at different frequencies [show [p → [+ 128 [× 128 [+ [noise [ ⁄ p 80]] [noise [ ⁄ p 40]] [noise [ ⁄ p 20]]]]]]]

“1/f noise” Important kind of noise Amplitude of frequency f is 1/f Self-similar (like fractals) Zoom in on it and it still looks like itself Approximated using bandpass noise Compute at different scales Sum with weights that vary inversely with frequency Also known as Brown noise (Brownian motion) Turbulence [show [p → [+ 128 [× 128 [+ [noise [ ⁄ p 80]] [ ⁄ [noise [ ⁄ p 40]] 2] [ ⁄ [noise [ ⁄ p 20]] 4]]]]]]

Perlin noise Ken Perlin (1985) Technique for approximating 1/f noise using interpolated bandpass noise Built into most graphics cards [turbulence point] Computes a sum of many calls to noise All you really need to understand for this class [show [p → [+ 128 [× 128 [turbulence [ ⁄ p 30]]]]]]

Annoying bug/misfeature You have to divide p by some number before calling noise or turbulence The noise function returns 0 for all points whose coordinates are both integers So you have to divide by something to make sure the coordinates are usually not integers

The Art of Noise [show [p → [× 255 [turbulence [ ⁄ p 30]]]]] Noise clips on low end [show [p → [abs [× 255 [turbulence [ ⁄ p 30]]]]]] Abs produces abrupt change on low end

The Art of Noise [show [with center = [point ] [p → [× 255 [sin [+ [ ⁄ [magnitude [− p center]] 10] [turbulence [ ⁄ p 30]]]]]]] Noise used in input to another function (sin) [show [p → [× 255 [sin [+ [turbulence [ ⁄ p 20]] [dot p [point ]]]]]]]

Extra arguments to turbulence Turbulence works by calling noise at different frequencies and summing You can call turbulence with three extra arguments Drop-off factor Amplitude of the new noise component drops by this factor each iteration Frequency multiplier Frequency get multiplied by this each iteration Iteration count Try playing with the extra arguments The default values are 2, 2, and 4 [show [p → [+ 127 [× 128 [turbulence [ ⁄ p 30] ]]]]]

Extra arguments to turbulence Turbulence works by calling noise at different frequencies and summing You can call turbulence with three extra arguments Drop-off factor Amplitude of the new noise component drops by this factor each iteration Frequency multiplier Frequency get multiplied by this each iteration Iteration count Try playing with the extra arguments The default values are 2, 2, and 4 [show [p → [+ 127 [× 128 [turbulence [ ⁄ p 30] 5 2 8]]]]]

The Art of Noise [show [p → [× 256 [turbulence [× p.X p.Y]]]]] You can also call noise or turbulence with a number as an argument (rather than a point) [show [p → [× 256 [cos [× 10 [turbulence [ ⁄ p 50]]]]]]]

Using the code from today’s lecture Meta is distributed with the code for brighten, invert, etc. To load it and make it available, just type: [using Examples.Painting] Doing it twice won’t hurt anything You only need to do this when you start using Meta But you have to do it over again if you exit Meta and run it again later