java.lang.Object
imagingbook.common.filter.linear.Kernel2D
- Direct Known Subclasses:
GaussianKernel2D
This class represents a 2D filter kernel.
- Version:
- 2020/12/29
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic float[][]
getEffectiveKernel
(Kernel1D Hx, Kernel1D Hy) Calculates the effective 2D kernel array from two 1D kernels assumed to be applied in x- and y-direction, respectively.float[][]
getH()
Returns the kernel's 2D array.int
Returns the height of this kernel.int
getWidth()
Returns the width of this kernel.int
getXc()
Returns the horizontal center coordinate of this kernel.int
getYc()
Returns the vertical center coordinate of this kernel.static float[][]
normalize
(float[][] A) Normalizes the specified array such that its sum becomes 1.
-
Constructor Details
-
Kernel2D
Constructor. Assumes that the kernel's structure is H[y][x] (i.e., vertical coordinate first) and the hot spot is at its center. The kernel is normalized by default.- Parameters:
H
- the 2D kernel array
-
Kernel2D
Full constructor. Assumes that the kernel's structure is H[y][x] (i.e., vertical coordinate first), the hot spot position must be specified. The kernel is optionally normalized.- Parameters:
H
- the 2D kernel arrayxc
- the x-coordinate of the kernel's hot spot, default is (width-1)/2yc
- the y-coordinate of the kernel's hot spot, default is (height-1)/2normalize
- if true the kernel is normalized (to sum = 1)
-
Kernel2D
Creates the effective 2D kernel from two 1D kernels.- Parameters:
Hx
- the 1D kernel for the x-directionHy
- the 1D kernel for the y-directionnormalize
- if true the kernel is normalized (to sum = 1)
-
-
Method Details
-
getEffectiveKernel
Calculates the effective 2D kernel array from two 1D kernels assumed to be applied in x- and y-direction, respectively. The result is not normalized. Use the constructorKernel2D(Kernel1D, Kernel1D, boolean)
to create the equivalent (optionally normalized) 2D kernel. Note that the kernel coordinates areH[y][x]
.- Parameters:
Hx
- the 1D kernel for the x-directionHy
- the 1D kernel for the y-direction- Returns:
- the effective 2D kernel matrix
-
getH
Returns the kernel's 2D array. Note that the kernel coordinates areH[y][x]
.- Returns:
- the kernel's 2D array
-
getWidth
Returns the width of this kernel.- Returns:
- the kernel's width
-
getHeight
Returns the height of this kernel.- Returns:
- the kernel's height
-
getXc
Returns the horizontal center coordinate of this kernel.- Returns:
- the kernel's x-center coordinate
-
getYc
Returns the vertical center coordinate of this kernel.- Returns:
- the kernel's y-center coordinate
-
normalize
Normalizes the specified array such that its sum becomes 1. Throws an exception if the array's sum is zero. The original array is not modified.- Parameters:
A
- a 2D array- Returns:
- the normalized array
- Throws:
ArithmeticException
- if the array sums to zero
-