[Insight-users] Diagonal line structuring Element

Dan Mueller dan.muel at gmail.com
Wed Jul 25 16:47:44 EDT 2012


Hi Loïc,

The version of itk::FlatStructuringElement on the Insight Journal has
a function FromImage. (Unfortunately this never made it into ITK
proper). You may also consider looking at that code for some
inspiration.
    http://www.insight-journal.org/browse/publication/124

HTH

Cheers, Dan

On 26 July 2012 00:26, David Doria <daviddoria at gmail.com> wrote:
> On Wed, Jul 25, 2012 at 10:37 AM, Loic.edv <loic.edv at gmail.com> wrote:
>>
>> Hi,
>>
>> How can i create a diagonal line structuring Element using
>> FlatStructuringElement ?
>>
>> for example :
>>
>> 00X
>> 0X0
>> X00
>>
>> thanks in advance,
>>
>> regards,
>>
>> Loïc
>>
>> Software engineer
>
>
> I'm not sure if this is the best way to do it - perhaps someone can
> provide a better way?
>
> This way is pretty awkward because it is linearly indexed, but it
> should do the trick. The following sets the center pixel to a value -
> you can easily modify this to make a line.
>
> #include "itkImage.h"
> #include "itkFlatStructuringElement.h"
>
> int main(int argc, char *argv[])
> {
>   typedef itk::Image<unsigned char, 2>  ImageType;
>
>   typedef itk::FlatStructuringElement<2> StructuringElementType;
>   StructuringElementType::RadiusType radius;
>   radius.Fill(1); // Make a 3x3 structuring element
>
>   StructuringElementType structuringElement;
>   structuringElement.SetRadius(radius);
>   unsigned int counter = 0;
>   for(StructuringElementType::Iterator iter =
> structuringElement.Begin(); iter != structuringElement.End(); ++iter)
>   {
>     if(counter == 4) // Set the center element (linear id = 4) to 2
>     {
>       *iter = 2;
>     }
>     counter++;
>   }
>
>   // Output the kernel
>   for(StructuringElementType::Iterator iter =
> structuringElement.Begin(); iter != structuringElement.End(); ++iter)
>   {
>     std::cout << *iter << std::endl;
>   }
>   return EXIT_SUCCESS;
> }
>
> David
> _____________________________________
> 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


More information about the Insight-users mailing list