From images to a matrix