Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp, python, and numpy
#1
Numpy is one of the things that makes Python an "in" language according to this StackOverflow blog. But it can also be used outside of data science. In practice it is a very efficient vector/matrix library and so is well suited to process image data.

Together with the ability to extract "pixel regions" with the Gimp python API, some pretty fast processing can be written quickly. See attached script for some exemples: median/average filter (the median filter is almost twice as fast as the one in GMIC), and an implementation of Color>Desaturate>Luminosity. If done properly, there are no loops in Python, all the pixel iteration is done by the numpy code on native data.

Of course, you have to add the numpy module to the python runtime used by Gimp. Very easily done in Linux... it could be more complicated to do on Windows/OSX, but not impossible.

Edit: updated the script 2017-12-05 (now uses 2D rectangular color planes instead of single vector ones)


Attached Files
.zip   numpyops.zip (Size: 1.23 KB / Downloads: 731)
Reply
#2
Im afraid i dont understand what this is doing.

Can i put this file in my plug-is folder ?
Reply
#3
You can, but if you didn't add the numpy module to the python runtime used by Gimp, you won't go very far.

This is more a code example than a real-life plugin. Numpy>Luminosity will do the same thing as Color>Desaturate (there are minute differences due to round-off errors), and Numpy>Average/Median computes the average or median of the visible layers. GMIC also does it...
Reply
#4
Question: How exactly, in Windows, would someone add the Numpy module to Gimp's python runtime? Does it involve a virtualenv or is it more complicated or (hopefully) more straightforward than that to do so? Unfortunately I haven't got around to learning too much about python just yet, but hope to resolve that soon.. Smile

cheers
Reply
#5
Normally you should be able to

  1. Add the python executable which comes with Gimp to your general Windows path (once this is done you have a "python" command available in the command prompt.
  2. Install PIP s indicated there:  (AFAIK Gimp's Python should be >= 2.7.9 so PIP could there already, otherwise, follow the indications).
  3. Download Numpy as indicated there.
Reply
#6
it would be really nice if some windows expert will post a text tutorial with all really detailed steps to have numpy installed on windows 10.
Reply
#7
(12-07-2017, 08:57 AM)dinasset Wrote: it would be really nice if some windows expert will post a text tutorial with all really detailed steps to have numpy installed on windows 10.

Only two steps required:
  • Install Ubuntu
  • "apt install python numpy" (or maybe even mark it installable in step 1)
Why should it be more complicated?  Angel
Reply
#8
Thanks Ofnuts, did a pip install of numpy, and sure enough "Requirement already satisfied:..", so as everything is in place as it should be, I have a system wide python PATH doo-dah so that comes up on command prompt - but don't think I did that specific first step, so will try that later and see how I get on, thanks.
Reply
#9
Ofnuts, I asked for an installation in Windows 10, I know you hate Windows; not me.
Reply
#10
(12-06-2017, 11:26 PM)Ofnuts Wrote: Normally you should be able to

  1. Add the python executable which comes with Gimp to your general Windows path (once this is done you have a "python" command available in the command prompt.
  2. Install PIP s indicated there:  (AFAIK Gimp's Python should be >= 2.7.9 so PIP could there already, otherwise, follow the indications).
  3. Download Numpy as indicated there.

My problem is I don't really know what I'm doing, well, i tried putting the path to the Gimp python executable in my "User variables" - (see pic) is that right or what should it be?
 Also is the numpy version I have correct? I have (installed with pip):- numpy-1.13.3 and it's in "C:\Python27\Lib\site-packages\.. " is that right? Or should I install it with pip via the wheel i.e. '"numpy-1.13.3+mkl-cp27-cp27m-win_amd64.whl'? Thanks.

   
Reply


Forum Jump: