[vtkusers] vtkImageViewer2 bug?

Francois Bertel francois.bertel at kitware.com
Fri Dec 7 10:03:33 EST 2007

A vtkImageData is a uniform grid (can be 3D, 2D or 1D) of points and cells.

The geometry part of this dataset is defined by some origin (position of the lower left deepest point) and some spacing (distance between two points, which is also the distance between the center of two cells, spacing can be different in each dimension)

In each dimension, there are n points (the number can be different in each dimension), point 0 defines the lowest geometry bound and point (n-1) the highest geometry bound. In each dimension, a cell is bounded by two points. There are (n-1) cells, indexed from 0 to n-2. Cell i is bounded by point i and point i+1. Point i is the boundary between cell i-1 and cell i.

An image on a png file is just a 2 dimensional array. There is no geometry attached to it. When it comes to VTK world, this array is stored as a vtkDataArray on a vtkImageData.

In a vtkImageData, there are two types of arrays, those associated with position of points (pointdata), those associated with the center of the cells (celldata). The vtkPNMReader makes the choice to attach this array to the points.

When it comes to display (map) this array to the imagedata geometry, the values are only defined at the position of the points, any other location between two points is an interpolated value. The type of interpolation is not unique.

In nearest interpolation mode, the value displayed is constant around the position of a point. As the first point and last points define also the boundary of the dataset, only one part of the domain they cover is displayed (the geometry does not exist on the left of the most left point, the geometry does not exist on the right of the most right point).

In linear mode, values displayed between points are linearly interpolated. That's probably the mode that makes more sense to visualize pointdata.

See the first figure in attachment (pointdata.png)

In order to display in nearest mode (as you tried on the images you sent in your first message), quads of the same size for each value of a png image, the dataarray has to be assigned to cells instead of points.

See the second figure in attachment (celldata.png)

Unfortunately, I don't thing this feature exists on the vtkPNMReader.

Similar remark for celldata: if you assign the dataarray to celldata and try to display the values in linear mode, the interpolation happens between the centers of two cells. Here comes the boundary issue again, as the most left cell does not have a left neighbor, interpolation cannot happens, the value of the cell remains constant on its left part. Same thing for the most right cell, the value on its right part remains constant until it reaches the right boundary of the imagedata.


shekharc wrote:
> Hi Guys,
> Thanks for the reply Mark, it appears you might be right. I loaded data
> into Paraview and found if one lets OpenGL handle the mapping it does
> what I described before and clips the image but if "Interpolate Colours"
> is checked everything is fine. This is linked to
> SetInterpolateScalarsBeforeMapping() member in vtkMapper I think.
> I have attached what I mean from screenshots. vtkImageViewer doesn't
> have the vtkImageViewer2 issue if I use vtkImageMagnify to turn of
> interpolation but doesn't have the same Interactor setup. I have used
> Image Actor's member InterpolateOff() which controls interpolation
> display but is no doubt the cause.
> All I want to do is to display an uninterpolated image but not clip the
>  image if thats even possible with vtkImageViewer2. Is there another
> lower function involving mapping/interpolation that I can use?
> Any help would be appreciated.
> Cheers
> Shakes
> Mark Wyszomierski wrote:
>> I've always noticed the same thing, I think it comes down to the way
>> the image is being texture mapped on the quad. I can't remember too
>> clearly but I looked into it about 2 years ago, I think it's just the
>> way opengl sticks it on there, I could be wrong on that though,
>> Mark
>> On Dec 6, 2007 3:48 AM, Shakes <Shekhar.Chandra at sci.monash.edu.au> wrote:
>>> Hi Guys,
>>> I have been using vtkImageViewer2 to display very small greyscale images
>>> (7x7) and found that it seems to clip half of a pixel of each pixel on
>>> the edge of the image despite the data being read in correctly. I have
>>> attached a screenshot with a comparison of volume plot, vtkImageViewer2,
>>> data table and with ImageJ (on the right) and also attached the original
>>> test image.
>>> No other image viewer has problems with the file and the vtkPNMReader
>>> appears to work correctly as I can check the data directly by eye and is
>>> correct (the table verifies this). It is also writen by vtkPNMWriter. I
>>> have also written a VTI file containing a stack of these and the volume
>>> display appears suffer the same effect (very left).
>>> Here the camera is reset and I have checked the extents and bounds of
>>> vtkImageActor (also checked display bounds and extents), vtkRenderWindow
>>> and QVTKWidget and all is fine.
>>> I was just wondering if this might be a bug as this would not be visible
>>> for large images? Or is there an invisible border? Or something else I
>>> can do to rectify it. I have already spent several hours on this and
>>> hoping someone can help me. :(
>>> Cheers
>>> Shakes
>>> Relevant Code:
>>> int bounds[6];
>>> vtkPNMReader* reader = vtkPNMReader::New();
>>> reader->SetFileName(name.toStdString().c_str());
>>> reader->Update();
>>> imageData = reader->GetOutput();
>>> imageData->GetExtent(bounds);
>>> cerr << "Image Size: " << bounds[1]+1 << "x" << bounds[3]+2 << endl;
>>> viewer->SetInput(imageData); //Doesn't matter if I use
>>> reader->GetOutputPort()
>>> viewer->GetRenderer()->ResetCamera();
>>> QVTKWidget::SetRenderWindow(viewer->GetRenderWindow());
>>> viewer->SetupInteractor(QVTKWidget::GetRenderWindow()->GetInteractor());
>>> Other Info:
>>> Tested on Kubuntu Gutsy (g++ 4.1.2) x86, openSuse 10.3 x64 and Vista x64
>>> (MSVC 2005 x64). Qt 4.3.2 and VTK 5.0.3.
>>> _______________________________________________
>>> This is the private VTK discussion list.
>>> Please keep messages on-topic. Check the FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers

François Bertel, PhD  | Kitware Inc. Suite 204
1 (518) 371 3971 x113 | 28 Corporate Drive
                      | Clifton Park NY 12065, USA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pointdata.png
Type: image/png
Size: 36539 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071207/38429768/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: celldata.png
Type: image/png
Size: 26871 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071207/38429768/attachment-0001.png>

More information about the vtkusers mailing list