private static ShortImageBuffer fromBufferedImage(BufferedImage input)
    {
        int w = input.getWidth();
        int h = input.getHeight();
        ShortImageBuffer greyscale = new ShortImageBuffer(h, w);
        byte[] pixels = ((DataBufferByte) input.getRaster().getDataBuffer()).getData();

        int index = 0;
        for(int y=0;y<h;y++)
        {
            for(int x=0;x<w;x++)
            {
                greyscale.set(y, x, (short)(
                        (
                            (pixels[index+2] & 0xFF) +
                                (pixels[index+1] & 0xFF) +
                                (pixels[index] & 0xFF)
                        )/3)
                );
                index += 3;
            }
        }
        return greyscale;
    }