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 04f9434ac9e4649dba4c394b00187a7f1004b0a4 (commit) via dad06bc1a3ee9080149efdce008821be2ce64754 (commit) via b348a1d81f3a985f258b57a467827fafbc2923d9 (commit) from fc824cf87cc0e855dbbc14082dbd9cfd1d41045d (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/04f9434ac9e4649dba4c394b00187a7f1004b...
commit 04f9434ac9e4649dba4c394b00187a7f1004b0a4 Author: Cyril Hrubis metan@ucw.cz Date: Fri Jun 29 22:57:13 2012 +0200
doc: Add Laplace based filter docs.
diff --git a/doc/README b/doc/README index 8298f04..87e78a6 100644 --- a/doc/README +++ b/doc/README @@ -2,7 +2,7 @@ This directory contains asciidoc documentation.
The html pages are generated by typing 'make'.
-In order to do that asciidoc and source-highlight must be installed. +In order to do that asciidoc and source-highlight, latex and dvipng must be installed.
The pdf documentation could be generated by typing 'make api.pdf' for that fop diff --git a/doc/filters.txt b/doc/filters.txt index 1abf977..9f6c012 100644 --- a/doc/filters.txt +++ b/doc/filters.txt @@ -476,6 +476,112 @@ Catch all function for symmetry filters. Linear filters ~~~~~~~~~~~~~~
+Linear filters family consists of filters based on discrete linear +convolution, that means that computed pixel value depends on linear +combination of the image pixels. + +It's defined as: +[latex, discrete_linear_convolution.png, 140] +------------------------------------------------------------------------------- +[ +O(x,y)=sum_{i=-infty}^{infty}sum_{j=-infty}^{infty}I(x-i,y-j) cdot K(i,j) +] +------------------------------------------------------------------------------- + +The K denotes convolution kernel and in practice, due to computional +complexity, the i and j are bounded in relatively small intervals. For example +if i and j are in (-1,1) the kernel size is 3x3. + +Note that pixel values around the image cornes are undefined. The linear +convolution in GFXprim simply uses the corner pixel values for all pixels +outside the image. + +Particular convolution kernel is called separable if it could be decomposed +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). + +[source,c] +------------------------------------------------------------------------------- +#include <GP_Filters.h> +/* or */ +#include <GP.h> + +int GP_FilterLaplace(const GP_Context *src, GP_Context *dst, + GP_ProgressCallback *callback); + +GP_Context *GP_FilterLaplaceAlloc(const GP_Context *src, + GP_ProgressCallback *callback); +------------------------------------------------------------------------------- + +Discrete laplace filter that produces a second derivative of the original +image. + +The convolution kernel is defined as: + +[latex, laplacian_kernel.png, 130] +------------------------------------------------------------------------------- +[ +begin{bmatrix} +0 & 1 & 0 \ +0 & -2 & 0 \ +0 & 1 & 0 +end{bmatrix} ++ +begin{bmatrix} +0 & 0 & 0 \ +1 & -2 & 1 \ +0 & 0 & 0 +end{bmatrix} += +begin{bmatrix} +0 & 1 & 0 \ +1 & -4 & 1 \ +0 & 1 & 0 +end{bmatrix} +] +------------------------------------------------------------------------------- + +NOTE: This filter is not separable but could be written as a sum of two one + dimensional filters as the kernel definition suggests. + +[source,c] +------------------------------------------------------------------------------- +#include <GP_Filters.h> +/* or */ +#include <GP.h> + +int GP_FilterEdgeSharpening(const GP_Context *src, GP_Context *dst, + float w, GP_ProgressCallback *callback); + +GP_Context *GP_FilterEdgeSharpeningAlloc(const GP_Context *src, float w, + GP_ProgressCallback *callback); +------------------------------------------------------------------------------- + +Laplace based edge sharpening filter, substracts weighted second derivative +from the original image. + +[latex, laplacian_edge_sharpening.png, 140] +------------------------------------------------------------------------------- +[ +O(x,y) = I(x,y) - w * I''(x,y) +] +------------------------------------------------------------------------------- + +.Original Image; Edge Sharpening w=0.1, w=0.3, w=0.5 +image:images/dither/lenna_small.png[ + "Original Image", + link="images/dither/lenna.png"] +image:images/edge_sharpening/lenna_small_w_0_1.png[ + "Edge Sharpening w=0.1", + link="images/edge_sharpening/lenna_w_0_1.png"] +image:images/edge_sharpening/lenna_small_w_0_3.png[ + "Edge Sharpening w=0.5", + link="images/edge_sharpening/lenna_w_0_3.png"] +image:images/edge_sharpening/lenna_small_w_0_5.png[ + "Edge Sharpening w=0.5", + link="images/edge_sharpening/lenna_w_0_5.png"] + [source,c] ------------------------------------------------------------------------------- #include <GP_Filters.h> diff --git a/doc/images/edge_sharpening/lenna_small_w_0_1.png b/doc/images/edge_sharpening/lenna_small_w_0_1.png new file mode 100644 index 0000000..848ccea Binary files /dev/null and b/doc/images/edge_sharpening/lenna_small_w_0_1.png differ diff --git a/doc/images/edge_sharpening/lenna_small_w_0_3.png b/doc/images/edge_sharpening/lenna_small_w_0_3.png new file mode 100644 index 0000000..a311e36 Binary files /dev/null and b/doc/images/edge_sharpening/lenna_small_w_0_3.png differ diff --git a/doc/images/edge_sharpening/lenna_small_w_0_5.png b/doc/images/edge_sharpening/lenna_small_w_0_5.png new file mode 100644 index 0000000..46891b2 Binary files /dev/null and b/doc/images/edge_sharpening/lenna_small_w_0_5.png differ diff --git a/doc/images/edge_sharpening/lenna_w_0_1.png b/doc/images/edge_sharpening/lenna_w_0_1.png new file mode 100644 index 0000000..405291f Binary files /dev/null and b/doc/images/edge_sharpening/lenna_w_0_1.png differ diff --git a/doc/images/edge_sharpening/lenna_w_0_3.png b/doc/images/edge_sharpening/lenna_w_0_3.png new file mode 100644 index 0000000..4417327 Binary files /dev/null and b/doc/images/edge_sharpening/lenna_w_0_3.png differ diff --git a/doc/images/edge_sharpening/lenna_w_0_5.png b/doc/images/edge_sharpening/lenna_w_0_5.png new file mode 100644 index 0000000..0a9e7c9 Binary files /dev/null and b/doc/images/edge_sharpening/lenna_w_0_5.png differ
http://repo.or.cz/w/gfxprim.git/commit/dad06bc1a3ee9080149efdce008821be2ce64...
commit dad06bc1a3ee9080149efdce008821be2ce64754 Author: Cyril Hrubis metan@ucw.cz Date: Fri Jun 29 22:54:26 2012 +0200
filters: Fix the laplace filter (it's not separable, gah)
diff --git a/include/filters/GP_Laplace.h b/include/filters/GP_Laplace.h index e250cd6..ead7e6e 100644 --- a/include/filters/GP_Laplace.h +++ b/include/filters/GP_Laplace.h @@ -32,17 +32,30 @@ #include "GP_Filter.h"
/* - * Laplace, second-derivative filter. + * Discrete Laplace, second-derivative filter. + * + * Implemented by separable linear convolution with kernels + * + * [1 -2 1] and [ 1 ] + * [-2 ] + * [ 1 ] */ int GP_FilterLaplace(const GP_Context *src, GP_Context *dst, GP_ProgressCallback *callback);
+GP_Context *GP_FilterLaplaceAlloc(const GP_Context *src, + GP_ProgressCallback *callback); + /* * Laplace based filter sharpening. * - * The w is direct weight used to multiply the result. + * This filter substract result of Laplace filter weigted by w from the + * original image which amplifies edges. */ int GP_FilterEdgeSharpening(const GP_Context *src, GP_Context *dst, float w, GP_ProgressCallback *callback);
+GP_Context *GP_FilterEdgeSharpeningAlloc(const GP_Context *src, float w, + GP_ProgressCallback *callback); + #endif /* FILTERS_GP_LAPLACE_H */ diff --git a/libs/filters/GP_Laplace.c b/libs/filters/GP_Laplace.c index 3de0a97..b6a91a1 100644 --- a/libs/filters/GP_Laplace.c +++ b/libs/filters/GP_Laplace.c @@ -32,30 +32,71 @@ int GP_FilterLaplace(const GP_Context *src, GP_Context *dst, { GP_DEBUG(1, "Laplace filter %ux%u", src->w, src->h);
- float kern[3] = {1, -2, 1}; + float kern[9] = {0, 1, 0, + 1, -4, 1, + 0, 1, 0};
- if (GP_FilterVHLinearConvolution_Raw(src, dst, kern, 3, 1, - kern, 3, 1, callback)) + if (GP_FilterLinearConvolution_Raw(src, dst, kern, 3, 3, 1, callback)) return 1;
return 0; }
+GP_Context *GP_FilterLaplaceAlloc(const GP_Context *src, + GP_ProgressCallback *callback) +{ + GP_Context *ret = GP_ContextCopy(src, 0); + + if (ret == NULL) + return NULL; + + if (GP_FilterLaplace(src, ret, callback)) { + GP_ContextFree(ret); + return NULL; + } + + return ret; +} + + int GP_FilterEdgeSharpening(const GP_Context *src, GP_Context *dst, float w, GP_ProgressCallback *callback) { - float kern[3] = {0, 1, 0}; - + /* Identity kernel */ + float kern[9] = {0, 0, 0, + 0, 1, 0, + 0, 0, 0}; + GP_DEBUG(1, "Laplace Edge Sharpening filter %ux%u w=%f", src->w, src->h, w);
- kern[0] -= 1.00 * w; - kern[1] -= -2.00 * w; - kern[2] -= 1.00 * w; + /* Create combined kernel */ + kern[1] -= 1.00 * w; + kern[3] -= 1.00 * w; + kern[4] -= -4.00 * w; + kern[5] -= 1.00 * w; + kern[7] -= 1.00 * w;
- if (GP_FilterVHLinearConvolution_Raw(src, dst, kern, 3, 1, - kern, 3, 1, callback)) + GP_FilterKernelPrint(kern, 3, 3, 1); + + if (GP_FilterLinearConvolution_Raw(src, dst, kern, 3, 3, 1, callback)) return 1;
return 0; } + +GP_Context *GP_FilterEdgeSharpeningAlloc(const GP_Context *src, float w, + GP_ProgressCallback *callback) +{ + GP_Context *ret = GP_ContextCopy(src, 0); + + if (ret == NULL) + return NULL; + + if (GP_FilterEdgeSharpening(src, ret, w, callback)) { + GP_ContextFree(ret); + return NULL; + } + + return ret; +}
http://repo.or.cz/w/gfxprim.git/commit/b348a1d81f3a985f258b57a467827fafbc292...
commit b348a1d81f3a985f258b57a467827fafbc2923d9 Author: Cyril Hrubis metan@ucw.cz Date: Fri Jun 29 22:43:19 2012 +0200
filters: Added GP_FilterKernelPrint() function.
diff --git a/include/filters/GP_Linear.h b/include/filters/GP_Linear.h index 56be135..ba286ec 100644 --- a/include/filters/GP_Linear.h +++ b/include/filters/GP_Linear.h @@ -112,4 +112,9 @@ int GP_FilterVHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst, float vkernel[], uint32_t kh, float vkern_div, GP_ProgressCallback *callback);
+/* + * Prints a kernel into the stdout. + */ +void GP_FilterKernelPrint(float kernel[], int kw, int kh, float kern_div); + #endif /* FILTERS_GP_LINEAR_H */ diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c index 6f906b8..c84b17b 100644 --- a/libs/filters/GP_Linear.c +++ b/libs/filters/GP_Linear.c @@ -464,3 +464,21 @@ int GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst, GP_ProgressCallbackDone(callback); return 0; } + +void GP_FilterKernelPrint(float kernel[], int kw, int kh, float kern_div) +{ + int i, j; + + for (i = 0; i < kw; i++) { + + if (i == kw/2) + printf("% 8.2f * | ", 1/kern_div); + else + printf(" | "); + + for (j = 0; j < kh; j++) + printf("% 8.2f ", kernel[j + i * kw]); + + printf("|n"); + } +}
-----------------------------------------------------------------------
Summary of changes: doc/README | 2 +- doc/filters.txt | 106 ++++++++++++++++++++++ doc/images/edge_sharpening/lenna_small_w_0_1.png | Bin 0 -> 127188 bytes doc/images/edge_sharpening/lenna_small_w_0_3.png | Bin 0 -> 143643 bytes doc/images/edge_sharpening/lenna_small_w_0_5.png | Bin 0 -> 156274 bytes doc/images/edge_sharpening/lenna_w_0_1.png | Bin 0 -> 429215 bytes doc/images/edge_sharpening/lenna_w_0_3.png | Bin 0 -> 476119 bytes doc/images/edge_sharpening/lenna_w_0_5.png | Bin 0 -> 514664 bytes include/filters/GP_Laplace.h | 17 +++- include/filters/GP_Linear.h | 5 + libs/filters/GP_Laplace.c | 61 +++++++++++-- libs/filters/GP_Linear.c | 18 ++++ 12 files changed, 196 insertions(+), 13 deletions(-) create mode 100644 doc/images/edge_sharpening/lenna_small_w_0_1.png create mode 100644 doc/images/edge_sharpening/lenna_small_w_0_3.png create mode 100644 doc/images/edge_sharpening/lenna_small_w_0_5.png create mode 100644 doc/images/edge_sharpening/lenna_w_0_1.png create mode 100644 doc/images/edge_sharpening/lenna_w_0_3.png create mode 100644 doc/images/edge_sharpening/lenna_w_0_5.png
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.