[Insight-users] Dilate using ITK binaryDilateImageFilter

cspl affable at hd2 . dot . net . in
Fri, 26 Jul 2002 15:38:25 +0530


This is a multi-part message in MIME format.

------=_NextPart_000_001B_01C234BA.7B49F100
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dear Mr.Bjorn and Friends,

I am working on Dilation of a image.But I am not getting any effect on =
o/p.What ever I/P I have given it is=20
giving same o/p.There is no difference.Where exactly I am doing =
wrong.Please
give me suggestion.I have written code as follows.

int main()//(int argc, char **argv)
{

=20

=20
  const char * inputFileName  =3D"100";// argv[1];
  const char * outputFileName =3D"output";// argv[4];

  const unsigned int nx =3D 256;//atoi( argv[2] );
  const unsigned int ny =3D 256;//atoi( argv[3] );

  typedef  unsigned short    PixelType;
  const    unsigned int     Dimension =3D 2;

  typedef  itk::Image< PixelType, Dimension >     ImageType;
 =20
  // Read a Raw File
  typedef  itk::ImageFileReader< ImageType >      FileSourceType;
  typedef  itk::RawImageIO<PixelType,Dimension>   RawReaderType;


  FileSourceType::Pointer fileSource =3D FileSourceType::New();
  fileSource->SetFileName( inputFileName );

  RawReaderType::Pointer  rawReader  =3D RawReaderType::New();
  rawReader->SetDimensions( 0, nx );
  rawReader->SetDimensions( 1, ny );
  fileSource->SetImageIO( rawReader );
  try
    {
    fileSource->Update();
    }
  catch( itk::ExceptionObject & e )
    {
    std::cerr << "Exception caught during Raw file reading " << =
std::endl;
    std::cerr << e << std::endl;
    return -1;
    }
  std::cout << "File succesfully read ! " << std::endl;
=20
  ImageType::Pointer  image =3D fileSource->GetOutput();
=20
  //Dialate Erode

 itk::Size<2> size =3D {256, 256};=20

=20
    typedef itk::NeighborhoodAllocator<PixelType>   NAllocator;
    NAllocator  *nat=3Dnew NAllocator;
    typedef itk::Neighborhood<PixelType,(unsigned int)2,NAllocator> =
KernelType;
    KernelType  *NA=3Dnew KernelType;
    std::cout<<"Radius(Input)  "<<size;
    NA->SetRadius(size);
    unsigned short cv=3DNA->GetCenterValue();=20
    std::cout<<"\ncenter value"<<"  "<<cv<<"\n";
    std::cout<<"\nRadius of the neighborhood  "<<NA->GetRadius();=20
    std::cout<<"\nRadius along a two dimension  "<<NA->GetRadius((const =
unsigned long)2);
    std::cout<<"\nRadius along a one dimension  "<<NA->GetRadius((const =
unsigned long)1);
    std::cout<<"\n\nsize (total length of sides) of the neighborhood =
"<<NA->GetSize();
    unsigned long size2=3DNA->GetSize((const unsigned long)2);
    unsigned long size1=3DNA->GetSize((const unsigned long)1);
    std::cout<<"\nsize2(along a two dimension) "<<"  =
"<<size2<<"\nsize1(one dimension)   "<<size1;
    typedef itk::BinaryDilateImageFilter<ImageType,ImageType,KernelType> =
  Morphology;
    Morphology::Pointer  GMF=3D Morphology::New();
    GMF->SetInput(image);
    GMF->SetDilateValue(25000);
 =20
    ImageType::Pointer  image1 =3D GMF->GetOutput();
=20
  // Write a Raw File
  typedef  itk::ImageFileWriter< ImageType >      FileSinkType;
  typedef  itk::RawImageIO<PixelType,Dimension>   RawWriterType;


  FileSinkType::Pointer   fileSink   =3D FileSinkType::New();
  RawWriterType::Pointer  rawWriter  =3D RawWriterType::New();

  rawWriter->SetDimensions( 0, nx );
  rawWriter->SetDimensions( 1, ny );
  fileSink->SetImageIO( rawWriter );
  fileSink->SetFileName( outputFileName );
  fileSink->SetInput( image1);

 =20
  try
    {
    fileSink->Write();
    }
  catch( itk::ExceptionObject & e )
    {
    std::cerr << "Exception caught during Raw file writing " << =
std::endl;
    std::cerr << e << std::endl;
    return -1;
    }
  std::cout << "File succesfully writen ! " << std::endl;
  return 0;

}





Thanking you,

Regards,
Ramakrishna

------=_NextPart_000_001B_01C234BA.7B49F100
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 and Friends,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am working on Dilation of a image.But =
I am not=20
getting any effect on o/p.What ever I/P I have given it is <BR>giving =
same=20
o/p.There is no difference.Where exactly I am doing wrong.Please<BR>give =
me=20
suggestion.I have written code as follows.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>int main()//(int argc, char=20
**argv)<BR>{</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;<BR>&nbsp; const char * =
inputFileName&nbsp;=20
=3D"100";// argv[1];<BR>&nbsp; const char * outputFileName =
=3D"output";//=20
argv[4];</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; const unsigned int nx =3D =
256;//atoi( argv[2]=20
);<BR>&nbsp; const unsigned int ny =3D 256;//atoi( argv[3] =
);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; typedef&nbsp; unsigned=20
short&nbsp;&nbsp;&nbsp; PixelType;<BR>&nbsp; const&nbsp;&nbsp;&nbsp; =
unsigned=20
int&nbsp;&nbsp;&nbsp;&nbsp; Dimension =3D 2;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; typedef&nbsp; itk::Image&lt; =
PixelType,=20
Dimension &gt;&nbsp;&nbsp;&nbsp;&nbsp; ImageType;<BR>&nbsp; <BR>&nbsp; =
// Read a=20
Raw File<BR>&nbsp; typedef&nbsp; itk::ImageFileReader&lt; ImageType=20
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileSourceType;<BR>&nbsp; =
typedef&nbsp;=20
itk::RawImageIO&lt;PixelType,Dimension&gt;&nbsp;&nbsp;=20
RawReaderType;</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><BR>&nbsp; FileSourceType::Pointer fileSource =3D=20
FileSourceType::New();<BR>&nbsp; fileSource-&gt;SetFileName( =
inputFileName=20
);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; RawReaderType::Pointer&nbsp; rawReader&nbsp; =3D=20
RawReaderType::New();<BR>&nbsp; rawReader-&gt;SetDimensions( 0, nx =
);<BR>&nbsp;=20
rawReader-&gt;SetDimensions( 1, ny );<BR>&nbsp; =
fileSource-&gt;SetImageIO(=20
rawReader );<BR>&nbsp; try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; =

fileSource-&gt;Update();<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; catch(=20
itk::ExceptionObject &amp; e )<BR>&nbsp;&nbsp;&nbsp; =
{<BR>&nbsp;&nbsp;&nbsp;=20
std::cerr &lt;&lt; "Exception caught during Raw file reading " &lt;&lt;=20
std::endl;<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt;=20
std::endl;<BR>&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp;&nbsp;&nbsp; =
}<BR>&nbsp;=20
std::cout &lt;&lt; "File succesfully read ! " &lt;&lt;=20
std::endl;<BR>&nbsp;<BR>&nbsp; ImageType::Pointer&nbsp; image =3D=20
fileSource-&gt;GetOutput();<BR>&nbsp;<BR>&nbsp; //Dialate Erode</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;itk::Size&lt;2&gt; size =3D {256, 256}; </DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;<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::Neighborhood&lt;PixelType,(unsigned int)2,NAllocator&gt;=20
KernelType;<BR>&nbsp;&nbsp;&nbsp; KernelType&nbsp; *NA=3Dnew=20
KernelType;<BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"Radius(Input)&nbsp;=20
"&lt;&lt;size;<BR>&nbsp;&nbsp;&nbsp;=20
NA-&gt;SetRadius(size);<BR>&nbsp;&nbsp;&nbsp; unsigned short=20
cv=3DNA-&gt;GetCenterValue(); <BR>&nbsp;&nbsp;&nbsp; =
std::cout&lt;&lt;"\ncenter=20
value"&lt;&lt;"&nbsp; "&lt;&lt;cv&lt;&lt;"\n";<BR>&nbsp;&nbsp;&nbsp;=20
std::cout&lt;&lt;"\nRadius of the neighborhood&nbsp;=20
"&lt;&lt;NA-&gt;GetRadius(); <BR>&nbsp;&nbsp;&nbsp; =
std::cout&lt;&lt;"\nRadius=20
along a two dimension&nbsp; "&lt;&lt;NA-&gt;GetRadius((const unsigned=20
long)2);<BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"\nRadius along a one=20
dimension&nbsp; "&lt;&lt;NA-&gt;GetRadius((const unsigned=20
long)1);<BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"\n\nsize (total length =
of=20
sides) of the neighborhood =
"&lt;&lt;NA-&gt;GetSize();<BR>&nbsp;&nbsp;&nbsp;=20
unsigned long size2=3DNA-&gt;GetSize((const unsigned=20
long)2);<BR>&nbsp;&nbsp;&nbsp; unsigned long =
size1=3DNA-&gt;GetSize((const=20
unsigned long)1);<BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"\nsize2(along =
a two=20
dimension) "&lt;&lt;"&nbsp; "&lt;&lt;size2&lt;&lt;"\nsize1(one=20
dimension)&nbsp;&nbsp; "&lt;&lt;size1;<BR>&nbsp;&nbsp;&nbsp; typedef=20
itk::BinaryDilateImageFilter&lt;ImageType,ImageType,KernelType&gt;&nbsp;&=
nbsp;=20
Morphology;<BR>&nbsp;&nbsp;&nbsp; Morphology::Pointer&nbsp; GMF=3D=20
Morphology::New();<BR>&nbsp;&nbsp;&nbsp;=20
GMF-&gt;SetInput(image);<BR>&nbsp;&nbsp;&nbsp;=20
GMF-&gt;SetDilateValue(25000);<BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
ImageType::Pointer&nbsp; image1 =3D =
GMF-&gt;GetOutput();<BR>&nbsp;<BR>&nbsp; //=20
Write a Raw File<BR>&nbsp; typedef&nbsp; itk::ImageFileWriter&lt; =
ImageType=20
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileSinkType;<BR>&nbsp; typedef&nbsp; =

itk::RawImageIO&lt;PixelType,Dimension&gt;&nbsp;&nbsp; =
RawWriterType;</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp; FileSinkType::Pointer&nbsp;&nbsp; fileSink&nbsp;&nbsp; =
=3D=20
FileSinkType::New();<BR>&nbsp; RawWriterType::Pointer&nbsp; =
rawWriter&nbsp; =3D=20
RawWriterType::New();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; rawWriter-&gt;SetDimensions( 0, nx );<BR>&nbsp;=20
rawWriter-&gt;SetDimensions( 1, ny );<BR>&nbsp; fileSink-&gt;SetImageIO( =

rawWriter );<BR>&nbsp; fileSink-&gt;SetFileName( outputFileName =
);<BR>&nbsp;=20
fileSink-&gt;SetInput( image1);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; <BR>&nbsp; try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; =

fileSink-&gt;Write();<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; catch(=20
itk::ExceptionObject &amp; e )<BR>&nbsp;&nbsp;&nbsp; =
{<BR>&nbsp;&nbsp;&nbsp;=20
std::cerr &lt;&lt; "Exception caught during Raw file writing " &lt;&lt;=20
std::endl;<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt;=20
std::endl;<BR>&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp;&nbsp;&nbsp; =
}<BR>&nbsp;=20
std::cout &lt;&lt; "File succesfully writen ! " &lt;&lt; =
std::endl;<BR>&nbsp;=20
return 0;</DIV>
<DIV>&nbsp;</DIV>
<DIV>}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanking you,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Regards,<BR>Ramakrishna</FONT></DIV></BODY></HTML>

------=_NextPart_000_001B_01C234BA.7B49F100--