[Insight-users] Building Unit Vector Field
Luis Ibanez
luis.ibanez at kitware.com
Mon May 28 20:16:57 EDT 2012
Hi Abayiz,
Since you declared the image type to be:
typedef itk::Image<VectorType, Dimension> VectorImageType;
where "VectorType" is the pixel type of the image,
Then SetPixel() method of the image is expecting
that you pass to it the parameters of type
image->SetPixel( IndexType, VectorType );
But in your code,
you are passing a VariableLenghtVector type
as second argument.
So, what you need to do is
to replace that for loop with simply:
VectorType unitVector;
unitVector[0] = 1.0;
unitVector[1] = 0.0;
unitVector[2] = 0.0;
image->FillBuffer( unitVector );
BTW, just for the record, the call
image->SetPixel( index, unitVector );
should also work, once you use the right
type for the unitVector variable.
Luis
-----------------------------------------------
On Thu, May 17, 2012 at 3:22 PM, Abayiz <abayiz at yahoo.com> wrote:
> Hello,
>
> I am trying to build a unit vector field, my code is as follows:
>
> ************************************
> typedef itk::Vector<float, Dimension >
> VectorType;
> typedef itk::Image<VectorType,Dimension>
> VectorImageType;
> typedef itk::ImageRegionConstIterator< VectorImageType >
> NeighborhoodIterator;
>
> VectorImageType::Pointer image = VectorImageType::New();
> image->SetRegions(vec_region);
> image->SetSpacing(vec_spacing_image);
> image->SetOrigin(vector_origin_image);
> image->SetDirection(vec_direction_image);
> image->SetNumberOfComponentsPerPixel(3);
> image->Allocate();
>
> VectorImageType::IndexType vec_start;
> vec_start[0] = 0;
> vec_start[1] = 0;
> vec_start[2] = 0;
>
> typedef itk::VariableLengthVector<double> VariableVectorType;
> VariableVectorType variableLengthVector;
> variableLengthVector.SetSize(2);
> variableLengthVector[0] = 1.0;
> variableLengthVector[1] = 0.0;
> variableLengthVector[2] = 0.0;
>
> NeighborhoodIterator vec_it(image, image->GetLargestPossibleRegion());
>
> for (vec_it_i.GoToBegin(); !vec_it_i.IsAtEnd(); ++vec_it_i)
> {
>
> image->SetPixel(vec_start, variableLengthVector);
>
> }
>
> ************************************
> Then I got an error, saying that "image" does not have a function for
> "SetPixel". Is there some one can help me?? How should I build a unit
> vector?
> Thanks in advance.
>
> Regards
> Abayiz
>
>
> _____________________________________
> 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.php
>
> 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 --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120528/f5a6a1bb/attachment.htm>
More information about the Insight-users
mailing list