[Insight-users] Diagonal line structuring Element
David Doria
daviddoria at gmail.com
Wed Jul 25 10:56:58 EDT 2012
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
More information about the Insight-users
mailing list