+

PHP ImagickgmentImage () Function

Syntax:
bool Imagick::segmentImage (int $COLORSPACE, float  $cluster_threshold, float $smooth_threshold, bool $verbose = FALSE)
Parameters:This function takes four parameters, as above and described below:
  • $COLORSPACE:specifies an integer value that matches one of the COLORSPACEconstants. You can also pass in direct constants such as imagick::COLORSPACE_RGB.
  • $cluster_threshold:specifies a percentage that describes the minimum number of pixels contained in hexedra before it is considered valid.
  • $smooth_threshold:specifies whether to remove noise from the histogram.
  • $verbose (Optional):specifies whether to display detailed information about the recognized classes. The default is false
A list of all COLORSPACE constants is given below:
  • imagick::COLORSPACE_UNDEFINED (0)
  • imagick::COLORSPACE_RGB (1)
  • imagick::COLORSPACE_GRAY (2)
  • imagick::COLORSPACE_TRANSPARENT (3)
  • imagick::COLORSPACE_OHTA (4)
  • imagick::COLORSPACE_LAB (5)
  • imagick::COLORSPACE_XYZ (6)
  • imagick::COLORSPACE_YCBCR (7)
  • imagick::COLORSPACE_YCC ( 8)
  • imagick::COLORSPACE_YIQ (9)
  • imagick::COLORSPACE_YPBPR (10)
  • imagick::COLORSPACE_YUV (11)
  • imagick::COLORSPACE_CMYK (12)
  • imagick::COLORSPACE_SRGB (13)
  • imagick::COLORSPACE_HSB (14)
  • imagick::COLORSPACE_HSL (15)
  • imagick::COLORSPACE_HWB (16)
  • imagick::COLORSPACE_REC601LUMA (17)
  • imagick::COLORSPACE_REC709LUMA (19)
  • imagick::COLORSPACE_LOG (21)
  • imagick::COLORSPACE_CMY (22)
Return th value:This function returns TRUE on success.Exceptions:This function throws an ImagickException on error.The following programs illustrate the Imagick::gmentImage() functionin PHP:Program 1:  
// Create a new imagick object $imagick = new Imagick ( ` https://media.engineerforengineer.org/wp-content/uploads/engineerforengineer-13.png ` );  
// Segment the image with color space as imagick::COLORSPACE_RGB $imagick -> segmentImage (1, 0, 12);  
// Show image header ( "Content-Type: image / png" ); echo $imagick -> getImageBlob(); ?>
Output: Program 2:  
// Create new imagick object $imagick = new Imagick ( ` https://media.engineerforengineer.org/wp-content/uploads/engineerforengineer-13.png ` );  
// Segment the image with color space as imagick::COLORSPACE_GRAY $imagick -> segmentImage (2, 5, 30);  
// Show image header ( "Content-Type: image / png" ); echo $imagick -> getImageBlob(); ?>
Output: Link: https://www.php.net/manual/en/imagick.segmentimage.php
Get Solution for free from DataCamp guru