This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 8890b06aa3269a9a264cf339ff402a746594fb16 (commit) via 43bc4241af8b359fcaf7c9cf088602f57ef22bc9 (commit) via 7ef8350018a08f4e825deac1f6079375b3f74b74 (commit) from 34e163b7791258eea5d8a0fc467e84f983e4273c (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/8890b06aa3269a9a264cf339ff402a746594f...
commit 8890b06aa3269a9a264cf339ff402a746594fb16 Author: Cyril Hrubis metan@ucw.cz Date: Sat Nov 9 21:12:13 2013 +0100
doc: Update/Add convolution docs.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/example_py_convolution.txt b/doc/example_py_convolution.txt new file mode 100644 index 0000000..0cdfe06 --- /dev/null +++ b/doc/example_py_convolution.txt @@ -0,0 +1,8 @@ +Block Blur Convolution Example +------------------------------ +.A simple program that loads image, blurs it and saves result + +[source,python] +------------------------------------------------------------------ +include::../demos/py_simple/convolution.py[] +------------------------------------------------------------------ diff --git a/doc/filters.txt b/doc/filters.txt index 93a2888..8cedbf9 100644 --- a/doc/filters.txt +++ b/doc/filters.txt @@ -458,8 +458,8 @@ into two one dimensional kernels (these when combined yields back the original kernel). Such convolution then could be applied as two one dimensional convolutions which is faster operation (especially for big kernels).
-Generic Linear Convolution -^^^^^^^^^^^^^^^^^^^^^^^^^^ +Bilinear Convolution +^^^^^^^^^^^^^^^^^^^^
Following paragraph describes linear convolution implementation as well as a little of the math background skip it if you just need to use one of the @@ -521,6 +521,8 @@ O(x,y)={1 over kern_div} cdot
NOTE: The number of kernel rows and columns is expected to be odd number.
+include::images/convolution/images.txt[] + [source,c] ------------------------------------------------------------------------------- #include <filters/GP_Linear.h> diff --git a/doc/filters_python.txt b/doc/filters_python.txt index 1d374e3..f1a438a 100644 --- a/doc/filters_python.txt +++ b/doc/filters_python.txt @@ -270,6 +270,60 @@ image:laplacian_edge_sharpening.png["Laplacian Edge Sharpening"]
include::images/edge_sharpening/images.txt[]
+Convolution +~~~~~~~~~~~ + +[source,python] +------------------------------------------------------------------------------- +import gfxprim.core as core +import gfxprim.filters as filters + + # Does in-place bilinear convolution with 3x3 box blur kernel + filters.Convolution(img, img, [[1, 1, 1], + [1, 1, 1], + [1, 1, 1]], 9, callback=None) + + # Does bilinear convolution with 3x3 box blur kernel. + # + # The image data from source starting at 20,20 of a size 250x250 are + # stored at 100,100 in res. + filters.ConvolutionEx(img, 20, 20, 250, 250, res, 100, 100, + [[1, 1, 1], + [1, 1, 1], + [1, 1, 1]], 9, callback=None) + + # Returns newly allocated image convolution with Laplacian 3x3 kernel + res = img.filters.ConvolutionAlloc([[ 0.00, -0.25, 0.00], + [-0.25, 1.00, -0.25], + [ 0.00, -0.25, 0.00]], + 1, callback=None) + + # Returns newly allocated subimage convolution with Sobel 3x3 kernel + res = img.filters.ConvolutionExAlloc(50, 50, 100, 100, + [[ 1, 0, -1], + [ 2, 0, -2], + [ 1, 0, -1]], 1, callback=None) +------------------------------------------------------------------------------- + +Bilinear convolution. The kernel is specified as two dimensional array of +numbers, the second number is divisor of the kernel weighed sum of pixels. + +//// +Generated in filters.txt +//// + +The pixel value is computed as: +image:discrete_linear_convolution_alg1.png["Bilinear Convolution"] + +Which is the same as: +image:discrete_linear_convolution_alg2.png["Bilinear Convolution"] + +NOTE: The number of kernel rows and columns is expected to be odd number. + +TIP: See link:example_py_convolution.html[convolution example]. + + +include::images/convolution/images.txt[]
Blurs ~~~~~
http://repo.or.cz/w/gfxprim.git/commit/43bc4241af8b359fcaf7c9cf088602f57ef22...
commit 43bc4241af8b359fcaf7c9cf088602f57ef22bc9 Author: Cyril Hrubis metan@ucw.cz Date: Sat Nov 9 20:54:26 2013 +0100
doc: Add Convolution examples to image generator.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/images/Makefile b/doc/images/Makefile index 76c4501..4762f35 100644 --- a/doc/images/Makefile +++ b/doc/images/Makefile @@ -1,7 +1,7 @@ -SUBDIRS=blur median edge_sharpening gaussian_noise +SUBDIRS=$(dir $(wildcard */images.txt))
-TARGETS=$(addsuffix /images.txt,$(SUBDIRS)) -IMGS=$(addsuffix /*.png,$(SUBDIRS)) +TARGETS=$(addsuffix images.txt,$(SUBDIRS)) +IMGS=$(addsuffix *.png,$(SUBDIRS))
all: $(TARGETS)
diff --git a/doc/images/blur/images.txt b/doc/images/blur/images.txt index 2c0d697..28113c0 100644 --- a/doc/images/blur/images.txt +++ b/doc/images/blur/images.txt @@ -2,19 +2,19 @@ image:images/orig/lenna_small.png[ "Original Image", link="images/orig/lenna.png"] -image:images/blur/lenna_small_2_2.png[ +image:images/blur/lenna_small_2,2.png[ "Gaussian Blur 2 2", - link="images/blur/lenna_2_2.png"] -image:images/blur/lenna_small_0_4.png[ + link="images/blur/lenna_2,2.png"] +image:images/blur/lenna_small_0,4.png[ "Gaussian Blur 0 4", - link="images/blur/lenna_0_4.png"] -image:images/blur/lenna_small_4_0.png[ + link="images/blur/lenna_0,4.png"] +image:images/blur/lenna_small_4,0.png[ "Gaussian Blur 4 0", - link="images/blur/lenna_4_0.png"] -image:images/blur/lenna_small_4_4.png[ + link="images/blur/lenna_4,0.png"] +image:images/blur/lenna_small_4,4.png[ "Gaussian Blur 4 4", - link="images/blur/lenna_4_4.png"] -image:images/blur/lenna_small_10_10.png[ + link="images/blur/lenna_4,4.png"] +image:images/blur/lenna_small_10,10.png[ "Gaussian Blur 10 10", - link="images/blur/lenna_10_10.png"] + link="images/blur/lenna_10,10.png"]
diff --git a/doc/images/brightness_contrast/images.txt b/doc/images/brightness_contrast/images.txt index 85812c3..f6412ef 100644 --- a/doc/images/brightness_contrast/images.txt +++ b/doc/images/brightness_contrast/images.txt @@ -2,16 +2,16 @@ image:images/orig/lenna_small.png[ "Original Image", link="images/orig/lenna.png"] -image:images/brightness_contrast/lenna_small_-0.2_0.8.png[ +image:images/brightness_contrast/lenna_small_-0.2,0.8.png[ "BrightnessContrast -0.2 0.8", - link="images/brightness_contrast/lenna_-0.2_0.8.png"] -image:images/brightness_contrast/lenna_small_-0.5_2.png[ + link="images/brightness_contrast/lenna_-0.2,0.8.png"] +image:images/brightness_contrast/lenna_small_-0.5,2.png[ "BrightnessContrast -0.5 2", - link="images/brightness_contrast/lenna_-0.5_2.png"] -image:images/brightness_contrast/lenna_small_0.2_0.8.png[ + link="images/brightness_contrast/lenna_-0.5,2.png"] +image:images/brightness_contrast/lenna_small_0.2,0.8.png[ "BrightnessContrast 0.2 0.8", - link="images/brightness_contrast/lenna_0.2_0.8.png"] -image:images/brightness_contrast/lenna_small_0.2_1.5.png[ + link="images/brightness_contrast/lenna_0.2,0.8.png"] +image:images/brightness_contrast/lenna_small_0.2,1.5.png[ "BrightnessContrast 0.2 1.5", - link="images/brightness_contrast/lenna_0.2_1.5.png"] + link="images/brightness_contrast/lenna_0.2,1.5.png"]
diff --git a/doc/images/brightness_contrast/lenna_0.2_0.5.png b/doc/images/brightness_contrast/lenna_0.2_0.5.png deleted file mode 100644 index 611122d..0000000 Binary files a/doc/images/brightness_contrast/lenna_0.2_0.5.png and /dev/null differ diff --git a/doc/images/brightness_contrast/lenna_0.4_0.5.png b/doc/images/brightness_contrast/lenna_0.4_0.5.png deleted file mode 100644 index 68cb7b1..0000000 Binary files a/doc/images/brightness_contrast/lenna_0.4_0.5.png and /dev/null differ diff --git a/doc/images/brightness_contrast/lenna_small_0.2_0.5.png b/doc/images/brightness_contrast/lenna_small_0.2_0.5.png deleted file mode 100644 index 6752bfb..0000000 Binary files a/doc/images/brightness_contrast/lenna_small_0.2_0.5.png and /dev/null differ diff --git a/doc/images/brightness_contrast/lenna_small_0.4_0.5.png b/doc/images/brightness_contrast/lenna_small_0.4_0.5.png deleted file mode 100644 index b6af555..0000000 Binary files a/doc/images/brightness_contrast/lenna_small_0.4_0.5.png and /dev/null differ diff --git a/doc/images/contrast/lenna_0.1.png b/doc/images/contrast/lenna_0.1.png deleted file mode 100644 index 9f20010..0000000 Binary files a/doc/images/contrast/lenna_0.1.png and /dev/null differ diff --git a/doc/images/contrast/lenna_4.png b/doc/images/contrast/lenna_4.png deleted file mode 100644 index ca033c8..0000000 Binary files a/doc/images/contrast/lenna_4.png and /dev/null differ diff --git a/doc/images/contrast/lenna_small_0.1.png b/doc/images/contrast/lenna_small_0.1.png deleted file mode 100644 index 529a120..0000000 Binary files a/doc/images/contrast/lenna_small_0.1.png and /dev/null differ diff --git a/doc/images/contrast/lenna_small_4.png b/doc/images/contrast/lenna_small_4.png deleted file mode 100644 index c8537e4..0000000 Binary files a/doc/images/contrast/lenna_small_4.png and /dev/null differ diff --git a/doc/images/convolution/images.txt b/doc/images/convolution/images.txt new file mode 100644 index 0000000..cf82020 --- /dev/null +++ b/doc/images/convolution/images.txt @@ -0,0 +1,20 @@ +.Original Image; 3x3 Box Blur, 5x5 Box Blur, 3x3 Laplacian, 3x3 Sobel, 3x3 Roberts +image:images/orig/lenna_small.png[ + "Original Image", + link="images/orig/lenna.png"] +image:images/convolution/lenna_small_(1,1,1)(1,1,1)(1,1,1),9.png[ + "3x3 Box Blur", + link="images/convolution/lenna_(1,1,1)(1,1,1)(1,1,1),9.png"] +image:images/convolution/lenna_small_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png[ + "5x5 Box Blur", + link="images/convolution/lenna_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png"] +image:images/convolution/lenna_small_(0,-1,0)(-1,4,-1)(0,-1,0),1.png[ + "3x3 Laplacian", + link="images/convolution/lenna_(0,-1,0)(-1,4,-1)(0,-1,0),1.png"] +image:images/convolution/lenna_small_(1,0,-1)(2,0,-2)(1,0,-1),1.png[ + "3x3 Sobel", + link="images/convolution/lenna_(1,0,-1)(2,0,-2)(1,0,-1),1.png"] +image:images/convolution/lenna_small_(0,0,0)(1,-1,0)(0,0,0),1.png[ + "3x3 Roberts", + link="images/convolution/lenna_(0,0,0)(1,-1,0)(0,0,0),1.png"] + diff --git a/doc/images/convolution/lenna_(0,-1,0)(-1,4,-1)(0,-1,0),1.png b/doc/images/convolution/lenna_(0,-1,0)(-1,4,-1)(0,-1,0),1.png new file mode 100644 index 0000000..cfd3fd9 Binary files /dev/null and b/doc/images/convolution/lenna_(0,-1,0)(-1,4,-1)(0,-1,0),1.png differ diff --git a/doc/images/convolution/lenna_(0,0,0)(1,-1,0)(0,0,0),1.png b/doc/images/convolution/lenna_(0,0,0)(1,-1,0)(0,0,0),1.png new file mode 100644 index 0000000..9da5f24 Binary files /dev/null and b/doc/images/convolution/lenna_(0,0,0)(1,-1,0)(0,0,0),1.png differ diff --git a/doc/images/convolution/lenna_(1,0,-1)(2,0,-2)(1,0,-1),1.png b/doc/images/convolution/lenna_(1,0,-1)(2,0,-2)(1,0,-1),1.png new file mode 100644 index 0000000..8db35ea Binary files /dev/null and b/doc/images/convolution/lenna_(1,0,-1)(2,0,-2)(1,0,-1),1.png differ diff --git a/doc/images/convolution/lenna_(1,1,1)(1,1,1)(1,1,1),9.png b/doc/images/convolution/lenna_(1,1,1)(1,1,1)(1,1,1),9.png new file mode 100644 index 0000000..d271e37 Binary files /dev/null and b/doc/images/convolution/lenna_(1,1,1)(1,1,1)(1,1,1),9.png differ diff --git a/doc/images/convolution/lenna_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png b/doc/images/convolution/lenna_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png new file mode 100644 index 0000000..b0b4e60 Binary files /dev/null and b/doc/images/convolution/lenna_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png differ diff --git a/doc/images/convolution/lenna_small_(0,-1,0)(-1,4,-1)(0,-1,0),1.png b/doc/images/convolution/lenna_small_(0,-1,0)(-1,4,-1)(0,-1,0),1.png new file mode 100644 index 0000000..17764a0 Binary files /dev/null and b/doc/images/convolution/lenna_small_(0,-1,0)(-1,4,-1)(0,-1,0),1.png differ diff --git a/doc/images/convolution/lenna_small_(0,0,0)(1,-1,0)(0,0,0),1.png b/doc/images/convolution/lenna_small_(0,0,0)(1,-1,0)(0,0,0),1.png new file mode 100644 index 0000000..95ced2e Binary files /dev/null and b/doc/images/convolution/lenna_small_(0,0,0)(1,-1,0)(0,0,0),1.png differ diff --git a/doc/images/convolution/lenna_small_(1,0,-1)(2,0,-2)(1,0,-1),1.png b/doc/images/convolution/lenna_small_(1,0,-1)(2,0,-2)(1,0,-1),1.png new file mode 100644 index 0000000..299c4f4 Binary files /dev/null and b/doc/images/convolution/lenna_small_(1,0,-1)(2,0,-2)(1,0,-1),1.png differ diff --git a/doc/images/convolution/lenna_small_(1,1,1)(1,1,1)(1,1,1),9.png b/doc/images/convolution/lenna_small_(1,1,1)(1,1,1)(1,1,1),9.png new file mode 100644 index 0000000..be202b1 Binary files /dev/null and b/doc/images/convolution/lenna_small_(1,1,1)(1,1,1)(1,1,1),9.png differ diff --git a/doc/images/convolution/lenna_small_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png b/doc/images/convolution/lenna_small_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png new file mode 100644 index 0000000..d498a09 Binary files /dev/null and b/doc/images/convolution/lenna_small_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png differ diff --git a/doc/images/gaussian_noise/images.txt b/doc/images/gaussian_noise/images.txt index a173f04..54781e3 100644 --- a/doc/images/gaussian_noise/images.txt +++ b/doc/images/gaussian_noise/images.txt @@ -2,19 +2,19 @@ image:images/orig/lenna_small.png[ "Original Image", link="images/orig/lenna.png"] -image:images/gaussian_noise/lenna_small_0.03_0.png[ +image:images/gaussian_noise/lenna_small_0.03,0.png[ "Gaussian Additive Noise 0.03 0", - link="images/gaussian_noise/lenna_0.03_0.png"] -image:images/gaussian_noise/lenna_small_0.05_0.png[ + link="images/gaussian_noise/lenna_0.03,0.png"] +image:images/gaussian_noise/lenna_small_0.05,0.png[ "Gaussian Additive Noise 0.05 0", - link="images/gaussian_noise/lenna_0.05_0.png"] -image:images/gaussian_noise/lenna_small_0.05_-0.1.png[ + link="images/gaussian_noise/lenna_0.05,0.png"] +image:images/gaussian_noise/lenna_small_0.05,-0.1.png[ "Gaussian Additive Noise 0.05 -0.1", - link="images/gaussian_noise/lenna_0.05_-0.1.png"] -image:images/gaussian_noise/lenna_small_0.05_0.1.png[ + link="images/gaussian_noise/lenna_0.05,-0.1.png"] +image:images/gaussian_noise/lenna_small_0.05,0.1.png[ "Gaussian Additive Noise 0.05 0.1", - link="images/gaussian_noise/lenna_0.05_0.1.png"] -image:images/gaussian_noise/lenna_small_0.07_0.0.png[ + link="images/gaussian_noise/lenna_0.05,0.1.png"] +image:images/gaussian_noise/lenna_small_0.07,0.0.png[ "Gaussian Additive Noise 0.07 0.0", - link="images/gaussian_noise/lenna_0.07_0.0.png"] + link="images/gaussian_noise/lenna_0.07,0.0.png"]
diff --git a/doc/images/gaussian_noise/lenna_0.02_0.png b/doc/images/gaussian_noise/lenna_0.02_0.png deleted file mode 100644 index dbdd21a..0000000 Binary files a/doc/images/gaussian_noise/lenna_0.02_0.png and /dev/null differ diff --git a/doc/images/gaussian_noise/lenna_small_0.02_0.png b/doc/images/gaussian_noise/lenna_small_0.02_0.png deleted file mode 100644 index c658937..0000000 Binary files a/doc/images/gaussian_noise/lenna_small_0.02_0.png and /dev/null differ diff --git a/doc/images/median/images.txt b/doc/images/median/images.txt index f656ca8..5def1a3 100644 --- a/doc/images/median/images.txt +++ b/doc/images/median/images.txt @@ -2,19 +2,19 @@ image:images/orig/lenna_small.png[ "Original Image", link="images/orig/lenna.png"] -image:images/median/lenna_small_3_3.png[ +image:images/median/lenna_small_3,3.png[ "Median 3 3", - link="images/median/lenna_3_3.png"] -image:images/median/lenna_small_5_5.png[ + link="images/median/lenna_3,3.png"] +image:images/median/lenna_small_5,5.png[ "Median 5 5", - link="images/median/lenna_5_5.png"] -image:images/median/lenna_small_7_7.png[ + link="images/median/lenna_5,5.png"] +image:images/median/lenna_small_7,7.png[ "Median 7 7", - link="images/median/lenna_7_7.png"] -image:images/median/lenna_small_9_9.png[ + link="images/median/lenna_7,7.png"] +image:images/median/lenna_small_9,9.png[ "Median 9 9", - link="images/median/lenna_9_9.png"] -image:images/median/lenna_small_12_12.png[ + link="images/median/lenna_9,9.png"] +image:images/median/lenna_small_12,12.png[ "Median 12 12", - link="images/median/lenna_12_12.png"] + link="images/median/lenna_12,12.png"]
diff --git a/doc/images/regen.py b/doc/images/regen.py index 6aaeb34..3e01756 100755 --- a/doc/images/regen.py +++ b/doc/images/regen.py @@ -6,13 +6,39 @@ import gfxprim.core as core import gfxprim.loaders as loaders import gfxprim.filters as filters
+def str_esc(x): + res = str(x) + if (res[0] == '-'): + res = '' + res + return res + +def to_str(x, to_str): + res = '' + if hasattr(x, '__iter__'): + for i in x: + if hasattr(i, '__iter__'): + res += ('(') + first = 1 + for j in i: + if (first): + first = 0 + else: + res += ',' + res += to_str(j) + res += (')') + else: + res += ('(' + to_str(i)+ ')') + else: + return to_str(x) + + return res + class ImgGen: def __init__(self, orig_path): self.orig_path = orig_path self.img = loaders.Load('../' + orig_path + 'lenna.png') self.img_small = loaders.Load('../' + orig_path + 'lenna_small.png')
- def write_asciidoc_head(self, dst_path, heading): self.f = open('../' + dst_path + 'images.txt', 'w') f = self.f @@ -31,29 +57,39 @@ class ImgGen: self.f.write('n') self.f.close()
- def gen(self, func, func_param_desc, func_params_arr, dst_path, func_name): + def gen(self, func, func_param_desc, func_params_arr, dst_path, func_name, descs=None):
print("Generating " + func_name)
- self.write_asciidoc_head(dst_path, func_name + ' ' + - ', '.join(map(lambda x: ' '.join([func_param_desc[i] + '=' + - str(x[i]) for i in range(0, len(x))]), func_params_arr))) + head = func_name + ' ' + head += ', '.join(map(lambda x: ' '.join([func_param_desc[i] + '=' + + str(x[i]) for i in range(0, len(x))]), func_params_arr)) + + if (descs is not None): + head = ', '.join(descs) + + self.write_asciidoc_head(dst_path, head) + + for i in range(0, len(func_params_arr)): + params = func_params_arr[i] + str_pars = [to_str(x, str) for x in params]
- for i in func_params_arr: - str_i = [str(x) for x in i] - desc = func_name + ' ' + ' '.join(str_i) + if (descs is not None): + desc = descs[i] + else: + desc = func_name + ' ' + ' '.join(str_pars)
print(' > ' + desc)
- fname = dst_path + 'lenna_' + '_'.join(str_i) + '.png' - fname_small = dst_path + 'lenna_small_' + '_'.join(str_i) + '.png' + fname = dst_path + 'lenna_' + ','.join(str_pars) + '.png' + fname_small = dst_path + 'lenna_small_' + ','.join(str_pars) + '.png'
self.write_img_asciidoc(desc, fname, fname_small)
- res = func(self.img, *i) + res = func(self.img, *params) res.loaders.Save('../' + fname)
- res = func(self.img_small, *i) + res = func(self.img_small, *params) res.loaders.Save('../' + fname_small)
self.write_asciidoc_tail() @@ -63,59 +99,86 @@ def main():
imggen.gen(filters.InvertAlloc, [], [[]], - 'images/invert/', 'Inverted') + 'images/invert/', 'Inverted')
imggen.gen(filters.BrightnessAlloc, ['p'], [[-.5], [-.2], [.2], [.5]], - 'images/brightness/', 'Brightness') + 'images/brightness/', 'Brightness')
imggen.gen(filters.ContrastAlloc, ['p'], [[.2], [.5], [1.5], [2], [3]], - 'images/contrast/', 'Contrast') + 'images/contrast/', 'Contrast')
imggen.gen(filters.BrightnessContrastAlloc, ['b', 'c'], [[-.2, .8], [-.5, 2], [.2, .8], [.2, 1.5]], - 'images/brightness_contrast/', 'BrightnessContrast') + 'images/brightness_contrast/', 'BrightnessContrast')
imggen.gen(filters.PosterizeAlloc, ['s'], [[2], [3], [4], [5], [6]], - 'images/posterize/', 'Posterize') + 'images/posterize/', 'Posterize')
imggen.gen(filters.MirrorHAlloc, [], [[]], - 'images/mirror_h/', 'Mirrored Horizontally') + 'images/mirror_h/', 'Mirrored Horizontally')
imggen.gen(filters.MirrorVAlloc, [], [[]], - 'images/mirror_v/', 'Mirrored Vertically') + 'images/mirror_v/', 'Mirrored Vertically')
imggen.gen(filters.Rotate90Alloc, [], [[]], - 'images/rotate_90/', 'Rotated by 90 degrees') + 'images/rotate_90/', 'Rotated by 90 degrees')
imggen.gen(filters.Rotate180Alloc, [], [[]], - 'images/rotate_180/', 'Rotated by 180 degrees') + 'images/rotate_180/', 'Rotated by 180 degrees')
imggen.gen(filters.Rotate270Alloc, [], [[]], - 'images/rotate_270/', 'Rotated by 270 degrees') + 'images/rotate_270/', 'Rotated by 270 degrees')
imggen.gen(filters.GaussianBlurAlloc, ['xsig', 'ysig'], [[2, 2], [0, 4], [4, 0], [4, 4], [10, 10]], - 'images/blur/', 'Gaussian Blur') + 'images/blur/', 'Gaussian Blur')
imggen.gen(filters.MedianAlloc, ['xr', 'yr'], [[3, 3], [5, 5], [7, 7], [9, 9], [12, 12]], - 'images/median/', 'Median') + 'images/median/', 'Median')
imggen.gen(filters.EdgeSharpeningAlloc, ['w'], [[0.1], [0.3], [0.5], [0.8], [1.0]], - 'images/edge_sharpening/', 'Edge Sharpening') + 'images/edge_sharpening/', 'Edge Sharpening')
imggen.gen(filters.GaussianNoiseAddAlloc, ['s', 'm'], [[0.03, 0], [0.05, 0], [0.05, -0.1], [0.05, 0.1], [0.07, 0.0]], - 'images/gaussian_noise/', 'Gaussian Additive Noise') + 'images/gaussian_noise/', 'Gaussian Additive Noise') + + imggen.gen(filters.ConvolutionAlloc, ['k', 'kd'], + [ + [[[1, 1, 1], + [1, 1, 1], + [1, 1, 1]], 9], + [[[1, 1, 1, 1, 1], + [1, 1, 1, 1, 1], + [1, 1, 1, 1, 1], + [1, 1, 1, 1, 1], + [1, 1, 1, 1, 1]], 25], + [[[ 0, -1, 0], + [-1, 4, -1], + [ 0, -1, 0]], 1], + [[[1, 0, -1], + [2, 0, -2], + [1, 0, -1]], 1], + [[[0, 0, 0], + [1, -1, 0], + [0, 0, 0]], 1], + ], + 'images/convolution/', 'Convolution', + ['3x3 Box Blur', + '5x5 Box Blur', + '3x3 Laplacian', + '3x3 Sobel', + '3x3 Roberts'])
if __name__ == '__main__': main()
http://repo.or.cz/w/gfxprim.git/commit/7ef8350018a08f4e825deac1f6079375b3f74...
commit 7ef8350018a08f4e825deac1f6079375b3f74b74 Author: Cyril Hrubis metan@ucw.cz Date: Sat Nov 9 17:57:43 2013 +0100
pywrap: Add wrapping around Convolution kernel
Now the python bindings converts python two dimensional array into GP_FilterKernel2D structure, yay!
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/py_simple/convolution.py b/demos/py_simple/convolution.py new file mode 100755 index 0000000..3dbc975 --- /dev/null +++ b/demos/py_simple/convolution.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +import sys + +import gfxprim.core as core +import gfxprim.loaders as loaders +import gfxprim.filters as filters + +def main(): + if len(sys.argv) != 2: + print("usage: convolution.py image") + sys.exit(1) + + # Load Image + img = loaders.Load(sys.argv[1]) + # Box blur kernel + kern = [[1, 1, 1, 1, 1], + [1, 1, 1, 1, 1], + [1, 1, 1, 1, 1], + [1, 1, 1, 1, 1], + [1, 1, 1, 1, 1]] + res = img.filters.ConvolutionAlloc(kern, 25); + # Save result into png + res.loaders.SavePNG("out.png") + +if __name__ == '__main__': + main() diff --git a/demos/py_simple/invert.py b/demos/py_simple/invert.py index 84a5b6f..684facc 100755 --- a/demos/py_simple/invert.py +++ b/demos/py_simple/invert.py @@ -14,7 +14,7 @@ def main(): img = loaders.Load(sys.argv[1]) # Invert image in-place img.filters.Invert(img); - # Save result into grayscale png + # Save result into png img.loaders.SavePNG("out.png")
if __name__ == '__main__': diff --git a/pylib/gfxprim/filters/__init__.py b/pylib/gfxprim/filters/__init__.py index d8bdd97..1ac3acb 100644 --- a/pylib/gfxprim/filters/__init__.py +++ b/pylib/gfxprim/filters/__init__.py @@ -10,7 +10,7 @@ from . import c_filters def _init(module): "Extend Context with filters submodule"
- from ..utils import extend_submodule + from ..utils import extend, extend_submodule from ..core import Context as _context
# New Context submodule @@ -44,6 +44,94 @@ def _init(module): 'HilbertPeano', 'HilbertPeanoAlloc']: extend_submodule(FiltersSubmodule, name, c_filters.__getattribute__('GP_Filter' + name))
+ def array_to_kern(kernel, kernel_div): + h = len(kernel) + w = len(kernel[0]) + + # Assert that array is matrix of numbers + for i in range(0, h): + assert(len(kernel[i]) == w) + + for j in kernel[i]: + assert(isinstance(j, float) or isinstance(j, int)) + + # flatten the python array into C array + karr = c_filters.new_float_array(w * h) + + for i in range(0, h): + for j in range(0, w): + c_filters.float_array_setitem(karr, i * w + j, kernel[i][j]) + + kern = c_filters.GP_FilterKernel2D(w, h, karr, kernel_div) + + return kern + + def array_del(kern): + c_filters.delete_float_array(kern.kernel) + + def Convolution(src, dst, kernel, kernel_div, callback=None): + """ + Convolution(src, dst, kernel, kernel_div, callback=None) + + Bilinear convolution. The kernel is two dimensional array of coefficients, + kern_div is used to divide the kernel weigthed sum. + """ + kern = array_to_kern(kernel, kernel_div) + ret = c_filters.GP_FilterConvolution(src, dst, kern, callback) + array_del(kern) + return ret + + extend_submodule(FiltersSubmodule, 'Convolution', Convolution) + + def ConvolutionEx(src, x_src, y_src, w_src, h_src, dst, x_dst, y_dst, + kernel, kernel_div, callback=None): + """ + ConvolutionEx(src, x_src, y_src, w_src, h_src, dst, x_dst, y_dst, + kernel, kernel_div, callback=None) + + Bilinear convolution. The kernel is two dimensional array of coefficients, + kern_div is used to divide the kernel weigthed sum. + """ + kern = array_to_kern(kernel, kernel_div); + ret = c_filters.GP_FilterConvolutionEx(src, x_src, y_src, + w_src, h_src, dst, x_dst, y_dst, + kern, callback) + array_del(kern) + return ret + + extend_submodule(FiltersSubmodule, 'ConvolutionEx', ConvolutionEx) + + def ConvolutionAlloc(src, kernel, kernel_div, callback=None): + """ + ConvolutionAlloc(src, kernel, kernel_div, callback=None) + + Bilinear convolution. The kernel is two dimensional array of coefficients, + kern_div is used to divide the kernel weigthed sum. + """ + kern = array_to_kern(kernel, kernel_div); + ret = c_filters.GP_FilterConvolutionAlloc(src, kern, callback) + array_del(kern) + return ret + + extend_submodule(FiltersSubmodule, 'ConvolutionAlloc', ConvolutionAlloc) + + def ConvolutionExAlloc(src, x_src, y_src, w_src, h_src, + kernel, kernel_div, callback=None): + """ + ConvolutionExAlloc(src, x_src, y_src, w_src, h_src, + kernel, kernel_div, callback=None) + + Bilinear convolution. The kernel is two dimensional array of coefficients, + kern_div is used to divide the kernel weigthed sum. + """ + kern = array_to_kern(kernel, kernel_div); + ret = c_filters.GP_FilterConvolutionExAlloc(src, x_src, y_src, + w_src, h_src, kern, callback) + array_del(kern) + return ret + + extend_submodule(FiltersSubmodule, 'ConvolutionExAlloc', ConvolutionExAlloc) + # Imports from the SWIG module import re def strip_GP_Filter(s): @@ -57,5 +145,10 @@ def _init(module): '^GP_Filter[A-Za-z0-9]*$', ])
+ module['Convolution'] = Convolution + module['ConvolutionAlloc'] = ConvolutionAlloc + module['ConvolutionEx'] = ConvolutionEx + module['ConvolutionExAlloc'] = ConvolutionExAlloc + _init(locals()) del _init diff --git a/pylib/gfxprim/filters/filters.i b/pylib/gfxprim/filters/filters.i index 9bd6daf..8bec204 100644 --- a/pylib/gfxprim/filters/filters.i +++ b/pylib/gfxprim/filters/filters.i @@ -1,5 +1,6 @@ %include "../common.i" %module(package="gfxprim.filters") c_filters +%include "carrays.i"
%{ #include "filters/GP_Filters.h" @@ -17,17 +18,6 @@ ERROR_ON_NULL(GP_Filter ## funcname ## Alloc); ERROR_ON_NONZERO(GP_Filter ## funcname); %enddef
-/* Listed in GP_Filters.h: */ -%extend GP_FilterParam { - ~GP_FilterParam() { - GP_DEBUG(2, "[wrapper] GP_FilterParamFree"); - GP_FilterParamDestroy($self); - } -} - -%newobject GP_FilterParamCreate; -%include "GP_FilterParam.h" - FILTER_FUNC(Invert); FILTER_FUNC(Brightness); FILTER_FUNC(Contrast); @@ -58,6 +48,32 @@ FILTER_FUNC(Symmetry); /* Convolutions */ FILTER_FUNC(Convolution); FILTER_FUNC(ConvolutionEx); + +%array_functions(float, float_array); + +%extend GP_FilterKernel2D { + ~GP_FilterKernel2D() { + free($self); + } + GP_FilterKernel2D(unsigned int w, unsigned int h, + float *kern, float kern_div) { + + GP_FilterKernel2D *kernel = malloc(sizeof(GP_FilterKernel2D)); + + if (!kernel) { + GP_DEBUG(1, "Malloc failed :("); + return NULL; + } + + kernel->w = w; + kernel->h = h; + kernel->div = kern_div; + kernel->kernel = kern; + + return kernel; + } +}; + %include "GP_Convolution.h"
/* Blur */
-----------------------------------------------------------------------
Summary of changes: demos/py_simple/{dither.py => convolution.py} | 13 ++- demos/py_simple/invert.py | 2 +- ...mple_py_blur.txt => example_py_convolution.txt} | 6 +- doc/filters.txt | 6 +- doc/filters_python.txt | 54 +++++++++ doc/images/Makefile | 6 +- doc/images/blur/images.txt | 20 ++-- doc/images/blur/{lenna_0_4.png => lenna_0,4.png} | Bin 236705 -> 236705 bytes .../blur/{lenna_10_10.png => lenna_10,10.png} | Bin 143058 -> 143058 bytes doc/images/blur/{lenna_2_2.png => lenna_2,2.png} | Bin 229699 -> 229699 bytes doc/images/blur/{lenna_4_0.png => lenna_4,0.png} | Bin 231739 -> 231739 bytes doc/images/blur/{lenna_4_4.png => lenna_4,4.png} | Bin 178703 -> 178703 bytes .../{lenna_small_0_4.png => lenna_small_0,4.png} | Bin 19492 -> 19492 bytes ...lenna_small_10_10.png => lenna_small_10,10.png} | Bin 10638 -> 10638 bytes .../{lenna_small_2_2.png => lenna_small_2,2.png} | Bin 18849 -> 18849 bytes .../{lenna_small_4_0.png => lenna_small_4,0.png} | Bin 18565 -> 18565 bytes .../{lenna_small_4_4.png => lenna_small_4,4.png} | Bin 14816 -> 14816 bytes doc/images/brightness_contrast/images.txt | 16 ++-- .../{lenna_-0.2_0.8.png => lenna_-0.2,0.8.png} | Bin 288118 -> 288118 bytes .../{lenna_-0.5_2.png => lenna_-0.5,2.png} | Bin 330382 -> 330382 bytes .../{lenna_0.2_0.8.png => lenna_0.2,0.8.png} | Bin 372199 -> 372199 bytes .../{lenna_0.2_1.5.png => lenna_0.2,1.5.png} | Bin 388546 -> 388546 bytes doc/images/brightness_contrast/lenna_0.2_0.5.png | Bin 313679 -> 0 bytes doc/images/brightness_contrast/lenna_0.4_0.5.png | Bin 314067 -> 0 bytes ...small_-0.2_0.8.png => lenna_small_-0.2,0.8.png} | Bin 24114 -> 24114 bytes ...nna_small_-0.5_2.png => lenna_small_-0.5,2.png} | Bin 26923 -> 26923 bytes ...a_small_0.2_0.8.png => lenna_small_0.2,0.8.png} | Bin 30145 -> 30145 bytes ...a_small_0.2_1.5.png => lenna_small_0.2,1.5.png} | Bin 30713 -> 30713 bytes .../brightness_contrast/lenna_small_0.2_0.5.png | Bin 26101 -> 0 bytes .../brightness_contrast/lenna_small_0.4_0.5.png | Bin 26099 -> 0 bytes doc/images/contrast/lenna_0.1.png | Bin 161387 -> 0 bytes doc/images/contrast/lenna_4.png | Bin 222137 -> 0 bytes doc/images/contrast/lenna_small_0.1.png | Bin 14173 -> 0 bytes doc/images/contrast/lenna_small_4.png | Bin 18249 -> 0 bytes doc/images/convolution/images.txt | 20 ++++ .../lenna_(0,-1,0)(-1,4,-1)(0,-1,0),1.png | Bin 0 -> 375033 bytes .../convolution/lenna_(0,0,0)(1,-1,0)(0,0,0),1.png | Bin 0 -> 285516 bytes .../lenna_(1,0,-1)(2,0,-2)(1,0,-1),1.png | Bin 0 -> 412063 bytes .../convolution/lenna_(1,1,1)(1,1,1)(1,1,1),9.png | Bin 0 -> 312990 bytes ...,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png | Bin 0 -> 260462 bytes .../lenna_small_(0,-1,0)(-1,4,-1)(0,-1,0),1.png | Bin 0 -> 25284 bytes .../lenna_small_(0,0,0)(1,-1,0)(0,0,0),1.png | Bin 0 -> 23982 bytes .../lenna_small_(1,0,-1)(2,0,-2)(1,0,-1),1.png | Bin 0 -> 26170 bytes .../lenna_small_(1,1,1)(1,1,1)(1,1,1),9.png | Bin 0 -> 24041 bytes ...,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png | Bin 0 -> 21102 bytes doc/images/gaussian_noise/images.txt | 20 ++-- doc/images/gaussian_noise/lenna_0.02_0.png | Bin 499974 -> 0 bytes .../{lenna_0.03_0.png => lenna_0.03,0.png} | Bin 534481 -> 534481 bytes .../{lenna_0.05_-0.1.png => lenna_0.05,-0.1.png} | Bin 595526 -> 595526 bytes .../{lenna_0.05_0.1.png => lenna_0.05,0.1.png} | Bin 600660 -> 600660 bytes .../{lenna_0.05_0.png => lenna_0.05,0.png} | Bin 597194 -> 597194 bytes .../{lenna_0.07_0.0.png => lenna_0.07,0.0.png} | Bin 640739 -> 640739 bytes doc/images/gaussian_noise/lenna_small_0.02_0.png | Bin 35601 -> 0 bytes ...nna_small_0.03_0.png => lenna_small_0.03,0.png} | Bin 36875 -> 36875 bytes ...all_0.05_-0.1.png => lenna_small_0.05,-0.1.png} | Bin 39579 -> 39579 bytes ...small_0.05_0.1.png => lenna_small_0.05,0.1.png} | Bin 39898 -> 39898 bytes ...nna_small_0.05_0.png => lenna_small_0.05,0.png} | Bin 39680 -> 39680 bytes ...small_0.07_0.0.png => lenna_small_0.07,0.0.png} | Bin 41654 -> 41654 bytes doc/images/median/images.txt | 20 ++-- .../median/{lenna_12_12.png => lenna_12,12.png} | Bin 174531 -> 174531 bytes doc/images/median/{lenna_3_3.png => lenna_3,3.png} | Bin 259580 -> 259580 bytes doc/images/median/{lenna_5_5.png => lenna_5,5.png} | Bin 224934 -> 224934 bytes doc/images/median/{lenna_7_7.png => lenna_7,7.png} | Bin 204463 -> 204463 bytes doc/images/median/{lenna_9_9.png => lenna_9,9.png} | Bin 190419 -> 190419 bytes ...lenna_small_12_12.png => lenna_small_12,12.png} | Bin 15174 -> 15174 bytes .../{lenna_small_3_3.png => lenna_small_3,3.png} | Bin 20584 -> 20584 bytes .../{lenna_small_5_5.png => lenna_small_5,5.png} | Bin 18652 -> 18652 bytes .../{lenna_small_7_7.png => lenna_small_7,7.png} | Bin 17299 -> 17299 bytes .../{lenna_small_9_9.png => lenna_small_9,9.png} | Bin 16276 -> 16276 bytes doc/images/regen.py | 115 +++++++++++++++----- pylib/gfxprim/filters/__init__.py | 95 ++++++++++++++++- pylib/gfxprim/filters/filters.i | 38 +++++-- 72 files changed, 342 insertions(+), 89 deletions(-) copy demos/py_simple/{dither.py => convolution.py} (52%) copy doc/{example_py_blur.txt => example_py_convolution.txt} (66%) rename doc/images/blur/{lenna_0_4.png => lenna_0,4.png} (100%) rename doc/images/blur/{lenna_10_10.png => lenna_10,10.png} (100%) rename doc/images/blur/{lenna_2_2.png => lenna_2,2.png} (100%) rename doc/images/blur/{lenna_4_0.png => lenna_4,0.png} (100%) rename doc/images/blur/{lenna_4_4.png => lenna_4,4.png} (100%) rename doc/images/blur/{lenna_small_0_4.png => lenna_small_0,4.png} (100%) rename doc/images/blur/{lenna_small_10_10.png => lenna_small_10,10.png} (100%) rename doc/images/blur/{lenna_small_2_2.png => lenna_small_2,2.png} (100%) rename doc/images/blur/{lenna_small_4_0.png => lenna_small_4,0.png} (100%) rename doc/images/blur/{lenna_small_4_4.png => lenna_small_4,4.png} (100%) rename doc/images/brightness_contrast/{lenna_-0.2_0.8.png => lenna_-0.2,0.8.png} (100%) rename doc/images/brightness_contrast/{lenna_-0.5_2.png => lenna_-0.5,2.png} (100%) rename doc/images/brightness_contrast/{lenna_0.2_0.8.png => lenna_0.2,0.8.png} (100%) rename doc/images/brightness_contrast/{lenna_0.2_1.5.png => lenna_0.2,1.5.png} (100%) delete mode 100644 doc/images/brightness_contrast/lenna_0.2_0.5.png delete mode 100644 doc/images/brightness_contrast/lenna_0.4_0.5.png rename doc/images/brightness_contrast/{lenna_small_-0.2_0.8.png => lenna_small_-0.2,0.8.png} (100%) rename doc/images/brightness_contrast/{lenna_small_-0.5_2.png => lenna_small_-0.5,2.png} (100%) rename doc/images/brightness_contrast/{lenna_small_0.2_0.8.png => lenna_small_0.2,0.8.png} (100%) rename doc/images/brightness_contrast/{lenna_small_0.2_1.5.png => lenna_small_0.2,1.5.png} (100%) delete mode 100644 doc/images/brightness_contrast/lenna_small_0.2_0.5.png delete mode 100644 doc/images/brightness_contrast/lenna_small_0.4_0.5.png delete mode 100644 doc/images/contrast/lenna_0.1.png delete mode 100644 doc/images/contrast/lenna_4.png delete mode 100644 doc/images/contrast/lenna_small_0.1.png delete mode 100644 doc/images/contrast/lenna_small_4.png create mode 100644 doc/images/convolution/images.txt create mode 100644 doc/images/convolution/lenna_(0,-1,0)(-1,4,-1)(0,-1,0),1.png create mode 100644 doc/images/convolution/lenna_(0,0,0)(1,-1,0)(0,0,0),1.png create mode 100644 doc/images/convolution/lenna_(1,0,-1)(2,0,-2)(1,0,-1),1.png create mode 100644 doc/images/convolution/lenna_(1,1,1)(1,1,1)(1,1,1),9.png create mode 100644 doc/images/convolution/lenna_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png create mode 100644 doc/images/convolution/lenna_small_(0,-1,0)(-1,4,-1)(0,-1,0),1.png create mode 100644 doc/images/convolution/lenna_small_(0,0,0)(1,-1,0)(0,0,0),1.png create mode 100644 doc/images/convolution/lenna_small_(1,0,-1)(2,0,-2)(1,0,-1),1.png create mode 100644 doc/images/convolution/lenna_small_(1,1,1)(1,1,1)(1,1,1),9.png create mode 100644 doc/images/convolution/lenna_small_(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1)(1,1,1,1,1),25.png delete mode 100644 doc/images/gaussian_noise/lenna_0.02_0.png rename doc/images/gaussian_noise/{lenna_0.03_0.png => lenna_0.03,0.png} (100%) rename doc/images/gaussian_noise/{lenna_0.05_-0.1.png => lenna_0.05,-0.1.png} (100%) rename doc/images/gaussian_noise/{lenna_0.05_0.1.png => lenna_0.05,0.1.png} (100%) rename doc/images/gaussian_noise/{lenna_0.05_0.png => lenna_0.05,0.png} (100%) rename doc/images/gaussian_noise/{lenna_0.07_0.0.png => lenna_0.07,0.0.png} (100%) delete mode 100644 doc/images/gaussian_noise/lenna_small_0.02_0.png rename doc/images/gaussian_noise/{lenna_small_0.03_0.png => lenna_small_0.03,0.png} (100%) rename doc/images/gaussian_noise/{lenna_small_0.05_-0.1.png => lenna_small_0.05,-0.1.png} (100%) rename doc/images/gaussian_noise/{lenna_small_0.05_0.1.png => lenna_small_0.05,0.1.png} (100%) rename doc/images/gaussian_noise/{lenna_small_0.05_0.png => lenna_small_0.05,0.png} (100%) rename doc/images/gaussian_noise/{lenna_small_0.07_0.0.png => lenna_small_0.07,0.0.png} (100%) rename doc/images/median/{lenna_12_12.png => lenna_12,12.png} (100%) rename doc/images/median/{lenna_3_3.png => lenna_3,3.png} (100%) rename doc/images/median/{lenna_5_5.png => lenna_5,5.png} (100%) rename doc/images/median/{lenna_7_7.png => lenna_7,7.png} (100%) rename doc/images/median/{lenna_9_9.png => lenna_9,9.png} (100%) rename doc/images/median/{lenna_small_12_12.png => lenna_small_12,12.png} (100%) rename doc/images/median/{lenna_small_3_3.png => lenna_small_3,3.png} (100%) rename doc/images/median/{lenna_small_5_5.png => lenna_small_5,5.png} (100%) rename doc/images/median/{lenna_small_7_7.png => lenna_small_7,7.png} (100%) rename doc/images/median/{lenna_small_9_9.png => lenna_small_9,9.png} (100%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.