[Insight-users] Gradient vector flow calculation

Gomez, Alberto alberto.gomez at kcl.ac.uk
Thu Feb 11 06:13:48 EST 2010


Hi,

You can visualize the vector field as arrows (or any other shape) using 
vtkGlyph. I found it quite unclear when I first did it and I don't know 
if I am doing it the best way, but here is an example of what works for me.

You need to provide a set of points and a set of vectors corresponding 
to those points (in world coords). I store them in two std::vector , 
"directions" and "positions":


//positions
    int num_pts = directions.size();
    vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
    pts->SetNumberOfPoints(num_pts);

    //directions
    vtkSmartPointer<vtkDoubleArray> vecArr = 
vtkSmartPointer<vtkDoubleArray>::New();
    vecArr->SetNumberOfComponents(3);
    vecArr->SetNumberOfTuples(num_pts);

    for( int i=0; i < num_pts; i++)
    {
        pts->InsertPoint(i, positions[i][0], positions[i][1], 
positions[i][2]);
        vecArr->InsertTuple3(i, directions[i][0]*sf, 
directions[i][1]*sf, directions[i][2]*sf);
    }

    // put vectors and positions into a grid which will be the glyph's input
    vtkSmartPointer<vtkUnstructuredGrid> uGrid = 
vtkSmartPointer<vtkUnstructuredGrid>::New();
        uGrid->SetPoints(pts);
        uGrid->GetPointData()->SetVectors(vecArr);



    // glyph construction
    // build arrow
    vtkSmartPointer<vtkArrowSource> arrow = 
vtkSmartPointer<vtkArrowSource>::New();
 
    //build arrow Field
    vtkSmartPointer<vtkGlyph3D> glyph = vtkSmartPointer<vtkGlyph3D>::New();
        glyph->SetInput(uGrid);
        glyph->SetSource(arrow->GetOutput());
        glyph->SetScaleModeToScaleByVector();

   //display
        vtkSmartPointer<vtkPolyDataMapper> gMapper = 
vtkSmartPointer<vtkPolyDataMapper>::New();
            gMapper->SetInput( glyph->GetOutput());
            gMapper->ScalarVisibilityOn();
            gMapper->SetScalarRange(uGrid->GetScalarRange());

        vtkSmartPointer<vtkActor> gactor = vtkSmartPointer<vtkActor>::New();
            gactor->SetMapper(gMapper);
            gactor->GetProperty()->SetColor(color);
        ren->AddActor(gactor);


Hope this helps,


Alberto






Kishore Mosaliganti wrote:
> For 2, you can use Paraview to visualize the vector field.
>
> Kishore
>
> On Wed, Feb 10, 2010 at 8:35 AM, Arunachalam Kana
> <Kana.Arunachalam at fh-wels.at> wrote:
>   
>> Hi User,
>>
>>
>>
>> My goal is to implement insight journal paper:
>>
>> "Edge based tube detection for coronary artery centerline extraction"
>>
>>
>>
>> From the paper i understood that i have to calculate the following:
>>
>> 1. Gradient vector field
>>
>> 2. Anisotropic diffusion of gradient vector
>>
>> 3. Gradient vector flow
>>
>> 4. Hessian matrix
>>
>>
>>
>> I calculate the gradientimage using itkGradientImageFilter. I use
>> itkGradientVectorFlowImageFilter
>>
>> to directly calculate the gradient vector flow as it is given the diffusion
>> is already inbuilt in
>>
>> itkGradientVectorFlowImageFilter.
>>
>>
>>
>> I use QVTK for visualisation. The image is loaded as vtk image. To apply
>>
>> itk algorithm, i convert the vtk image to itk image using vtkKWEITKImage.cxx
>>
>> from vtkedge. The same file is used for itk image to vtk image for display.
>>
>>
>>
>> typedef itk::Image< T, 3 >   InputImageType; //input image type
>>
>> typedef itk::Image< float, 3 >   OutputImageType; //outputimage type
>>
>>
>>
>> /// cast filter which converts any inputimage type to outputimage type
>>
>> typedef itk::CastImageFilter <InputImageType, OutputImageType> castType;
>>
>> castType::Pointer castfilter = castType::New();
>>
>>
>>
>> // image is vtkKWEITKImage object
>>
>> castfilter->SetInput( dynamic_cast< InputImageType * >( image->GetITKImage()
>> ) );
>>
>>
>>
>> //itk vector image declaration
>>
>> typedef itk::CovariantVector<float, 3> VectorPixelType;
>>
>> typedef itk::Image<VectorPixelType, 3> VectorImageType;
>>
>>
>>
>> //calculate the gradient vector of image
>>
>> typedef itk::GradientImageFilter <OutputImageType, float, float>
>> GradientType;
>>
>> GradientType::Pointer gradient = GradientType::New();
>>
>> gradient->SetInput(castfilter->GetOutput());
>>
>> gradient->Update();
>>
>>
>>
>> //calculation of gradient vector flow from diffused gradient vector
>>
>> typedef itk::GradientVectorFlowImageFilter<VectorImageType, VectorImageType,
>> double> VectorFlowType;
>>
>> VectorFlowType::Pointer flowfilter = VectorFlowType::New();
>>
>> flowfilter->SetInput(gradient->GetOutput());
>>
>>
>>
>> //observer of algorithm execution for time
>>
>> p->Observe( flowfilter );
>>
>>
>>
>> //the image object is updated with output image from flowfilter
>>
>> image->SetImage( flowfilter->GetOutput( ) );
>>
>> image->Modified();
>>
>>
>>
>> flowfilter->ReleaseDataFlagOn();
>>
>> return EXIT_SUCCESS;
>>
>>
>>
>> Questions:
>>
>>
>>
>> 1. I would like to know whether itkGradientVectorFlowImageFilter computes
>> anisotropic diffusion or gaussian diffusion ?
>>
>>
>>
>> 2. I want to visualise the gradient vector flow as arrows. How can i achieve
>> this visualisation?
>>
>>
>>
>> 3. If there is any example, which would help me fully or partially I would
>> like to know.
>>
>>
>>
>> Thank you in advance.
>>
>>
>>
>> Regards,
>>
>> Kana
>>
>>
>>
>> _____________________________________
>> 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
>>
>>
>>     
> _____________________________________
> 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
>   


-- 

Alberto Gómez

/Division of Imaging Sciences
The Rayne Institute
4th Floor, Lambeth Wing
St Thomas' Hospital
London SE1 7EH /

phone: +44 (0) 20 718 88364
email: alberto.gomez at kcl.ac.uk <mailto:alberto.gomez at kcl.ac.uk>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100211/be4b9ce1/attachment.htm>


More information about the Insight-users mailing list