[vtkusers] vtkImageData pixel values of a Binary Image resulting -5.4861292803319049e+303 ; Instead of 0 & 1

Neel007 sayanmaity.10 at gmail.com
Mon Jul 13 18:45:18 EDT 2015


I am trying to read series of 2D *.tif images and then convert it to
vtkImageData. The vtkImageData pixel values of a Binary Image resulting 
-5.4861292803319049e+303 ; Instead of 0 & 1, Any suggestion if I am missing
something will be highly appreciated: 

the output screen and code: 

<http://vtk.1045678.n5.nabble.com/file/n5732873/1.png> 


int _tmain(int argc, _TCHAR* argv[]) 
{ 
  
  // Start by loading some data. 
   vtkSmartPointer<vtkTIFFReader> reader = 
    vtkSmartPointer<vtkTIFFReader>::New(); 
  reader->SetFileNameSliceOffset(1); 
  reader->SetFileNameSliceSpacing(1); 
 
reader->SetFilePattern("C:\\Users\\Neel\\Desktop\\VTK_try\\test_images\\2.%d.bspline.tif"); 
  reader->SetDataExtent(0, 63, 0, 63, 1, 2); 
  
  reader->SetOrientationType(3); 
  reader->Update(); 

  // Conver it to an image data 
  vtkSmartPointer<vtkImageData> imageData = 
    vtkSmartPointer<vtkImageData>::New(); 
  //vtkImageData *imageData=0; 
  imageData->AllocateScalars(VTK_DOUBLE,1); 
  imageData =reader->GetOutput() ; 

  int* dims = imageData->GetDimensions(); 
  // int dims[3]; // can't do this 
  
  std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: "
<< dims[2] << std::endl; 
  
  std::cout << "Number of points: " << imageData->GetNumberOfPoints() <<
std::endl; 
  std::cout << "Number of cells: " << imageData->GetNumberOfCells() <<
std::endl; 
  int extent[6]; 
  imageData->GetExtent(extent) ; 

  vtkIdType numberOfPointArrays =
imageData->GetPointData()->GetNumberOfArrays(); 
  std::cout << "Number of PointData arrays: " << numberOfPointArrays <<
std::endl; 

  cout<< "Number of Scalar Components:
"<<imageData->GetNumberOfScalarComponents()<<endl; 

  for(vtkIdType i = 0; i < numberOfPointArrays; i++) 
    { 
    // The following two lines are equivalent 
   
//arrayNames.push_back(polydata->GetPointData()->GetArray(i)->GetName()); 
    //arrayNames.push_back(polydata->GetPointData()->GetArrayName(i)); 
    int dataTypeID = imageData->GetPointData()->GetArray(i)->GetDataType(); 
    std::cout << "Array " << i << ": " <<
reader->GetOutput()->GetPointData()->GetArrayName(i) 
              << " (type: " << dataTypeID << ")" << std::endl; 
        
    } 

  // Retrieve the entries from the image data and print them to the screen 
  std::vector<double> vec_vals; 
  for (int z = 0; z < dims[2]; z++) 
    { 
    for (int y = 0; y < dims[1]; y++) 
      { 
      for (int x = 0; x < dims[0]; x++) 
        { 
        double* pixel = static_cast<double*>(imageData->GetScalarPointer()); 
        // do something with v 

        //std::cout << pixel[0] << " "; 
                vec_vals.push_back(pixel[0]); 
        } 
      std::cout << std::endl; 
      } 
    std::cout << std::endl; 
    } 

}



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkImageData-pixel-values-of-a-Binary-Image-resulting-5-4861292803319049e-303-Instead-of-0-1-tp5732873.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list