If I have a numpy array like so:
[[[137 153 135]
[138 154 136]
[138 153 138]
...,
[134 159 153]
[136 159 153]
[135 158 152]]
...,
[ 57 44 34]
[ 55 47 37]
[ 55 47 37]]]
How can I apply a function to each [000 000 000] entry, modifying it?
# a = numpy array
for x in a:
for y in x:
y = modify(y)
What I'd like to achieve is modifying each (r,g,b) pixel in a PIL image that was converted to a numpy array.
y
there is your rgb array, isn't it?or more generally:
A simple answer to your question is
This won't be very efficient, though. An efficient solution should avoid Python loops over all pixels. (That's somehow what NumPy is all about -- vectorise your code!) A vectorised version for the case at hand would be