[Insight-users] ContourSpatialObject

Anja Ende anja.ende at googlemail.com
Wed May 21 14:52:14 EDT 2008


Hi Richard,

Thanks for the reply. I just ended up using the PolygonSpatialObject.

Cheers,
Anja

2008/5/21 Richard Beare <richard.beare at gmail.com>:
> Perhaps playing with SetDefaultInsideValue will help. I had that
> problem with cylinder objects.
>
> On Wed, May 21, 2008 at 7:44 PM, Anja Ende <anja.ende at googlemail.com> wrote:
>> Hello,
>>
>> This is my ongoing battle to create a binary image out of a user
>> defined set of points.
>>
>> I noticed that there is a spatial object based class called
>> ContourSpatialObject. I have been trying to use it but it does not
>> produce any output. I used the following code:
>>
>> typedef itk::ContourSpatialObject<2>  ContourType;
>> typedef ContourType::Pointer ContourPointer;
>> typedef itk::ContourSpatialObjectPoint<2> ContourPointType;
>>
>> ContourType::ControlPointListType list;
>> ContourPointType p1;
>> p1.SetPosition(10, 10);
>> p1.SetRed(1);
>> p1.SetGreen(1);
>> p1.SetBlue(1);
>> p1.SetNormal(0, 0, 1);
>> list.push_back(p1);
>>
>> ContourPointType p2;
>> p2.SetPosition(20, 10);
>> p2.SetRed(1);
>> p2.SetGreen(1);
>> p2.SetBlue(1);
>> p2.SetNormal(0, 0, 1);
>> list.push_back(p2);
>>
>> ContourPointType p3;
>> p3.SetPosition(20, 5);
>> p3.SetRed(1);
>> p3.SetGreen(1);
>> p3.SetBlue(1);
>> p3.SetNormal(0, 0, 1);
>> list.push_back(p3);
>>
>> ContourPointType p4;
>> p4.SetPosition(10, 5);
>> p4.SetRed(1);
>> p4.SetGreen(1);
>> p4.SetBlue(1);
>> p4.SetNormal(0, 0, 1);
>> list.push_back(p4);
>>
>> ContourPointType p5;
>> p5.SetPosition(10, 10);
>> p5.SetRed(1);
>> p5.SetGreen(1);
>> p5.SetBlue(1);
>> p5.SetNormal(0, 0, 1);
>> list.push_back(p5);
>>
>> ContourPointer contour = ContourType::New();
>> contour->GetProperty()->SetName("My Blob");
>> contour->SetId(1);
>> contour->SetControlPoints(list);
>>
>> typedef itk::Image<unsigned char, 2> ImageType;
>> typedef itk::SpatialObjectToImageFilter<ContourType, ImageType>
>> SpatialObjectToImageFilterType;
>> typedef SpatialObjectToImageFilterType::Pointer
>> SpatialObjectToImageFilterTypePointer;
>>
>> SpatialObjectToImageFilterTypePointer filter =
>> SpatialObjectToImageFilterType::New();
>> filter->SetInput(contour);
>> ImageType::SizeType size;
>> size[0] = 128;
>> size[1] = 128;
>> filter->SetSize(size);
>> filter->Update();
>>
>> typedef itk::RescaleIntensityImageFilter<ImageType, ImageType>  CastFilterType;
>> CastFilterType::Pointer castFilter = CastFilterType::New();
>> castFilter->SetOutputMinimum( 0 );
>> castFilter->SetOutputMaximum( 255 );
>> castFilter->SetInput(filter->GetOutput() );
>> typedef itk::ImageFileWriter<ImageType> WriterType;
>> WriterType::Pointer writer = WriterType::New();
>> writer->SetFileName("/home/anja/Desktop/test.jpg");
>> writer->SetInput(castFilter->GetOutput());
>> try
>> {
>>        writer->Update();
>> }
>>
>> catch( itk::ExceptionObject & err )
>> {
>>        std::cout << "Problems" << std::endl;
>> }
>>
>> So, I have created 5 points that should be a closed contour and then I
>> am converting the output of the spatial object to an image using the
>> itk::SpatialObjectToImageFilter and writing it to a file after
>> rescaling the values. However, the output is a totally black image. I
>> tried this technique with the BlobSpatialObject and the output was as
>> extected. Here, I had extected to see a contour with the area inside
>> the contour to be all filled with the value of 255.
>>
>> Any ideas what I might be missing?
>>
>> Cheers,
>>
>> Anja
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>



-- 
Cheers,

Anja


More information about the Insight-users mailing list