Image matrix util functions.