[vtkusers] bugs in vtkImageConstantPad? vtkExtractVOI?
Lawrence M. Lifshitz
Lawrence.Lifshitz at umassmed.edu
Fri Jun 30 16:37:16 EDT 2000
Hi, I'm trying to use vtkImageConstantPad to pad an image so that
it is a power of 2 in each direction (thus not needing pixel resampling
when texture mapping with it, thus preserving exact pixel values).
Two problems seem to arise. First, it seems like it is padding over
the high x and high y pixels in my original data
(eg, input image of dims (7,6,1) which I'm padding to (8,8,1) has pixels
at (6,*,1) and (*,5,1) set to constant - but they are part of the
original data).
Could this be because ExtractVOI sets the update extent incorrectly (see
below)?
Second, it does not seem to handle vtk_unsigned_short images, I think.
At least when I start off
with structuredpoints as vtk_unsigned_short, I get 0 as the pixel values
in my original image, and when
I start off with vtk_floats it seems to work. [but before I put the
padding step in, the display
worked fine with unsigned short - ie, non powers of two, resampled and
texture mapped, so vtkImageConstantPad has something to do with the
problem I think].
Could this have something to do with ExtractVOI seeming to change the
type
to float even when I start with unsigned short?
The unsigned short version fails (the float version succeeds):
vtkScalars *scalars = vtkScalars::New(VTK_UNSIGNED_SHORT);
//alternatively as float (which works)
vtkStructuredPoints *vol = vtkStructuredPoints::New();
iptr = iimage; // short int data and ptr
for (i=0;i<numpix;i++,iptr++)
{if (*iptr < 0) *iptr = 0;
scalars->InsertScalar(i,*iptr); //alternatively: fval = *iptr;
InsertScalar(i,fval);
// this works
}
vol->GetPointData()->SetScalars(scalars);
vtkPlaneSource *concPlane;
vtkExtractVOI *concSection;
vtkImageConstantPad *padim;
concSection = vtkExtractVOI::New();
concSection->SetVOI (0,dims[0]-1, 0,dims[1]-1, 0, 0); // dims[] are
my original dimensions
concSection->SetInput(vol);
concSection->SetSampleRate(1,1,1);
//pad to power of two so concTexture doesn't resample it
concSection->Update(); // necessary ?
padim = vtkImageConstantPad::New();
padim->SetNumberOfThreads(1); // from
imaging/examplesPython/TestConstantPad.py
padim->ReleaseDataFlagOff();
padim->SetInput(concSection->GetOutput());
newdim[0] = 0; newdim[2] = 0; newdim[4]=newdim[5] = 0;
newdim[1] = FindPowerOfTwo(dims[0]) -1;
newdim[3] = FindPowerOfTwo(dims[1]) - 1;
padim->SetOutputWholeExtent(newdim);
concSection->Update(); // necessary ?
padim->Update();
padim->SetConstant(128.0);
padim->GetOutput()->GetDimensions(mydims);
*********** printout from a vtk unsigned short run (pixel intensities
display as 0):
vol
ScalarType = VTK_UNSIGNED_SHORT
WholeExtent: (0 - 6,0 - 5,0 - 4)
UpdateExtent: (0 - 6,0 - 5,0 - 4)
Extent: (0 - 6,0 - 5,0 - 4)
Dims: (7,6,5)
concSection Output
ScalarType = VTK_FLOAT <----- why has this changed to float?
WholeExtent: (0 - 5,0 - 4,0 - 0) <------ why this ??
UpdateExtent: (0 - 5,0 - 4,0 - 0)
Extent: (0 - 6,0 - 5,0 - 0)
Dims: (7,6,1)
padim Output
ScalarType = VTK_FLOAT
WholeExtent: (0 - 7,0 - 7,0 - 0)
UpdateExtent: (0 - 7,0 - 7,0 - 0)
Extent: (0 - 7,0 - 7,0 - 0)
Dims: (8,8,1)
************ printout from a VTK_FLOAT run:
vol
ScalarType = VTK_FLOAT
WholeExtent: (0 - 6,0 - 5,0 - 4)
UpdateExtent: (0 - 6,0 - 5,0 - 4)
Extent: (0 - 6,0 - 5,0 - 4)
Dims: (7,6,5)
concSection Output
ScalarType = VTK_FLOAT
WholeExtent: (0 - 5,0 - 4,0 - 0)
UpdateExtent: (0 - 5,0 - 4,0 - 0) <------ why this ??
Extent: (0 - 6,0 - 5,0 - 0)
Dims: (7,6,1)
padim Output
ScalarType = VTK_FLOAT
WholeExtent: (0 - 7,0 - 7,0 - 0)
UpdateExtent: (0 - 7,0 - 7,0 - 0)
Extent: (0 - 7,0 - 7,0 - 0)
Dims: (8,8,1)
thanks.
Larry
--
Lawrence M. Lifshitz, Ph.D.
Biomedical Imaging Group - University of Massachusetts Medical School
Phone: (508) 856-3392 email: Lawrence.Lifshitz at umassmed.edu
FAX: (508) 856-1840 web: http://invitro.umassmed.edu/~lml
More information about the vtkusers
mailing list