Download presentation
Presentation is loading. Please wait.
Published byThomas Edwards Modified over 9 years ago
1
CDS 130 - 003 Fall, 2010 Computing for Scientists Visualization (Oct. 28, 2010 – Nov. 09, 2010) Jie Zhang Copyright ©
2
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
3
1. Introduction What is visualization? Why visualization?
4
Picture A Picture Is Worth a Thousand Words Cave Painting: the dawn of civilization
5
Graph: Height-Plot Height plot of the Predator-Prey Model Numeric output of the Predator-Prey Model A graph is worth one thousand numbers Year Population
6
Graph: 3-D Height-Plot Numeric output: a 2-Dimension data array, which is the same as ……
7
Graph: 3-D Height-Plot Height plot A graph is worth one million numbers
8
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
9
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
10
Goal of Scientific Visualization Provide scientific insights Effective communication
11
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
12
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
13
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 dataRendered data
14
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
15
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.
16
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--
17
2. Computer Visualization Pipeline How to do it by a computer? We illustrate the process using the well known 2-D Gaussian function:
18
Gaussian Function in 1-D It is straightforward to visualize the 1-D Gaussian function (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: x 1 =-3.0, x 2 =-2.5, x 3 =-2.0, x 4 =-2.5……….X 13 =3.0 (3)Calculate the corresponding functional value f(x i ) (4)Draw the 13 data points (x i, f(x i )) for i=1:13 (5)Connecting these points to form a curve, which shows the Gaussian function
19
Gaussian Function in 1-D x=-3.0:0.1:3.0; %declare the domain space and define the grid % x: one dimensional data array y=exp(-power(x,2)); %calculate the discrete functional value % y: also one dimensional data array plot(x,y,'*') hold on plot(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
20
Gaussian Function in 1-D
21
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? A 3-D height plot showing the Gaussian Surface The Grid on the domain Created by PARAVIEW, a power visualization package
22
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]
23
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)
24
Pipeline Step 2: Data Mapping Quadrilateral shape
25
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 shading Gaussian Example: Viewed from top-front From a point light source in the front Smooth shading
26
Shading Flat ShadingGouraud Shading
27
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
28
Visualization Pipeline float data[N_x,N_y] Quadrilateral in 3D Continuous data Discrete dataset Geometric object Displayed image 1. Data Acquisition 2. Data Mapping 3. Rendering
29
Visualization Pipeline: Summary Step 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).
30
3. 2-D data Visualization- (Nov. 1, 2010)
31
Visualization with Matlab Watch Matlab tutorial video on arrays, including indexing and “find” function: “http://www.mathworks.com/demos/matlab/visu alizing-data-overview-matlab-video- demonstration.html”
32
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
33
Height-Plot Method
34
Height Plot Population plot from Natalia Lattanzio
35
Gaussian Function (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: x 1 =-3.0, x 2 =-2.9, x 3 =-2.8, x 4 =-2.7……….X 13 =3.0 (3)Calculate the corresponding functional value f(x i ) (4)Draw the 61 data points (x i, f(x i )) for i=1:61 (5)Connecting these points to form a curve, which shows the Gaussian function
36
Gaussian Function in 1-D %find number of intervals x_start=-3.0 x_end=3.0 x_sub=0.1 N=(x_end-x_start)/x_sub %number of iteration N+1 %for loop to find discrete x and y values for i=[1:N+1] x(i)=x_start+(i-1)*x_sub; y(i)=exp(-power(x(i),2)); end plot(x,y,'*') hold on plot(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
37
Gaussian Function in 1-D
38
sine Function (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: x 1 =-6.28, x 2 =-6.18, x 3 =-6.08.8, x 4 =-2.7…x..=6.28 (3)Calculate the corresponding functional value f(x i ) (4)Connecting these points to form a curve, which shows the sine function Class activity y=sin(x) % sine function in Matlab
39
Height-Plot of 2-D Gaussian
40
2-D Array Watch Matlab tutorial video on arrays, including indexing and “find” function: “http://www.mathworks.com/demos/matlab/wor king-with-arrays-matlab-video-tutorial.html” A large amount of scientific data are in the format of 2-D array, e.g., images
41
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^2 for 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)
42
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
43
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
44
(continued) (Nov. 4, 2010)
45
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 array a= 1 2 3 4 5 6 7 8 9 >>surf(a)
46
2-D Array Re-assign the value of the elements >> a=(2,2) ans = 5 >>a(2,2)=10 a= 1 2 3 4 10 6 7 8 9
47
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
48
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; end 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
49
Nested FOR loops for i=[1:3] for j=[1:3] a(i,j)=i+j end End a= ? ? ? Find the values of the following double FOR loops:
50
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
51
2-D height plot x_start=-3.0 x_end=3.0 x_sub=0.1 Nx=(x_end-x_start)/x_sub %number of points along x y_start=-3.0 y_end=3.0 y_sub=0.1 Ny=(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))) end surf(f)
52
2-D height plot
53
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 Group exercise:
54
2-D height plot
55
Image method and Colormap (Nov. 4, 2010)
56
Color Question: Do scientific data have intrinsic color? For example, temperature reading around the globe. For example, the values of 2-D Gaussian function
57
Color Answer: 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.
58
Colormap Gray-scale MapRainbow Colormap
59
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)
60
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,375 Or 16 million different colors The monitor shows true color Human eyes discern 10 million color
61
(continued) (Nov. 9, 2010)
62
RGB Cube R G B yellow magenta Cyan
63
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): ?
64
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
65
Example: Re-usable function function gauss = Gaussian_2d () x_start=-3.0 x_end=3.0 x_sub=0.1 Nx=(x_end-x_start)/x_sub %number of points along x y_start=-3.0 y_end=3.0 y_sub=0.1 Ny=(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))) end gauss=f; endfunction Return value
66
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)
67
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:
68
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 1 Row 2 Row 3 Row 4 Row 5 ----- Row 62 Row 63 Row 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
69
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
70
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?
71
“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?
72
“image” method in Matlab 2-D Gaussian image in gray colormap 2-D Gaussian image in jet colormap
73
colormap Group exercise: visualize the following 2-D array using “image” method >for i=[1:64] >for j=[1:64] >f(i,j)=i >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
74
Question: what visualization techniques are used in this image?
75
The End
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.