Imagick::getImageHistogram

(PECL imagick 2, PECL imagick 3)

Imagick::getImageHistogram画像のヒストグラムを取得する

説明

publicImagick::getImageHistogram(): array

画像のヒストグラムを ImagickPixel オブジェクトの配列で返します。

パラメータ

この関数にはパラメータはありません。

戻り値

画像のヒストグラムを ImagickPixel オブジェクトの配列で返します。

エラー / 例外

エラー時に ImagickException をスローします。

例1 Generates Imagick::getImageHistogram()

<?php
function getColorStatistics($histogramElements, $colorChannel) {
$colorStatistics = [];

foreach (
$histogramElements as $histogramElement) {
$color = $histogramElement->getColorValue($colorChannel);
$color = intval($color * 255);
$count = $histogramElement->getColorCount();

if (
array_key_exists($color, $colorStatistics)) {
$colorStatistics[$color] += $count;
}
else {
$colorStatistics[$color] = $count;
}
}

ksort($colorStatistics);

return
$colorStatistics;
}



function
getImageHistogram($imagePath) {

$backgroundColor = 'black';

$draw = new \ImagickDraw();
$draw->setStrokeWidth(0); //make the lines be as thin as possible

$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);

$histogramWidth = 256;
$histogramHeight = 100; // the height for each RGB segment

$imagick = new \Imagick(realpath($imagePath));
//Resize the image to be small, otherwise PHP tends to run out of memory
To Top