[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> </DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff size=2>Try using an
itk::BinaryBallStructuringElement as your structuring element. 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> </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> </DIV>
<DIV><SPAN class=603212113-26072002><FONT color=#0000ff
size=2></FONT></SPAN> </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> </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> </DIV>
<DIV><FONT face=Arial size=2>int main()//(int argc, char
**argv)<BR>{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><BR> const char * inputFileName
="100";// argv[1];<BR> const char * outputFileName ="output";//
argv[4];</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> const unsigned int nx = 256;//atoi(
argv[2] );<BR> const unsigned int ny = 256;//atoi( argv[3]
);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> typedef unsigned
short PixelType;<BR> const unsigned
int Dimension = 2;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> typedef itk::Image< PixelType,
Dimension > ImageType;<BR> <BR> // Read
a Raw File<BR> typedef itk::ImageFileReader< ImageType
> FileSourceType;<BR> typedef
itk::RawImageIO<PixelType,Dimension>
RawReaderType;</FONT></DIV>
<DIV> </DIV><FONT face=Arial size=2>
<DIV><BR> FileSourceType::Pointer fileSource =
FileSourceType::New();<BR> fileSource->SetFileName( inputFileName
);</DIV>
<DIV> </DIV>
<DIV> RawReaderType::Pointer rawReader =
RawReaderType::New();<BR> rawReader->SetDimensions( 0, nx
);<BR> rawReader->SetDimensions( 1, ny );<BR>
fileSource->SetImageIO( rawReader );<BR> try<BR>
{<BR> fileSource->Update();<BR>
}<BR> catch( itk::ExceptionObject & e )<BR>
{<BR> std::cerr << "Exception caught during Raw file
reading " << std::endl;<BR> std::cerr << e
<< std::endl;<BR> return -1;<BR>
}<BR> std::cout << "File succesfully read ! " <<
std::endl;<BR> <BR> ImageType::Pointer image =
fileSource->GetOutput();<BR> <BR> //Dialate Erode</DIV>
<DIV> </DIV>
<DIV> itk::Size<2> size = {256, 256}; </DIV>
<DIV> </DIV>
<DIV><BR> typedef
itk::NeighborhoodAllocator<PixelType>
NAllocator;<BR> NAllocator *nat=new
NAllocator;<BR> typedef
itk::Neighborhood<PixelType,(unsigned int)2,NAllocator>
KernelType;<BR> KernelType *NA=new
KernelType;<BR> std::cout<<"Radius(Input)
"<<size;<BR>
NA->SetRadius(size);<BR> unsigned short
cv=NA->GetCenterValue(); <BR> std::cout<<"\ncenter
value"<<" "<<cv<<"\n";<BR>
std::cout<<"\nRadius of the neighborhood
"<<NA->GetRadius(); <BR> std::cout<<"\nRadius
along a two dimension "<<NA->GetRadius((const unsigned
long)2);<BR> std::cout<<"\nRadius along a one
dimension "<<NA->GetRadius((const unsigned
long)1);<BR> std::cout<<"\n\nsize (total length of
sides) of the neighborhood "<<NA->GetSize();<BR>
unsigned long size2=NA->GetSize((const unsigned
long)2);<BR> unsigned long size1=NA->GetSize((const
unsigned long)1);<BR> std::cout<<"\nsize2(along a two
dimension) "<<" "<<size2<<"\nsize1(one
dimension) "<<size1;<BR> typedef
itk::BinaryDilateImageFilter<ImageType,ImageType,KernelType>
Morphology;<BR> Morphology::Pointer GMF=
Morphology::New();<BR>
GMF->SetInput(image);<BR>
GMF->SetDilateValue(25000);<BR> <BR>
ImageType::Pointer image1 = GMF->GetOutput();<BR> <BR> //
Write a Raw File<BR> typedef itk::ImageFileWriter< ImageType
> FileSinkType;<BR> typedef
itk::RawImageIO<PixelType,Dimension> RawWriterType;</DIV>
<DIV> </DIV>
<DIV><BR> FileSinkType::Pointer fileSink =
FileSinkType::New();<BR> RawWriterType::Pointer rawWriter =
RawWriterType::New();</DIV>
<DIV> </DIV>
<DIV> rawWriter->SetDimensions( 0, nx );<BR>
rawWriter->SetDimensions( 1, ny );<BR> fileSink->SetImageIO(
rawWriter );<BR> fileSink->SetFileName( outputFileName );<BR>
fileSink->SetInput( image1);</DIV>
<DIV> </DIV>
<DIV> <BR> try<BR> {<BR>
fileSink->Write();<BR> }<BR> catch(
itk::ExceptionObject & e )<BR> {<BR>
std::cerr << "Exception caught during Raw file writing " <<
std::endl;<BR> std::cerr << e <<
std::endl;<BR> return -1;<BR> }<BR>
std::cout << "File succesfully writen ! " << std::endl;<BR>
return 0;</DIV>
<DIV> </DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Thanking you,</DIV>
<DIV> </DIV>
<DIV>Regards,<BR>Ramakrishna</FONT></DIV></BLOCKQUOTE></BODY></HTML>
------_=_NextPart_001_01C234A8.41B123CE--