title: SimpleITK - How to increment/decrement the value of every Pixel in an Image efficiently?
body: <p>I wanted to know if there is an efficient way of incrementing or decrementing the value of every pixel in an ITK-Image-Object by 1.</p>
  
  <pre><code>def increment_image(image,value):
  imageSize = image.GetSize()
  for z in range(imageSize[2]):
      for y in range(imageSize[1]):
          for x in range(imageSize[0]):
              if (image.GetPixel(x,y,z) + value) &gt;  255:
                  image.SetPixel(x,y,z,255)
              else:
                  image.SetPixel(x,y,z,image.GetPixel(x,y,z)+value)
  </code></pre>
  
  <p>This is the way i made it up, basically it's just looping trough every pixel of my 3D Image and adds 1 to the value....</p>
  
  <p>This works but is highly inefficient, an 512x512x25 sized image takes about 10 minutes on my machine and it should work with images sizes way bigger than that, soo maybe you guys have ideas :)</p>
  
  <p>Thanks for your help :)</p>
  
  <p>PS: No third party libraries out of SITK / NumPy please :)</p>