CSE Lecture 6 – Complex Numbers & Images

Slides:



Advertisements
Similar presentations
Pixels and Digital Images Yrd. Doc. Dr. Ahmet Sayar Kocaeli Universitesi Bilgisayar Muhendisligi Ileri Bilgisayar Grafikleri.
Advertisements

Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Digital Imaging and Image Analysis
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment.
Bit Depth and Spatial Resolution SIMG-201 Survey of Imaging Science © 2002 CIS/RIT.
Capturing and optimising digital images for research Gilles Couzin.
Graphics File Formats. 2 Graphics Data n Vector data –Lines –Polygons –Curves n Bitmap data –Array of pixels –Numerical values corresponding to gray-
Fundamentals of Python: From First Programs Through Data Structures
Manipulating 2D arrays in Java
Image representation methods. Bitmap graphic method of a black-and-white image.
Image Representation.
Graphics in the web Digital Media: Communication and Design
March 2006Taner Erig - EMU2-1 Metamorphosis of Information How is information represented and how do computers store information?
How Images are Represented Bitmap images (Dots used to draw the image) Monochrome images 8 bit grey scale images 24 bit colour Colour lookup tables Vector.
Bitmapped Images 27 th November 2014 With Mrs
Two-week ISTE workshop on Effective teaching/learning of computer programming Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal.
1 Internet Graphics. 2 Representing Images  Raster Image: Images consist of “dots” of color, not lines  Pixel: Picture element-tiny rectangle  Resolution:
1 The UNIX date command myclock.cpp example The C/C++ time() and ctime() functions myclock2.cpp example Inline function definitions Inline class member.
GCSE Computing#BristolMet Session Objectives#9 MUST identify the data needed for a computer to display an image correctly (metadata) SHOULD describe the.
© GCSE Computing Candidates should be able to:  explain the representation of an image as a series of pixels represented in binary  explain the need.
Welcome Topic: Pixels A.M.Meshkatur Rahman Class: vii Roll: 07.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
Lab #5-6 Follow-Up: More Python; Images Images ● A signal (e.g. sound, temperature infrared sensor reading) is a single (one- dimensional) quantity that.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Objective Understand concepts used to create digital graphics. Course Weight : 15% Part Three : Concepts of Digital Graphics.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 14 Introduction to Computer Graphics.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Images Data Representation. Objectives  Understand the terms bitmap & pixel  Understand how bitmap images are stored using binary in a computer system.
© 1999 Rochester Institute of Technology Introduction to Digital Imaging.
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
Number Systems CIT Network Math
COSC 1P02 Introduction to Computer Science 7.1 Cosc 1P02 Week 7 Lecture slides "There are two ways of constructing a software design; one way is to make.
Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class.
Color and Resolution Introduction to Digital Imaging.
Pictures Looping through pixels.. Lab Review (1) Objects  Instantiated from Class  Turtle myTut = new Turtle(myWorld);  new operator creates an instance.
1 Ethics of Computing MONT 113G, Spring 2012 Session 10 HTML Tables Graphics on the Web.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
1 COMS 161 Introduction to Computing Title: Digital Images Date: November 12, 2004 Lecture Number: 32.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Graphics. Graphic is the important media used to show the appearance of integrative media applications. According to DBP dictionary, graphics mean drawing.
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
Image Representation. Digital Cameras Scanned Film & Photographs Digitized TV Signals Computer Graphics Radar & Sonar Medical Imaging Devices (X-Ray,
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Quiz # 1 Chapters 1,2, & 3.
DIGITAL IMAGE. Basic Image Concepts An image is a spatial representation of an object An image can be thought of as a function with resulting values of.
Color Web Design Professor Frank. Color Displays Based on cathode ray tubes (CRTs) or back- lighted flat-screen Monitors transmit light - displays use.
COMPUTER GRAPHICS. Can refer to the number of pixels in a bitmapped image Can refer to the number of pixels in a bitmapped image The amount of space it.
Digital Images are represented by manipulating this…
June 14, ‘99 COLORS IN MATLAB.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Announcements Assignment 1 will be regraded for all who’s score (not percentage) is less than 6 (out of 65). If your score is 6 or higher, but you feel.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
More Digital Representation Discrete information is represented in binary (PandA), and “continuous” information is made discrete.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Hank Childs, University of Oregon April “29 th”, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / /
Unit 2.6 Data Representation Lesson 3 ‒ Images
AP CSP: Pixelation – B&W/Color Images
Representation of image data
Images Data Representation.
Data Representation Images.
The Machine Model Memory
Sampling, Quantization, Color Models & Indexed Color
Binary Representation in Audio and Images
How to Convert Pictures into Numbers
COMS 161 Introduction to Computing
Hank Childs, University of Oregon
Fundamentals of Image Processing Digital Image Representation
SPL – PS1 Introduction to C++.
Presentation transcript:

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

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

Images (photographic)

Images (fractal)

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

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

Color Maps red green blue 1 20 2 100 3 255 … pixel 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 red green blue 1 20 2 100 3 255 … Black Dark Red Medium Yellow Bright Cyan White

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

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<pixel> image(500,500,pixel(255,255,255)); // set color of pixel3,4 image[3][4].setColor(100,20,255); // get color (r,g,b) of pixeli,j unsigned char r,g,b; image[i][j].getColor(r,g,b);

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

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)) = ((a1a2+b1b2) / (a2a2+b2b2)) + ((a2b1-a1b2) / (a2a2+b2b2)) j

Complex Number Plane

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

Mandelbrot Set Images

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-1*Zn-1 + C For each pixel (complex number C) apply the function and count the number of applications before the magnitude(Zn) > 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

Julia Set Images

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 -1.5 .. +1.5 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-1*Zn-1 + C For each pixel (complex number Z1) apply the function and count the number of applications before the magnitude(Zn) > 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

Suggested Ranges Images at least 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

Portable Pix Map (PPM) File format for *.ppm image files <magic number> <comment> <width & height> <max color value> <data bytes> P6 # creator: JHS 9/4/2004 640 480 255 d0^g%8%#$.......<EOF>

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

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

G++ g++ is the GNU C++ compiler Command line options Examples: -c compiles to object file -o <name> 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

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: <target> : <list of files target depends on> <tab> <command to build target> Rule example: ctester: ctester.o complex.o g++ -g -o ctester ctester.o complex.o –lm

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

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

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

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

Summary Image Pixel ColorTable Complex numbers 2D matrix of pixels 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

Summary 2 Mandelbrot & Julia Sets Mandelbrot Set Julia Set Complex numbers attracted to origin (Mandelbrot Set) or to another point C in the complex plane (Julia Set) Based on recursive function Zn = Zn-1*Zn-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

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

Summary 4 G++ Make Debugging 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