[Insight-users] change every voxel value of a 3d image

Sergio Vera sergio.vera at alma3d.com
Mon May 17 10:08:49 EDT 2010


Hi Marco,
The correct way of traversing elements of a image in ITK is through
iterators:

typedef itk::ImageRegionIterator<TITKImgType> IteratorType;
IteratorType it(image,image->GetRequestedRegion());

for (it.GoToBegin(); !it.IsAtEnd(); ++it) {
  it.SetPixel(it.GetPixel()+100);
}

This is an example and I don't know if it will compile or not, but you get
the idea on how to use an iterator to traverse all image pixels. Not only
the code is much simpler but also faster.

For more info you can look at the itkSoftwareGuide, that has a part dealing
with iterators

Regards

On Mon, May 17, 2010 at 4:00 PM, Marco Gheza <
marcogheza4mailinglists at gmail.com> wrote:

> Hi,
> i'm trying to access every single voxel of a 3d image and change some
> values. In particular, i want to change that values that are not black;
> every value has to be increased by a value of 100 for example. If a voxel
> has value of 10, i want to give it value of 110.
>
> Here is my code:
>
> imageCT->DisconnectPipeline();
> for(i=0;i<512;i++)
>    {
> for(j=0;j<512;j++)
>  {
> for(k=0;k<311;k++)
> {
>  pixelIndex[0] = i;   // x position
> pixelIndex[1] = j;   // y position
>  pixelIndex[2] = k;   // z position
>
> ImageType::PixelType   pixelValuePT = imagePT->GetPixel( pixelIndex );
>
> ImageType::PixelType  newValue = pixelValueCT+100;
>
> if(pixelValueCT!=0)
>  {
> imageCT->SetPixel(   pixelIndex,   newValue  );
>  }
> }
> }
>    }
>
> This code doesn't do the work well. Do you know how to change it?
> Thank you,
> bye,
>
> Marco
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>


-- 
Sergio Vera

Alma IT Systems
C/ Vilana, 4B, 4º 1ª
08022 Barcelona
T. (+34) 932 380 592
www.alma3d.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100517/0808c9e1/attachment-0001.htm>


More information about the Insight-users mailing list