public TiledGrayscaleMatrix(final GrayscaleMatrix matrix,final int tileWidth,final int tileHeight){
  if (matrix.getWidth() < tileWidth || matrix.getHeight() < tileHeight) {
    throw new IllegalArgumentException("Tile size must be smaller than original matrix!");
  }
  if (tileWidth <= 0 || tileHeight <= 0) {
    throw new IllegalArgumentException("Illegal tile size!");
  }
  this.tileWidth=tileWidth;
  this.tileHeight=tileHeight;
  this.tilesX=matrix.getWidth() / tileWidth;
  this.tilesY=matrix.getHeight() / tileHeight;
  int roundedWidth=tilesX * tileWidth;
  int roundedHeight=tilesY * tileHeight;
  tiles=new ArrayList<GrayscaleMatrix>(roundedWidth * roundedHeight);
  for (int i=0; i < tilesY; i++) {
    for (int j=0; j < tilesX; j++) {
      tiles.add(GrayscaleMatrix.createFromRegion(matrix,tileWidth,tileHeight,this.tileWidth * j,this.tileHeight * i));
    }
  }
}

public TiledGrayscaleMatrix ( final GrayscaleMatrix matrix , final int tileWidth , final int tileHeight ) { if ( matrix . getWidth ( ) < tileWidth || matrix . getHeight ( ) < tileHeight ) { throw new IllegalArgumentException ( "Tile size must be smaller than original matrix!" ) ; } if ( tileWidth <= 0 || tileHeight <= 0 ) { throw new IllegalArgumentException ( "Illegal tile size!" ) ; } this . tileWidth = tileWidth ; this . tileHeight = tileHeight ; this . tilesX = matrix . getWidth ( ) / tileWidth ; this . tilesY = matrix . getHeight ( ) / tileHeight ; int roundedWidth = tilesX * tileWidth ; int roundedHeight = tilesY * tileHeight ; tiles = new ArrayList < GrayscaleMatrix > ( roundedWidth * roundedHeight ) ; for ( int i = 0 ; i < tilesY ; i ++ ) { for ( int j = 0 ; j < tilesX ; j ++ ) { tiles . add ( GrayscaleMatrix . createFromRegion ( matrix , tileWidth , tileHeight , this . tileWidth * j , this . tileHeight * i ) ) ; } } }
instantiates a new tiled grayscale matrix .
