Visualization of an Image
Abstract
This problem combines image data, visualization, 3D file formats
and producing a meaningful image for a viewer.
The input data will be pixel values in an image.
The pixels values are averaged in blocks of 10 by 10 pixels.
These averages are converted into prisms to represent the values.
The prisms are converted into a 3D file format.
Then a program reads and displays the image and the representations
of the density information.
Outline
You need to write a sequence of programs to produce an answer.
The first program reads an image file and converts into a data structure
description of the visualization.
The second program reads and displays the image and the visualization.
Goals
This project has a number of goals.
One is to introduce some concepts of visualization.
Related to this is the goal of you being able to translate some problems
into a visualization.
Another goal is allow you to see images as collections of data.
Graphics goals are to deal with representations of 3D objects and building
complex collections of information.
The last major goal to get you familiar to the idea of using and building
tools to handle parts of problems.
Objectives
You will be able to take numeric sets and translate them
into a visualization.
You will be able to take an image and do processing on the pixel values.
You will be able to write a program to build structures of 3D items.
You will write one or more tool programs to aid in solving a problem
(in small steps).
Prerequest Background
You need the basic ideas of 3D space and how to build a simple program
displaying items in 3D space.
Content
Write a program to convert a pgm image (see following) into a vtk file with 3D
bar charts and an overlaying (semi transparent) gray scale image map.
The bars (or rectangle solids) are to average the values of a 10x10 set of
input pixals with the height representing that average.
If you prefer, you can read in a ppm (color) file and convert it to
a gray scale image by averaging the three values (RGB) for each pixel.
Note, this is a sloppy, inaccurate way to do this.
However, it is also good enough for most uses.
See the book for the
correct conversion formula.
You also need to write a vtk program to read in these vtk format files
and display them.
The full process after you have the programs working is
image -------------> image.pgm -------> image.vtk -------->display
use xv, giftopnm your your vtk
or other program program
image converter
As an example, if you have a 20 x 20 (pixel) image.
Then average the pixel values in each of the four 10 x 10 blocks.
Then place above the image the bar to represent the block average.
In a pgm file each pixal can have a value in the range 0 to 255.
part of a pgm (ascii) file
---------------------------------------------------
P2
# CREATOR: XV Version 3.10 Rev: 12/16/94
480 270
255
109 109 109 109 109 109 109 109 109 109 109 109 109 109 109 109 109
109 109 109 109 109 109 109 109 109 109 109 109 109 109 109 109 109
...
BNF for a pgm (ascii) file.
pgm-p2-file :: P2<cr> <comments>* <num-rows> b <num-cols><cr>255<cr><data>
<comment> :: # <text> <cr>
<data> :: (<number><white-space>)^(<num-cols><num-rows>)
This is the man page for pgm file format.
And this is the man page for ppm file format.
To set the color of a vtk object:
pickActor->GetProperty()->SetColor(1,0,0);
To set the transparency/opacity:
pickActor->GetProperty()->SetOpacity(0.7);
An example of a vtk file is
cube.vtk from the vtk book.
A start on the vtk program you need to write is
pjReadvtk.cxx. This
program can read a vtk type file and display it.
A copy of this can be found on the sod cluster
in vtk312.
If you need to process a binary file in c++, the following example
could help. It creates a binary copy of the input file.
//binary file copy
#include
#include
voild main()
{ ifsteam fin("hello.exe",ios::binary);
ofstream fout("thecopy.exe",ios::binary);
for(usigned char c = fin.get();fin.good();fin.get(ch)) fout << ch;
fin.close();
fout.close();
}
Another example is a small program to read a P5 type file (pgm binary)
and convert it to another format. This program does not have the
code to skip the
# CREATOR: XV Version 3.10 Rev: 12/16/94
put in by xv.
Here is the
pgmtotop.c
program.
Posttest
Once you complete this project you should be able to solve problems such as:
Write a program to determine the average gray value in an image.
Write a program to populate a number of city blocks with identical houses.