Class Convolution

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--Convolution
Direct Known Subclasses:
Laplacian

public class Convolution
extends java.lang.Thread

Convolution is the code for applying the convolution operator.


Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Convolution()
          Default no-arg constructor.
 
Method Summary
static int applyConvolution(int[][] input, int x, int y, double[][] k, int kernelWidth, int kernelHeight)
           
static int[] convolution_image(int[] input, int width, int height, double[][] kernel, int kernelWidth, int kernelHeight, double scale, double offset)
          Applies the convolution2DPadded algorithm and an offset and scale factors
static double[][] convolution2D(double[][] input, int width, int height, double[][] kernel, int kernelWidth, int kernelHeight)
          Takes a 2D array of grey-levels and a kernel and applies the convolution over the area of the image specified by width and height.
static double[][] convolution2DPadded(double[][] input, int width, int height, double[][] kernel, int kernelWidth, int kernelHeight)
          Takes a 2D array of grey-levels and a kernel, applies the convolution over the area of the image specified by width and height and returns a part of the final image.
static double[] convolutionDouble(double[][] input, int width, int height, double[][] kernel, int kernelWidth, int kernelHeight)
          Takes a 2D array of grey-levels and a kernel and applies the convolution over the area of the image specified by width and height.
static double[] convolutionDoublePadded(double[][] input, int width, int height, double[][] kernel, int kernelWidth, int kernelHeight)
          Takes a 2D array of grey-levels and a kernel and applies the convolution over the area of the image specified by width and height.
 double[][] convolutionType1(double[][] input, int width, int height, double[][] kernel, int kernelWidth, int kernelHeight, int iterations)
          Applies the convolution2D algorithm to the input array as many as iterations.
 double[][] convolutionType2(double[][] input, int width, int height, double[][] kernel, int kernelWidth, int kernelHeight, int iterations)
          Applies the convolution2DPadded algorithm to the input array as many as iterations.
static int[] doublesToValidPixels(double[] greys)
          Converts a greylevel array into a pixel array.
static double singlePixelConvolution(double[][] input, int x, int y, double[][] k, int kernelWidth, int kernelHeight)
          Takes an image (grey-levels) and a kernel and a position, applies the convolution at that position and returns the new pixel value.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Convolution

public Convolution()
Default no-arg constructor.
Method Detail

singlePixelConvolution

public static double singlePixelConvolution(double[][] input,
                                            int x,
                                            int y,
                                            double[][] k,
                                            int kernelWidth,
                                            int kernelHeight)
Takes an image (grey-levels) and a kernel and a position, applies the convolution at that position and returns the new pixel value.
Parameters:
input - The 2D double array representing the image.
x - The x coordinate for the position of the convolution.
y - The y coordinate for the position of the convolution.
k - The 2D array representing the kernel.
kernelWidth - The width of the kernel.
kernelHeight - The height of the kernel.
Returns:
The new pixel value after the convolution.

applyConvolution

public static int applyConvolution(int[][] input,
                                   int x,
                                   int y,
                                   double[][] k,
                                   int kernelWidth,
                                   int kernelHeight)

convolution2D

public static double[][] convolution2D(double[][] input,
                                       int width,
                                       int height,
                                       double[][] kernel,
                                       int kernelWidth,
                                       int kernelHeight)
Takes a 2D array of grey-levels and a kernel and applies the convolution over the area of the image specified by width and height.
Parameters:
input - the 2D double array representing the image
width - the width of the image
height - the height of the image
kernel - the 2D array representing the kernel
kernelWidth - the width of the kernel
kernelHeight - the height of the kernel
Returns:
the 2D array representing the new image

convolution2DPadded

public static double[][] convolution2DPadded(double[][] input,
                                             int width,
                                             int height,
                                             double[][] kernel,
                                             int kernelWidth,
                                             int kernelHeight)
Takes a 2D array of grey-levels and a kernel, applies the convolution over the area of the image specified by width and height and returns a part of the final image.
Parameters:
input - the 2D double array representing the image
width - the width of the image
height - the height of the image
kernel - the 2D array representing the kernel
kernelWidth - the width of the kernel
kernelHeight - the height of the kernel
Returns:
the 2D array representing the new image

convolutionDouble

public static double[] convolutionDouble(double[][] input,
                                         int width,
                                         int height,
                                         double[][] kernel,
                                         int kernelWidth,
                                         int kernelHeight)
Takes a 2D array of grey-levels and a kernel and applies the convolution over the area of the image specified by width and height.
Parameters:
input - the 2D double array representing the image
width - the width of the image
height - the height of the image
kernel - the 2D array representing the kernel
kernelWidth - the width of the kernel
kernelHeight - the height of the kernel
Returns:
the 1D array representing the new image

convolutionDoublePadded

public static double[] convolutionDoublePadded(double[][] input,
                                               int width,
                                               int height,
                                               double[][] kernel,
                                               int kernelWidth,
                                               int kernelHeight)
Takes a 2D array of grey-levels and a kernel and applies the convolution over the area of the image specified by width and height.
Parameters:
input - the 2D double array representing the image
width - the width of the image
height - the height of the image
kernel - the 2D array representing the kernel
kernelWidth - the width of the kernel
kernelHeight - the height of the kernel
Returns:
the 1D array representing the new image

doublesToValidPixels

public static int[] doublesToValidPixels(double[] greys)
Converts a greylevel array into a pixel array.
Parameters:
the - 1D array of greylevels.
Returns:
the 1D array of RGB pixels.

convolutionType1

public double[][] convolutionType1(double[][] input,
                                   int width,
                                   int height,
                                   double[][] kernel,
                                   int kernelWidth,
                                   int kernelHeight,
                                   int iterations)
Applies the convolution2D algorithm to the input array as many as iterations.
Parameters:
input - the 2D double array representing the image
width - the width of the image
height - the height of the image
kernel - the 2D array representing the kernel
kernelWidth - the width of the kernel
kernelHeight - the height of the kernel
iterations - the number of iterations to apply the convolution
Returns:
the 2D array representing the new image

convolutionType2

public double[][] convolutionType2(double[][] input,
                                   int width,
                                   int height,
                                   double[][] kernel,
                                   int kernelWidth,
                                   int kernelHeight,
                                   int iterations)
Applies the convolution2DPadded algorithm to the input array as many as iterations.
Parameters:
input - the 2D double array representing the image
width - the width of the image
height - the height of the image
kernel - the 2D array representing the kernel
kernelWidth - the width of the kernel
kernelHeight - the height of the kernel
iterations - the number of iterations to apply the convolution
Returns:
the 2D array representing the new image

convolution_image

public static int[] convolution_image(int[] input,
                                      int width,
                                      int height,
                                      double[][] kernel,
                                      int kernelWidth,
                                      int kernelHeight,
                                      double scale,
                                      double offset)
Applies the convolution2DPadded algorithm and an offset and scale factors
Parameters:
input - the 1D int array representing the image
width - the width of the image
height - the height of the image
kernel - the 2D array representing the kernel
kernelWidth - the width of the kernel
kernelHeight - the height of the kernel
scale - the scale factor to apply
offset - the offset factor to apply
Returns:
the 1D array representing the new image