[vtkusers] Cannot differentiate between different float values

ankit master ankit.master at gmail.com
Mon Nov 21 12:25:16 EST 2011


Hello,

I am newbie to the world of ITK and VTK and my question is due to my
ignorance.

I am reading a float image using ITK and want to visualize this float image
using VTK.

I simulate this float image to have different values in it. E.g. one of the
simulated images will have all of its values as 100.00 and other may have
all of its values as 5.0.

So when I bring up these two images using VTK I do not see any differences
between them, I mean I would expect some changes in the color or intensity
or something like that for me to say which image is which .

Purpose of this test tool later is going to be able able to read an actual
float image (with different pixels having different intensity values)

Following is my code, could anyone please help me understand why do I just
see black image despite having pixels with different float values.


#include<iostream>
#include<fstream>
#include <string>
#include <cmath>

#include "itkImage.h"
#include "itkImagetoVTKImageFilter.h"
#include "itkImportImageFilter.h"  // convert an array into itkImage type
#include "itkTileImageFilter.h"


#include <vtkImageDataGeometryFilter.h>
#include <vtkProperty.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkImageMapper.h>
#include <vtkActor2D.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkImageViewer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>

struct f32complex{
float re,im;

};




int main(int argc, char* argv[])
{
// read binary file  readBinaryDataFromDisk();
std::string filename = "complexImage.dat" ;
         int length;
f32complex * buffer;

std::ifstream is;
 is.open(filename.c_str());

// get length of file:
is.seekg (0, std::ios::end);
 length = is.tellg();
is.seekg (0, std::ios::beg);

// allocate memory:
 buffer = new f32complex [length];

// read data as a block:
 is.read ((char*)buffer,length);

is.close();

//assuming symmetry of data in both dimensions
 float val1 = length/8;    // 4 + 4 bytes , float data type
int dim[2];

 float dimension = sqrt(val1) ;
dim[1]= dim[0] = dimension;

 // get real image
    float *realImage = new float[length] ;
for (int i=0; i<length; i++)
 realImage[i]= buffer[i].re;

    // get imaginary part  getImaginaryImage();
    float *imaginaryImage = new float[length] ;
for (int i=0; i<length; i++)
 imaginaryImage[i]= buffer[i].im;
    delete [] buffer;
  typedef itk::Image< float, 2 > ImageType;
//typedef itk::ImageFileReader<ImageType>      ReaderType;
 typedef itk::ImageToVTKImageFilter< ImageType>   FilterType;

typedef itk::ImportImageFilter< float, 2 >   ImportFilterType;

   //  ReaderType::Pointer reader = ReaderType::New();
     //FilterType::Pointer connector = FilterType::New();

 ImportFilterType::Pointer importFilter = ImportFilterType::New();
ImportFilterType::SizeType  size;
 int totalNumofPixels = size[0]*size[1];
 size[0]  = int (dim[0]);  // size along X
 size[1]  = int (dim[1]) ;  // size along Y
  importFilter -> SetImportPointer(imaginaryImage, totalNumofPixels, true
);
importFilter->Update();
 FilterType::Pointer connector = FilterType:: New();
connector->SetInput(importFilter->GetOutput()) ;
 vtkImageViewer * viewer = vtkImageViewer::New();
vtkRenderWindowInteractor *renWinInt = vtkRenderWindowInteractor::New();


viewer->SetupInteractor(renWinInt);
viewer->SetInput(connector->GetOutput() );
 viewer->Render();
viewer->SetColorWindow(255);
viewer->SetColorLevel(128);
 renWinInt->Start();
  //viewer->Delete();
//renWin->Delete();
 //renWinInt->Delete();
}



Thank you in advance

Ankit

-- 

>From the withered tree, a flower blooms.
                                                         - Zen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111121/94a3831a/attachment.htm>


More information about the vtkusers mailing list