Open In App

PHP | Imagick segmentImage() Function

The Imagick::segmentImage() function is an inbuilt function in PHP which is used to segment an image.

Syntax:



bool Imagick::segmentImage(int $COLORSPACE, 
float $cluster_threshold, float $smooth_threshold, 
bool $verbose = FALSE )

Parameters: This function accepts four parameters as mentioned above and described below:

List of all COLORSPACE constants are given below:



Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the Imagick::segmentImage() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Segment the image with colorspace as imagick::COLORSPACE_RGB
$imagick->segmentImage(1, 0, 12);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output:

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Segment the image with colorspace as imagick::COLORSPACE_GRAY
$imagick->segmentImage(2, 5, 30);
  
// Display the image
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

Output:

Reference: https://www.php.net/manual/en/imagick.segmentimage.php


Article Tags :