The provided example is wrong. Here's a correct sample:
$matrix = [[1,-1,1],[-1,1,-1],[1,-1,1]];
$kernel = \ImagickKernel::fromMatrix($matrix);
$imagick = new Imagick();
$imagick->readimage($file.'/z.png');
$imagick->convolveImage ($kernel);
$imagick->writeimage('convolve.png');
$imagick->clear();
$imagick->destroy();