get eigenvalue pca with java

Posted by Muhamad Burhanudin on Stack Overflow See other posts from Stack Overflow or by Muhamad Burhanudin
Published on 2013-06-30T00:54:52Z Indexed on 2013/10/31 3:54 UTC
Read the original article Hit count: 282

Filed under:
|
|
|

I try use PCA to reduce dimention, and i use jama for help me using matrix. but, i got problem when get eigenvalue with jama. for example i hava 2 image dimention 100x100, then i create single matrix 2 image x (100x100). there is 20.000 pixel. and how to get reduction with eigenvalue? this is sample my code :

public static void main(String[] args) {
    BufferedImage bi;
    int[] rgb;
    int R, G, B;
    // int[] jum;
    double[][] gray = new double[500][500] ;
    String[] baris = new String[1000];
    try {
        //bi = ImageIO.read(new File("D:\\c.jpg"));
        int[][] pixelData = new int[bi.getHeight() * bi.getWidth()][3];

        int counter = 0;
        for (int i = 0; i < bi.getHeight(); i++) {
            for (int j = 0; j < bi.getWidth(); j++) {
                gray[i][j] = getPixelData(bi, i, j);
                // R = getR(bi, i, j);
                //G = getG(bi, i, j);
                //B = getB(bi, i, j);
                //jum = R + G + B;
                // gray[counter] = Double.toString(R + G + B / 3);
                // System.out.println("Gray " +gray);
                //for (int k = 0; k < rgb.length; k++) {
                //   pixelData[counter][k] = rgb[k];
                // }

                counter++;
            }
        }


    } catch (IOException e) {
        e.printStackTrace();
    }
    Matrix matrix =  new Matrix(gray);
    PCA pca = new PCA(matrix);
    pca.getEigenvalue(6);
    String n = pca.toString();
    System.err.println("nilai n "+n);
    //double dete = pcadete(matrix,3600);
}

private static int getPixelData(BufferedImage bi, int x, int y) {
    int argb = bi.getRGB(y, x);
    int r, g, b;
    int gray;
    int rgb[] = new int[]{
        (argb >> 16) & 0xff, //red
        (argb >> 8) & 0xff, //green
        (argb) & 0xff //blue
    };
    r = rgb[0];
    g = rgb[1];
    b = rgb[2];

    gray = (r + g + b) / 3;
    System.out.println("gray: " + gray);
    return gray;
}

when i show eigenvalue in this code :

PCA pca = new PCA(matrix);
    pca.getEigenvalue(6);
    String n = pca.toString();
    System.err.println("nilai n "+n);

Result is :

nilai n PCA@c3e9e9

Can, u tell me what way to get eigenvalue and reduction dimension.

© Stack Overflow or respective owner

Related posts about java

Related posts about pca