[vtkusers] How do i port an image from ITK to VTK

Prename Surname bsd.diverse at gmail.com
Wed Oct 11 13:27:54 EDT 2006


And i forgot to mention. The image is of the format analyze, consisting of
182 slices, where slice nr. 160-182 is really actually static. But the rest
of the slices, meaning slice 1 to 160 has data which is real, and not noise.

Could this have something to do with it?
Regards


2006/10/11, Prename Surname <bsd.diverse at gmail.com>:
>
> Hello again.
> I managed to compile and run the program. But there seems to be a problem.
> The output just shows static noise, it can be seen here: http://www.coachkontakt.dk/rendered.jpg
>
>
> A cube of green static noise. The image should be okay since i have seen
> it in other programs where it looks just fine. So i suspect something has
> gone wrong in the conversion.
> I am a bit lost here, I hope you have some suggestions as of what is
> wrong.
>
> Thank you very much.
>
> My code looks like this :
>
> //Used for the analyze reader
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"//
>
> #include "itkImageToVTKImageFilter.h"//Makes ITK->VTK pipeline (remember
> to set path in CMakeLists.txt firs)
>
> #include "vtkImageViewer.h"//Makes 2D images in VTK
>
> //Use for volumerendering
> #include "vtkStructuredPointsReader.h"
> #include "vtkPiecewiseFunction.h"
> #include "vtkColorTransferFunction.h"
> #include "vtkVolumeProperty.h"
> #include "vtkVolumeRayCastCompositeFunction.h"
> #include "vtkVolumeRayCastMapper.h"
> #include "vtkVolume.h"
>
>
> //Used for the vtk examples
> #include "vtkSphereSource.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkActor.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderer.h "
> #include "vtkRenderWindowInteractor.h"
>
> #include "itkVTKImageExport.h"
> #include "vtkImageImport.h"
>
> //Used for string manipulation in c++
> #include <strstream>
> #include <string>
> #include <iostream>
>
> void showSphere();
> void readAFile();
>
> int main( int , char * argv[])
> {
>  typedef unsigned char PixelType;
>  const unsigned int Dimension=3;
>
>  typedef itk::Image<PixelType,Dimension> ImageType;
>  typedef itk::ImageFileReader<ImageType> ReaderType;
>  typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
>
>  ReaderType::Pointer reader = ReaderType::New();
>  ConnectorType::Pointer connector = ConnectorType::New();
>
>  reader->SetFileName("D:\\skole\\thesis\\Data\\KDIGWKFN\\ANALYZE\\KDIGWKFN_mpr_pip.img");
>
>  connector->SetInput(reader->GetOutput());//In connector lies now the
> imagedata. Retrieve it by calling GetOutput()
>
>  vtkStructuredPointsReader *vtkReader=vtkStructuredPointsReader::New();
>
>
>  //Create transfer mapping scalar value to color
>  vtkPiecewiseFunction
> *opacityTransferfunction=vtkPiecewiseFunction::New();
>  opacityTransferfunction->AddPoint(20.,0.0);
>  opacityTransferfunction->AddPoint(255., 0.2);
>
>  vtkColorTransferFunction
> *colorTransferFunction=vtkColorTransferFunction::New();
>  colorTransferFunction->AddRGBPoint(0.0,0.0,0.0,0.0);
>  colorTransferFunction->AddRGBPoint(64.0,1.0,0.0,0.0);
>  colorTransferFunction->AddRGBPoint( 128.0,0.0,0.0,1.0);
>  colorTransferFunction->AddRGBPoint(192.0,0.0,1.0,0.0);
>  colorTransferFunction->AddRGBPoint(255.0,0.0,0.2,0.0);
>
>  vtkVolumeProperty *volumeProperty=vtkVolumeProperty::New();
>  volumeProperty->SetColor(colorTransferFunction);
>  volumeProperty->SetScalarOpacity(opacityTransferfunction);
>
>  vtkVolumeRayCastCompositeFunction *compositeFunction =
> vtkVolumeRayCastCompositeFunction::New();
>  vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New();
>  volumeMapper->SetVolumeRayCastFunction(compositeFunction);
>  volumeMapper->SetInput(connector->GetOutput());
>
>  vtkVolume *volume=vtkVolume::New();
>  volume->SetMapper(volumeMapper);
>  volume->SetProperty(volumeProperty);
>
>  // A renderer and render window
>  vtkRenderer *ren1 = vtkRenderer::New();
>  vtkRenderWindow *renWin = vtkRenderWindow::New();
>
>  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>  iren->SetRenderWindow(renWin);
>
>
>
>  // Add the actor to the scene
>  ren1->AddProp(volume);
>
>  renWin->AddRenderer(ren1);
>
>  //Render an image(lights and camera are created automatically)
>  renWin->Render();
>
>  //Begin mouse interaction
>  iren->Start();
>
>  return 0;
> }
>
>
>
> 2006/10/11, Kevin H. Hobbs <hobbsk at ohiou.edu>:
> >
> > On Wed, 2006-10-11 at 16:07 +0200, Prename Surname wrote:
> > > Hello Brian.
> > > I have tried to do what you said, and it makes good sense. I think i
> > > almost got i working, but i still have a doubt about how exactly i can
> > > connect the
> > > itk::ImageToVTKImageFilter to the vtkVolumeRayCastMapper.
> > > It seems that  ImageToVTKImageFilter->GetOutput(...) returns a
> > > vtkImageData, and
> > > vtkVolumeRayCastMapper->SetInputConnection(...) only accepts a
> > > vtkAlgorithmOutput object.
> > >
> > >
> >
> > I do VTK -> ITK -> VTK to stream through ITK filters in the attached
> > file. I want the pieces in a specific order so I mess with them. You can
> > ignore that part.
> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061011/c20b3475/attachment.htm>


More information about the vtkusers mailing list