import javax.swing.*; import java.awt.*; import java.awt.image.*; import java.text.DecimalFormat; import java.text.FieldPosition; import java.io.*; class gait { // No. at start of gait cycle private static int start = 62; public static void main(String args[]) { gait prog = new gait(); } public gait() { System.out.println("Gait program started"); // Make the next filename //String file = "./moments.csv"; PrintStream ps = null; try { ps = new PrintStream(new FileOutputStream(new File("./moments.csv"))); } catch(Exception e) {}; for(int person = 13; person < 18; person++) { for (int sequence = 0; sequence < 7; sequence++) { String path = null; String fileName = null; StringBuffer sb = new StringBuffer(); DecimalFormat format = new DecimalFormat("000"); format.format(person, sb, new FieldPosition(0)); path = "./008a" + sb + "s"; fileName = "008a" + sb + "s"; sb = new StringBuffer(); format = new DecimalFormat("00"); format.format(sequence, sb, new FieldPosition(0)); path = path + sb + "L/"; fileName = fileName + sb + "L_"; System.out.println(path); FileReader reader = null; try { reader = new FileReader(path + "start.txt"); } catch(FileNotFoundException e) { System.out.println(e); } BufferedReader br = new BufferedReader(reader); String thestart = null; try { thestart = br.readLine(); } catch(IOException e) { System.out.println(e); } System.out.println("start = " + thestart); start = Integer.parseInt(thestart); // Arrays for results double I_one[] = new double[30]; double I_two[] = new double[30]; double I_eight[] = new double[30]; int pixels[][] = new int[30][]; int width[] = new int[30]; int height[] = new int[30]; for(int i = start; i < (start + 30); i++) { sb = new StringBuffer(); format = new DecimalFormat("0000"); format.format(i, sb, new FieldPosition(0)); // Make the next filename String file = path + fileName + sb + "_scaled.png"; System.out.println(file); // A helpful index no int ind = i-start; // Create an imageicon and get the image from it ImageIcon iconIm = new ImageIcon(file); Image image = iconIm.getImage(); while(iconIm.getImageLoadStatus() != MediaTracker.COMPLETE); // Get width and height width[ind] = iconIm.getIconWidth(); height[ind] = iconIm.getIconHeight(); // Initialise array to store pixels pixels[ind] = new int[width[ind]*height[ind]]; // Create a pixelgrabber to grab the pixels PixelGrabber grabber = new PixelGrabber(image, 0, 0, width[ind], height[ind], pixels[ind], 0, width[ind]); try { grabber.grabPixels(); } catch(InterruptedException e) { System.out.println(e); } } System.out.println("Images loaded"); for(int i = 0; i < 30; i++) { int centre[] = new int[2]; // Precalculate centre of mass centreOfMass(pixels[i], centre, width[i], height[i]); // Precalculate moments //long centralised02 = centralisedMoment(pixels[i] ,0 , 2, centre[0], centre[1], width[i], height[i]); //long centralised20 = centralisedMoment(pixels[i] ,2 , 0, centre[0], centre[1], width[i], height[i]); //long centralised11 = centralisedMoment(pixels[i] ,1 , 1, centre[0], centre[1], width[i], height[i]); //long moment00 = moment(pixels[i], 0, 0, width[i], height[i]); // Faster moment calculation long centralised02 = 0; long centralised20 = 0; long centralised11 = 0; long moment00 = 0; for(int j = 0; j < width[i]; j++) { for(int k = 0; k < height[i]; k++) { if(pixels[i][(k*width[i])+j] != 0xff000000) { centralised02 += Math.pow((k-centre[1]), 2); centralised20 += Math.pow((j-centre[0]), 2); centralised11 += (j-centre[0]) * (k-centre[1]); moment00++; } } } I_one[i] = ((double)(centralised20 + centralised02)) / ((double)Math.pow(moment00, 2)); I_two[i] = (double)Math.pow((centralised20 - centralised02), 2) + (double)Math.pow((4 * centralised11), 2); I_two[i] /= (double)Math.pow(moment00, 4); I_eight[i] = (double)(centralised20 * centralised02) - (double)Math.pow(centralised11, 2); I_eight[i] /= (double)Math.pow(moment00, 4); //I_one[i] = Ione(pixels[i], width[i], height[i], centre[0], centre[1]); //I_two[i] = Itwo(pixels[i], width[i], height[i], centre[0], centre[1]); //I_eight[i] = Ieight(pixels[i], width[i], height[i], centre[0], centre[1]); System.out.println(I_one[i] + "," + I_two[i] + "," + I_eight[i]); } // calcerate mean and variance double sumI_one = 0; // sum of all the elements double sumI_two = 0; double sumI_eight = 0; double sumI_oneSq = 0; double sumI_twoSq = 0; double sumI_eightSq = 0; for (int i=0; i