[Insight-users] Problem of writing .png to .vtk volume
Luis Ibanez
luis.ibanez at kitware.com
Sun Sep 13 10:44:06 EDT 2009
Hi Yili,
1) You are using unsigned char as the pixels type.
2) Does that mean that the .png images were the
result of rescaling an input CT(?) volume down
to 8 bits ?
3) Most likely you iso-contour value of 128.0 is
not the proper value for extracting the lung,
given the intensity scale that you have now.
4) If you were using CT (in Hounsfield units)
you probably should use a threshold value
close to 700HU.
5) Also, given that the lungs are an internal structure,
you will need to do a segmentation in order to get
something clear to visualize. Otherwise, what you
are going to get as a surface now is a combination
of the external surfaces (skin) and internal surfaces
(lung wall and lung vasculature).
6) What you may want to do first is to load your image
series in to Paraview (www.paraview.org) and to
experiment with it Contour filter at different threshold
values. This will give you an idea of the correct value
to use.
Regards,
Luis
--------------------------------------------------------------------------------------
On Thu, Sep 10, 2009 at 11:11 AM, Yili Pan <pyl0420 at gmail.com> wrote:
> Hi everyone:
>
> I have a series of .png lung data and I use ImageSeriesReadWrite example to
> write the series into volume. Then I use VTK to display the volume.
> The former part of the project seems to work well, since I got the .vtk
> volume. However, the window shows nothing at last when I was trying to use
> vtkContourFilter as the filter to display the lung.
> I am not sure if I missed to set some data of the volume or this is the
> visualization problem. Can you help me with this?
> Thanks a lot!
> Best,
> Yili
> This is the code I changed from the example:
> int main( int argc, char ** argv )
> {
>
> if( argc < 4 )
> {
> std::cerr << "Usage: " << std::endl;
> std::cerr << argv[0] << " firstSliceValue lastSliceValue
> outputImageFile " << std::endl;
> return EXIT_FAILURE;
> }
>
>
> typedef unsigned char PixelType;
> const unsigned int Dimension = 3;
> typedef itk::Image< PixelType, Dimension > ImageType;
> typedef itk::ImageSeriesReader< ImageType > ReaderType;
> typedef itk::ImageFileWriter< ImageType > WriterType;
> ReaderType::Pointer reader = ReaderType::New();
> WriterType::Pointer writer = WriterType::New();
>
> const unsigned int first = atoi( argv[1] );
> const unsigned int last = atoi( argv[2] );
> const char * outputFilename = argv[3];
> //============================================Reader
> Part==============================================
> typedef itk::NumericSeriesFileNames NameGeneratorType;
> NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
>
>
> nameGenerator->SetSeriesFormat( "h1-1.%03d.png" );
> nameGenerator->SetStartIndex( first );
> nameGenerator->SetEndIndex( last );
> nameGenerator->SetIncrementIndex( 1 );
> system("pause");
> itk::PNGImageIO::Pointer pngIO=itk::PNGImageIO::New();
> pngIO->SetNumberOfDimensions(3);
>
> pngIO->SetDimensions(0,512);
> pngIO->SetDimensions(1,512);
> pngIO->SetDimensions(2,259);
> reader->SetImageIO( pngIO);
>
>
>
> reader->SetFileNames( nameGenerator->GetFileNames() );
> system("pause");
> reader->Update();
> system("pause");
> std::cout<<pngIO->GetImageSizeInBytes()<<" "<<512*512<<std::endl;
> std::cout<<pngIO->GetIORegion()<<std::endl;
> //===============================================Writer
> Part=============================================
> itk::VTKImageIO::Pointer vtkIO=itk::VTKImageIO::New();
> vtkIO->SetFileTypeToBinary();
> vtkIO->SetNumberOfDimensions(3);
> vtkIO->SetNumberOfComponents(1);
> vtkIO->SetDimensions(0,512);
> vtkIO->SetDimensions(1,512);
> vtkIO->SetDimensions(2,259);
> vtkIO->SetSpacing(0,1);
> vtkIO->SetSpacing(1,1);
> vtkIO->SetSpacing(2,2.23776);
> writer->SetImageIO(vtkIO);
>
> writer->SetFileName( outputFilename );
> writer->SetInput( reader->GetOutput() );
> try
> {
> writer->Update();
> }
> catch( itk::ExceptionObject & err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> return EXIT_FAILURE;
> }
> std::cout<<vtkIO->GetIORegion()<<std::endl;
> //==========================================Visualizing
> Part===============================================
>
> vtkStructuredPointsReader* vtkReader=vtkStructuredPointsReader::New();
> vtkReader->SetFileName("h1-1.vtk");
> vtkReader->Update();
>
> vtkContourFilter *iso=vtkContourFilter::New();
> iso->SetInputConnection(vtkReader->GetOutputPort());
> iso->SetValue(0,128.0f);
>
> vtkRenderer* ren=vtkRenderer::New();
> vtkRenderWindow* renWin=vtkRenderWindow::New();
> renWin->AddRenderer(ren);
>
> vtkPolyDataMapper* volumeMapper=vtkPolyDataMapper::New();
> volumeMapper->SetInputConnection(iso->GetOutputPort());
> volumeMapper->ScalarVisibilityOff();
>
> vtkRenderWindowInteractor* iren=vtkRenderWindowInteractor::New();
> vtkActor* isoActor=vtkActor::New();
> isoActor->SetMapper(volumeMapper);
>
> vtkProperty* prop=vtkProperty::New();
> prop->SetColor(0,1,0);
>
> isoActor->SetProperty(prop);
> isoActor->ApplyProperties();
>
> ren->AddActor(isoActor);
>
> iren->SetRenderWindow(renWin);
> renWin->SetSize(400,400);
> iren->Initialize();
> iren->Start();
>
> return EXIT_SUCCESS;
> }
>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
More information about the Insight-users
mailing list