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