[Insight-users] Spatial Objects and the SpatialObjectToImageFilter
Julien Jomier
jjomier at cs.unc.edu
Mon May 2 18:47:33 EDT 2005
Hi Dominique,
You need to define all the point that should be considered. That means,
for instance, that if you want a diagonal line you need to do something
like:
for(unsigned int i=0;i<128;i++)
{
p.SetPosition(i,i);
pointlist.push_back(p);
}
The SpatialObjectToImageFilter will look if the specific location of a
pixel corresponds to the location of a point in the pointlist. If there
is a point then the pixel will be set to a high value.
Hope that helps,
Julien
Dominique Belhachemi wrote:
> Hi Julien,
>
> sorry but now i am not sure if i have understand the itkLineSpatialObject.
>
> If i set for example 4 Points A, B, C and D i expect that the Image
> contains 3 connected lines AB, BC and CD.
> Is this your definition of a polyline?
>
> However your proposal to define a loop doesnt work. I still see only the
> endpoints.
>
> Dominique
>
>
>
> ----- Original Message ----- From: "Julien Jomier" <jjomier at cs.unc.edu>
> To: "Dominique Belhachemi" <domibel at cs.tu-berlin.de>
> Cc: <insight-users at itk.org>
> Sent: Tuesday, May 03, 2005 12:15 AM
> Subject: Re: [Insight-users] Spatial Objects and the
> SpatialObjectToImageFilter
>
>
>> Dominique,
>>
>> The itkLineSpatialObject is actually a polyline so it's defined by a
>> set of points and not only the two end points. You need to do a loop
>> to fill in the gap between the two end points manually.
>>
>> Julien
>>
>> Dominique Belhachemi wrote:
>>
>>> Hi Julien,
>>>
>>> now i can see the endpoints of the line.
>>> This is good, but the line between the endpoints are still black.
>>>
>>> Thx Dominique
>>>
>>>
>>>
>>> ----- Original Message ----- From: "Julien Jomier" <jjomier at cs.unc.edu>
>>> To: "Dominique Belhachemi" <domibel at cs.tu-berlin.de>
>>> Cc: <insight-users at itk.org>
>>> Sent: Monday, May 02, 2005 11:49 PM
>>> Subject: Re: [Insight-users] Spatial Objects and the
>>> SpatialObjectToImageFilter
>>>
>>>
>>>> Hi Dominique,
>>>>
>>>> I think the problem comes from the internal Bounding Box computation.
>>>>
>>>> Can you try to add the following line:
>>>>
>>>> line1->ComputeBoundingBox();
>>>>
>>>> after
>>>> line1->SetPoints(pointlist);
>>>>
>>>> I'll fix the SpatialObject to recompute the bounding box when the
>>>> list of points is set.
>>>>
>>>> Let us know if that fixes the problem,
>>>>
>>>> Julien
>>>>
>>>> Dominique Belhachemi wrote:
>>>>
>>>>> Hi Julien,
>>>>>
>>>>> i still have the same problem. I am not able to produce an Image of
>>>>> a LineSpatialObject.....
>>>>>
>>>>> Please have a look at my example-source. It should write a
>>>>> LineSpatialObject and a EllipseSpatialObject to disk in a jpg-file
>>>>> "2D-Line.jpg".
>>>>> But i can see only the Ellipse. Where is the failure?
>>>>>
>>>>> Dominique
>>>>>
>>>>>
>>>>> ----- Original Message ----- From: "Julien Jomier"
>>>>> <jjomier at cs.unc.edu>
>>>>> To: "Dominique Belhachemi" <domibel at cs.tu-berlin.de>
>>>>> Cc: <insight-users at itk.org>
>>>>> Sent: Monday, May 02, 2005 5:37 AM
>>>>> Subject: Re: [Insight-users] Spatial Objects and the
>>>>> SpatialObjectToImageFilter
>>>>>
>>>>>
>>>>>> Hi Dominique,
>>>>>>
>>>>>> The IsInside() function is not implemented for the
>>>>>> ArrowSpatialObject so the SpatialObjectToImageFilter cannot be
>>>>>> used with this object.
>>>>>>
>>>>>> However, for Line, Surface and BlobSpatialObject the
>>>>>> SpatialObjectToImageFilter should work. As you probably know these
>>>>>> objects are composed of points (each point having at least a
>>>>>> location plus other parameters). The SpatialObjectToImageFilter
>>>>>> will set a bright pixel if at least one point lies inside a pixel.
>>>>>>
>>>>>> My guess is that you are not creating the
>>>>>> Line/Surface/BlobSpatialObject correctly. You can look at the
>>>>>> SoftwareGuide (chapter 5) for more information on how to create
>>>>>> these objects.
>>>>>>
>>>>>> Let us know if you have further problems,
>>>>>>
>>>>>> Julien
>>>>>>
>>>>>> Dominique Belhachemi wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> after creating a SpatialObject i can produce an Image of this
>>>>>>> SpatialObject with the SpatialObjectToImageFilter.
>>>>>>>
>>>>>>> This process works fine in the case of CylinderSpatialObject or
>>>>>>> EllipseSpatialObjects for example.
>>>>>>>
>>>>>>> But this process produces for a few SpatialObjects like
>>>>>>> - ArrowSpatialObject
>>>>>>> - LineSpatialObject
>>>>>>> - SurfaceSpatialObject
>>>>>>> - BlobSpatialObject
>>>>>>> only Images with grayvalue zero. (This means the pictures are black)
>>>>>>>
>>>>>>>
>>>>>>> Is this volitional ?
>>>>>>> How can i solve this problem?
>>>>>>>
>>>>>>>
>>>>>>> Dominique
>>>>>>> _______________________________________________
>>>>>>> Insight-users mailing list
>>>>>>> Insight-users at itk.org
>>>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> #include "itkImage.h"
>>>>> #include "itkImageFileWriter.h"
>>>>> #include "itkGroupSpatialObject.h"
>>>>> #include "itkLineSpatialObject.h"
>>>>> #include "itkEllipseSpatialObject.h"
>>>>> #include "itkLineSpatialObjectPoint.h"
>>>>> #include "itkSpatialObjectToImageFilter.h"
>>>>> #include "itkRescaleIntensityImageFilter.h"
>>>>>
>>>>>
>>>>> int main( int argc, char *argv[] )
>>>>> {
>>>>> const int Dimension = 2;
>>>>> typedef itk::GroupSpatialObject< Dimension > GroupType;
>>>>> typedef itk::EllipseSpatialObject< Dimension > EllipseType;
>>>>> typedef itk::LineSpatialObject< Dimension > LineType;
>>>>> typedef itk::LineSpatialObjectPoint< Dimension >
>>>>> LinePointType;
>>>>> typedef itk::CovariantVector<double, Dimension > VectorType;
>>>>>
>>>>> typedef itk::Image< double, Dimension > ImageType;
>>>>> typedef itk::Image< unsigned char, Dimension > OutputImageType;
>>>>> typedef itk::ImageFileWriter< OutputImageType > WriterType;
>>>>> typedef itk::RescaleIntensityImageFilter< ImageType,
>>>>> OutputImageType > CastFilterType;
>>>>> typedef itk::SpatialObjectToImageFilter< GroupType, ImageType >
>>>>> SpatialObjectToImageFilterType;
>>>>>
>>>>>
>>>>> GroupType::Pointer group = GroupType::New();
>>>>>
>>>>> EllipseType::Pointer ellipse1 = EllipseType::New();
>>>>> LineType::Pointer line1 = LineType::New();
>>>>>
>>>>> group->AddSpatialObject(ellipse1); // visualisation works
>>>>> group->AddSpatialObject(line1); // visualisation doesnt
>>>>> works
>>>>>
>>>>> EllipseType::ArrayType radius;
>>>>> radius[0] = 5;
>>>>> radius[1] = 10;
>>>>> ellipse1->SetRadius(radius);
>>>>>
>>>>> LineType::PointListType pointlist; //STL std::vector<
>>>>> LinePointType >
>>>>>
>>>>> LinePointType p;
>>>>> VectorType normal;
>>>>>
>>>>> normal[0] = 1;
>>>>> normal[1] = 6;
>>>>> p.SetNormal(normal,0);
>>>>> p.SetPosition(10,10);
>>>>> p.SetColor(1, 0, 0, 1);
>>>>> pointlist.push_back(p);
>>>>>
>>>>> normal[0] = 13;
>>>>> normal[1] = 3;
>>>>> p.SetNormal(normal,0);
>>>>> p.SetPosition(20,20);
>>>>> p.SetColor(1, 1, 0, 1);
>>>>> pointlist.push_back(p);
>>>>>
>>>>> normal[0] = 12;
>>>>> normal[1] = 4;
>>>>> p.SetNormal(normal,0);
>>>>> p.SetPosition(100,100);
>>>>> p.SetColor(1, 0, 0, 1);
>>>>> pointlist.push_back(p);
>>>>>
>>>>> normal[0] = 4;
>>>>> normal[1] = 1;
>>>>> p.SetNormal(normal,0);
>>>>> p.SetPosition(20,200);
>>>>> p.SetColor(1, 0, 0, 1);
>>>>> pointlist.push_back(p);
>>>>>
>>>>> line1->SetPoints(pointlist);
>>>>> LineType::PointListType::const_iterator it =
>>>>> line1->GetPoints().begin(); while(it != line1->GetPoints().end())
>>>>> {
>>>>> std::cout << "Position = " << (*it).GetPosition() <<
>>>>> std::endl;
>>>>> std::cout << "Color = " << (*it).GetColor() << std::endl;
>>>>> std::cout << "First normal = " << (*it).GetNormal(0) <<
>>>>> std::endl;
>>>>> std::cout << std::endl;
>>>>> it++;
>>>>> }
>>>>>
>>>>> EllipseType::TransformType::OffsetType offset;
>>>>> offset[0] = 40.0;
>>>>> offset[1] = 40.0;
>>>>> ellipse1->GetObjectToParentTransform()->SetOffset(offset);
>>>>> ellipse1->ComputeObjectToWorldTransform();
>>>>>
>>>>> SpatialObjectToImageFilterType::Pointer imageFilter =
>>>>> SpatialObjectToImageFilterType::New();
>>>>> imageFilter->SetInput( group );
>>>>> ImageType::SizeType size;
>>>>> size[ 0 ] = 128;
>>>>> size[ 1 ] = 128;
>>>>> imageFilter->SetSize( size );
>>>>> imageFilter->Update();
>>>>>
>>>>> CastFilterType::Pointer castFilter = CastFilterType::New();
>>>>> castFilter->SetOutputMinimum( 0 );
>>>>> castFilter->SetOutputMaximum( 255 );
>>>>> castFilter->SetInput( imageFilter->GetOutput() );
>>>>>
>>>>> WriterType::Pointer writer = WriterType::New();
>>>>> writer->SetFileName( "2D-Line.jpg" );
>>>>> writer->SetInput( castFilter->GetOutput() );
>>>>> try {
>>>>> writer->Update(); }
>>>>> catch( itk::ExceptionObject & err ) {
>>>>> std::cout << "ExceptionObject caught !" << std::endl;
>>>>> std::cout << err << std::endl; return -1;
>>>>> }
>>>>>
>>>>> return 0;
>>>>> }
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Insight-users mailing list
>>>>> Insight-users at itk.org
>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>
>
More information about the Insight-users
mailing list