HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelTutorial Source codeReport an issue
Category
Example

Adaptive threshold image

← adaptiveSharpenImage   addNoiseImage →
Selects an individual threshold for each pixel based on the range of intensity values in its local neighborhood. This allows for thresholding of an image whose global intensity histogram doesn't contain distinctive peaks.
function adaptiveThresholdImage($image_path, $width, $height, $adaptiveOffset)
{
    $imagick = new \Imagick(realpath($image_path));
    $adaptiveOffsetQuantum = intval($adaptiveOffset * \Imagick::getQuantum());
    $imagick->adaptiveThresholdImage($width, $height, $adaptiveOffsetQuantum);
    header("Content-Type: image/jpeg");
    echo $imagick->getImageBlob();
}