[Insight-users] Getting a reference to a pixel from an iterator
David Doria
daviddoria at gmail.com
Mon Feb 28 09:37:12 EST 2011
On Mon, Feb 28, 2011 at 9:10 AM, Cory Quammen <cquammen at cs.unc.edu> wrote:
> David,
>
> The Get() method in the iterator makes a copy of the pixel value and
> returns it to the caller. This copy exists in a temporary variable,
> and you are taking the address of that copy (not the original), thus
> the warning. To my knowledge, there is no way to operate directly on
> the pixel value through the Get() method in the iterator.
>
> This should let you do what you are looking to do.
>
> PixelType pixel = imageIterator->Get();
> // modify pixel value
> imageIterator->Set(pixel);
>
> It's an extra line to set the new pixel value, but this is likely less
> error prone than operating on a reference to a pixel value.
>
> Cory
>
Thanks for confirming there is no way to do this. Using Set() won't work for
me - what I was trying to do was:
std::vector<PixelType*> pixels;
itk::ImageRegionIterator<ImageType> imageIterator =
itk::ImageRegionIterator<ImageType>(image, region);
while(!imageIterator.IsAtEnd())
{
if(someCondition(pixel))
pixels.push_back(&pixel);
}
ChangePixels(pixels);
How do you think a proposition of adding a GetAddress() function to the
iterators would go?
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110228/779921b9/attachment.htm>
More information about the Insight-users
mailing list