[Insight-users] itk snap . Question

Luis Ibanez luis.ibanez at kitware.com
Tue Mar 16 16:57:54 EDT 2010


Hi Ali,

Please find attached two example programs that will:

1) Extract an iso-surface from an ITK-generated image

and

2) Generate a screenshot from that iso-surface
     (or visualize it interactively).


These two files can also be found in:

    InsightApplications/Auxiliary/vtk/
                             ScreenShotGenerator.cxx
                             ExtractIsoSurface.cxx

http://public.kitware.com/cgi-bin/viewcvs.cgi/Auxiliary/vtk/ExtractIsoSurface.cxx?root=InsightApplications&sortby=date&view=log

http://public.kitware.com/cgi-bin/viewcvs.cgi/Auxiliary/vtk/ScreenShotGenerator.cxx?root=InsightApplications&sortby=date&view=log


In order to compile them you also need the files:

         InsightApplications/Auxiliary/vtk/
                                     vtkKWImage.cxx
                                     vtkKWImage.h
                                     vtkKWImageIO.cxx
                                     vtkKWImageIO.h


Once you build the executables, you can run them as:

  ./ExtractIsoSurface  image.mha    surface.vtp    128

where

A) "image.mha" is the segmented image
     that you can save from SNAP.

     No need to save the image as "raw" anymore,
     please save the segmented image from SNAP
     as a MetaImage, in this way you conserve
     information about origin, spacing, orientation,
     pixel type and image grid.

B)  "surface.vtp" is the output surface

C)  "128"  is the iso-value at which the
      surface  will be extracted.  Typically, this is
      the iso-value that you want to use, given that
      segmented images are usually encoded with
      the two values : 0 and 255.

      However, in the particular case of SNAP, the
      segmentation is encoded in an image of pixel
      type "unsigned char" with values :  0 and 1.

      Therefore, for segmentation images generated
      from SNAP, you should use an iso-valule of "0.5"

      In summary you want to use:

       ./ExtractIsoSurface  snap.mha  snap.vtp   0.5


The second executable can be run as:

 ./ScreenShotGenerator snap.vtp  image.jpg  text  0


where

1) snap.vtp is the filename of the surface that
    you just extracted from the segmentation

2) image.jpg is the output file name to save a screenshot

3) "text" is a textual annotation to include in the screenshot

4) the value "1" (or "0") sets whether the visualization is
    interactive or not. If you set "1" you will be able to move
    the surface around with the mouse. If you set it to "0"
    the program will simply generate a screenshot and it
    will quit immediately.

--

Note that the process of extracting the iso-surface also
corrects the positions of points in physical space.

This is necessary because vtkImageData doesn't take
into account the image orientation stored in the itk::Image,
therefore the points resulting from an iso-contour extraction
must be mapped back to the native coordinate system
of the image.


Please give it a try at this code and let us know if you
find any problems,


     Thanks


          Luis


---------------------------------------------------------------------------------------------
On Tue, Mar 16, 2010 at 3:35 PM, Ali Habib <ali.mahmoud.habib at gmail.com> wrote:
> dear luis,
> i want to display the segmented part using vtk , but the problem when save
> segmented data  and try to display it nothing appear , just blank data , how
> to reconstruct the 3D of the segmented part
> best regards
> On Tue, Mar 16, 2010 at 7:57 PM, Luis Ibanez <luis.ibanez at kitware.com>
> wrote:
>>
>> Hi Ali,
>>
>> Thanks for your detailed post.
>>
>>
>> It seems however that you missed
>> to describe what the problem is.
>>
>> What exactly is what you want to fix ?
>>
>> ---
>>
>> If you are looking for examples on how to use
>> VTK to visualize a segmentation produced by ITK,
>> then you may want to look at:
>>
>> InsightApplications/Auxiliary/vtk/
>>     itkReadITKImage3DSegmentShowVTK.cxx
>>
>>
>> http://www.itk.org/cgi-bin/viewcvs.cgi/Auxiliary/vtk/itkReadITKImage3DSegmentShowVTK.cxx?root=InsightApplications&view=log
>>
>>
>>      Regards,
>>
>>
>>             Luis
>>
>>
>> -----------------------------------------------------------
>> On Fri, Mar 12, 2010 at 3:36 PM, Ali Habib <ali.mahmoud.habib at gmail.com>
>> wrote:
>> > Dear All,
>> > I use ITK snap program to segment , then save the segmentation output to
>> > raw
>> > image data (using the menu segmentation --> Save As )
>> > I read it using vtk, and try t extract the bone ad reconstruct it using
>> > the
>> > following code :
>> >  vtkMetaImageReader metaImageReader = new vtkMetaImageReader();
>> >             metaImageReader.SetFileName(@"C:\Users\Eng. Ali
>> > Mahmoud\Desktop\yyymhdmhd");
>> >             metaImageReader.Update();
>> >
>> >             vtkImageShrink3D VIS = new vtkImageShrink3D();
>> >             VIS.SetShrinkFactors(2, 2, 2);
>> >             VIS.SetInputConnection(metaImageReader.GetOutputPort());
>> >             VIS.Update();
>> >             vtkImageThreshold VIT = new vtkImageThreshold();
>> >             VIT.ThresholdBetween(200, 2000);
>> >             VIT.SetInputConnection(VIS.GetOutputPort());
>> >             VIT.Update();
>> >             vtkImageMarchingCubes imageMarchingCubes = new
>> > vtkImageMarchingCubes();
>> >             imageMarchingCubes.SetInput(VIT.GetOutput());
>> >             imageMarchingCubes.SetValue(0, 500);
>> >             imageMarchingCubes.ComputeScalarsOff();
>> >             imageMarchingCubes.ComputeNormalsOff();
>> >             imageMarchingCubes.ComputeGradientsOff();
>> >             imageMarchingCubes.Update();
>> >              vtkPolyDataMapper map =new vtkPolyDataMapper();
>> >   map.SetInput(imageMarchingCubes.GetOutput());
>> >   // actor coordinates geometry, properties, transformation
>> >   vtkActor aSphere =new vtkActor();
>> >   aSphere.SetMapper(map);
>> >   aSphere.GetProperty().SetColor(0,0,1); // sphere color blue
>> >   // a renderer and render window
>> >   vtkRenderer ren1 =new vtkRenderer();
>> >   vtkRenderWindow renWin =new vtkRenderWindow();
>> >   renWin.AddRenderer(ren1);
>> >   // an interactor
>> >   vtkRenderWindowInteractor iren =new vtkRenderWindowInteractor();
>> >   iren.SetRenderWindow(renWin);
>> >   // add the actor to the scene
>> >   ren1.AddActor(aSphere);
>> >   ren1.SetBackground(1,1,1); // Background color white
>> >   // render an image (lights and cameras are created automatically)
>> >   renWin.Render();
>> >   // begin mouse interaction
>> >    iren.Start();
>> >
>> > how to fix that
>> > Best regards
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > _____________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Kitware offers ITK Training Courses, for more information visit:
>> > http://www.kitware.com/products/protraining.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
>> >
>> >
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ExtractIsoSurface.cxx
Type: text/x-c++src
Size: 4222 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100316/0cac279f/attachment.cxx>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ScreenShotGenerator.cxx
Type: text/x-c++src
Size: 4603 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100316/0cac279f/attachment-0001.cxx>


More information about the Insight-users mailing list