I'm working on a python plugin for GIMP and I would like to obtain the RGB matrix of a layer as a numpy array. To access the layer in the python plugin I use the next code:
def python_function(img, layer):
layer = img.layers[0]
I would like to make layer
variable, instead of a gimp.Image variable, a numpy array containing, for each pixel, its RGB values. What I use in other nonGimp-python code is this next line: frame2 = misc.imread('C:\Users\User\Desktop\image2.png').astype(np.float32)
. If I print frame2
I get a matrix such as this one, containing for each pixel its RGB values:
[[[ 111. 179. 245.]
[ 111. 179. 245.]
[ 111. 179. 245.]
...,
[ 95. 162. 233.]
[ 95. 162. 233.]
[ 95. 162. 233.]]
[[ 111. 179. 245.]
[ 111. 179. 245.]
[ 111. 179. 245.]
...,
[ 95. 162. 233.]
[ 95. 162. 233.]
[ 95. 162. 233.]]
[[ 111. 179. 245.]
[ 111. 179. 245.]
[ 111. 179. 245.]
...,
[ 95. 162. 233.]
[ 95. 162. 233.]
[ 95. 162. 233.]]
...,
[ 113. 127. 123.]
[ 113. 127. 123.]
[ 113. 127. 123.]]
[[ 98. 112. 108.]
[ 98. 112. 108.]
[ 98. 112. 108.]
...,
[ 113. 127. 123.]
[ 113. 127. 123.]
[ 113. 127. 123.]]]
Is there any way to convert a gimp.Image type variable to a numpy array without saving it on a file and reloading it using Scipy?
Thanks.