[vtkusers] extracting binary label image from poly data contour

Lars Friedrich Lars lars-friedrich at gmx.net
Wed Feb 18 08:42:51 EST 2009


Dear VTK-users,

I am trying to extract the image region defined by a poly data contour (from vtkContourWidget - stripped and decimated) from a white source image (3D, but 1 slice --> more or less a 2D image) in order to get a binary label image.
I am using the code below. Unfortunately, all I get is a black image ...
Do you know where the error could be? Could you give me hints where or how I should search for the error, please?
I think that the coordinates of the contour and the image match - don't understand why it doesn't work ...

Thank you!

lars


**** the code:

bool LabelingCode()
{
  vtkImageData *whiteImage = vtkImageData::New();
  
  whiteImage->SetDimensions(472, 387, 1);
  whiteImage->SetOrigin(0, 0, 0);
  whiteImage->SetSpacing(0.84, 0.84, 1.0);
  whiteImage->SetExtent(0, 471, 0, 386, 0, 0);
  whiteImage->SetScalarTypeToFloat();
  whiteImage->AllocateScalars();
  
  vtkIdType count = whiteImage->GetNumberOfPoints();
  
  for (vtkIdType i = 0; i < count; ++i)
    whiteImage->GetPointData()->GetScalars()->SetTuple1(i, 255.0);
  
  // here I retrieve the input contour (debug output is printed):
  vtkPolyData *pd = GetFinalContour();
  
  // print debug info of input contour and white image:
  vtkIndent id;
  pd->PrintSelf(std::cerr, id);
  whiteImage->PrintSelf(std::cerr, id);
    
  vtkLinearExtrusionFilter *extruder = vtkLinearExtrusionFilter::New();
  extruder->SetInput(pd);
  extruder->SetScaleFactor(1);
  extruder->SetExtrusionTypeToNormalExtrusion();
  extruder->SetVector(0, 0, 1);
  extruder->Update();
  
  vtkPolyDataToImageStencil *pol2stenc = vtkPolyDataToImageStencil::New();
  
  //pol2stenc->SetInformationInput(whiteImage);
  pol2stenc->SetInput(extruder->GetOutput());
  pol2stenc->SetOutputOrigin(0, 0, 0);
  pol2stenc->SetOutputSpacing(0.84, 0.84, 1.0);
  pol2stenc->SetOutputWholeExtent(0, 471, 0, 386, 0, 0);    
  pol2stenc->Update();
  
  vtkImageStencil *imgstenc = vtkImageStencil::New();
  
  imgstenc->SetInput(whiteImage);
  //imgstenc->SetInput(m_ParentModel->GetImageWrapper()->GetVTKImage());
  imgstenc->SetStencil(pol2stenc->GetOutput());
  imgstenc->ReverseStencilOff();
  imgstenc->SetBackgroundValue(0.);    
  imgstenc->Update();  
  
  vtkMetaImageWriter *wm = vtkMetaImageWriter::New();
  wm->SetInput(imgstenc->GetOutput());
  wm->SetFileName("/data/image-stuff/XrayRegistrationExamples/INN_015/w2.mhd");
  wm->Write();
  
  return true;
}

**** the debug output of the polydata-set:

Debug: Off
Modified Time: 180037
Reference Count: 3
Registered Events: (none)
Source: (none)
Information: 0x544a990
Data Released: False
Global Release Data: Off
UpdateTime: 0
Release Data: Off
UpdateExtent: Not Initialized
MaximumNumberOfPieces: -1
RequestExactExtent: Off
 Field Data:
  Debug: Off
  Modified Time: 180024
  Reference Count: 1
  Registered Events: (none)
  Number Of Arrays: 0
  Number Of Components: 0
  Number Of Tuples: 0
Number Of Points: 1074
Number Of Cells: 1
Cell Data:
  Debug: Off
  Modified Time: 180035
  Reference Count: 1
  Registered Events: (none)
  Number Of Arrays: 0
  Number Of Components: 0
  Number Of Tuples: 0
  Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
  Interpolate Flags: ( 1 1 1 1 1 0 0 )
  Pass Through Flags: ( 1 1 1 1 1 1 1 )
  Scalars: (none)
  Vectors: (none)
  Normals: (none)
  TCoords: (none)
  Tensors: (none)
  GlobalIds: (none)
  PedigreeIds: (none)
Point Data:
  Debug: Off
  Modified Time: 180037
  Reference Count: 1
  Registered Events: (none)
  Number Of Arrays: 0
  Number Of Components: 0
  Number Of Tuples: 0
  Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
  Interpolate Flags: ( 1 1 1 1 1 0 0 )
  Pass Through Flags: ( 1 1 1 1 1 1 1 )
  Scalars: (none)
  Vectors: (none)
  Normals: (none)
  TCoords: (none)
  Tensors: (none)
  GlobalIds: (none)
  PedigreeIds: (none)
Bounds: 
  Xmin,Xmax: (56.3585, 163.082)
  Ymin,Ymax: (0.0452085, 133.734)
  Zmin,Zmax: (0, 0)
Compute Time: 180207
Number Of Points: 1074
Point Coordinates: 0x6194770
Locator: 0
Number Of Vertices: 0
Number Of Lines: 1
Number Of Polygons: 0
Number Of Triangle Strips: 0
Number Of Pieces: 1
Piece: 0
Ghost Level: 0

**** the debug output of the image:

Debug: Off
Modified Time: 180205
Reference Count: 3
Registered Events: (none)
Source: (none)
Information: 0x544b980
Data Released: False
Global Release Data: Off
UpdateTime: 0
Release Data: Off
UpdateExtent: Not Initialized
RequestExactExtent: Off
 Field Data:
  Debug: Off
  Modified Time: 180084
  Reference Count: 1
  Registered Events: (none)
  Number Of Arrays: 0
  Number Of Components: 0
  Number Of Tuples: 0
Number Of Points: 182664
Number Of Cells: 181806
Cell Data:
  Debug: Off
  Modified Time: 180087
  Reference Count: 1
  Registered Events: (none)
  Number Of Arrays: 0
  Number Of Components: 0
  Number Of Tuples: 0
  Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
  Interpolate Flags: ( 1 1 1 1 1 0 0 )
  Pass Through Flags: ( 1 1 1 1 1 1 1 )
  Scalars: (none)
  Vectors: (none)
  Normals: (none)
  TCoords: (none)
  Tensors: (none)
  GlobalIds: (none)
  PedigreeIds: (none)
Point Data:
  Debug: Off
  Modified Time: 180205
  Reference Count: 1
  Registered Events: (none)
  Number Of Arrays: 1
  Array 0 name = NULL
  Number Of Components: 1
  Number Of Tuples: 182664
  Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
  Interpolate Flags: ( 1 1 1 1 1 0 0 )
  Pass Through Flags: ( 1 1 1 1 1 1 1 )
  Scalars: 
    Debug: Off
    Modified Time: 180202
    Reference Count: 1
    Registered Events: (none)
    Name: (none)
    Data type: float
    Size: 182664
    MaxId: 182663
    NumberOfComponents: 1
    Information: 0
    Name: (none)
    Number Of Components: 1
    Number Of Tuples: 182664
    Size: 182664
    MaxId: 182663
    LookupTable: (none)
    Array: 0x66b97b0
  Vectors: (none)
  Normals: (none)
  TCoords: (none)
  Tensors: (none)
  GlobalIds: (none)
  PedigreeIds: (none)
Bounds: 
  Xmin,Xmax: (0, 395.64)
  Ymin,Ymax: (0, 324.24)
  Zmin,Zmax: (0, 0)
Compute Time: 0
ScalarType: 10
NumberOfScalarComponents: 1
Spacing: (0.84, 0.84, 1)
Origin: (0, 0, 0)
Dimensions: (472, 387, 1)
Increments: (0, 0, 0)
Extent: (0, 471, 0, 386, 0, 0)


-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01



More information about the vtkusers mailing list