Topics notes only - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Topics notes only

Description:

CSE 331 Lecture 6. Mandelbrot Set. Coloring image points. Julia Set ... set, color it based on the count, indicating the 'speed' with which it departed ... – PowerPoint PPT presentation

Number of Views:124
Avg rating:3.0/5.0
Slides: 31
Provided by: alaneu
Category:

less

Transcript and Presenter's Notes

Title: Topics notes only


1
CSE 331 Lecture 6
Topics (notes only) Images Pixels Color Color
Tables Complex Numbers Representation Operatio
ns Complex number plane Mandelbrot Julia
Sets Recursive function Strange
attractor Color coding nonmembers
Mandelbrot Set Coloring image points Julia
Set Initial conditions Image
Representation File (PPM file format) C
system() function Linux environment g make x
view, eog, xv ddd xxgdb (debuggers) Summary
2
Shellsort (quick aside)
  • Sorts using decreasing intervals (1,4,13,40,.)
  • Finding max interval kn 3 kn-1 1
  • Finding next smaller interval kn-1 (kn 1)/3
  • Rough algorithm
  • for each interval k (max downto 1)
  • for each sublist of elements k positions apart
  • insertion Sort the sublist
  • Detailed algorithm 1
  • for each interval k (max downto 1)
  • for each j (first in k separated sublist)
  • for each i (j upto n-k stepsize k)
  • temp elementi
  • shift larger elements in sublist
  • copy (insert) temp into hole

3
Shellsort (cont)
  • Detailed algorithm 2
  • Note middle two loops are merged into one that
    scans list only once and for each element inserts
    next value in the appropriate k separated sublist
  • for each interval k (max downto 1)
  • for each i (j upto n-1 stepsize 1)
  • temp elementi
  • shift larger elements in this k-sublist
  • copy (insert) temp into hole

4
Images (photographic)
5
Images (fractal)
6
Image Representation
  • An image is a rectangular grid of pixels
  • A pixel is a single picture element
  • Each pixel has a value representing the color (or
    intensity) of a single point in the image
  • Image size is in pixels (640 x 480, etc.)
  • Image resolution is in pixels / inch

7
Pixel Color
8
Color Maps
  • If each pixel is a single byte, its value is
    often used as an index into a color map
  • (a table of actual 3 byte color codes)

Black Dark Red Medium Yellow Bright Cyan White
9
Pixel Class
  • class pixel
  • public
  • pixel (unsigned char r 0, unsigned char g 0,
  • unsigned char b 0)
  • red(r), green(g), blue(b)
  • setColor (unsigned char r, unsigned char g,
  • unsigned char b)
  • red r green g blue b
  • getColor(unsigned char r, unsigned char g,
  • unsigned char b)
  • ( r red g green b blue
  • private
  • unsigned char
  • red, green, blue // true color components

10
Image in memory
  • // matrix template class from Ch 5
  • // is 2-D grid using vector of vectors
  • include d_matrix.h
  • // declare white image of 500 x 500 pixels
  • matrixltpixelgt image(500,500,pixel(255,255,255))
  • // set color of pixel3,4
  • image34.setColor(100,20,255)
  • // get color (r,g,b) of pixeli,j
  • unsigned char r,g,b
  • imageij.getColor(r,g,b)

11
Complex Numbers
  • External format a b j
  • a and b are real coefficients
  • j is sqrt(-1)
  • Represents a point on a 2D Cartesian plane
  • Real (horizontal) axis
  • Imaginary (vertical) axis
  • Addition x1 x2
  • (a1 b1 j) (a2 b2 j) (a1 a2) (b1 b2)
    j
  • Subtraction x1 - x2
  • (a1 b1 j) - (a2 b2 j) (a1 - a2) (b1 - b2)
    j

12
Complex Numbers
  • Multiplication x1 x2
  • (a1 b1 j) (a2 b2 j) (a1a2 - b1b2) (a1b2
    a2b1) j
  • Division x1 / x2
  • Note multiply top bottom by complex conjugate
  • (a1 b1 j) / (a2 b2 j)
  • ((a1 b1 j) (a2 - b2 j)) / ((a2 b2 j) (a2
    - b2 j))
  • ((a1a2b1b2) / (a2a2b2b2)) ((a2b1-a1b2) /
    (a2a2b2b2)) j

13
Complex Number Plane
14
Mandelbrot Julia Sets
  • Both based on repeated (recursive) application of
    the following function, where C and Z are both
    complex numbers
  • Zn Zn-1Zn-1 C
  • If the distance of Zn from the origin never
    exceeds 2.0 then the original point is a member
    of the set
  • 100 applications of the function is a sufficient
    test

15
Mandelbrot Sets
  • There is ONLY ONE Mandelbrot Set
  • Initial conditions are .
  • Z1 0 0 j and
  • C a complex number corresponding to a point on
    the complex number plane in the range -2.25 ..
    0.75 real and -1.5 .. 1.5 imaginary (also
    corresponding to a pixel in the image being
    produced)
  • Zn Zn-1Zn-1 C
  • For each pixel (complex number Z1) apply the
    function and count the number of applications
    before the magnitude(Zn) gt 2.0
  • If count 100 then C is in the set, color it
    Black
  • If count lt 100 then C is not in the set, color it
    based on the count, indicating the speed with
    which it departed

16
Julia Sets
  • There are infinitely many Julia Sets (one for
    each constant C)
  • Initial conditions are .
  • Z1 a complex number corresponding to a point on
    the complex number plane in the range -2.25 ..
    0.75 real and -1.5 .. 1.5 imaginary (also
    corresponding to a pixel in the image)
  • C is another complex number chosen and held
    constant during tests of all other points
  • Zn Zn-1Zn-1 C
  • Again, apply the function starting at each
    complex number Z1 corresponding to an image point
    and count the number of applications before the
    magnitude(Zn) gt 2.0
  • If count 100 C is in the set, color it Black
  • If count lt 100 C is not in the set, color it
    based on the count, indicating the speed with
    which it departed

17
Suggested Ranges
  • Images 600 x 600 pixels
  • Mandelbrot sets (Complex plane)
  • -2.25 .. 0.75 real
  • -1.5 .. 1.5 imaginary
  • Julia Sets (Complex Plane)
  • -1.5 .. 1.5 real
  • -1.5 .. 1.5 imaginary

18
Portable PixMap (PPM)
  • File format for .ppm image files

19
C system() function
  • Requests operating system to run a command
  • Command may be system command or another program
  • Examples
  • // List all PPM image files in curent directory
  • system(ls .ppm) // lists all ppm image files
  • // Start Eye of Gnome (eog) to display m1.pp
    image
  • system(eog m1.ppm)
  • Requires literal string or C-style char array as
    argument

20
System()
  • Example of building and executing command with
    string class
  • string prog, filename, command
  • cout ltlt Which viewer (xv, xview, eog)?
  • cin gtgt prog
  • system(ls .ppm)
  • cout ltlt Enter name of file to display
  • cin gtgt filename
  • command prog filename
  • system(comand.c_str())

21
G
  • g is the GNU C compiler
  • Command line options
  • -c compiles to object file
  • -o ltnamegt creates named executable
  • -g compiles to allow debugging
  • -lm links to math library
  • Examples
  • g -g -c ctester.cpp
  • g -g -c complex.cpp
  • g -g -o ctester ctester.o complex.o lm

22
Make Makefiles
  • Make reads instruction in makefile or Makefile
    and performs indicated actions, by recursive
    application of rules
  • Rules based on targets, dependency lists, and
    time stamps on files
  • Rule format
  • lttargetgt ltlist of files target depends ongt
  • lttabgt ltcommand to build targetgt
  • Rule example
  • ctester ctester.o complex.o
  • g -g -o ctester ctester.o complex.o lm

23
Using make
  • To make 1st target in makefile or Makefile
  • make
  • To make 1st target in some other file
  • make f ltmakefile_namegt
  • To make specific target
  • make lttargetgt

24
Phony Targets
  • Some targets are used to invoke commands BUT NOT
    actually build a target
  • They are identified using the term phony
  • Example
  • note comments beginning with
  • phony target for use in clearing directory
  • of all object files
  • use make clean
  • phony clean
  • clean
  • rm .o

25
Makefile for programs 2
  • CSE 331 Program 2 makefile (JHS 9/10/2004 Notre
    Dame)
  • all prog2_1 ctester prog2_2
  • prog2_1 prog2_1.cpp sorts.h
  • g -g -o prog2_1 prog2_1.cpp
  • ctester ctester.o complex.o
  • g -g -o ctester ctester.o complex.o
  • complex.o complex.cpp complex.h
  • g -g -c complex.cpp
  • ctester.o ctester.cpp complex.h
  • g -g -c ctester.cpp
  • prog2_2 prog2_2.o complex.o
  • g -g -o prog2_2 prog2_2.o complex.o
  • prog2_2.o prog2_2.cpp complex.h pixel.h
    d_matrix.h
  • g -g -c prog2_2.cpp

26
Debugging in Linux/Unix
  • Gdb is the command line debugger
  • ddd is a GUI version of gdb for Linux
  • xxgdb is a GUI version of gdb for Unix/X11
  • All versions support breakpoints, steps into and
    out of functions, data value examination, etc.
  • Program must be compiled with g option to use
    debuggers

27
Summary
  • Image
  • 2D matrix of pixels
  • Pixel
  • Picture Element
  • Index into color table or true (rgb) color
  • ColorTable
  • Indexed list or true (RGB) color values for
    pixels
  • Complex numbers
  • Real and imaginary components
  • Represent points on 2D complex plane

28
Summary 2
  • Mandelbrot Julia Sets
  • Complex numbers attracted to origin (Mandelbrot
    Set) or to another point C in the complex plane
    (Julia Set)
  • Based on recursive function Zn Zn-1Zn-1 C
  • Mandelbrot Set
  • Initially, Z1 is origin and C is point being
    tested in plane
  • Julia Set
  • Initially, Z1 point being tested in plane and C
    is some point held constant for entire Julia Set
  • Non-member points are color coded based on value
    of n when Zn moves more than 2.0 units from
    origin, escaping the strange attractor

29
Summary 3
  • Portable PixMap (simple image file format)
  • P6
  • comment (creator and date)
  • width height
  • max_color
  • image data in bytes (rgbrgb....)

30
Summary 4
  • G
  • GNU C compiler
  • Command line options (-g -o c ....)
  • Make
  • Executes rules in makefiles to build targets and
    perform other tasks
  • Recursively follows rules back through dependency
    lists
  • Phony rules execute commands but do not build
    targets
  • Debugging
  • ddd, xxgdb, gdb
Write a Comment
User Comments (0)
About PowerShow.com