[Insight-users] Dilate using ITK binaryDilateImageFilter

Miller, James V (Research) millerjv at crd . ge . com
Fri, 26 Jul 2002 09:27:58 -0400


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C234A8.41B123CE
Content-Type: text/plain;
	charset="iso-8859-1"

You haven't set the elements in the structuring element. So you are dilating with a structuring
element that only has zeros.
 
Try using an itk::BinaryBallStructuringElement as your structuring element.  This will allow 
you to dilate with a ball (ellipsoid) of prescribe radii.
 
Take a look at Insight/Code/Testing/BasicFilters/itkBinaryDilateImageFilterTest.cxx to see
how to setup a structuring element.
 
 

-----Original Message-----
From: cspl [mailto:affable@hd2.dot.net.in]
Sent: Friday, July 26, 2002 6:08 AM
To: insight-users@public.kitware.com
Cc: bhs@pvv.org
Subject: [Insight-users] Dilate using ITK binaryDilateImageFilter


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 
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)
{
 
 
 

  const char * inputFileName  ="100";// argv[1];
  const char * outputFileName ="output";// argv[4];
 
  const unsigned int nx = 256;//atoi( argv[2] );
  const unsigned int ny = 256;//atoi( argv[3] );
 
  typedef  unsigned short    PixelType;
  const    unsigned int     Dimension = 2;
 
  typedef  itk::Image< PixelType, Dimension >     ImageType;
  
  // Read a Raw File
  typedef  itk::ImageFileReader< ImageType >      FileSourceType;
  typedef  itk::RawImageIO<PixelType,Dimension>   RawReaderType;
 


  FileSourceType::Pointer fileSource = FileSourceType::New();
  fileSource->SetFileName( inputFileName );
 
  RawReaderType::Pointer  rawReader  = 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;
 
  ImageType::Pointer  image = fileSource->GetOutput();
 
  //Dialate Erode
 
 itk::Size<2> size = {256, 256}; 
 

    typedef itk::NeighborhoodAllocator<PixelType>   NAllocator;
    NAllocator  *nat=new NAllocator;
    typedef itk::Neighborhood<PixelType,(unsigned int)2,NAllocator> KernelType;
    KernelType  *NA=new KernelType;
    std::cout<<"Radius(Input)  "<<size;
    NA->SetRadius(size);
    unsigned short cv=NA->GetCenterValue(); 
    std::cout<<"\ncenter value"<<"  "<<cv<<"\n";
    std::cout<<"\nRadius of the neighborhood  "<<NA->GetRadius(); 
    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=NA->GetSize((const unsigned long)2);
    unsigned long size1=NA->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= Morphology::New();
    GMF->SetInput(image);
    GMF->SetDilateValue(25000);
  
    ImageType::Pointer  image1 = GMF->GetOutput();
 
  // Write a Raw File
  typedef  itk::ImageFileWriter< ImageType >      FileSinkType;
  typedef  itk::RawImageIO<PixelType,Dimension>   RawWriterType;
 

  FileSinkType::Pointer   fileSink   = FileSinkType::New();
  RawWriterType::Pointer  rawWriter  = RawWriterType::New();
 
  rawWriter->SetDimensions( 0, nx );
  rawWriter->SetDimensions( 1, ny );
  fileSink->SetImageIO( rawWriter );
  fileSink->SetFileName( outputFileName );
  fileSink->SetInput( image1);
 

  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_001_01C234A8.41B123CE
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 6.00.2715.400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff size=2>You haven't set 
the elements in the structuring element. So you are dilating with a 
structuring</FONT></SPAN></DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff size=2>element that only 
has zeros.</FONT></SPAN></DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff size=2>Try using an 
itk::BinaryBallStructuringElement as your structuring element.&nbsp; This will 
allow </FONT></SPAN></DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff size=2>you to dilate 
with a ball (ellipsoid) of prescribe radii.</FONT></SPAN></DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff size=2>Take a look at 
Insight/Code/Testing/BasicFilters/itkBinaryDilateImageFilterTest.cxx to 
see</FONT></SPAN></DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff size=2>how to setup a 
structuring element.</FONT></SPAN></DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> cspl 
  [mailto:affable@hd2.dot.net.in]<BR><B>Sent:</B> Friday, July 26, 2002 6:08 
  AM<BR><B>To:</B> insight-users@public.kitware.com<BR><B>Cc:</B> 
  bhs@pvv.org<BR><B>Subject:</B> [Insight-users] Dilate using ITK 
  binaryDilateImageFilter<BR><BR></FONT></DIV>
  <DIV><FONT face=Arial size=2>Dear Mr.Bjorn and Friends,</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>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 <BR>giving same 
  o/p.There is no difference.Where exactly I am doing wrong.Please<BR>give me 
  suggestion.I have written code as follows.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>int main()//(int argc, char 
  **argv)<BR>{</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2><BR>&nbsp; const char * inputFileName&nbsp; 
  ="100";// argv[1];<BR>&nbsp; const char * outputFileName ="output";// 
  argv[4];</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>&nbsp; const unsigned int nx = 256;//atoi( 
  argv[2] );<BR>&nbsp; const unsigned int ny = 256;//atoi( argv[3] 
  );</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>&nbsp; typedef&nbsp; unsigned 
  short&nbsp;&nbsp;&nbsp; PixelType;<BR>&nbsp; const&nbsp;&nbsp;&nbsp; unsigned 
  int&nbsp;&nbsp;&nbsp;&nbsp; Dimension = 2;</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>&nbsp; typedef&nbsp; itk::Image&lt; PixelType, 
  Dimension &gt;&nbsp;&nbsp;&nbsp;&nbsp; ImageType;<BR>&nbsp; <BR>&nbsp; // Read 
  a Raw File<BR>&nbsp; typedef&nbsp; itk::ImageFileReader&lt; ImageType 
  &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileSourceType;<BR>&nbsp; typedef&nbsp; 
  itk::RawImageIO&lt;PixelType,Dimension&gt;&nbsp;&nbsp; 
  RawReaderType;</FONT></DIV>
  <DIV>&nbsp;</DIV><FONT face=Arial size=2>
  <DIV><BR>&nbsp; FileSourceType::Pointer fileSource = 
  FileSourceType::New();<BR>&nbsp; fileSource-&gt;SetFileName( inputFileName 
  );</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp; RawReaderType::Pointer&nbsp; rawReader&nbsp; = 
  RawReaderType::New();<BR>&nbsp; rawReader-&gt;SetDimensions( 0, nx 
  );<BR>&nbsp; rawReader-&gt;SetDimensions( 1, ny );<BR>&nbsp; 
  fileSource-&gt;SetImageIO( rawReader );<BR>&nbsp; try<BR>&nbsp;&nbsp;&nbsp; 
  {<BR>&nbsp;&nbsp;&nbsp; fileSource-&gt;Update();<BR>&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp; catch( itk::ExceptionObject &amp; e )<BR>&nbsp;&nbsp;&nbsp; 
  {<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Exception caught during Raw file 
  reading " &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e 
  &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp; std::cout &lt;&lt; "File succesfully read ! " &lt;&lt; 
  std::endl;<BR>&nbsp;<BR>&nbsp; ImageType::Pointer&nbsp; image = 
  fileSource-&gt;GetOutput();<BR>&nbsp;<BR>&nbsp; //Dialate Erode</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;itk::Size&lt;2&gt; size = {256, 256}; </DIV>
  <DIV>&nbsp;</DIV>
  <DIV><BR>&nbsp;&nbsp;&nbsp; typedef 
  itk::NeighborhoodAllocator&lt;PixelType&gt;&nbsp;&nbsp; 
  NAllocator;<BR>&nbsp;&nbsp;&nbsp; NAllocator&nbsp; *nat=new 
  NAllocator;<BR>&nbsp;&nbsp;&nbsp; typedef 
  itk::Neighborhood&lt;PixelType,(unsigned int)2,NAllocator&gt; 
  KernelType;<BR>&nbsp;&nbsp;&nbsp; KernelType&nbsp; *NA=new 
  KernelType;<BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"Radius(Input)&nbsp; 
  "&lt;&lt;size;<BR>&nbsp;&nbsp;&nbsp; 
  NA-&gt;SetRadius(size);<BR>&nbsp;&nbsp;&nbsp; unsigned short 
  cv=NA-&gt;GetCenterValue(); <BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"\ncenter 
  value"&lt;&lt;"&nbsp; "&lt;&lt;cv&lt;&lt;"\n";<BR>&nbsp;&nbsp;&nbsp; 
  std::cout&lt;&lt;"\nRadius of the neighborhood&nbsp; 
  "&lt;&lt;NA-&gt;GetRadius(); <BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"\nRadius 
  along a two dimension&nbsp; "&lt;&lt;NA-&gt;GetRadius((const unsigned 
  long)2);<BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"\nRadius along a one 
  dimension&nbsp; "&lt;&lt;NA-&gt;GetRadius((const unsigned 
  long)1);<BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"\n\nsize (total length of 
  sides) of the neighborhood "&lt;&lt;NA-&gt;GetSize();<BR>&nbsp;&nbsp;&nbsp; 
  unsigned long size2=NA-&gt;GetSize((const unsigned 
  long)2);<BR>&nbsp;&nbsp;&nbsp; unsigned long size1=NA-&gt;GetSize((const 
  unsigned long)1);<BR>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"\nsize2(along a two 
  dimension) "&lt;&lt;"&nbsp; "&lt;&lt;size2&lt;&lt;"\nsize1(one 
  dimension)&nbsp;&nbsp; "&lt;&lt;size1;<BR>&nbsp;&nbsp;&nbsp; typedef 
  itk::BinaryDilateImageFilter&lt;ImageType,ImageType,KernelType&gt;&nbsp;&nbsp; 
  Morphology;<BR>&nbsp;&nbsp;&nbsp; Morphology::Pointer&nbsp; GMF= 
  Morphology::New();<BR>&nbsp;&nbsp;&nbsp; 
  GMF-&gt;SetInput(image);<BR>&nbsp;&nbsp;&nbsp; 
  GMF-&gt;SetDilateValue(25000);<BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; 
  ImageType::Pointer&nbsp; image1 = GMF-&gt;GetOutput();<BR>&nbsp;<BR>&nbsp; // 
  Write a Raw File<BR>&nbsp; typedef&nbsp; itk::ImageFileWriter&lt; ImageType 
  &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; = 
  FileSinkType::New();<BR>&nbsp; RawWriterType::Pointer&nbsp; rawWriter&nbsp; = 
  RawWriterType::New();</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp; rawWriter-&gt;SetDimensions( 0, nx );<BR>&nbsp; 
  rawWriter-&gt;SetDimensions( 1, ny );<BR>&nbsp; fileSink-&gt;SetImageIO( 
  rawWriter );<BR>&nbsp; fileSink-&gt;SetFileName( outputFileName );<BR>&nbsp; 
  fileSink-&gt;SetInput( image1);</DIV>
  <DIV>&nbsp;</DIV>
  <DIV> <BR>&nbsp; try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; 
  fileSink-&gt;Write();<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; catch( 
  itk::ExceptionObject &amp; e )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; 
  std::cerr &lt;&lt; "Exception caught during Raw file writing " &lt;&lt; 
  std::endl;<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; 
  std::endl;<BR>&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; 
  std::cout &lt;&lt; "File succesfully writen ! " &lt;&lt; std::endl;<BR>&nbsp; 
  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></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C234A8.41B123CE--