Analyses the image and identifies units that are similar. This method is available if Imagick has been compiled against ImageMagick version 6.4.5 or newer.

This function is quite slow and prone to time out. Large values for the cluster and smooth threshold appear to be faster, and so safer.


This function is quite slow and prone to time out. Large values for the cluster and smooth threshold appear to be faster, and so safer.

function segmentImage($image_path, $colorSpace, $clusterThreshold, $smoothThreshold)
{
    $imagick = new \Imagick(realpath($image_path));
    $imagick->segmentImage($colorSpace, $clusterThreshold, $smoothThreshold);
    header("Content-Type: image/jpeg");
    echo $imagick->getImageBlob();
}