This script is intended for a series of photographs with (on each photgraph different) unwanted objects on it, e.g. a large place with moving people.
V1.1 works with rectangular selections!
The plugin creates a new layer or a new image consisting of the arithmetical, geometrical or harmonic mean of every pixel, thereby creating a 'ghost effect' of the moving objects.
If rather you want to remove objects, choose the 'cutoff' function, which removes outlier pixels after sorting the RGB values. This is also known as winsorizing. Also median and mode remove outliers, but less efficiently.
For best results, try to cutoff only on dark, bright or on both sides.
Working on selections only greatly improves speed. Just make a rectangular selection in your image and then call the "Average Layer" script.
This was inspired by reports of a friend of mine on a Photoshop plugin, which also removes unwanted objects from a series of photographs. I haven't seen it myself nor do I know the algorithm behind it. If someone knows better algorithms than winsorizing means, tips are welcome!
You need Scipy, a scientific computing package for python. Get it at the Scipy homepage.
Before:
After arithmetical mean with 67% cutoff (dark outlier pixels):
Some shades are still left, one might correct this quite easily with other tools.
Attachment | Size |
---|---|
Iron_Teddy_1.jpg | 5.14 KB |
Iron_Teddy_Arithmetical_Mean_Cutoff_dark.jpg | 1.69 KB |
average_layer.py | 8.7 KB |
Comments
Cannlot Load the plugin
Hi I am trying to use your plugin, on Gimp2.8. I installed Scipy. but something is wrong.
Here is the detail of the error :
Querying plug-in: '/home/louis/.gimp-2.8/plug-ins/average_layer.py'
Traceback (most recent call last):
File "/home/louis/.gimp-2.8/plug-ins/average_layer.py", line 32, in
from scipy.stats.stats import mode, gmean, hmean, median
ImportError: cannot import name median
(gimp:22229): LibGimpBase-WARNING **: gimp: gimp_wire_read(): error
Terminating plug-in: '/home/louis/.gimp-2.8/plug-ins/average_layer.py'
Do you see something I can do to fix this ?
How to make this work with Gimp 2.8, Win32
I got it to work, though I can't say it was worth the trouble for this plugin alone - it won't work on large images, but you wouldn't want it to because it is, unfortunately, very, very slow in its main appeal (median averaging) and the result is only so-so. See bottom of post for alternatives.
If you want to try it anyway, here's the steps, starting from a setup where only The GIMP was installed. Note that I have no idea what I'm doing, this is just what resulted in the plugin working - there may be more appropriate steps. Single quotes should not be entered in code, paths, etc.
"/Filters/Layer Tools/A_verage Layer",
to
"A_verage Layer",
do_the_work)
to
do_the_work,
menu="/Filters/Layer Tools/")
from scipy.stats.stats import median
fails. GIMP will simply say the plugin crashed. I do not know why. But thankfully you can replace median with nanmedian, which is the same function but ignores NaN values. Those don't exist in our context (gimp image data), so that's fine.from scipy.stats.stats import mode, gmean, hmean, median
to
from scipy.stats.stats import mode, gmean, hmean, nanmedian
self.meanarray=median(self.sarray)
to
self.meanarray=nanmedian(self.sarray)
[PF_RADIO, "meantype", "Choose mean method", "arith", (
add these lines:[PF_IMAGE, "image", "Input image", None],
[PF_DRAWABLE, "drawable", "Input drawable", None],
After that, this plugin should work - as far as I tested it. Here's some pitfalls:
This is not a jab at the author - it does what it's supposed to and its processing prowess is subject to the limits of the system. But if you're really looking for a utility that will keep same-y areas between images(/layers), discarding the outliers, you'd do well to look elsewhere.
Can't numpy and scipy just be
Can't numpy and scipy just be unpacked into the site-packages directory of GIMP's own Python? Even if they come as installer packages in a .exe file, a reasonably capable archiving application - e.g. 7-zip - might be able to unpack them.
Quite possibly - I believe
Quite possibly - I believe there are plain .zip files available as well, though I was just going by what was mentioned here;"install scipy". On the other hand, if you're installing Python and all that anyway, then you might as well have numpy/scipy available 'officially' for whatever other Python things you might install, rather than just GIMP.
error in median filter?
File "C:\Program Files\GIMP-2.0\lib\gimp\2.0\plug-ins\average_layer.py", line 205, in do_the_work working_class.export() File "C:\Program Files\GIMP-2.0\lib\gimp\2.0\plug-ins\average_layer.py", line 183, in export self.write_out(meanlayer, self.meanarray) File "C:\Program Files\GIMP-2.0\lib\gimp\2.0\plug-ins\average_layer.py", line 95, in write_out assert(byte_image.size == self.selection_width * self.selection_height * self.bpp) AssertionError
-> heeelp... Edit: it seems that this line returns an empty array:self.meanarray=median(self.sarray)
Image size?
installation
Installation
:-(
Installation
Pages