[Insight-users] From Vtk To itk...
yasser salman
yass71 at yahoo.com
Fri, 6 Feb 2004 04:58:48 -0800 (PST)
--0-418025320-1076072328=:97060
Content-Type: text/plain; charset=us-ascii
Content-Id:
Content-Disposition: inline
hi Luis ..,
About ur suggestion to use the same filter
"Itk::ImageToVTKImageFilter" to connect vtk->Itk->Vtk
agian.., i wrote this code at the attachment but it
didn't work..,
can u help me to show me how to connect these
pipeLines..,
thanx..,
--- Luis Ibanez <luis.ibanez at kitware.com> wrote:
>
> Yasser,
>
> If you need to convert a VTK image
> into an ITK one you use the filter
> itkVTKImageToImageFilter.
>
> You will find the files in the directory:
>
> InsightApplications/Auxiliary/vtk
>
> itkVTKImageToImageFilter.h
> itkVTKImageToImageFilter.txx
>
>
> With this filter you can do:
>
>
> VTKReader-->VTK2ITK---ITKSegmentation-->
>
> --->ITK2VTK--->VTKContour..... visualization
>
>
> Please look at the tutorial session
>
>
http://www.itk.org/CourseWare/Training/GettingStarted-II.pdf
>
>
>
>
> Regards,
>
>
> Luis
>
>
> ----------------------------
> yasser salman wrote:
> > hi ALL..,
> >
> > i run sample code that Luis sent and it works
> well
> > (thanx luis..)..,
> > but at the begining i read the files or volumes
> using
> > Vtk , like that
> >
> >
> > Reader->SetFilePrefix(VolData_FName);
> > Reader->SetFilePattern("%s%.1d.dcm");
> > Reader->SetDataByteOrderToLittleEndian();
> > Reader->SetDataScalarTypeToUnsignedShort();
> >
> > Reader->SetDataExtent
> >
> (0,VolData_Width,0,VolData_Height,1,VolData_Images);
> > Reader->SetDataOrigin(0,0,0);
> >
> >
>
Reader->SetDataSpacing(VolData_Xsize,VolData_Ysize,VolData_Zsize);
> > Reader->Update();
> >
> > so how can i send this volume to Itk (and then use
> > Luis code for segmentation and back again to
> > visualize)..
> > thanx All..,
> > yasser
> >
> >
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html
--0-418025320-1076072328=:97060
Content-Type: text/plain; name="SegmenterViewer2.cxx"
Content-Description: SegmenterViewer2.cxx
Content-Disposition: inline; filename="SegmenterViewer2.cxx"
#include "itkImageFileReader.h"
#include "itkImageToVTKImageFilter.h"
#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkConfidenceConnectedImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkImageActor.h"
#include "vtkImageShiftScale.h"
#include "vtkitkImageToImageFilter.h"
#include "vtkMarchingCubes.h"
#include "vtkProperty.h"
#include "vtkPolyDataNormals.h"
#include "vtkContourFilter.h"
#include "vtkImageViewer.h"
#include "vtkImageReader2.h"
#include "vtkVolumeRayCastFunction.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkPiecewiseFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkColorTransferFunction.h"
#include "vtkImageViewer2.h"
#include "vtkPolyData.h"
#include "vtkImageActor.h"
#include "vtkImageActor.h"
#include "vtkImageData.h"
#include "vtkDICOMImageReader.h"
#include "vtkImageFlip.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
int main( int argc, char ** argv )
{
typedef unsigned char InputPixelType;
typedef unsigned char InternalPixelType;
typedef unsigned char SegmentedPixelType;
typedef itk::Image< InputPixelType, 3 > InputImageType;
typedef itk::Image< InternalPixelType, 3> InternalImageType;
typedef itk::Image< SegmentedPixelType, 3 > SegmentedImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::CastImageFilter<
InputImageType,
InternalImageType > CastImageFilterType;
typedef itk::CurvatureFlowImageFilter<
InternalImageType,
InternalImageType > CurvatureFlowImageFilterType;
typedef itk::ConfidenceConnectedImageFilter<
InternalImageType,
SegmentedImageType > ConfidenceConnectedImageFilterType;
typedef itk::ImageToVTKImageFilter< SegmentedImageType > ConnectorFilterType;
vtkDICOMImageReader *Reader=vtkDICOMImageReader::New();
vtkImageViewer2 *viewer = vtkImageViewer2::New();
Reader->SetDirectoryName("D:/imagedata/Dicom/1Nesma");
Reader->Update();
vtkImageFlip *flipY = vtkImageFlip::New();
flipY->SetInput (Reader->GetOutput());
flipY->SetFilteredAxis (1);
viewer->SetInput(flipY->GetOutput());
int VolData_Images = viewer->GetWholeZMax ();
for (int i=1;i<VolData_Images;i++)
{
viewer->SetZSlice(i);
viewer->SetSize(512,512);
viewer->SetPosition(500,0);
viewer->SetColorWindow(512);
viewer->SetColorLevel(256);
viewer->Render();
// TODO: Add your command handler code here
}
//----------------------------------
// ITK Pipeline
//----------------------------------
ReaderType::Pointer reader = ReaderType::New();
CastImageFilterType::Pointer cast = CastImageFilterType::New();
CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New();
ConfidenceConnectedImageFilterType::Pointer confidence = ConfidenceConnectedImageFilterType::New();
ConnectorFilterType::Pointer connector = ConnectorFilterType::New();
connector->SetInput((itk::Image<unsigned char,3> *) Reader ->GetOutput());
cast->SetInput( (itk::Image<unsigned char,3> *)connector->GetOutput() );
smoothing->SetInput( cast->GetOutput() );
confidence->SetInput( smoothing->GetOutput() );
smoothing->SetTimeStep( 0.125 );
smoothing->SetNumberOfIterations( 2 );
confidence->SetMultiplier( 5.0 );
confidence->SetNumberOfIterations( 2 );
confidence->SetReplaceValue( 250 );
typedef ConfidenceConnectedImageFilterType::IndexType IndexType;
IndexType seed;
seed[0] = 50;
seed[1] = 50;
seed[2] = 5;
std::cout << "Using seed = " << seed << std::endl;
confidence->SetSeed( seed );
confidence->SetInitialNeighborhoodRadius( 3);
connector->SetInput(confidence ->GetOutput());
connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
//----------------------------------
// VTK Pipeline
//----------------------------------
vtkRenderer * renderer = vtkRenderer::New();
vtkRenderWindow * renderWindow = vtkRenderWindow::New();
vtkRenderWindowInteractor * renderWindowInteractor = vtkRenderWindowInteractor::New();
vtkImageActor* imageactor = vtkImageActor::New();
renderWindow->AddRenderer( renderer );
renderWindow->SetInteractor( renderWindowInteractor );
vtkMarchingCubes *mc = vtkMarchingCubes::New();
mc->SetInput((vtkImageData * )connector->GetOutput());
mc->SetValue(0,127);
vtkPolyDataMapper* mcmap=vtkPolyDataMapper::New();
mcmap->SetInput(mc->GetOutput());
mcmap->ScalarVisibilityOff();
vtkActor* mcactor=vtkActor::New();
mcactor->SetMapper(mcmap);
renderer->AddActor(mcactor);
renderer->SetBackground( 0.1, 0.2, 0.4 );
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}
--0-418025320-1076072328=:97060--