refine by replacing ilpimage with mat