User Tools

Site Tools


eman2:tutorials_iter_pixels

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

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

Note that you can do any of:

a[x]
a[x,y]
a[x,y,z]
a[attr_name]

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

Alternatively, you can convert EMData objects to/from NumPy.

eman2/tutorials_iter_pixels.txt · Last modified: by steveludtke