[Insight-users] Problem with Update function
cspl
affable at hd2 . dot . net . in
Thu, 1 Aug 2002 20:07:44 +0530
This is a multi-part message in MIME format.
------=_NextPart_000_001B_01C23997.193B0B20
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Dear Friends,
I am working on the ConnectedThresholdImageFilter.I using following =
code.This code is not running properly.I debugged the application when =
cursor is arriving at input->Update(); and filter->Update(); it is =
giving exception.Please give me suggestion.Remaing filter updates are =
working in my system.
written code as follows.
#include <fstream>
#include "itkConnectedThresholdImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageRegionIterator.h"
int main(int ac, char** av)=20
{
if(ac < 3)
{
std::cerr << "Usage: " << av[0] << " InputImage BaselineImage\n";
return -1;
}
=20
typedef unsigned char PixelType;
typedef itk::Image<PixelType, 2> myImage;
itk::ImageFileReader<myImage>::Pointer input=20
=3D itk::ImageFileReader<myImage>::New();
input->SetFileName(av[1]);
=20
// Create a filter
typedef itk::ConnectedThresholdImageFilter<myImage,myImage> =
FilterType;
FilterType::Pointer filter =3D FilterType::New();
filter->SetInput(input->GetOutput());
FilterType::IndexType seed; seed[0] =3D 165; seed[1] =3D 90;
filter->SetSeed(seed);
filter->SetLower(0);
filter->SetUpper(150);
filter->SetReplaceValue(255);
try
{
input->Update();
filter->Update();
}
catch (itk::ExceptionObject& e)
{
std::cerr << "Exception detected: " << e.GetDescription();
return -1;
}
// now read the regression image
itk::ImageFileReader<myImage>::Pointer baseline=20
=3D itk::ImageFileReader<myImage>::New();
baseline->SetFileName(av[2]);
try
{
baseline->Update();
}
catch (itk::ImageFileReaderException& e)
{
std::cerr << "Exception in file reader: " << e.GetDescription() << =
std::endl;
return -1;
}
=20
// compare the two images
itk::ImageRegionIterator<myImage> =
it(filter->GetOutput(),filter->GetOutput()->GetBufferedRegion());
itk::ImageRegionIterator<myImage> =
rit(baseline->GetOutput(),baseline->GetOutput()->GetBufferedRegion());
int status =3D 0;
while (!it.IsAtEnd())
{
if (it.Get() !=3D rit.Get())
{
status++;
}=20
++it;
++rit; =20
}
std::cout<<"status: "<<status;
return status;
}
Thanking you,
Regards,
satyanarayana.
------=_NextPart_000_001B_01C23997.193B0B20
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 Friends,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I am working on the =
ConnectedThresholdImageFilter.I=20
using following code.This code is not running properly.I debugged the=20
application when cursor is arriving at input->Update(); and=20
filter->Update(); it is giving exception.Please give me =
suggestion.Remaing=20
filter updates are working in my system.<BR>written code as=20
follows.</FONT></DIV>
<DIV> </DIV><FONT face=3DArial size=3D2>
<DIV><BR>#include <fstream><BR>#include=20
"itkConnectedThresholdImageFilter.h"<BR>#include=20
"itkImageFileReader.h"<BR>#include "itkImageRegionIterator.h"</DIV>
<DIV> </DIV>
<DIV>int main(int ac, char** av) <BR>{<BR> if(ac <=20
3)<BR> {<BR> std::cerr << =
"Usage: "=20
<< av[0] << " InputImage =
BaselineImage\n";<BR> =20
return -1;<BR> }<BR> <BR> typedef unsigned =
char=20
PixelType;<BR> typedef itk::Image<PixelType, 2> =
myImage;<BR> =20
itk::ImageFileReader<myImage>::Pointer input =
<BR> =3D=20
itk::ImageFileReader<myImage>::New();<BR> =20
input->SetFileName(av[1]);<BR> <BR> // Create a =
filter<BR> =20
typedef itk::ConnectedThresholdImageFilter<myImage,myImage>=20
FilterType;</DIV>
<DIV> </DIV>
<DIV> FilterType::Pointer filter =3D=20
FilterType::New();<BR> =20
filter->SetInput(input->GetOutput());</DIV>
<DIV> </DIV>
<DIV> FilterType::IndexType seed; seed[0] =3D 165; =
seed[1] =3D=20
90;<BR> filter->SetSeed(seed);</DIV>
<DIV> </DIV>
<DIV> filter->SetLower(0);<BR> =20
filter->SetUpper(150);<BR> =20
filter->SetReplaceValue(255);<BR> try<BR> =20
{<BR> input->Update();<BR> =20
filter->Update();<BR> }<BR> catch=20
(itk::ExceptionObject& e)<BR> =
{<BR> =20
std::cerr << "Exception detected: " <<=20
e.GetDescription();<BR> return =
-1;<BR> =20
}</DIV>
<DIV> </DIV>
<DIV> // now read the regression image<BR> =20
itk::ImageFileReader<myImage>::Pointer baseline =
<BR> =3D=20
itk::ImageFileReader<myImage>::New();<BR> =20
baseline->SetFileName(av[2]);</DIV>
<DIV> </DIV>
<DIV> try<BR> {<BR> =20
baseline->Update();<BR> }<BR> catch=20
(itk::ImageFileReaderException& e)<BR> =20
{<BR> std::cerr << "Exception in file reader: =
" =20
<< e.GetDescription() << std::endl;<BR> =
return=20
-1;<BR> }<BR> <BR> // compare the two=20
images<BR> itk::ImageRegionIterator<myImage>=20
it(filter->GetOutput(),filter->GetOutput()->GetBufferedRegion())=
;<BR> =20
itk::ImageRegionIterator<myImage>=20
rit(baseline->GetOutput(),baseline->GetOutput()->GetBufferedRegi=
on());<BR> =20
int status =3D 0;<BR> while (!it.IsAtEnd())<BR> =20
{<BR> if (it.Get() !=3D=20
rit.Get())<BR> =
{<BR> =20
status++;<BR> } <BR> =20
++it;<BR> ++rit; <BR> =
}<BR> =20
std::cout<<"status: "<<status;<BR> return =
status;<BR>}</DIV>
<DIV> </DIV>
<DIV><BR>Thanking =
you,<BR>Regards,<BR>satyanarayana.</FONT></DIV></BODY></HTML>
------=_NextPart_000_001B_01C23997.193B0B20--