[Insight-users] erode using a buffer

cspl affable at hd2 . dot . net . in
Sat, 27 Jul 2002 19:49:39 +0530


This is a multi-part message in MIME format.

------=_NextPart_000_0034_01C235A6.BE3FCA10
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dear Mr.Bjorn & Friends,

I got the o/p using files.Now I am giving i/p from buffer and put o/p in =
buffer.I am getting o/p using itkGrayScaleDialteImageFilter.
when using itkgrayscaleErodeImageFilter o/p is not getting.It is giving =
some black screen.


Volume* IntensityScaleVolume(Volume *vol)
{=20

 if (vol =3D=3D NULL) return ;
 unsigned short *Buffer =3D new unsigned short[vol->width * vol->height =
* vol->depth];
 typedef  unsigned short    PixelType;
 Buffer =3D (unsigned short *) vol->Mem;
 typedef itk::Image<unsigned short,3> ImageType;
 itk::RawImageIO<unsigned short, 3>::Pointer output_io
       =3D itk::RawImageIO<unsigned short, 3>::New();
=20
     output_io->SetByteOrderToLittleEndian();
     output_io->SetFileTypeToBinary();
     output_io->SetFileDimensionality(3);

     // Initialize the initial and target volumes.
        ImageType::Pointer vol_init =3D ImageType::New();
 ImageType::Pointer vol_init1 =3D ImageType::New();
   =20
    ImageType::SizeType sz;
    sz[0] =3D vol->width;
    sz[1] =3D vol->height;
    sz[2]=3Dvol->depth;=20
   =20
   =20
    ImageType::IndexType idx;
    idx[0] =3D 0;
    idx[1] =3D 0;
    idx[2] =3D 0;
    unsigned short pval;
   =20
    ImageType::RegionType reg; =20
    reg.SetSize(sz);
    reg.SetIndex(idx);
   =20
    vol_init->SetRegions(reg);
    vol_init->Allocate();
  =20
 for(unsigned int z=3D0; z<vol->depth; ++z )
 {=20
  idx[2]=3Dz;
=20
      for (unsigned int y =3D 0; y < vol->height; ++y)
        {
          idx[1] =3D y;
          for (unsigned int x =3D 0; x < vol->width; ++x)
            {
              idx[0] =3D x;
             vol_init->SetPixel(idx, *(Buffer =
+(z*vol->height*vol->width)+y *vol->width +x) );
 =20
            }
        }
 }
         =20
   =20

  //Dilate Erode
 itk::Size<3> size =3D {5,5,2};=20
    typedef itk::NeighborhoodAllocator<PixelType>   NAllocator;
    NAllocator  *nat=3Dnew NAllocator;
    typedef itk::BinaryBallStructuringElement<unsigned short,3>
    KernelType;
   KernelType  *NA=3Dnew KernelType;
 NA->SetRadius(size);
 NA->CreateStructuringElement();
=20

 typedef itk::GrayscaleErodeImageFilter<ImageType,ImageType,KernelType>  =
 Morphology;
 Morphology::Pointer  GMF=3D Morphology::New();
 GMF->SetInput(vol_init);
 GMF->SetKernel(*NA);
 GMF->Update();
 vol_init=3DGMF->GetOutput();///here I think I am doing something wrong

=20
=20
 for(unsigned int z=3D0; z<vol->depth; ++z )
 {
  idx[2]=3Dz;
=20
      for (unsigned int y =3D 0; y < vol->height; ++y)
        {
          idx[1] =3D y;
          for (unsigned int x =3D 0; x < vol->width; ++x)
            {
              idx[0] =3D x;
   //here it is not able to write into buffer
        *(Buffer +(z*vol->height*vol->width)+y *vol->width =
+x)=3Dvol_init->GetPixel(idx);
          =20
    }
        }
 }

 vol->Mem =3D Buffer;
    return vol;
  =20
}


Please give me suggestion.

Thanking you,
Regards,
Ramakrishna

------=_NextPart_000_0034_01C235A6.BE3FCA10
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dear Mr.Bjorn &amp; =
Friends,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I got the o/p using files.Now I am =
giving i/p from=20
buffer and put o/p in buffer.I am getting o/p using=20
itkGrayScaleDialteImageFilter.<BR>when using =
itkgrayscaleErodeImageFilter o/p is=20
not getting.It is giving some black screen.</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><BR>Volume* IntensityScaleVolume(Volume *vol)<BR>{&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;if (vol =3D=3D NULL) return ;<BR>&nbsp;unsigned short *Buffer =
=3D new=20
unsigned short[vol-&gt;width * vol-&gt;height *=20
vol-&gt;depth];<BR>&nbsp;typedef&nbsp; unsigned short&nbsp;&nbsp;&nbsp;=20
PixelType;<BR>&nbsp;Buffer =3D (unsigned short *) =
vol-&gt;Mem;<BR>&nbsp;typedef=20
itk::Image&lt;unsigned short,3&gt;=20
ImageType;<BR>&nbsp;itk::RawImageIO&lt;unsigned short, 3&gt;::Pointer=20
output_io<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D =
itk::RawImageIO&lt;unsigned=20
short, 3&gt;::New();<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
output_io-&gt;SetByteOrderToLittleEndian();<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
output_io-&gt;SetFileTypeToBinary();<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
output_io-&gt;SetFileDimensionality(3);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp; // Initialize the initial and target=20
volumes.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
ImageType::Pointer=20
vol_init =3D ImageType::New();<BR>&nbsp;ImageType::Pointer vol_init1 =3D =

ImageType::New();<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
ImageType::SizeType sz;<BR>&nbsp;&nbsp;&nbsp; sz[0] =3D=20
vol-&gt;width;<BR>&nbsp;&nbsp;&nbsp; sz[1] =3D=20
vol-&gt;height;<BR>&nbsp;&nbsp;&nbsp; sz[2]=3Dvol-&gt;depth;=20
<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
ImageType::IndexType idx;<BR>&nbsp;&nbsp;&nbsp; idx[0] =3D=20
0;<BR>&nbsp;&nbsp;&nbsp; idx[1] =3D 0;<BR>&nbsp;&nbsp;&nbsp; idx[2] =3D=20
0;<BR>&nbsp;&nbsp;&nbsp; unsigned short pval;<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; ImageType::RegionType reg;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;=20
reg.SetSize(sz);<BR>&nbsp;&nbsp;&nbsp; =
reg.SetIndex(idx);<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; =
vol_init-&gt;SetRegions(reg);<BR>&nbsp;&nbsp;&nbsp;=20
vol_init-&gt;Allocate();<BR>&nbsp; &nbsp;<BR>&nbsp;for(unsigned int =
z=3D0;=20
z&lt;vol-&gt;depth; ++z )<BR>&nbsp;{=20
<BR>&nbsp;&nbsp;idx[2]=3Dz;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
for=20
(unsigned int y =3D 0; y &lt; vol-&gt;height;=20
++y)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idx[1] =3D=20
y;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for =
(unsigned int x=20
=3D 0; x &lt; vol-&gt;width;=20
++x)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
idx[0] =3D=20
x;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;=20
vol_init-&gt;SetPixel(idx, *(Buffer +(z*vol-&gt;height*vol-&gt;width)+y=20
*vol-&gt;width +x) );<BR>&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; </DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; //Dilate Erode<BR>&nbsp;itk::Size&lt;3&gt; size =3D {5,5,2}; =

<BR>&nbsp;&nbsp;&nbsp; typedef=20
itk::NeighborhoodAllocator&lt;PixelType&gt;&nbsp;&nbsp;=20
NAllocator;<BR>&nbsp;&nbsp;&nbsp; NAllocator&nbsp; *nat=3Dnew=20
NAllocator;<BR>&nbsp;&nbsp;&nbsp; typedef=20
itk::BinaryBallStructuringElement&lt;unsigned =
short,3&gt;<BR>&nbsp;&nbsp;&nbsp;=20
KernelType;<BR>&nbsp; &nbsp;KernelType&nbsp; *NA=3Dnew=20
KernelType;<BR>&nbsp;NA-&gt;SetRadius(size);<BR>&nbsp;NA-&gt;CreateStruct=
uringElement();<BR>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;typedef=20
itk::GrayscaleErodeImageFilter&lt;ImageType,ImageType,KernelType&gt;&nbsp=
;&nbsp;=20
Morphology;<BR>&nbsp;Morphology::Pointer&nbsp; GMF=3D=20
Morphology::New();<BR>&nbsp;GMF-&gt;SetInput(vol_init);<BR>&nbsp;GMF-&gt;=
SetKernel(*NA);<BR>&nbsp;GMF-&gt;Update();<BR>&nbsp;vol_init=3DGMF-&gt;Ge=
tOutput();///here=20
I think I am doing something wrong</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;<BR>&nbsp;<BR>&nbsp;for(unsigned int z=3D0; =
z&lt;vol-&gt;depth; ++z=20
)<BR>&nbsp;{<BR>&nbsp;&nbsp;idx[2]=3Dz;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
for (unsigned int y =3D 0; y &lt; vol-&gt;height;=20
++y)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idx[1] =3D=20
y;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for =
(unsigned int x=20
=3D 0; x &lt; vol-&gt;width;=20
++x)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
idx[0] =3D x;<BR>&nbsp;&nbsp;&nbsp;//here it is not able to write into=20
buffer<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *(Buffer=20
+(z*vol-&gt;height*vol-&gt;width)+y *vol-&gt;width=20
+x)=3Dvol_init-&gt;GetPixel(idx);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;vol-&gt;Mem =3D Buffer;<BR>&nbsp;&nbsp;&nbsp; return =
vol;<BR>&nbsp;=20
&nbsp;<BR>}</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>Please give me suggestion.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanking you,<BR>Regards,<BR>Ramakrishna</FONT></DIV></BODY></HTML>

------=_NextPart_000_0034_01C235A6.BE3FCA10--