Class Kernel2D

java.lang.Object
imagingbook.common.filter.linear.Kernel2D
Direct Known Subclasses:
GaussianKernel2D

public class Kernel2D extends Object
This class represents a 2D filter kernel.
Version:
2020/12/29
  • Constructor Summary

    Constructors
    Constructor
    Description
    Kernel2D(float[][] H)
    Constructor.
    Kernel2D(float[][] H, int xc, int yc, boolean normalize)
    Full constructor.
    Kernel2D(Kernel1D Hx, Kernel1D Hy, boolean normalize)
    Creates the effective 2D kernel from two 1D kernels.
  • Method Summary

    Modifier and Type
    Method
    Description
    static float[][]
    Calculates the effective 2D kernel array from two 1D kernels assumed to be applied in x- and y-direction, respectively.
    float[][]
    Returns the kernel's 2D array.
    int
    Returns the height of this kernel.
    int
    Returns the width of this kernel.
    int
    Returns the horizontal center coordinate of this kernel.
    int
    Returns the vertical center coordinate of this kernel.
    static float[][]
    normalize(float[][] A)
    Normalizes the specified array such that its sum becomes 1.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Kernel2D

      public Kernel2D(float[][] H)
      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

      public Kernel2D(float[][] H, int xc, int yc, boolean normalize)
      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 array
      xc - the x-coordinate of the kernel's hot spot, default is (width-1)/2
      yc - the y-coordinate of the kernel's hot spot, default is (height-1)/2
      normalize - if true the kernel is normalized (to sum = 1)
    • Kernel2D

      public Kernel2D(Kernel1D Hx, Kernel1D Hy, boolean normalize)
      Creates the effective 2D kernel from two 1D kernels.
      Parameters:
      Hx - the 1D kernel for the x-direction
      Hy - the 1D kernel for the y-direction
      normalize - if true the kernel is normalized (to sum = 1)
  • Method Details

    • getEffectiveKernel

      public static 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. The result is not normalized. Use the constructor Kernel2D(Kernel1D, Kernel1D, boolean) to create the equivalent (optionally normalized) 2D kernel. Note that the kernel coordinates are H[y][x].
      Parameters:
      Hx - the 1D kernel for the x-direction
      Hy - the 1D kernel for the y-direction
      Returns:
      the effective 2D kernel matrix
    • getH

      public float[][] getH()
      Returns the kernel's 2D array. Note that the kernel coordinates are H[y][x].
      Returns:
      the kernel's 2D array
    • getWidth

      public int getWidth()
      Returns the width of this kernel.
      Returns:
      the kernel's width
    • getHeight

      public int getHeight()
      Returns the height of this kernel.
      Returns:
      the kernel's height
    • getXc

      public int getXc()
      Returns the horizontal center coordinate of this kernel.
      Returns:
      the kernel's x-center coordinate
    • getYc

      public int getYc()
      Returns the vertical center coordinate of this kernel.
      Returns:
      the kernel's y-center coordinate
    • normalize

      public static float[][] normalize(float[][] A) throws ArithmeticException
      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