Iterating through the pixels in the EMData object

In your Python script you can use commands like this to iterate through the pixels in an EMData object

   1 a = test_image()
   2 for k in xrange(a["nz"]):
   3     for j in xrange(a["ny"]):
   4         for i in xrange(a["nx"]):
   5             pixel_value = a[i,j,k] # get the pixel value
   6             a[i,j,k]=pixel_value*3 # set the pixel value

Note that you can do any of:

   1 a[x]
   2 a[x,y]
   3 a[x,y,z]
   4 a[attr_name]

The fourth form allows getting and setting attributes equivalent to set_attr() and get_attr().

EMAN2/Tutorials/iter_pixels (last edited 2015-08-14 22:11:14 by SteveLudtke)