Download presentation

Presentation is loading. Please wait.

Published byBraden Carr Modified about 1 year ago

1
1 Images Complex Numbers Mandelbrot & Julia Sets Image File Format (.ppm) C/C++ system() function g++, make & makefiles Debuggers CSE Lecture 6 – Complex Numbers & Images

2
2 Quick Aside Group Project Guidelines … are posted on web page Due: Tuesday, September 22 nd Initial Group membership Brief description of project you plan to complete Initial references you have found …

3
3 Images (photographic)

4
4 Images (fractal)

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

6
6 Pixel Color Pixel size# of colors possible 1 bit2 (Black or White) Binary image 1 byte (8 bit)256 shades of gray or 256 distinct colors 3 byte (24 bit)2 24 colors (true color) (millions of colors)

7
7 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) pixel redgreenblue … Black Dark Red Medium Yellow Bright Cyan White

8
8 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 };

9
9 Image in memory // matrix template class found in Ford & Topp Ch 5 // is a 2-D grid using a vector of vectors #include “d_matrix.h” // declare white image of 500 x 500 pixels matrix image(500,500,pixel(255,255,255)); // set color of pixel 3,4 image[3][4].setColor(100,20,255); // get color (r,g,b) of pixel i,j unsigned char r,g,b; image[i][j].getColor(r,g,b);

10
10 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 x 1 + x 2 = (a 1 + b 1 j) + (a 2 + b 2 j) = (a 1 + a 2 ) + (b 1 + b 2 ) j Subtraction x 1 - x 2 = (a 1 + b 1 j) - (a 2 + b 2 j) = (a 1 - a 2 ) + (b 1 - b 2 ) j

11
11 Complex Numbers Multiplication x 1 * x 2 = (a 1 + b 1 j) * (a 2 + b 2 j) = (a 1 a 2 - b 1 b 2 ) + (a 1 b 2 + a 2 b 1 ) j Division x 1 / x 2 = (Note: multiply top & bottom by complex conjugate) (a 1 + b 1 j) / (a 2 + b 2 j) = ((a 1 + b 1 j) * (a 2 - b 2 j)) / ((a 2 + b 2 j) * (a 2 - b 2 j)) = ((a 1 a 2 +b 1 b 2 ) / (a 2 a 2 +b 2 b 2 )) + ((a 2 b 1 -a 1 b 2 ) / (a 2 a 2 +b 2 b 2 )) j

12
12 Complex Number Plane

13
13 Mandelbrot & Julia Sets Both based on repeated (recursive) application of the following function, where C and Z are both complex numbers Z n = Z n-1 *Z n-1 + C If the distance of Z n 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

14
14 Mandelbrot Set Images

15
15 Mandelbrot Sets There is ONLY ONE Mandelbrot Set Initial conditions are …. Z 1 = j and C = a complex number corresponding to a point on the complex number plane in the range real and imaginary (also corresponding to a pixel in the image being produced) Z n = Z n-1 *Z n-1 + C For each pixel (complex number C) apply the function and count the number of applications before the magnitude(Z n ) > 2.0 If count == 100 then C is in the set, color it Black If count < 100 then C is not in the set, color it based on the count, indicating the “speed” with which it departed

16
16 Julia Set Images

17
17 Julia Sets There are infinitely many Julia Sets (one for each constant C) Initial conditions are …. Z 1 = a complex number corresponding to a point on the complex number plane in the range real and imaginary (also corresponding to a pixel in the image) C is another complex number chosen and held constant during tests of all other points Z n = Z n-1 *Z n-1 + C For each pixel (complex number Z 1 ) apply the function and count the number of applications before the magnitude(Z n ) > 2.0 If count == 100 C is in the set, color it Black If count < 100 C is not in the set, color it based on the count, indicating the “speed” with which it departed

18
18 Suggested Ranges Images at least 600 x 600 pixels Mandelbrot sets (Complex plane) real imaginary Julia Sets (Complex Plane) real imaginary

19
19 Portable Pix Map (PPM) File format for *.ppm image files P6 # creator: JHS 9/4/ d0^g%8%#$

20
20 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 current directory system(“ls *.ppm”); // Start Eye of Gnome (eog) to display m1.pp image system(“eog m1.ppm”); Requires literal string or C-style char array as argument

21
21 System() Example of building and executing command with string class string prog, filename, command; cout << “Which viewer (gimp, eog)? ”; cin >> prog; system(“ls *.ppm”); cout << “Enter name of file to display: “; cin >> filename; command = prog + “ “ + filename + “ &”; system(command.c_str());

22
22 G++ g++ is the GNU C++ compiler Command line options -c compiles to object file -o creates named executable -gcompiles to allow debugging -lmlinks to math library Examples: g++ -g -c ctester.cpp g++ -g -c complex.cpp g++ -g -o ctester ctester.o complex.o –lm

23
23 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: : Rule example: ctester: ctester.o complex.o g++ -g -o ctester ctester.o complex.o –lm

24
24 Using make To make 1 st target in makefile or Makefile make To make 1 st target in some other file make –f To make specific target make

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

26
26 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 myVector.h myMatrix.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 myVector.h myMatrix.h g++ -g -c prog2_2.cpp phony: clean clean: rm *.o

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

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

29
29 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 Z n = Z n-1 *Z n-1 + C Mandelbrot Set Initially, Z 1 is origin and C is point being tested in plane Julia Set Initially, Z 1 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 Z n moves more than 2.0 units from origin, escaping the strange attractor

30
30 Summary 3 Portable Pix Map (simple image file format) P6 #comment (creator and date) width height max_color image data in bytes (rgbrgb....)

31
31 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; do not build targets Debugging ddd, xxgdb, gdb

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google