Iterating over an image in python
<p>I would like to iterate over an image in python. 
This is my code so far:</p>

<pre><code>def imageIteration(greyValueImage):
    for (x,y), pixel in np.ndenumerate(greyValueImage):
        vals = greyValueImage[x, y]
        print(vals)
</code></pre>

<p>The problem here ist that I get the following exception:</p>

<pre><code>for (x,y), pixel in np.ndenumerate(greyValueImage):
ValueError: too many values to unpack
</code></pre>

<p>Now my question is what is the fastest way to solve this?
Do I really need to split the image into a few peaces, but taking this step how do I get the count of the necessary loops without trying out?</p>

<p>Thanks for Your ideas </p>

<p>P.s.
im = Image.open(args["image"])
im_grey = im.convert('LA') # convert to grayscale</p>

<p>You can of course just use a for loop to iterate over each pixel. An example is shown below:</p>

<pre><code># assuming greyValueImage is a numpy array

rows, cols = greyValueImage.shape() # get the shape of the array
for x in range (cols):
    for y in range (rows):
        vals = greyValueImage[x,y]
        print (vals)
</code></pre>

<p>Using a simple array for an example:</p>

<pre><code>random_array = np.random.randint(0,2,(3,4))
rows, cols = random_array.shape

print (random_array)

for x in range(cols):
    for y in range(rows):
        print (random_array[y,x])
</code></pre>

<p>Running the example produces the output:</p>

<pre><code>[[0 1 1 0]
 [0 0 1 0]
 [1 0 1 0]]

0
0
1
1
0
0
1
1
1
0
0
0
</code></pre>

python image loops for-loop iteration