[Insight-users] Problem with HistogramType::ConstIterator inside function

Radhika Sivaramakrishna radhika.sivaramakrishna at synarc.com
Wed, 11 Feb 2004 11:18:19 -0800


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_01C3F0D3.CE9D36E2
Content-Type: text/plain


Hi Luis and Jim,

I was trying to use the ScalarImageToHistogramGenerator inside a function to
which I pass an image and mask. I am running into some problems.

My function is templated and is defined like this:

template <class PixelType>
void HistogramThreshold(const itk::Image< PixelType, 3> * image,
            itk::Image< PixelType, 3> * mask)

The code where I get the error is very similar to one of the histogram
examples and is like this:

typedef itk::Statistics::ScalarImageToHistogramGenerator<
                                                    ImageType
                                                          >
HistogramGeneratorType;

  HistogramGeneratorType::Pointer histogramGenerator =
HistogramGeneratorType::New();

histogramGenerator->SetInput(  image );

  histogramGenerator->SetNumberOfBins( NumberOfBins );
  histogramGenerator->SetMarginalScale( MarginalScale );
  histogramGenerator->Compute();

  typedef HistogramGeneratorType::HistogramType  HistogramType;

  const HistogramType * histogram = histogramGenerator->GetOutput();

  const unsigned int histogramSize = histogram->Size();

  std::cout << "Histogram size " << histogramSize << std::endl;

  HistogramType::ConstIterator itr = histogram->Begin();
  HistogramType::ConstIterator end = histogram->End();

The compile error I am getting is hardly descriptive. It says that there is
a parse error in this definition of itr and end (see above). I do not get
this error when this whole thing is one main function.

My suspicion is it has something to do with typename etc. Can you tell me
exactly how to define the two Histogram iterators without getting this
error?

Thanks
Radhika

                                                     
-----------------------------------------------------  
Confidentiality Notice. 
This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message. If you are the intended recipient, please be
advised that the content of this message is subject to access, review and
disclosure by the sender's Email System Administrator.

------_=_NextPart_001_01C3F0D3.CE9D36E2
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2656.87">
<TITLE>Problem with HistogramType::ConstIterator inside =
function</TITLE>
</HEAD>
<BODY>
<BR>

<P><FONT SIZE=3D2>Hi Luis and Jim,</FONT>
</P>

<P><FONT SIZE=3D2>I was trying to use the =
ScalarImageToHistogramGenerator inside a function to which I pass an =
image and mask. I am running into some problems.</FONT></P>

<P><FONT SIZE=3D2>My function is templated and is defined like =
this:</FONT>
</P>

<P><FONT SIZE=3D2>template &lt;class PixelType&gt;</FONT>
<BR><FONT SIZE=3D2>void HistogramThreshold(const itk::Image&lt; =
PixelType, 3&gt; * image,</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; itk::Image&lt; PixelType, 3&gt; * mask)</FONT>
</P>

<P><FONT SIZE=3D2>The code where I get the error is very similar to one =
of the histogram examples and is like this:</FONT>
</P>

<P><FONT SIZE=3D2>typedef =
itk::Statistics::ScalarImageToHistogramGenerator&lt;</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; ImageType</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&gt;&nbsp;&nbsp; HistogramGeneratorType;</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; HistogramGeneratorType::Pointer =
histogramGenerator =3D HistogramGeneratorType::New();</FONT>
</P>

<P><FONT SIZE=3D2>histogramGenerator-&gt;SetInput(&nbsp; image =
);</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; histogramGenerator-&gt;SetNumberOfBins( =
NumberOfBins );</FONT>
<BR><FONT SIZE=3D2>&nbsp; histogramGenerator-&gt;SetMarginalScale( =
MarginalScale );</FONT>
<BR><FONT SIZE=3D2>&nbsp; histogramGenerator-&gt;Compute();</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; typedef =
HistogramGeneratorType::HistogramType&nbsp; HistogramType;</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; const HistogramType * histogram =3D =
histogramGenerator-&gt;GetOutput();</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; const unsigned int histogramSize =3D =
histogram-&gt;Size();</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; std::cout &lt;&lt; &quot;Histogram size &quot; =
&lt;&lt; histogramSize &lt;&lt; std::endl;</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; HistogramType::ConstIterator itr =3D =
histogram-&gt;Begin();</FONT>
<BR><FONT SIZE=3D2>&nbsp; HistogramType::ConstIterator end =3D =
histogram-&gt;End();</FONT>
</P>

<P><FONT SIZE=3D2>The compile error I am getting is hardly descriptive. =
It says that there is a parse error in this definition of itr and end =
(see above). I do not get this error when this whole thing is one main =
function.</FONT></P>

<P><FONT SIZE=3D2>My suspicion is it has something to do with typename =
etc. Can you tell me exactly how to define the two Histogram iterators =
without getting this error?</FONT></P>

<P><FONT SIZE=3D2>Thanks</FONT>
<BR><FONT SIZE=3D2>Radhika</FONT>
</P>

<P><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT =
SIZE=3D2>-----------------------------------------------------&nbsp; =
</FONT>
<BR><FONT SIZE=3D2>Confidentiality Notice. </FONT>
<BR><FONT SIZE=3D2>This email message is for the sole use of the =
intended recipient(s) and may contain confidential and privileged =
information. Any unauthorized review, use, disclosure or distribution =
is prohibited. If you are not the intended recipient, please contact =
the sender by reply email and destroy all copies of the original =
message. If you are the intended recipient, please be advised that the =
content of this message is subject to access, review and disclosure by =
the sender's Email System Administrator.</FONT></P>

</BODY>
</HTML>
------_=_NextPart_001_01C3F0D3.CE9D36E2--