4 The python binding maps mostly to the C API with the 'GP_Filter' prefix
7 The filter functions could be called directly as +filters.Foo(img, ..)+ or
8 from submodule as +img.filters.Foo(..)+. Note that in the second case the
9 image is passed automatically as a first parameter.
11 If filter has been aborted from callback 'OSError' with 'errno' set to
12 'ECANCELED' is raised.
21 -------------------------------------------------------------------------------
22 import gfxprim.core as core
23 import gfxprim.filters as filters
25 # Inverts image in-place
26 img.filters.Invert(img, callback=None)
28 # Returns newly allocated inverted image
29 res = img.filters.InvertAlloc(callback=None)
31 -------------------------------------------------------------------------------
33 The pixel channel values are counted as +chann_max - val+.
35 include::images/invert/images.txt[]
41 -------------------------------------------------------------------------------
42 import gfxprim.core as core
43 import gfxprim.filters as filters
45 # Increses images brightness in-place by channel_max * 0.2
46 img.filters.Brightness(img, 0.2, callback=None)
48 # Returns image with brightness decreased by channel_max * -0.5
49 res = img.filters.BrightnessAlloc(img, -0.5, callback=None)
51 -------------------------------------------------------------------------------
53 The pixel channel values are counted as +val + chann_max * p+.
55 include::images/brightness/images.txt[]
61 -------------------------------------------------------------------------------
62 import gfxprim.core as core
63 import gfxprim.filters as filters
65 # Increses images contrast by 1.2
66 img.filters.Contrast(img, 1.2, callback=None)
68 # Returns image with contrast decreased by 0.2
69 res = img.filters.ContrastAlloc(img, 0.2, callback=None)
71 -------------------------------------------------------------------------------
73 The pixel channel values are counted as +val * p+.
75 include::images/contrast/images.txt[]
81 -------------------------------------------------------------------------------
82 import gfxprim.core as core
83 import gfxprim.filters as filters
85 # Increses images contrast by 1.2 decreases brightness by -0.2
86 img.filters.BrightnessContrast(img, -0.2, 1.2, callback=None)
88 # Returns image with contrast decreased by 0.2 brightness increased by .5
89 res = img.filters.BrightnessContrastAlloc(img, 0.5, 0.2, callback=None)
91 -------------------------------------------------------------------------------
93 The pixel channel values are counted as +val * c + chann_max * b+.
95 include::images/brightness_contrast/images.txt[]
101 -------------------------------------------------------------------------------
102 import gfxprim.core as core
103 import gfxprim.filters as filters
105 # Posterizes image using 2 steps
106 img.filters.Posterize(img, 2, callback=None)
108 # Returns image posterized into 4 levels
109 res = img.filters.PosterizeAlloc(img, 4, callback=None)
111 -------------------------------------------------------------------------------
113 The pixel channel values are quantized into number of levels.
115 include::images/posterize/images.txt[]
117 Rotations and Mirroring
118 ~~~~~~~~~~~~~~~~~~~~~~~
124 -------------------------------------------------------------------------------
125 import gfxprim.core as core
126 import gfxprim.filters as filters
128 # Mirrors in-place image horizontally
129 img.filters.MirrorH(img, callback=None)
131 # Mirrors image horizontally
132 res = img.filters.MirrorHAlloc(callback=None)
134 -------------------------------------------------------------------------------
136 Mirrors image horizontally.
138 include::images/mirror_h/images.txt[]
144 -------------------------------------------------------------------------------
145 import gfxprim.core as core
146 import gfxprim.filters as filters
148 # Mirrors in-place image vertically
149 img.filters.MirrorV(img, callback=None)
151 # Mirrors image vertically
152 res = img.filters.MirrorVAlloc(callback=None)
154 -------------------------------------------------------------------------------
156 Mirrors image vertically.
158 include::images/mirror_v/images.txt[]
164 -------------------------------------------------------------------------------
165 import gfxprim.core as core
166 import gfxprim.filters as filters
168 # Rotate in-place by 90 degrees
169 img.filters.Rotate90(img, callback=None)
171 # Rotate by 90 degrees
172 res = img.filters.Rotate90Alloc(callback=None)
174 -------------------------------------------------------------------------------
176 Rotate image by 90 degrees clockwise.
178 include::images/rotate_90/images.txt[]
184 -------------------------------------------------------------------------------
185 import gfxprim.core as core
186 import gfxprim.filters as filters
188 # Rotate in-place by 180 degrees
189 img.filters.Rotate180(img, callback=None)
191 # Rotate by 180 degrees
192 res = img.filters.Rotate180Alloc(callback=None)
194 -------------------------------------------------------------------------------
196 Rotate image by 180 degrees clockwise.
198 include::images/rotate_180/images.txt[]
204 -------------------------------------------------------------------------------
205 import gfxprim.core as core
206 import gfxprim.filters as filters
208 # Rotate in-place by 270 degrees
209 img.filters.Rotate270(img, callback=None)
211 # Rotate by 270 degrees
212 res = img.filters.Rotate270Alloc(callback=None)
214 -------------------------------------------------------------------------------
216 Rotate image by 270 degrees clockwise.
218 include::images/rotate_270/images.txt[]
220 Gaussian Additive Noise
221 ~~~~~~~~~~~~~~~~~~~~~~~
224 -------------------------------------------------------------------------------
225 import gfxprim.core as core
226 import gfxprim.filters as filters
228 # Adds Gaussian noise in-place with sigma=0.2 mu=0.0
229 filters.GaussianNoiseAdd(img, img, 0.2, 0.0, callback=None)
231 # Returns newly allocated noisy image
232 res = img.filters.GaussianNoiseAddAlloc(0.2, 0.0, callback=None)
234 -------------------------------------------------------------------------------
236 Gaussian additive noise filter adds gaussian distributed noise to an image
237 with a defined sigma and mu. Both sigma and mu weights mapped to '[0,1]'
240 include::images/gaussian_noise/images.txt[]
243 Laplacian Edge Sharpening
244 ~~~~~~~~~~~~~~~~~~~~~~~~~
247 -------------------------------------------------------------------------------
248 import gfxprim.core as core
249 import gfxprim.filters as filters
251 # Does in-place Edge Sharpening
252 filters.EdgeSharpening(img, img, 0.2, callback=None)
254 # Returns newly allocated sharpened image
255 res = img.filters.EdgeSharpening(0.2, callback=None)
257 -------------------------------------------------------------------------------
259 Laplace based edge sharpening filter, subtracts weighted second derivative
260 from the original image.
262 The float paramerter is multiplicative weight applied on the second
263 derivative. Reasonable results are when the parameter is between '0.1' and
267 Generated in filters.txt
269 image:laplacian_edge_sharpening.png["Laplacian Edge Sharpening"]
271 include::images/edge_sharpening/images.txt[]
277 -------------------------------------------------------------------------------
278 import gfxprim.core as core
279 import gfxprim.filters as filters
281 # Does in-place bilinear convolution with 3x3 box blur kernel
282 filters.Convolution(img, img, [[1, 1, 1],
284 [1, 1, 1]], 9, callback=None)
286 # Does bilinear convolution with 3x3 box blur kernel.
288 # The image data from source starting at 20,20 of a size 250x250 are
289 # stored at 100,100 in res.
290 filters.ConvolutionEx(img, 20, 20, 250, 250, res, 100, 100,
293 [1, 1, 1]], 9, callback=None)
295 # Returns newly allocated image convolution with Laplacian 3x3 kernel
296 res = img.filters.ConvolutionAlloc([[ 0.00, -0.25, 0.00],
297 [-0.25, 1.00, -0.25],
298 [ 0.00, -0.25, 0.00]],
301 # Returns newly allocated subimage convolution with Sobel 3x3 kernel
302 res = img.filters.ConvolutionExAlloc(50, 50, 100, 100,
305 [ 1, 0, -1]], 1, callback=None)
306 -------------------------------------------------------------------------------
308 Bilinear convolution. The kernel is specified as two dimensional array of
309 numbers, the second number is divisor of the kernel weighed sum of pixels.
312 Generated in filters.txt
315 The pixel value is computed as:
316 image:discrete_linear_convolution_alg1.png["Bilinear Convolution"]
318 Which is the same as:
319 image:discrete_linear_convolution_alg2.png["Bilinear Convolution"]
321 NOTE: The number of kernel rows and columns is expected to be odd number.
323 TIP: See link:example_py_convolution.html[convolution example].
326 include::images/convolution/images.txt[]
332 -------------------------------------------------------------------------------
333 import gfxprim.core as core
334 import gfxprim.filters as filters
336 # Does in-place Gaussian blur, the image is modified in-place
337 filters.GaussianBlur(img, img, x_sigma, y_sigma, callback=None)
339 # Returns newly alocated blurred image
340 res = img.filters.GaussianBlur(x_sigma, y_sigma, callback=None)
342 -------------------------------------------------------------------------------
344 Gaussian blur (low pass) filters implemented as bilinear separable
347 TIP: See link:example_py_blur.html[blur example].
349 include::images/blur/images.txt[]
355 -------------------------------------------------------------------------------
356 import gfxprim.core as core
357 import gfxprim.filters as filters
359 # Returns img dithered to 1-bit Grayscale as a new image
360 res = img.filters.FloydSteinbergAlloc(core.C.PIXEL_G1, callback=None)
362 # Returns img dithered to 1-bit Grayscale as a new image
363 res = img.filters.HilbertPeanoAlloc(core.C.PIXEL_G1, callback=None)
365 -------------------------------------------------------------------------------
367 Returns new 1-bit Grayscale image which is result from Floyd-Steinberg,
368 Hilbert-Peano dithering.
370 The first parameter is pixel type, the second is progress callback.
372 For more information and example images see link:filters_dithering.html[C
373 dithering documentation].
375 TIP: See link:example_py_dithering.html[dithering example].
381 -------------------------------------------------------------------------------
382 import gfxprim.core as core
383 import gfxprim.filters as filters
385 # Returns result of median filter over a rectangle of a side 2 * 3 + 1 pixels
386 res = img.filters.MedianAlloc(3, 3, callback=None)
388 # Applies median filter in-place
389 img.filters.Median(3, 3, callback=None)
390 -------------------------------------------------------------------------------
392 Constant time median filter (the computational complexity is independent of
395 The parameters are radius values for x and y. The algorithm uses x
396 respectively y pixel neighbors from each side so the result is median of
397 rectangle of +2 * x + 1+ x +2 * y + 1+ pixels.
399 include::images/median/images.txt[]