Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Week 4: Surface and Image Manipulation Xenios Papademetris.

Slides:



Advertisements
Similar presentations
Dr. Will Schroeder, Kitware
Advertisements

Programming with OpenGL - Getting started - Hanyang University Han Jae-Hyek.
Reconstruction from Voxels (GATE-540)
Yingcai Xiao Chapter 6 Fundamental Algorithms. Types of Visualization Transformation Types 1.Data (Attribute Transformation) 2.Topology (Topological Transformation)
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Graphics Pipeline.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Week 5: Image Manipulation and Display Xenios Papademetris.
Real-Time Rendering TEXTURING Lecture 02 Marina Gavrilova.
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Information Visualization.
Slide 1 Visualization of scientific data under Linux - Techniques and data wrangling Mike Walterman, Manager of Graphics Programming, Scientific Computing.
VTK & ParaView Ray Gasser SCV Visualization Workshop – Fall 2008.
Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Xenios Papademetris BML 325,
2003 by Jim X. Chen: Introduction to Modeling Jim X. Chen George Mason University.
Introduction to Volume Visualization Mengxia Zhu Fall 2007.
Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Week 2: An Introduction to Tcl Xenios Papademetris
Further Programming for 3D applications CE Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and.
Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Week 3: Simple Visualization Tasks Xenios Papademetris
Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Xenios Papademetris BML 325,
Visualization Knowledge (VisKo): Leveraging the Semantic Web to Support VisualizationVisKo University of Texas at El Paso Computer Science.
Visualization Knowledge (VisKo): Leveraging the Semantic Web to Support VisualizationVisKo Nicholas Del Rio CyberShARE Center University of Texas at El.
Introduction to Modeling. What is CG Modeling? Combination of Sculpting, Architecture, Drafting, and Painting. The core component of computer animation.
MULTIMEDIA TECHNOLOGY SMM 3001 MEDIA - GRAPHICS. In this chapter how the computer creates, stores, and displays graphic images how the computer creates,
Modeling and representation 1 – comparative review and polygon mesh models 2.1 Introduction 2.2 Polygonal representation of three-dimensional objects 2.3.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
Copyright © 2008 PolyMLib is a trademark of Solid Modeling Solutions, Inc. PolyMLib 2.0 An interactive modular geometry processing toolkit.
VTK: Data Shroeder et al. Chapter 5 University of Texas – Pan American CSCI 6361, Spring 2014 After Taku Komura and other lecture sets
VTK: The Visualization Toolkit Part I: Overview and object models March 28, 2001.
Lecture 3 : Direct Volume Rendering Bong-Soo Sohn School of Computer Science and Engineering Chung-Ang University Acknowledgement : Han-Wei Shen Lecture.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Chapter 3 Digital Representation of Geographic Data.
Marching Cubes: A High Resolution 3D Surface Construction Algorithm William E. Lorenson Harvey E. Cline General Electric Company Corporate Research and.
Segmentation support in Slicer Csaba Pinter Laboratory for Percutaneous Surgery, Queen’s University, Canada.
VTK. VTK Online Resources On-line Resources VTK –Manual: –Examples:
Visualization Knowledge (VisKo): Leveraging the Semantic Web to Support VisualizationVisKo Paulo Pinheiro da Silva and Nicholas Del Rio CyberShARE Center.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Multimedia System and Networking UTD Slide- 1 University of Texas at Dallas B. Prabhakaran Rigging.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CHAPTER 8 Color and Texture Mapping © 2008 Cengage Learning EMEA.
NA-MIC, 2008 June Workshop, IHK Akademie Westerham VTK
VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.
Visualization Knowledge Query Language (VKQL) Workshop Nicholas Del Rio University of Texas at El Paso Computer Science.
IS&T Scientific Visualization Tutorial – Spring 2010
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Hank Childs, University of Oregon Isosurfacing (Part 3)
Color and Color Models Angel 2.5 Angel: Interactive Computer Graphics5E © Addison-Wesley
OpenGL Graphics Textures. Quiz You didn't see that coming!
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Hank Childs, University of Oregon Overview of VTK (Pt 3)
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
VTK: The Visualization Toolkit
Programming with OpenGL Part 2: Complete Programs
The Graphics Rendering Pipeline
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Computer Graphics 4Practical Lesson
Programming with OpenGL Part 2: Complete Programs
MATLAB stands for MATrix LABoratory.
Presentation transcript:

Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Week 4: Surface and Image Manipulation Xenios Papademetris BML 325, Man Pages etc: and

Revised Schedule for Part 1 1.Introduce VTK (9/3) 2.Introduce Tcl/Tk (9/10) 3.Simple Visualization Tasks (9/17) 4.Surface and Image Manipulation (9/23) 5.Image Display (Volume Rendering) (10/1) 6.Local Extensions (10/8) 7.Tk and GUIs (10/15) 8.[Incr] Tcl and other extensions (10/22)

Revision -- VTK Pipeline (I) SourcesFiltersMappers File Output Props vtkDataSet

Data Representation (vtkDataSet) Data Set Points (vtkPoints) Define Location Cells (vtkCellArray) Define Topology Point Attributes (vtkPointData) Point Properties (e.g. intensity) Cell Attributes (vtkCellData) Cell Properties (e.g. normal) Arrays of Numbers (one per point or cell) vtkDataArray

A Closer Look at vtkPolyData vtkPolyData is a complex class which has many members. The key ones are: –Points of type vtkPoints – represents the geometry of the surface (i.e. the points) –Polys of type vtkCellArray – represents part of the topology of the surface (i.e. the polygons) –PointData of type vtkPointData – represents data associated with the points (e.g. normals, colors etc) –CellData of type vtkCellData – represents data associated with the points (e.g. again normals, colors etc) –Lots of other members …..

Representing arrays with vtkDataArray vtkDataArray is an abstract superclass for classes representing arrays of vectors called tuples (or numbers treated as vectors of length 1). Each tuple consists of a set of numbers or components. Derived Classes include vtkUnsignedCharArray, vtkShortArray, vtkFloatArray, vtkDoubleArray etc. Can function either as a dynamic array (lower performance) or a fixed length array All data in VTK is stored ultimately in one of the many derived classes of vtkDataArray, e.g. in the case of vtkImageData the intensities are stored in a vtkDataArray having dimensions equal to the number of voxels and vector length typically equal to 1 (3 for color images, Number of Frames for multiframe data such as fMRI cardiac etc.)

vtkDataArray Hierarchy

A concrete example vtkFloatArray Mode 1 – Fixed Length Array: To create in TCL type vtkFloatArray arr arr SetNumberOfComponents 1 arr SetNumberOfTuples 20 arr SetComponent arr SetTuple set b [ arr GetComponent 10 0 ] This creates an array of 20 (Number of Tuples) vectors each having size 1 (Number of Components) We access elements in this array be using the SetComponent and GetComponent methods. All indices start at 0.

A concrete example vtkFloatArray Mode 2 – Dynamic Array To create in TCL type vtkFloatArray arr arr SetNumberOfComponents 1 arr InsertNextTuple1 5 arr InsertNextTuple1 10 set b [ arr GetComponent 1 0 ] This creates a dynamic array of vectors each having size 1 (Number of Components). The InsertNextTuple command allocates memory dynamically and places the value there Note also (InsertNextTuple2, InsertNextTuple3,4,9 for multi- component arrays)

A final note on vtkDataArray In C+ one can use the generic command vtkDataArray::CreateDataArray(type) to create an array of type to be specified at run-time. In Tcl there is a less elegant solution as vtkDataArray can not be accessed directly. Here one creates a specific empty array (e.g. vtkFloatArray) and then uses this to create another array e.g. vtkFloatArray emptyshell set shortarray [ emptyshell CreateDataArray VTK_SHORT ] set doublearray [ emptyshell CreateDataArray VTK_DOUBLE ] The following constants are often defined set VTK_VOID 0 set VTK_BIT 1 set VTK_CHAR 2 set VTK_UNSIGNED_CHAR 3 set VTK_SHORT 4 set VTK_UNSIGNED_SHORT 5 set VTK_INT 6 set VTK_UNSIGNED_INT 7 set VTK_LONG 8 set VTK_UNSIGNED_LONG 9 set VTK_FLOAT 10 set VTK_DOUBLE 11

Creating a Surface Manually – Step 1 # Create Points for a cube vtkPoints pt pt SetNumberOfPoints 8 pt SetPoint ; pt SetPoint ; pt SetPoint ; pt SetPoint pt SetPoint ; pt SetPoint pt SetPoint ; pt SetPoint # Create Polygons vtkCellArray cl # Insert a Square cl InsertNextCell 4 cl InsertCellPoint 0; cl InsertCellPoint 1; cl InsertCellPoint 2; cl InsertCellPoint 3; # Insert a Triangle cl InsertNextCell 3 cl InsertCellPoint 2; cl InsertCellPoint 3; cl InsertCellPoint 6

Creating a Surface Manually – Step 2 # Create the Surface vtkPolyData sur # Set the points and cleanup sur SetPoints pt; pt Delete # Set the polygons and cleanup sur SetPolys cl; cl Delete # Create a Mapper and set its input vtkPolyDataMapper map; map SetInput sur # Create the actor and set it to display wireframes vtkActor act; act SetMapper map set property [ act GetProperty ] $property SetColor ; $property SetAmbient 1.0 $property SetDiffuse 0.0; $property SetSpecular 0.0 $property SetRepresentationToWireframe # Create the renderer vtkRenderer ren; ren AddActor act # Set camera mode to Orthographic as opposed to Perspective [ ren GetActiveCamera ] ParallelProjectionOn

Creating a Surface Manually – Step 3 example4_1.tcl example4_1.tcl # Rest is standard window/interactor etc. # Render Window vtkRenderWindow renWin renWin AddRenderer ren renWin SetSize # Interactor vtkRenderWindowInteractor iren iren SetRenderWindow renWin iren Initialize iren AddObserver SetExitMethod { exit } # prevent the tk window from showing up then start the event loop wm withdraw. vwait forever

Finishing the Cube example4_2.tcl example4_2.tcl # Insert rest of cube – rest of the definitions cl InsertNextCell 4 cl InsertCellPoint 0; cl InsertCellPoint 1; cl InsertCellPoint 5; cl InsertCellPoint 4; cl InsertNextCell 4 cl InsertCellPoint 0; cl InsertCellPoint 3; cl InsertCellPoint 7; cl InsertCellPoint 4; cl InsertNextCell 4 cl InsertCellPoint 1; cl InsertCellPoint 2; cl InsertCellPoint 6; cl InsertCellPoint 5; cl InsertNextCell 4 cl InsertCellPoint 4; cl InsertCellPoint 5; cl InsertCellPoint 6; cl InsertCellPoint 7; cl InsertNextCell 3 cl InsertCellPoint 3; cl InsertCellPoint 7; cl InsertCellPoint 6

Adding Colors example4_3.tcl example4_3.tcl … cl InsertNextCell 3 cl InsertCellPoint 3; cl InsertCellPoint 7; cl InsertCellPoint 6 # Create color array, colors stored as RGB values # vtkUnsignedCharArray ar ar SetNumberOfComponents 3 ar SetNumberOfTuples 8 ar SetTuple ; ar SetTuple ar SetTuple ; ar SetTuple ar SetTuple ; ar SetTuple ar SetTuple ; ar SetTuple vtkPolyData sur sur SetPoints pt ; pt Delete sur SetPolys cl; cl Delete # Set The Colors and Cleanup [ sur GetPointData ] SetScalars ar ar Delete

Viewing Surface with Solid Faces example4_4.tcl, example4_5.tcl example4_4.tclexample4_5.tcl vtkUnsignedCharArray ar ar SetNumberOfComponents 3 ar SetNumberOfTuples 8 ar SetTuple ; ar SetTuple ar SetTuple ; ar SetTuple ar SetTuple ; ar SetTuple ar SetTuple vtkPolyData sur sur SetPoints pt; pt Delete sur SetPolys cl; cl Delete # Add Colors to polygons not points (i.e. use Cell Data) [ sur GetCellData ] SetScalars ar ar Delete

Viewing Surface with Solid Faces vtkFloatArray ar ar SetNumberOfComponents 1 ar SetNumberOfTuples 7 ar SetTuple1 0 0 ; ar SetTuple1 1 1 ar SetTuple1 2 2 ; ar SetTuple1 3 3 ar SetTuple1 4 4 ; ar SetTuple1 5 5 ar SetTuple1 6 6 # Colors are Red/Green/Blue/Opacity in range 0 to 1 vtkLookupTable lkup lkup SetNumberOfTableValues 7 lkup SetTableRange 0 6 lkup SetTableValue lkup SetTableValue lkup SetTableValue lkup SetTableValue lkup SetTableValue lkup SetTableValue lkup SetTableValue

Viewing Surface with Solid Faces example4_6.tcl example4_6.tcl vtkPolyData sur sur SetPoints pt pt Delete sur SetPolys cl cl Delete # Add Colors to polygons not points (i.e. use Cell Data) [ sur GetCellData ] SetScalars ar ar Delete vtkPolyDataMapper map map SetInput sur map SetScalarRange 0 6 map SetScalarModeToUseCellData

Images are Simpler vtkImageData Points (vtkPoints) Define Location Cells (vtkCellArray) Define Topology Point Attributes (vtkPointData) Point Properties (e.g. intensity) Cell Attributes (vtkCellData) Cell Properties (e.g. normal) Arrays of Numbers (one per point or cell) vtkDataArray Implicitly Defined by Image Specification Rarely Used

vtkImageData vtkImageData is the basic VTK class for storing images. It is defined by 4 key elements –Dimensions -- these define the size of the image –Origin -- the position in 3D space of point –Spacing -- the voxel dimensions –Scalar Type -- the type of the image (e.g. float, short etc) An 4x4x4 image has 4x4x4=64 points and 3x3x3=27 cubic cells (both are implicitly defined)

Manually Creating an Image vtkImageDataimg img SetDimensions img SetOrigin img SetSpacing img SetScalarType VTK_SHORT img SetNumberOfScalarComponents 1 img AllocateScalars Intensity values can be accessed using the scalar array i.e. Point 0 is (0,0,0), point 1 is (1,0,0), point 10 is (0,1,0), point 100 is (0,0,1) set data [ [ img GetPointData ] GetScalars ] $data SetComponent set v [ $data GetComponent 10 0 ] Set v2 [ $img GetScalarComponentAsFloat ] ( this unfortunately is the nearest vtk comes to a getvoxel, no set voxel command)

The Image as a Function VTK treats an image as a function which takes values equal to those specified at the points and interpolates in- between Standard Interpolation is (Tri-)Linear In some cases (vtkImageReslice) other interpolation schemes are available.

Image File Read/Write VTK supports by default a number of standard image file formats for read/write –Binary – vtkImageReader –JPEG – vtkJPEGReader, vtkJPEGWriter –PNG – vtkPNGReader, vtkPNGWriter (ppm,pgm) –TIFF – vtkTIFFReader, vtkTIFFWriter –BMP – vtkBMPReader, vtkBMPWriter There are local extensions for reading Analyze, Signa LX/SPR, Prism (SPECT) etc

ImageToImage Filters There a number of ImageToImage Filters which are analogous to the surface to surface filters we have met before. There are exist standard filters derived from vtkImageToImageFilter for among others –Smoothing – vtkImageGaussianSmooth, vtkImageMedian3D –Computing Gradiens/Laplacians – vtkImageGradient, vtkImageLaplacian –Fourier Operations – vtkImageFFT,vtkImageRFT –Resampling/Reslicing – vtkImageResample, vtkImageReslice (vtkImageReslice on its own is reason enough to learn VTK, it implements enough operations that would take more than a year to code from scratch!) –Flipping, Permutting – vtkImageFlip,vtkImagePermute

Visualizing Images Images are displayed as textures mapped on polygons In OpenGL all textures must have dimensions that are powers of two Images are interpolated before display, hence some (small) loss of sharpness takes place (only visible in small images) –E.g. an 100x50 image will be resampled to 128x64 before display Similar issues for color display i.e. scalars vs lookup tables as in surfaces We will examine image display next week!