if you really want to use what you write, then check out these methods to map a function to an array (mapping is what your “somefunction” would mean):
But I would not use that, the easiest and fastest way of greyscaling I know using the mean would be this one line:
images_g = np.mean(images, -1)
At least for your example above it looks identical (looking at the pics with plt.imshow() ) and is fully vectorized = fast, faster than mapping your python function (which is irrelevant for 2 pics, but I assume that’s not your usecase…)
Thanks to the link, it seems this should be on par with the fastest method:
images_g = np.array([to_grayscale(images[i]) for i in range(images.shape[0])])
Please let me know if there is a more elegant way to do this (except for np.mean which is great for the specific case where I don’t ever need to change the 0.333 values in the function).
Having a numpy -> fastai Image and vice versa would be helpful without and file save, or file open… if there is a one line way of doing this please let me know!