import java.applet.*; import java.awt.*; import java.awt.image.*; import java.net.*; import java.util.*; import java.io.*; import java.lang.Math; import java.awt.Color.*; /** * Code for the median smoothing algorithm. * * @author Simon Horne. */ public class MedianSmooth extends Thread { /** * Default no-args constructor. */ public MedianSmooth() { } /** * Gets the maximum value from a list. * * @param values the list of values to be checked * @return the maximum value */ public int getMax(ArrayList values){ Iterator it = values.iterator(); int max = 0;//((Integer) it.next()).intValue(); while(it.hasNext()){ int current = ((Integer) it.next()).intValue(); if(current>max) max=current; } return max; } /** * Removes a single occurence of the maximum value from a list. * * @param values the input list * @return the input list minus a single maximum element */ public ArrayList removeMax(ArrayList values){ int max = getMax(values); Iterator it = values.iterator(); while(it.hasNext()){ if(((Integer) it.next()).intValue() == max){ it.remove(); return values; } } return values;//never reaches this point as values contains a max } //Assume all positive integers /** * 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). * * @param values the input list * @return the median value */ public int getMedian(ArrayList values){ int median; if(values.size()/2 == (values.size()+1)/2){//if even number of elements for(int i=0;i<(values.size()-1)/2;++i){ removeMax(values); } median = getMax(values);//median is mean of two central values removeMax(values); median = median + getMax(values); median = median/2;//mean of x,y is (x+y)/2 }else{//if odd number of elements for(int i=0;i=0) && ((y-1+j)>=0) && ((x-1+i)0){ int [][] inputArrays = new int [width][height]; int [][] kernelArrays = new int [3][3]; int [][] outputArrays = new int [width][height]; for(int j=0;j128){ k=1; }else{ k=0; } */ kernelArrays[i][j] = k; } } for(int j=0;j