<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">OK,<div><br></div><div>Then another approach is to take advantage that the iterators are default constructible. Something like this:</div><div><br></div><div>ImageRegionIterator it2;</div><div>if (myfeatureImage2)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>it = ImageRegionIterator(myfeatureImage2, region);</div><div>}</div><div><br></div><div>There are a lot of options.</div><div><br></div><div>Hope one works for you,</div><div>Brad</div><div><br><div><div>On Mar 11, 2014, at 9:04 AM, Jan Ehrhardt <<a href="mailto:ehrhardt@imi.uni-luebeck.de">ehrhardt@imi.uni-luebeck.de</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<div text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi Brad,<br>
<br>
yes this is an alternative way, but the code inside the loop has
approx. 200 lines (is quite complicated stuff) and I'm still
testing and in your solution, I have to maintain the code four
times...<br>
<br>
Best regards,<br>
Jan<br>
<br>
On 03/11/2014 01:55 PM, Bradley Lowekamp wrote:<br>
</div>
<blockquote cite="mid:09A25EB0-AD0D-4A5A-98D6-A8797109D4F3@mail.nih.gov" type="cite">
Hello,
<div><br>
</div>
<div>You are right that the GetPixel methods are slow, but that's
why iterators are recommended.</div>
<div><br>
</div>
<div>Currently you are trying to have you "if( featureImage2 )" in
side the per-pixel loop. Not only does this cause you iterator
initialization issue it also is slower of have this if statement
inside the loop.</div>
<div><br>
</div>
<div>Here is an alternative way to construct your logic:</div>
<div><br>
</div>
<div><a moz-do-not-send="true" href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/ImageFilterBase/include/itkBinaryFunctorImageFilter.hxx#L224-L297">https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/ImageFilterBase/include/itkBinaryFunctorImageFilter.hxx#L224-L297</a></div>
<div><br>
</div>
<div>Hope this help,</div>
<div>Brad</div>
<div><br>
<div>
<div>On Mar 11, 2014, at 8:34 AM, Jan Ehrhardt <<a moz-do-not-send="true" href="mailto:ehrhardt@imi.uni-luebeck.de">ehrhardt@imi.uni-luebeck.de</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi Matt,<br>
<br>
yes, I currently use the ITK iterators, but I have the
following problem. <br>
<br>
Standard code looks like:<br>
<br>
itk::ImageRegionIterator<ImageType1> it( radius,
myImage, region );<br>
itk::ImageRegionIterator<ImageType2> featureIt1(
radius, featureImage1, region );<br>
itk::ImageRegionIterator<ImageType3> featureIt2(
radius, featureImage2, region );<br>
<br>
it.GotoBegin();<br>
featureIt1.GotoBegin();<br>
featureIt2.GotoBegin();<br>
<br>
while(!it.IsAtEnd())<br>
{<br>
// do some complicated processing stuff with or
without feature1 and/or feature2<br>
<br>
++it;<br>
++featureIt1;<br>
++featureIt2;<br>
}<br>
<br>
I only know at runtime, whether featureImage1 and/or
featureImage2 are available. If<br>
featureImage1 or featureImage2 is NULL, a segmentation
fault occurs.<br>
<br>
Therefore, I have currently implemented:<br>
<br>
itk::ConstNeighborhoodIterator<ImageType1> it(
radius, myImage, region );<br>
<br>
it.GotoBegin();<br>
<br>
while(!it.IsAtEnd())<br>
{<br>
currentIndex=it.GetIndex();<br>
if( featureImage1.IsNotNull())<br>
{<br>
// use featureImage1->GetPixel(currentIndex)
to process feature 1<br>
}<br>
if( featureImage2.IsNotNull())<br>
{<br>
// use featureImage2->GetPixel(currentIndex)
to process feature 2<br>
}<br>
<br>
// do some other stuff<br>
<br>
++it;<br>
}<br>
<br>
The Image::GetPixel() method is quite time-consuming and
therefore I look for a more efficient method<br>
to implement this code (without writing four different
versions).<br>
<br>
Any suggestions?<br>
<br>
Best regards,<br>
Jan<br>
<br>
On 03/11/2014 06:12 AM, Matt McCormick wrote:<br>
</div>
<blockquote cite="mid:CALzTN-RujRXRUR6UQh=3QT-bcqD8YAi8eir4bn23LBzqYLyoQA@mail.gmail.com" type="cite">
<div dir="ltr">Hi Jan,
<div><br>
</div>
<div>To iterator through an Image or VectorImage, use
the Iterators as described in the Software Guide [1]</div>
<div><br>
</div>
<div>HTH,</div>
<div>Matt</div>
<div><br>
</div>
<div>[1] <a moz-do-not-send="true" href="http://itk.org/ItkSoftwareGuide.pdf">http://itk.org/ItkSoftwareGuide.pdf</a></div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Thu, Mar 6, 2014 at 8:23
AM, Jan Ehrhardt <span dir="ltr"><<a moz-do-not-send="true" href="mailto:ehrhardt@imi.uni-luebeck.de" target="_blank">ehrhardt@imi.uni-luebeck.de</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Hi
folks,<br>
<br>
I want to iterate through a vector image without
an iterator. My approach was:<br>
<br>
MultiChannelImageType::AccessorType accessor =
pImage->GetPixelAccessor();<br>
MultiChannelImageType::InternalPixelType*
pBuffer = pImage->GetBufferPointer();<br>
<br>
for( OffsetValueType i = from; i < to; ++i
)<br>
{<br>
vecPixel = accessor.Get(*pBuffer, i);<br>
}<br>
<br>
but the results are not correct (see bug(?)
below). If the bug(?) in
DefaultVectorPixelAccessor is corrected (
m_OffsetMultiplier = l ) the behaviour of standard
itk iterators change. I assume, I don't understand
the parameters of
DefaultVectorPixelAccessor::Get() correctly.<br>
How can I use the DefaultVectorPixelAccessor
correctly?<br>
<br>
best,<br>
jan
<div class="HOEnZb">
<div class="h5"><br>
<br>
On 03/06/2014 12:25 PM, Jan Ehrhardt wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex"> Hi folks,<br>
<br>
there is a bug in DefaultVectorPixelAccessor
(ITK 4.4.0):<br>
<br>
void SetVectorLength(VectorLengthType l)<br>
{<br>
m_VectorLength = l;<br>
m_OffsetMultiplier = ( l - 1 );<br>
}<br>
<br>
DefaultVectorPixelAccessor(VectorLengthType
l)<br>
{<br>
m_VectorLength = l;<br>
m_OffsetMultiplier = l - 1;<br>
}<br>
<br>
OffsetMultiplier should be
m_OffsetMultiplier = l;<br>
<br>
Best regards,<br>
Jan<br>
<br>
</blockquote>
<br>
_______________________________________________<br>
Community mailing list<br>
<a moz-do-not-send="true" href="mailto:Community@itk.org" target="_blank">Community@itk.org</a><br>
<a moz-do-not-send="true" href="http://public.kitware.com/cgi-bin/mailman/listinfo/community" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</div>
_______________________________________________<br>
Community mailing list<br>
<a moz-do-not-send="true" href="mailto:Community@itk.org">Community@itk.org</a><br>
<a class="moz-txt-link-freetext" href="http://public.kitware.com/cgi-bin/mailman/listinfo/community">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</div>
</blockquote></div><br></div></body></html>