cds 130 - 003 fall, 2010 computing for scientists visualization (oct. 28, 2010 – nov. 09, 2010)...

75
CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct . 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Upload: thomas-edwards

Post on 21-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

CDS 130 - 003Fall, 2010

Computing for Scientists

Visualization(Oct . 28, 2010 – Nov. 09, 2010)

Jie Zhang Copyright ©

Page 2: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Content

1. Introduction

2. Computer Visualization Pipeline

3. 2-D Data Visualization– Height-plot method– Color map method

References:

(1) “Data Visualization: Principles and Practice”, by Alexandru C. Telea, A. K. Peters Ltd, ISBN-13: 978-1-56881-306-6, 2008

(2) CDS 301 “Scientific Information and Data Visualization”, Fall 2009 at http://solar.gmu.edu/teaching/2009_CDS301/index.html

Page 3: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

1. Introduction

What is visualization? Why visualization?

Page 4: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Picture

A Picture Is Worth a Thousand Words

Cave Painting: the dawn of civilization

Page 5: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Graph: Height-Plot

Height plot of thePredator-Prey Model

Numeric output of thePredator-Prey Model

A graph is worth one thousand numbers

YearP

opu

latio

n

Page 6: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Graph: 3-D Height-Plot

Numeric output: a 2-Dimension data array,

which is the same as ……

Page 7: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Graph: 3-D Height-Plot

Height plot

A graph is worth one million numbers

Page 8: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Visualization is a cognitive process performed by humans in forming a mental image of a domain space

Visualization - Cognition

Human Cognition

•Most effective way human takes in information, digest information, making decision, and being creative.•The most important among the five senses

Page 9: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Scientific visualization is an interdisciplinary branch of science primarily concerned with the visualization of three dimensional phenomena (meteorological, medical, biological etc) where the emphasis is on realistic rendering of volumes, surfaces, illumination sources with a dynamic (time) component.

Friendly (2008), also

http://en.wikipedia.org/wiki/Scientific_visualization

What is Scientific Visualization

At Information Age

Page 10: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Goal of Scientific Visualization

• Provide scientific insights

• Effective communication

Page 11: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Example: Scalar Data

•Height plot of a 2-D data, and the contour lines•In topology, the data are of 2-D: a curved surface •The data are mapped into 3-D geometric space in computer memory•The data are then rendered onto a 2-D visual plane on a screen

Page 12: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Example: Vector Data

Stream tubes: show how water flows through a box with an inlet at the top-right and an outlet at the lower-left of the

box; the data are (1) 3-D volume, (2) vector

Page 13: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Example: Unstructured Data

Scattered Point Cloud and Surface Reconstruction.The data are a set of sampled data points in 3-D space, and the distribution of data is unstructured; need to reconstruct the surface from the scattered points

Sampled data Rendered data

Page 14: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Example: Volume Visualization

3-D data of human head. Instead of showing a subset (e.g, a slice as in CT images), the whole 3-D data are shown at once using the technique of Opacity Transfer Function

Page 15: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Example: Information Visu.

•The file system of FFmpeg, a popular software package for encoding audio and video data into digital format•Information, such as name and address, can not be interpolated; the visualization focuses on the relations.

Page 16: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

An attempt at visualizing the Fourth Dimension: Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.

--Albert Einstein--

Page 17: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2. Computer Visualization Pipeline

How to do it by a computer?

We illustrate the process using the well known 2-D Gaussian function:

)( 22

),f( yxeyx

Page 18: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Gaussian Function in 1-D

It is straightforward to visualize the 1-D Gaussian function

)( 2

)f( xex

(1) Choose a data domain, e.g., x in [-3.0, 3.0]

(2) Choose a set of regular points in x, e.g., step size 0.5: x1=-3.0, x2=-2.5, x3=-2.0, x4=-2.5……….X13=3.0

(3) Calculate the corresponding functional value f(xi)

(4) Draw the 13 data points (xi, f(xi)) for i=1:13

(5) Connecting these points to form a curve, which shows the Gaussian function

Page 19: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Gaussian Function in 1-D)( 2

)f( xex x=-3.0:0.1:3.0; %declare the domain space and define the grid % x: one dimensional data arrayy=exp(-power(x,2)); %calculate the discrete functional value % y: also one dimensional data arrayplot(x,y,'*')hold onplot(x,y)

xlabel('x')ylabel('y')title('Gaussian 1D')print -dpng 'Gaussian_1d.png'

X: 1-D data array interval or domain: from -3.0 to 3.0 sub-interval: 0.1 value=[-3.0, -2.9, -2.8,………2.9, 3.0] number of elements: N=61

Page 20: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Gaussian Function in 1-D)( 2

)f( xex

Page 21: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Gaussian Function in 2-D

We know the result. In a height-plot format, It should look like something below. But how to do it through the computer?

)( 22

),f( yxeyx

A 3-D height plot showingthe Gaussian Surface

The Grid on the domain

Created by PARAVIEW, a power visualization package

Page 22: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Pipeline Step 1: Data Acquisition

Step 1: data acquisition. For any input data (experiment, simulation etc) , convert the data into a discrete dataset over a regular grid

Gaussian Example: •Choose a uniform grid in the domain space

•Nx=30 (i=1:30)•Ny=30 (j=1:30)

•Calculate the functional value at these grid points•This creates a set of 30 X 30, or 900 in total discrete 3D data points [x,y,z]

Page 23: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Pipeline Step 2: Data Mapping

Step 2: Mapping the discrete dataset onto a 3-D scene. Neighboring discrete data points are grouped to form graphic primitive shapes that a computer can handle efficiently, e.g., point, line, triangle, quadrilateral, and tetrahedron

Computer graphics only handles a 3-D scene

Gaussian Example:•Form a set of four-vertex polygons or quadrilateral in 3-D space•For each quadrilateral, the position of the four vertices are known, and its normal direction is calculated (in order to determine its luminance)

Page 24: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Pipeline Step 2: Data Mapping

Quadrilateral shape

Page 25: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Pipeline Step 3: Rendering

Step 3: Computer graphics renders the 3-D scene (a set of primitive shapes) onto a 2D projected place, by

1. Choose the view angle

2. Choose the light source

3. Choose the shadingGaussian Example:•Viewed from top-front•From a point light source in the front•Smooth shading

Page 26: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Shading

Flat Shading Gouraud Shading

Page 27: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Shading•Flat shading:

•Given a polygon surface (e.g., quadrilateral), flat shading applies the lighting model once for the complete polygon, e.g., for the center point•The whole polygon surface has the same light intensity•The least expensive•But visual artifact of the “faceted” surface

•Gouraud shading (or smooth shading):•Apply lighting model at every vertex of the polygon•The intensity between the vertices are calculated using interpolation, thus yielding smooth variation

Page 28: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Visualization Pipeline

float data[N_x,N_y]

Quadrilateral in 3D

)( 22

),f( yxeyx Continuous data

Discrete dataset

Geometric object

Displayed image

1. Data Acquisition

2. Data Mapping

3. Rendering

Page 29: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Visualization Pipeline: SummaryStep 1: data acquisition, which is to convert any input data into a discrete dataset within a domain. For Gaussian function, the input is a continuous Gaussian function, the output is a discrete dataset

Step 2: data mapping: which is to map the discrete dataset from step one (input) onto a 3-D scene (output) in computer memory. For Gaussian function, the output is a set of quadrilaterals in 3-D space. Each quadrilateral has four vertexes.

Step 3: rendering, which is to display the 3-D scene created in step 2 (input) onto a projected 2-D image (output).

Page 30: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

3. 2-D data Visualization-(Nov. 1, 2010)

Page 31: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Visualization with Matlab

Watch Matlab tutorial video on arrays, including indexing and “find” function:“http://www.mathworks.com/demos/matlab/visualizing-data-overview-matlab-video-demonstration.html”

Page 32: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D Data Visualization

•Method 1: Height plot•Create 2-D data array in Matlab•Nested “For” loop in Matlab•“surf” in Matlab

•Method 2: Colormap•RGB color system•“image” in Matlab

Page 33: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Height-Plot Method

Page 34: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Height Plot

0 5 10 15 20 25 30 35 400

20

40

60

80

100

120

Years

Pop

ulat

ion

Population Evolution Over the Period of 40 years

Population plot from Natalia Lattanzio

Page 35: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Gaussian Function

)( 2

)f( xex

(1) Choose a data domain, e.g., x in [-3.0, 3.0]

(2) Choose a set of regular points in x with a subinterval of 0.1: x1=-3.0, x2=-2.9, x3=-2.8, x4=-2.7……….X13=3.0

(3) Calculate the corresponding functional value f(xi)

(4) Draw the 61 data points (xi, f(xi)) for i=1:61

(5) Connecting these points to form a curve, which shows the Gaussian function

Page 36: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Gaussian Function in 1-D)( 2

)f( xex %find number of intervalsx_start=-3.0x_end=3.0x_sub=0.1N=(x_end-x_start)/x_sub %number of iteration N+1

%for loop to find discrete x and y valuesfor i=[1:N+1] x(i)=x_start+(i-1)*x_sub; y(i)=exp(-power(x(i),2));end

plot(x,y,'*')hold onplot(x,y)

X: 1-D data array interval or domain: from -3.0 to 3.0 sub-interval: 0.1 value=[-3.0, -2.9, -2.8,………2.9, 3.0] number of elements: N=61

Page 37: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Gaussian Function in 1-D)( 2

)f( xex

Page 38: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

sine Function xx sin)f(

(1) Choose a data domain, x in [-6.28, 6.28] or [-2π,2π]

(2) Choose a set of regular points in x with a subinterval of 0.1: x1=-6.28, x2=-6.18, x3=-6.08.8, x4=-2.7…x..=6.28

(3) Calculate the corresponding functional value f(xi)

(4) Connecting these points to form a curve, which shows the sine function

Class activity

y=sin(x) % sine function in Matlab

Page 39: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Height-Plot of 2-D Gaussian)( 22

),f( yxeyx

Page 40: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D Array

Watch Matlab tutorial video on arrays, including indexing and “find” function:“http://www.mathworks.com/demos/matlab/working-with-arrays-matlab-video-tutorial.html”

A large amount of scientific data are in the format of 2-D array, e.g., images

Page 41: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D Array • Create 1-D array

>> a=[1,2,3,4,5]>> a=[1 2 3 4 5]>> a=1:5>> a=[1:5]

%indexing and assigning values using for loops%.e.g., assign x^2for i=[1:5]

x(i)=power(i,2)end

%what are x?

• Index is used to access the array

1 2 3 4 5>>x(3)

Page 42: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D Array • Create 2-D array

>> a=[1,2,3;4,5,6;7,8,9] %3 x 3 array

a= 1 2 3 4 5 6 7 8 9

Page 43: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D Array

• Index of 2-D array

(1,1) (1,2) (1,3) (2,1) (2,2) (2,3) (3,1) (3,2) (3,3)

>>a(1,1) 1>>a(2,3) 6

>>a(i,j)

• Index of a 2-D array has two subscripts• First subscript, often noted by “i”, indicate the

row number• Second subscript, often noted by “j”, indicate

the column number

Page 44: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

(continued)(Nov. 4, 2010)

Page 45: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D Array

• Visualize the index and the value of a 2-D array

>> a=[1,2,3;4,5,6;7,8,9] %3 x 3 arraya= 1 2 3 4 5 6 7 8 9>>surf(a)

Page 46: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D Array

• Re-assign the value of the elements

>> a=(2,2)ans = 5

>>a(2,2)=10a= 1 2 3 4 10 6 7 8 9

Page 47: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D Array

a= 2 2 2 3 4 5 6 6 6

Group exercise: (1) Create the following 2-D array(2) Visualize it using “surf”(3) Change the element at (2,2) to 20(4) Visualize the new 2-D array

Page 48: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Nested FOR loops

• Create a 2-D array using nested FOR loops

for i=[1:3] for j=[1:3] a(i,j)=j+(i-1)*3; endend

a= 1 2 3 4 5 6 7 8 9

• Double FOR loop is a quick way to go through every data elements in the 2-D data array

• Assign the value• Check the value• Change the value

Page 49: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Nested FOR loops

for i=[1:3] for j=[1:3] a(i,j)=i+j endEnd

a= ? ? ? ? ? ? ? ? ?

Find the values of the following double FOR loops:

Page 50: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D height plot

Draw a 2-D function in the following domain space:

(1) x between [-3, 3], with step size of 0.1

(2) y between [-3,3] , with step size of 0.1

)( 22

),f( yxeyx

Page 51: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D height plotx_start=-3.0x_end=3.0x_sub=0.1Nx=(x_end-x_start)/x_sub %number of points along x

y_start=-3.0y_end=3.0y_sub=0.1Ny=(y_end-y_start)/y_sub %number of points along y

for i=[1:Nx] for j=[1:Ny] x(i)=x_start+i*x_sub;

y(j)=y_start+j*y_sub;f(i,j)=exp(-(power(x(i),2)+power(y(j),2)))

endend

surf(f)

Page 52: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D height plot)( 22

),f( yxeyx

Page 53: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D height plot

Draw the following 2-D function in the following domain space:

(1) x between [-3, 3], with step size of 0.1

(2) y between [-3,3] , with step size of 0.1

22),f( yxyx

Group exercise:

Page 54: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

2-D height plot22),f( yxyx

Page 55: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Image method and

Colormap(Nov. 4, 2010)

Page 56: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

ColorQuestion:

Do scientific data have intrinsic color?

For example, temperature reading around the globe.

For example, the values of 2-D Gaussian function

Page 57: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

ColorAnswer:

•Most scientific data concern about value, strength, or intensity. They have no color

•Color image of scientific data are called pseudo-color image, which uses color as a cue to indicate the value of the data.

Page 58: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Colormap

Gray-scale Map Rainbow Colormap

Page 59: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Computer Color•A special type of vector with dimension c=3

•The value of a color = (R, G, B)

•RGB system: convenient for computer•R: red•G: green•B: blue

•HSV system: intuitive for human•H: Hue (the color, from red to blue)•S: Saturation (purity of the color, or how much is mixed with white•V: Value (the brightness)

Page 60: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Computer Color•A pixel of a LCD monitor contains three sub-pixels: R, G, B•Each sub-pixel displays the intensity of one primary color•Modern LCD monitor uses 1 Byte or 8 bits to determine the intensity of the primary color

•Each primary color has 255 intensity levels•The number of colors of a LCD monitor= 255 (red) x 255 (green) x 255 (blue)= 16,581,375Or 16 million different colors•The monitor shows true color

•Human eyes discern 10 million color

Page 61: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

(continued)(Nov. 9, 2010)

Page 62: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

RGB CubeR

G

B

yellow

magenta

Cyan

Page 63: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

RGB System•Every color is represented as a mix of “pure” red, green and blue colors in different amount•Equal amounts of the three colors give gray shades•RGB cube

• main diagonal line connecting the points (0,0,0) and (1,1,1) is the locus of all the grayscale value

•Color (0,0,0): dark•Color (1,1,1): white•Color (0.5,0.5,0.5): gray level between dark and white•Color (1,0,0): Red•Color (0,1,0): Green•Color (1,1,0): ?•(1,0,1): ?•(0,1,1): ?

Page 64: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Colormap in Matlab

To select a colormap interactively: Use the “Colormap” menu in the “Figure Properties” pane of the “Plot Tools GUI”

Matlab built-in Colormap

Page 65: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Example: Re-usable functionfunction gauss = Gaussian_2d ()

x_start=-3.0x_end=3.0x_sub=0.1Nx=(x_end-x_start)/x_sub %number of points along xy_start=-3.0y_end=3.0y_sub=0.1Ny=(y_end-y_start)/y_sub %number of points along y

for i=[1:Nx] for j=[1:Ny] x(i)=x_start+i*x_sub;

y(j)=y_start+j*y_sub;f(i,j)=exp(-(power(x(i),2)+power(y(j),2)))

endend

gauss=f;endfunction

)( 22

),f( yxeyx

Return value

Page 66: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Colormap in Matalb

>z=Gaussian_2d>surf(z) %default color map “jet”>colormap(gray)>colormap(jet)

Call the function you created and visualize it

Use “Colormap” to change color

colormap(jet) colormap(gray)

Page 67: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

colormap

Create the following 2-D array in Matlab/Octave

>a=(1,2,3;4,5,6;7,8,9)

Visualize it using “surf” function, the surface function or 3-D height-plot provided by Matalb

Change to colormap to “gray”, “jet”, “spring”, ‘hot” et al.

Group exercise:

Page 68: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Colormap in Matalb

>m=gray>size(m)ans = 64 3>m 0.000 0.000 0.000 0.015 0.015 0.015 0.031 0.031 0.031 0.047 0.047 0.047 0.063 0.063 0.063 ………. 0.968 0.968 0.968 0.984 0.984 0.984 1.000 1.000 1.000

How does a colormap work? • map your data value on each pixel (e.g., row i,

column j) into a color based on the colormap• Re-scale is needed

Row 1Row 2Row 3Row 4Row 5-----Row 62Row 63Row 64

• A data value of 5.0 will correspond to color (0.063, 0.063, 0.063), and computer understands this color and will display it correctly

• A data value of 0 will correspond to color (0, 0, 0), or dark pixel

• A data value of 64 will correspond to color (1, 1, 1) or a white pixel

• Your data need to be re-scaled between 0 and 64

• “surf” do re-scale for you

Page 69: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Colormap: re-scale

What happens in computer is that, the data range of the 2-D Gaussian function from 0 to 1, is mapped to the color range from 1 to 64.

• 0 in function value corresponds to color number 1• 1 in function value corresponds to color number 64• Any value in between in function is re-scaled to a

value between 1 and 64• 0.5 in function corresponds to color number 32

you use a colormap of 64 colors to visualize a 2-D data, e.g., 2-D Gaussian

Page 70: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

colormap

Create the following 2-D array in Matlab/Octave

>a=(1,2,3;4,5,6;7,8,9)

Visualize it using “surf” function, the surface function or 3-D height-plot provided by Matalb

Change the size of the colormap

>surf(a)

>colormap(gray(64)) % gray colormap with 64 colors

>colormap(gray(9)) % gray colormap with 9 colors

>colormap(gray(2)) % gray colormap with 2 colors

>m=colormap(gray(2))

Group exercise: Do you understand the changes?

Page 71: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

“image” method in Matlab•For many applications, you want to show your data as a flat image, when your data are given as a 2-D matrix.•“image” does the trick for you

•“image” does not scale the data for you.

>z=Gaussian_2d %get the 2-D data>colormap(gray) %choose gray colormap>image(z) % show the image % but it does not work % it is dark

>image(z*64)

>image(z*256)

It does not work!

It works! Why?

Why it saturates at the center?

Page 72: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

“image” method in Matlab

2-D Gaussian image in gray colormap

2-D Gaussian image in jet colormap

Page 73: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

colormapGroup exercise: visualize the following 2-D array using “image” method

>for i=[1:64]>for j=[1:64]>f(i,j)=i>end>end >colormap(gray(64))>image(a)

%repeat the process, but change f(i,j)=j %Do you fully understand what you get?

%what if colormap(gray(32))%what if colormap(gray(128))

>m=colormap(jet(10)) % check out the color array

Page 74: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

Question: what visualization techniques are used in this image?

Page 75: CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©

The End