0

I have to find the matrix of an image first , I have this code ,that gives me an error here L[row][col] = image.getRGB(row, col); the error is"java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!" What are the reasons for that error??

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import Jama.EigenvalueDecomposition;
import Jama.Matrix;

public class eigenvalues {

    double L[][], A[];

    public static void main(String[] args) throws IOException { 
        File file = new File("C:\\Users\\lina\\workspace\\eigen\\koala.jpg");

        BufferedImage image= ImageIO.read(file);
        int width = image.getWidth();
        int height = image.getHeight();
        double[][] L = new double[height][width];

        for (int row = 0; row < height; row++) {
            for (int col = 0; col < width; col++) {
                L[row][col] = image.getRGB(row, col);
            }
        }
        Matrix A=new Matrix(L);
        EigenvalueDecomposition e = A.eig();
        Matrix V = e.getV();
        Matrix D = e.getD();
        System.out.print("A =");
        A.print(9, 6);
        System.out.print("D =");
        D.print(9, 6);
        System.out.print("V =");
        V.print(9, 6);
lina
  • 9
  • 2

2 Answers2

0

Method getRGB() has this signature

public int getRGB(int x, int y)

So this line of code

L[row][col] = image.getRGB(row, col);

need to be changed

L[row][col] = image.getRGB(col, row); 
v.ladynev
  • 19,275
  • 8
  • 46
  • 67
0

You inverted the order of X et Y in getRGB() method.

Try with : L[row][col] = image.getRGB(col, row);

Pierre
  • 1,162
  • 12
  • 29
  • @lina You are welcome. It will be nice if you mark my answer and v.ladynev's answer as useful ;) – Pierre Dec 29 '15 at 15:14