Image
Low threshold
High threshold
Channel
function randomThresholdimage($imagePath, $lowThreshold, $highThreshold, $channel)
{
    $imagick = new \Imagick(realpath($imagePath));

    $imagick->randomThresholdimage(
        $lowThreshold * \Imagick::getQuantum(),
        $highThreshold * \Imagick::getQuantum(),
        $channel
    );
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}