Image processing to form sparse matrices - donr