1 /**
2 * Copyright (c) 2011, The University of Southampton and the individual contributors.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * * Neither the name of the University of Southampton nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package org.openimaj.image.processing.convolution;
31
32 import org.openimaj.image.FImage;
33
34 /**
35 * A set of standard derivative kernels. These kernels help estimate the derivative over various orders at a point in a matrix.
36 * This is approximated by applying a finite difference derivative operation on a gaussian kernel with a very low sigma. i.e. a gaussian
37 * kernel that looks like:
38 *
39 * [
40 * [0,0,0],
41 * [0,1,0],
42 * [0,0,0]
43 * ]
44 *
45 * By successive derivative calculations in the x direction and y direction it is possible to estimate derivatives in both directions as well.
46 *
47 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
48 *
49 */
50 public class BasicDerivativeKernels {
51 static class DxKernel extends FConvolution {
52 public DxKernel() { super(new FImage(new float[][] {{-0.5f,0,0.5f}})); }
53 }
54
55 static class DyKernel extends FConvolution {
56 public DyKernel() { super(new FImage(new float[][] {{-0.5f}, {0}, {0.5f}})); }
57 }
58
59 static class DxxKernel extends FConvolution {
60 public DxxKernel() { super(new FImage(new float[][] {{1,-2,1}})); }
61 }
62
63 static class DxyKernel extends FConvolution {
64 public DxyKernel() { super(new FImage(new float[][] {{0.25f,0,-0.25f}, {0,0,0}, {-0.25f,0,0.25f}})); }
65 }
66
67 static class DyyKernel extends FConvolution {
68 public DyyKernel() { super(new FImage(new float[][] {{1}, {-2}, {1}})); }
69 }
70
71 static class DxxxxKernel extends FConvolution {
72 public DxxxxKernel() { super(new FImage(new float[][] {{1,-4 ,6 ,-4 ,1}})); }
73 }
74
75 static class DyyyyKernel extends FConvolution {
76 public DyyyyKernel() { super(new FImage(new float[][] {{1}, {-4},{6},{-4},{1}})); }
77 }
78
79 static class DxxyyKernel extends FConvolution {
80 public DxxyyKernel() { super(new FImage(new float[][] {{1f,-2f,1f},{-2f,4f,-2f},{1f,-2f,1f}})); }
81 }
82
83 /**
84 * kernel approximating the first derivative of a low-sigma gaussian in the x-direction [-0.5, 0, 0.5].
85 * Useful for giving an estimate of the second derivative in x of any given point
86 */
87 public static final FConvolution DX_KERNEL = new DxKernel();
88
89 /**
90 * kernel approximating the first derivative of a low-sigma gaussian in the y-direction [-0.5, 0, 0.5]'.
91 * Useful for giving an estimate of the second derivative in y of any given point
92 */
93 public static final FConvolution DY_KERNEL = new DyKernel();
94
95 /**
96 * kernel approximating the second derivative of a low sigma gaussian in the x-direction [1, -2, 1].
97 * Useful for giving an estimate of the second derivative in x of any given point
98 */
99 public static final FConvolution DXX_KERNEL = new DxxKernel();
100
101 /**
102 * kernel approximating the first derivative of a low sigma gaussian in the x-direction and y-direction [[-0.25, 0, 0.25], [0, 0, 0], [0.25, 0, -0.25]] .
103 * Useful for giving an estimate of the first order derivative in x then y of any given point
104 */
105 public static final FConvolution DXY_KERNEL = new DxyKernel();
106
107 /**
108 * kernel approximating the second derivative of a low sigma gaussian in the y-direction [1, -2, 1]'.
109 * Useful for giving an estimate of the second derivative in y of any given point
110 */
111 public static final FConvolution DYY_KERNEL = new DyyKernel();
112
113
114 /**
115 * kernel approximating the fourth derivative of a low sigma gaussian in the x-direction [1,-4,6,-4,1]^T
116 * Useful for giving an estimate of the fourth derivative in y of any given point
117 */
118 public static final FConvolution DXXXX_KERNEL = new DxxxxKernel();
119
120 /**
121 * kernel approximating the second derivative of a low sigma gaussian in the x-direction and y-direction [[1,-2,1],[-2,4,-2],[1,-2,1]] .
122 * Useful for giving an estimate of the second order derivative in x then y of any given point
123 */
124 public static final FConvolution DXXYY_KERNEL = new DxxyyKernel();
125 /**
126 * kernel approximating the fourth derivative of a low sigma gaussian in the y-direction [1,-4,6,-4,1]^T
127 * Useful for giving an estimate of the fourth derivative in y of any given point
128 */
129 public static final FConvolution DYYYY_KERNEL = new DyyyyKernel();
130 }