Class MedianSmooth

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--MedianSmooth

public class MedianSmooth
extends java.lang.Thread

Code for the median smoothing algorithm.

Author:
Simon Horne.

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
MedianSmooth()
          Default no-args constructor.
 
Method Summary
 boolean emptyKernel(int[] kernel)
          Returns true if the kernel consists of all 0s.
 int[][] generateInputArrays(int[] input, int width, int height)
          Converts a 1D array to a 2D array.
 int[] generateOutputArray(int[][] outputArrays, int width, int height)
          Converts a 2D array to a 1D array.
 int getMax(java.util.ArrayList values)
          Gets the maximum value from a list.
 int getMedian(java.util.ArrayList values)
          Gets the median value from an input list by removing half of the maximum values and then returning the remaining maximum value or the mean of the two maximum values (if even number of elements).
 int medianNeighbour(int[][] input, int[][] kernel, int w, int h, int x, int y)
          Takes a 2D input image array and a kernel and a pixel location and calculates the new pixel value by calculating the median of its neighbours.
 java.util.ArrayList removeMax(java.util.ArrayList values)
          Removes a single occurence of the maximum value from a list.
 int[] smooth_image(int[] input, int[] kernel, int width, int height, int iterations)
          Takes an image and a kernel and smoothes the image the specified number of iterations.
 int[][] smooth(int[][] input, int[][] kernel, int width, int height, int iterations)
          Takes an image and a kernel and smoothes the image the specified number of iterations.
 int[] smoothImage(int[] input, int width, int height, int[] kernel, int kernelWidth, int kernelHeight, int iterations)
          Takes an image and a kernel and smoothes the image the specified number of iterations.
 
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

MedianSmooth

public MedianSmooth()
Default no-args constructor.
Method Detail

getMax

public int getMax(java.util.ArrayList values)
Gets the maximum value from a list.
Parameters:
values - the list of values to be checked
Returns:
the maximum value

removeMax

public java.util.ArrayList removeMax(java.util.ArrayList values)
Removes a single occurence of the maximum value from a list.
Parameters:
values - the input list
Returns:
the input list minus a single maximum element

getMedian

public int getMedian(java.util.ArrayList values)
Gets the median value from an input list by removing half of the maximum values and then returning the remaining maximum value or the mean of the two maximum values (if even number of elements).
Parameters:
values - the input list
Returns:
the median value

medianNeighbour

public int medianNeighbour(int[][] input,
                           int[][] kernel,
                           int w,
                           int h,
                           int x,
                           int y)
Takes a 2D input image array and a kernel and a pixel location and calculates the new pixel value by calculating the median of its neighbours.
Parameters:
input - the 2D image array
kernel - the kernel array
w - the width of the input image
h - the height of the input image
x - the x coordinate of the pixel at the centre of the neighbourhood
y - the y coordinate of the pixel at the centre of the neighbourhood
Returns:
the new pixel value

generateInputArrays

public int[][] generateInputArrays(int[] input,
                                   int width,
                                   int height)
Converts a 1D array to a 2D array.
Parameters:
input - the 1D array
width - of the image
height - of the image
Returns:
the 2D array

generateOutputArray

public int[] generateOutputArray(int[][] outputArrays,
                                 int width,
                                 int height)
Converts a 2D array to a 1D array.
Parameters:
outputArrays - the 2D array
width - of the image
height - of the image
Returns:
the 1D array

emptyKernel

public boolean emptyKernel(int[] kernel)
Returns true if the kernel consists of all 0s.
Parameters:
kernel - the array representing the kernel
Returns:
True or false (true is all 0s)

smooth

public int[][] smooth(int[][] input,
                      int[][] kernel,
                      int width,
                      int height,
                      int iterations)
Takes an image and a kernel and smoothes the image the specified number of iterations.
Parameters:
input - the input image array
kernel - the kernel array
width - of the image
height - of the image
iterations - to be carried out
Returns:
the new smoothed image array

smooth_image

public int[] smooth_image(int[] input,
                          int[] kernel,
                          int width,
                          int height,
                          int iterations)
Takes an image and a kernel and smoothes the image the specified number of iterations.
Parameters:
input - the input image array
kernel - the kernel array
width - of the image
height - of the image
iterations - to be carried out
Returns:
the new smoothed image array

smoothImage

public int[] smoothImage(int[] input,
                         int width,
                         int height,
                         int[] kernel,
                         int kernelWidth,
                         int kernelHeight,
                         int iterations)
Takes an image and a kernel and smoothes the image the specified number of iterations.
Parameters:
input - the input image array
kernel - the kernel array
width - of the image
height - of the image
iterations - to be carried out
Returns:
the new smoothed image array