Karma Home Page
Next: kpvslice: interactive position-velocity slicing Up: Karma User Manual Previous: 4 Viewing Images and

# 5 Volume Rendering a Cube

The <xray> programme is used to volume render cubes.

# 5.1 How the rendering is done

You can think of the way a data cube is rendered as lines of sight going from every pixel of the display through the data cube and the voxels (visualisation speak for volume element of the data cube) on a line of sight contribute in some way to the colour and intensity of the display pixel. To decide how every voxel contributes, a number of algorithms (called shaders) are available.

## 5.1.1 Shaders

Below are two lists with the shaders available. The first list contains simple shaders. The Voxel sum and the Maximum voxel shaders are useful for exploring the data cube, because they are relatively fast and give a reasonable display of the data.

- Voxel sum The value of the display pixel is the sum of all voxel values along the line of sight. This is a fast and quite useful way of representing the data. With this shader, one gets a good global view of the emission. It is less useful for looking at small details

- Minimum voxel The pixel value is the minimum voxel along the line of sight

- Maximum voxel The pixel value is the maximum voxel along the line of sight. This is a fast way of getting a reasonable image. It also allows, depending on your data, to have a view of the `inside' of your data, the object looks more transparent than with the Voxel sum shader

- Front voxel The pixel gets the value of the first voxel along the line of sight above a specified threshold (not usually useful, the image is very blocky and has many holes). You get a control window where you can change the threshold value by clicking the left mouse button

The second kind of shaders uses an equation of radiative transfer to compute the images. These are called hot gas shaders.

The contribution of a voxel to the pixel on the display is calculated using a simple equation of radiative transfer, where a voxel is partly absorbed by voxels that are in front of it:

where is the intensity along a line of sight after adding the voxel in front, the intensity of the voxel added, the intensity along the line of sight that is behind the voxel, and the opacity of the voxel i. This calculation is done `back-to-front', so voxels in the back of the cube are partly obscured by voxels in the front part of the cube.

If the opacity for a voxel is zero, that voxel becomes completely transparent but also invisible. This closely resembles the behaviour of a self-radiating cloud of hot gas, where gas particles both emit and absorb radiation. Regions with high gas particle density will have a higher surface brightness, but will also have a higher cross-sectional area of absorption.

The resulting rendered image appears like a cloud of glowing gas, which shows both internal and external structure.

You can use this to make features disappear (eg. noise). The disadvantage is that in order to make the data that you want to see transparent, you also make it barely visible. Consequently, the opacity of data you want to see has to be not too low and as a result one will tend to see only the surface of the emission regions.

There are a few versions of this implemented, differing in whether they do the rendering monochromatically or in colour.

- Hot Gas: substances This works as follows: the value range [-127, 127] of the voxels is divided into a number of subranges (typically eight). Each subrange has a colour and an opacity associated to it and is called a substance. Like every colour in computer displays, a colour consists of red, green and blue.

  The contribution of a voxel to the colour of the pixel on the display is calculated using the radiative transfer, but for each colour (red, green or blue) separately. This means that if a blue voxel is behind a red one, the blue is still visible. This makes the data appear more transparent. It also means that this shader produces images that are 24-bit deep (one byte for every colour) and to change colours on the display, you will have to manipulate the substances. It also means that to play movies made with this shader, you may want to convert the images to 8 bit using the conv24to8 programme.

  A practical disadvantage of this shader is that it is difficult to set the colours and the opacities of the substances exactly as you want, there are many many parameters to set. It takes quite some time to produce reasonable images with this shader. You can save time by only defining a small number of substances (say the default eight), but then the representation of the data is somewhat schematic. If you define the maximum number of substances, you can set up a substance table with a smoother colour transition, but of course it takes more time for you to set up the table.

  A strong advantage of this shader is it can be useful to display both absorption and emission in a datacube.

- Hot Gas Mono This shader also uses opacities, but the control is much simpler. This shader takes

  where o is again the opacity, v the value of the voxel. By setting you can control which parts of the data are visible/opaque. A small value of makes low-level emission already quite opaque, while a large value will show only the brighter voxels. Also, the computation is done on the floating point data, not on colours (hence the mono). This increases the dynamic range of the image very much. Images produced by this shaders are floating point.

  An option offered with this shader that the intensity can be transformed before rendering, according to a similar function as above:

  where s is the value used for the voxel in the radiative transfer and v is the value of the voxel.

- Hot Gas Continuous this shader is a mix between the Hot Gas Substances and the Hot Gas Mono shaders. There are now 254 substances, but the opacity is defined in the same way as in Hot Gas Mono. The user interface of this shader is much better than that of hot gas substances. Also this shader produces 24bit images and to play movies made with this shader, you will have to convert the images to 8 bit using the conv24to8 programme.

# 5.2 Starting up the Volume Rendering Tool

To start the rendering software on any workstation type

``xray``

## 5.2.1 Options

<xray> supports several command line options which are all documented in the manual page. The options of general interest are:

- -private_cmap This option will force <xray> to use a private colourmap for its PseudoColour window. Otherwise, <xray> trys to allocate colours from the default colourmap
- -num_colours This option specifies the number of colour cells that <xray> will try to allocate for its PsuedoColour window upon startup. If less colours are available it allocates as many as possible (minimum 2).
- -fullscreen This option will make the image display window take up the entire screen. This is useful if you wish to make a video of the data. You will need to configure your window manager to cycle the window stacking order when a special key is pressed (e.g. the "Back" key with the Open Look window manager). See also the appendix on making videos.
- -no_slice_win This option will disable the 3D slicing window similar to what you get in kslice_3d

After starting up, many windows will appear:

- the control window, with which of course you control the rendering program
- a slice window. This shows the data cube along the three principle planes: XY, ZY and XZ. By moving the mouse (press left), the windows will be updated. To make things run smoothly, click on Precompute. This is also available as a stand-alone program kslice_3d and is quite useful for inspecting your data. This window will appear after you have loaded a cube (and possibly converted to bytes)

Another window that you will see (after the first time you render the cube) is the image display. This window is similar to the display window in many of the other tools (see section 2.15).

# 5.3 Loading Data into xray

<xray> supports many data formats like any other Karma programme. For reasons of memory use and speed, the preferred data format used by <xray> is that the data is stored as bytes, with values ranging from -127 to 127 (the value -128 is used for blank or missing data). The values in your data cube will have to be scaled into this range.

If you load a non-byte data cube, <xray> will display a window showing the histogram of the data values in the cube. If you want to use the full range of values in the cube (good for a first look at the data), click (left) on the Full Range button. If you want to select a sub-range of the data, click (left) in the histogram window to define the lower bound and click (right) to define the upper bound. You then click (left) on Apply to tell <xray> to compress the cube to a byte cube. You will then be able to click (left) on the Save button, to save the compressed data cube. The default filename is ``scaled'', but you can change this prior to saving. Once you have saved a compressed cube, the next time you load it in <xray> it will load much faster.

The proper values for the scaling range of course depend on the data in the cube and on what you want to see in the data, but here are some hints. Normally, the histogram has a large peak around zero (The Noise). Unless you want to have a look at the noise in your data cube (eg. because you want to look at subtle calibration errors or errors in the continuum subtraction, errors that show up quite well with the rendering software), it may be a good idea to take the minimum such that most of this peak is excluded. Depending on which voxel algorithm you use in the rendering (see later), if you include data at the noise level, your rendered data cube will have a lot of noise `in front' of your object of interest and it may just be in the way. There are however also other ways (see below) to hide the noise.

Consider that with the rendering software you may see faint structures in your data that you were not aware of. So you may not want the minimum to be too high either otherwise you may miss interesting features in your data. Of course, when there is absorption in the data, the noise will have to be included.

Also consider that the because the data is scaled into [-127, 127], the dynamic range is limited, so in some cases it may be a good idea to choose the maximum not too high. You will be able to see more detail in the fainter emission.

# 5.4 The main control window

A screen snapshot is available here.

The following controls are available:

- Files this pops up a standard Filepopup widget (section 2.1) with which you can load your cube
- Show Orientation this pops up a window which shows a wireframe of the cube. As you change the cube rotations this is updated immediately. This should give you a feel for which way the cube will rotate before you press Compute
- Make Movie this pops up a movie control panel. This is descibed in section 5.5
- Rescale if you loaded a non-byte cube then you can bring up the histogram display using this button and then you can set the data scaling again
- Filter this pops up a filtering control panel described in section 5.6
- Quit this will quit the application
- Hide Wireframe if disabled, a wireframe showing the visible edges of the cube is displayed over the rendered data, to show how the data cube is rotated. It also helps the brain to perceive the data as three dimensional. If you don't like the wireframe, you should enable this toggle
- Stereo if your are sitting in front of phoenix and you started the window system in stereo mode, clicking on Stereo will enable stereo display. The way this works is that slightly different images are displayed in your left and right eyes, mimicking the way you see depth normally. You will hopefully see the rendered cube as a three-dimensional object with depth. To make use of this you need to wear a pair of ``Crystal Eyes'' glasses (these fit over most prescription glasses). If you want to use this feature please ask the system administrator who will lend you the glasses. These things are rather expensive so we don't just leave them lying around.

  Because of a problem with the vendors graphics library it is best to use the stereo option when rendering to 24bit images (i.e. when using the ``Hot Gas Substances'' or ``Hot Gas Continuous'' shaders)

- 2-D Cursor Menu

  This menu allows you to switch from the default cursor to an experimental 2-dimensional ``active'' cursor. The default (or ``dumb'') cursor will allow you to read image values and positions in the display window in the conventional way. The ``active'' cursor allows you to point at a feature (say a blob) on your volume rendered cube and obtain the 3-dimensional position of that feature. The horizontal and vertical position information is accurate, however the depth position is computed using a heuristic and is less accurate. In another window you will see a plot of the cube values versus the position along the line of sight, drawn in white. A yellow vertical line shows the depth of the feature you are pointing at (really the depth the algorithm thinks the feature is at). Both the 3-dimensional position information and the plot window are dynamically updated as you move the cursor in the image display window.

- Shader Menu this allows you to select which shader to use. See section 5.1.1
- Projection Menu this allows you to select a prjection. Two projections are available: Orthogonal and Perspective. If you select the perspective projection, you can control the distance of the cube (i.e. the amount of perspective) with the Distance slider in the control window. The main reason that the Perspective projection is there is that this is quite useful for stereo display. Even if you are not using stereo mode, you may want to try it anyway. It helps for the 3D perception of the images
- Mode Menu this allows you to choose the rendering mode. The process of projecting rays into the data volume and collecting the data along each ray can be quite involved, and there are speed/quality tradeoffs. The Mode Menu allows you to choose between these tradeoffs.
- 3-D Cursor Menu this allows you to choose the kind of 3-dimensional cursor available. This code is currently in development, so things may change rapidly. An overlay cursor is available (the cursor is drawn over the rendered volume), so the cursor will not dissappear behind a feature in the data. A proper translucent cursor is also available. You can move the position of the 3-D cursor by pressing the left mouse button in any of the three slice windows (the ones with the red crosshairs) and dragging the mouse
- Compute this will cause the cube to be rendered using all the current parameters
- Reset Orientation this will reset the view and then renderer the cube

- Load Segments this will bring up a file browser which allows you to load files with extension `.seg`. These files contain pairs of three-dimensional co-ordinates, each pair defining a line in the world co-ordinate system of the volume. These 3D lines are drawn through the volume and are obscured by opaque structure in the volume data. The files are simple ASCII format, where each line defines one pair of 3D points. Note that the endpoints are projected from 3D to screen co-ordinates, and then the points are joined by a straight line on the screen. For best results your lines in 3D space should be short
- Roll Slider this controls the roll angle. Think of an airplane rotating about it's long axis
- Pitch Slider this controls the pitch angle. The nose of the airplane dips up and down
- Yaw Slider this controls the yaw angle. The nose of the airplane swings left and right
- Start X Slider this controls the starting X position of the subcube to render
- Start Y Slider this controls the starting Y position of the subcube to render
- Start Z Slider this controls the starting Z position of the subcube to render
- End X Slider this controls the end X position of the subcube to render
- End Y Slider this controls the end Y position of the subcube to render
- End Z Slider this controls the end Z position of the subcube to render
- Distance this changes the distance your viewpoint is from the cube. This only has effect when using the Perspective projection
- Image Expansion Often, the image generated by the volume redering software is rather small (this is because the original cube was small). The software automatically expands the image so that it fills as much as possible the display window, using simple pixel replication. This results in blocky images, which may be undesirable. Setting the expansion factor to a value greater than 1 uses an anti-aliasing image expansion algorithm which maintains the original smoothness of the image. (See note on anti-alising for more information). Setting this to too large a value will result in very large movies, which is undesirable. Try a vlaue of 2 to start with
- Eye Separation When viewing the cube in stereo mode, it is useful to enhance or diminish the stereo separation. The lower the value, the closer the left and right eye viewpoints, and hence the lesser the stereo effect.

## 5.4.1 Rendering Modes

The following rendering modes are defined:

- normal this is the default mode. Because rays through the volume will not fall exactly on grid points, some approximation of the value has to be made. In this mode the ray is snapped to a grid point. This can result in aliasing problems, but is the fastest mode. In most cases the aliasing is not a problem. In addition, this mode computes a rotated version of the cube in a cache in the background while you are not doing anything (the background processing does not slow down normal rendering operations). The cube is rotated using the same grid snapping technique, so has the same aliasing problems. However, provided you do not keep changing the view (or the cube), subsequent render operations (such as changing the shader) are four to ten times faster. Whenever you rotate the cube (or change it) the cache is automatically built up again. <xray> always uses as much of the cache as it can
- smooth cache will build up the cache using a better algorithm when a ray falls between grid points. The value computed uses a distance weighted contribution from each of the nearest surrounding values; in effect an interpolation. This algorithm does not suffer from aliasing. The cache takes about four times longer to build up than in normal mode, but once it's done rendering is as fast as using the cache that normal mode produces. In fact, it doesn't matter how complex the cache building process is, once it's built rendering times are the same (for the same shader, of course). If the cache is not completed, part of the rendering uses the normal mode when you request an update. This can lead to the interesting side-effect that the lower part of the rendered volume is smoother whilst the upper part is rougher (and possibly shows aliasing artefacts)
- always smooth will always render using the interpolation algorithm. It does this by waiting for the cache to be built using the interpolation algorithm and then rendering. If you don't change your view or cube, subsequent rendering operations are still at maximum speed. If you find that you are having aliasing problems, you should use this option when making a movie (otherwise the movie generation process will not wait for the cache to be built up)
- smooth delayed will first render using the normal mode and will then build up the cache using the interpolation algorithm in the background. Provided you don't change the view or cube parameters, once the cache is computed the cube will be rendered again and you will see a refined image. Note that if you render the cube (with normal mode) and then idly change the view or cube parameters and sit back, a little while later the cube will suddenly rotate, even though you haven't clicked on Apply Orientation

## 5.4.2 Rotating the cube

With the sliders Roll, Pitch and Yaw you can rotate the data cube by hand. The coordinate axes are defined such that the X-axis is horizontal, the Y-axis vertical and the Z-axis pointing into the display. The Roll rotation is around the X-axis, Pitch around the Y-axis and Yaw around the Z-axis. Since rotations do not commute, it is important to know that the order of the rotations is Roll first, then Pitch and then Yaw.

To see the cube in the orientation you specify, click (left) on Compute. Reset Orientation resets the orientation to face-on.

# 5.5 Making a Movie

The main problem with volume rendering data cubes is that one does not really get a three dimensional perception of the rendered cube. One can display a scene from daily life in a very crude way and still perceive it as a 3D scene. But this apparently is not true for data cubes. The brain does not recognize the object in the image and therefore it does not make a three dimensional perception. One way to get a three dimensional perception of the data is to make a movie in which the data cube is rotated while it is rendered.

For making such a movie, click (left) on Make Movie, and the movie control window will pop up. This window allows you to make a series of images where the data cube is rotated in steps. Use the sliders to set the increment in Roll, Pitch and Yaw, and the number of images you want. Start Movie then starts computing this sequence. To save a movie, type in a filename and click Save Movie. Once the movie has been generated an animation control window will appear, allowing you to view the movie.

One consideration is the size of the movie. If this is too large (i.e. larger than about 40 Mbyte on phoenix), playing the movie will be slow. An estimate of the size of a movie is

where x, y and z are the size of the axes of the data cube in pixels and the zoom factor. My experience is that rotating the cube in steps of 10 degrees (so the movie is 36 frames) is in general sufficient to get a smooth movie.

It may not be a good idea to make a movie of images with a large Image Expand Factor, depending on the sizes of the axes of the cube. You will find that when you play such a movie, it will be slow because it has to swap images in and out. You can always zoom afterwards when you play the movie by resizing the window, although the result may not be as good.

# 5.6 Filtering your data

Often, there will be problems with the data (too noisy, confusing or bright continuum sources) which make it difficult to see your data. To help, there are a few filtering alogorithms implemented which should help. Click on Filter in the main control window and a filtering control panel will pop up.

The following filtering algorithms are available:

- simple one of the adaptive filtering algorithms
- slow median mask one of the adaptive filtering algorithms
- fast median mask one of the adaptive filtering algorithms
- 3D one of the adaptive filtering algorithms
- subtract continuum the continuum-subtraction algorithm

## 5.6.1 Adaptive Filtering

One problem with volume rendering is that in order to see faint structures in the data cube, one has to set the opacities, intensity transformation and clips such that also the noise becomes bright. As a consequence, the emission is visible only through a thick fog of noise and this noise hides a lot of information.

One solution is to apply adaptive filtering to the data cube: the data is smoothed where the emission is faint and extended (or absent), while the data is left intact if it is stronger or more pointlike. There are several techniques to do this. At the moment two algorithms are implemented, but we are working on other filters.

The filters are based on work of J.-L. Starck, F. Murtagh and A. Bijaoui with a few extentions of our own. They consists of making a wavelet transform of each channel in the cube. This allows to consider the data locally at different resolutions and modify it such that the signal-to-noise is improved. For more information, have a look at Adaptive Filtering and Masking of HI Data Cubes, Tom Oosterloo, ESF workshop on Vision Modeling and Information Coding', Nice, 4-6 October 1995 Note that the wavelet transforms can be 3D and 2D (channel by channel).

The adaptive filtering algorithms available are:

- Simple this is a very simple filter. It is a bit crude, but it has the advantage that it is fast, the other filters are quite a bit slower. It gets rid of most of the noise. This filter makes a wavelet transform and in each wavelet plane, it clips the wavelet coefficients that are below the noise level (defined by the parameter filter clip), to zero. This filter is only slighty more complicated than simple clipping the data below a certain level. The fact that it looks at the data with different resolutions makes it more efficient
- Median mask (fast) & (slow) the first step of this filter is identical to the simple filter. This filter also makes a wavelet transform of the data, and makes a logical mask for each wavelet plane defining where there is significant signal for every resolution, and inverse transforms only the significant wavelet coefficients. Now an iteration cycle begins. It transforms the difference between the original data and the filtered data, retains only the coefficients of the transform of the differnece for those positions and resolutions where there is significant signal in the data using the logical mask. It inverse transforms this masked difference and adds this filtered difference to the filtered data. For the second iteration cycle, it again defines a mask, takes the difference between the original data and this second filtered data, masks the wavelet coefficients and adds the masked difference to the filtered data. etc. etc. The iteration cycle ensures that the wavelet coefficients of the filtered data are identical to those of the original data for those resolutions and positions where there is significant signal.

  An important element of this filter is that it does a median filtering on the logical mask. This makes isolated noise peaks disappear and makes the data look more 'consistent'.

  The difference between the fast and slow version of this filter is that in the fast version 2 iterations are done, compared to 6 iterations in the slow version. The fast filter still leaves some noise blobs in the data, but fewer than the simple filter. The slow filter gets rid of almost all of them

There are two parameters to set for this filtering:

- levels this specifies the number of wavelet planes to be computed. The best values to are either 1 or 2. Using more than 2 planes produces artifacts for the simple filter. Usually it is also not necessary to consider more than 2 planes.

  Specifying Levels to 0 the original unfiltered data cube is rendered, but with noise clipping applied

- filter clip this specifies the clip level to be applied to the wavelet planes, in units of the noise level. Recommended values are 3 for the simple filter. For the median mask filter use 2 or 3.

## 5.6.2 Contintuum Subtraction

Often when you observe a spectral-line source you may have a confusing continuum source in the field. Your data reduction package should have a programme to subtract the continuum (e.g. ``uvlin'' in Miriad). The problem with some of these programmes is that in order to compute a fit to the spectrum of the continuum source, you first have to tell the programme which channels contain the spectral-line emission so that it can ignore those channels when computing the fit. The problem is how to find out which channels contain the line emission?

An effective technique is to invert your UV data into a cube before subtracting the continuum and then using <xray> to render it. Of course, if the continuum source is brighter than your spectral-line source (it usually is), the spectral-line source will be washed out. This is where you can use the subtract continuum filter. This will subtract the average flux in a spectral profile, for every point on the sky image. This is a good continuum-subtraction algorithm, to first order: it should filter out more than 90% of the continuum source.

Once you have your first order continuum-subtracted cube, you can use <xray> to find the spectral-line emission. In particular, you should find the 3D slicing window very handy, since it will give you the 3D co-ordinates of a point. Be warned that Karma programmes count from 0, whereas most astronomical reduction packages count from 1. If you take a channel index from Karma and put it into Miriad, remember to add the value 1.

Now that you have identified the spectral-line emission, you can run a programme like ``uvlin'' to do a better job of subtracting the continuum.

## 5.6.3 Other Controls

To apply the filtering. click on Do Filter. The cube is rendered automatically.

To get back the original data without any filtering, click on Undo Filter.

You may also Save the filtered cube for later use.

# 5.7 Hot Gas Substances control panel

A screen snapshot is available here.

This controls the settings for the Hot Gas Substances. You should see a window with a histogram of the data values in the cube (actually the logarithm of the distribution), and in the bottom part you will see space for the colours of the substances. Each colour has a horizontal line on it. This is an indicator for the opacity of the substance.

To change the colour of a substances you have to click (left) on the space on the bottom of the window that is reserved for the substance. This selects the substance. To change the colour, move the mouse in the upper part of the window and drag (middle, not left!!) the mouse around until you have the colour you want. The saturation of the colour can be changed by moving the mouse around while you drag with the right button. To change the opacity, put the mouse on the substance and drag with the middle mouse button vertically.

To change the value ranges for the substances, drag (left) the mouse in the upper part of the window. In the upper part, there are a few symbols that help to orient yourself. The + is the setting for the value ranges, the O the setting for the substance you have selected, and the horizontal line on the left of the window is the saturation of that substance. With this window, one is only able to change the value ranges in a way similar to a normal colour table control.

To use the settings you have made, click (left) on Apply and a new image will be calculated.

The button Save brings up a window to save substances.

To load a substance table click on Load and select your file.

# 5.8 Hot Gas Mono control panel

A screen snapshot is available here.

The control window for this allows you to set the opacity law of the Hot Gas Mono shader, as well as the exponent for the intensity transformation. One can also set the range of voxel values that are set to blank.

The following controls are available:

- Close this will close the window
- Compute this will render the cube
- Intensity Alpha this controls the value of in equation 5.3
- Opacity Alpha this controls the value of in equation 5.2
- Blank Start Slider this controls the start of a region of data values which will be blanked
- Blank End Slider this controls the end of a region of data values which will be blanked. If this value is greater than that of Blank Start Slider then some range of data will be blanked. The blanking is implemented by setting the opacities for that range to 0

In the display canvas under the controls you will see a log-histogram of your data (in white) as well as a red curve showing the transfer function between data value and intensity (see equation 5.3) and a yellow curve showing the transfer function between data value and intensity (see equation 5.2. The opacity curve also reflects the blanked range of values.

# 5.9 Hot Gas Continuous control panel

This shader is a cross between Hot Gas Substances and Hot Gas Mono. It has a similar control as the Hot Gas Mono shader in <xray>. Also here the exponent of the opacity law can be set, as well as the values range for valid data. The difference is that one can set the connection between voxel value and colour using a colourtable-like interface.

# 5.10 Hot Gas Three Colour control panel

This shader is an extension of the Hot Gas Continuous shader. It allows you to divide the data range into three regions, with independant opacity and colour transfer functions for each region. This shader is a little esoteric, and is designed for rendering data with two or three distinct populations of data values. This kind of data does not occur in radio astronomy. You may generate this data by combining two datacubes together. This shader would allow you to render one dataset in one colour and another dataset in another colour.

Karma Home Page
Next: kpvslice: interactive position-velocity slicing Up: Karma User Manual Previous: 4 Viewing Images and