[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>&nbsp;</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-&gt;Update(); and=20
filter-&gt;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>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><BR>#include &lt;fstream&gt;<BR>#include=20
"itkConnectedThresholdImageFilter.h"<BR>#include=20
"itkImageFileReader.h"<BR>#include "itkImageRegionIterator.h"</DIV>
<DIV>&nbsp;</DIV>
<DIV>int main(int ac, char** av) <BR>{<BR>&nbsp; if(ac &lt;=20
3)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; =
"Usage: "=20
&lt;&lt; av[0] &lt;&lt; " InputImage =
BaselineImage\n";<BR>&nbsp;&nbsp;&nbsp;=20
return -1;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; <BR>&nbsp; typedef unsigned =
char=20
PixelType;<BR>&nbsp; typedef itk::Image&lt;PixelType, 2&gt; =
myImage;<BR>&nbsp;=20
itk::ImageFileReader&lt;myImage&gt;::Pointer input =
<BR>&nbsp;&nbsp;&nbsp; =3D=20
itk::ImageFileReader&lt;myImage&gt;::New();<BR>&nbsp;=20
input-&gt;SetFileName(av[1]);<BR>&nbsp; <BR>&nbsp; // Create a =
filter<BR>&nbsp;=20
typedef itk::ConnectedThresholdImageFilter&lt;myImage,myImage&gt;=20
FilterType;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; FilterType::Pointer filter =3D=20
FilterType::New();<BR>&nbsp;&nbsp;&nbsp;=20
filter-&gt;SetInput(input-&gt;GetOutput());</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; FilterType::IndexType seed; seed[0] =3D 165; =
seed[1] =3D=20
90;<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetSeed(seed);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; filter-&gt;SetLower(0);<BR>&nbsp;&nbsp;&nbsp;=20
filter-&gt;SetUpper(150);<BR>&nbsp;&nbsp;&nbsp;=20
filter-&gt;SetReplaceValue(255);<BR>&nbsp; try<BR>&nbsp;&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp; input-&gt;Update();<BR>&nbsp;&nbsp;&nbsp;=20
filter-&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 detected: "&nbsp; &lt;&lt;=20
e.GetDescription();<BR>&nbsp;&nbsp;&nbsp; return =
-1;<BR>&nbsp;&nbsp;&nbsp;=20
}</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; // now read the regression image<BR>&nbsp;=20
itk::ImageFileReader&lt;myImage&gt;::Pointer baseline =
<BR>&nbsp;&nbsp;&nbsp; =3D=20
itk::ImageFileReader&lt;myImage&gt;::New();<BR>&nbsp;&nbsp;&nbsp;=20
baseline-&gt;SetFileName(av[2]);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;=20
baseline-&gt;Update();<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; catch=20
(itk::ImageFileReaderException&amp; e)<BR>&nbsp;&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Exception in file reader: =
"&nbsp;=20
&lt;&lt; e.GetDescription() &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp; =
return=20
-1;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; <BR>&nbsp; // compare the two=20
images<BR>&nbsp; itk::ImageRegionIterator&lt;myImage&gt;=20
it(filter-&gt;GetOutput(),filter-&gt;GetOutput()-&gt;GetBufferedRegion())=
;<BR>&nbsp;=20
itk::ImageRegionIterator&lt;myImage&gt;=20
rit(baseline-&gt;GetOutput(),baseline-&gt;GetOutput()-&gt;GetBufferedRegi=
on());<BR>&nbsp;=20
int status =3D 0;<BR>&nbsp; while (!it.IsAtEnd())<BR>&nbsp;&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp; if (it.Get() !=3D=20
rit.Get())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
status++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>&nbsp;&nbsp;&nbsp;=20
++it;<BR>&nbsp;&nbsp;&nbsp; ++rit;&nbsp; <BR>&nbsp;&nbsp;&nbsp; =
}<BR>&nbsp;=20
std::cout&lt;&lt;"status: "&lt;&lt;status;<BR>&nbsp; return =
status;<BR>}</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>Thanking =
you,<BR>Regards,<BR>satyanarayana.</FONT></DIV></BODY></HTML>

------=_NextPart_000_001B_01C23997.193B0B20--