(PECL imagick >= 3.3.0)
ImagickKernel::scale — 按给定量缩放内核列表
按给定量缩放给定的内核列表,在给定标志下,对内核值的总和进行归一化或不进行归一化。此函数的确切行为取决于使用的归一化类型,有关详细信息,请参阅 http://www.imagemagick.org/api/morphology.php#ScaleKernelInfo。
scale
normalizeFlag
范例 #1 ImagickKernel::scale()
<?php
function renderKernelTable($matrix) {
$output = "<table class='infoTable'>";
foreach ($matrix as $row) {
$output .= "<tr>";
foreach ($row as $cell) {
$output .= "<td style='text-align:left'>";
if ($cell === false) {
$output .= "false";
}
else {
$output .= round($cell, 3);
}
$output .= "</td>";
}
$output .= "</tr>";
}
$output .= "</table>";
return $output;
}
$output = "";
$matrix = [
[-1, 0, -1],
[ 0, 4, 0],
[-1, 0, -1],
];
$kernel = \ImagickKernel::fromMatrix($matrix);
$kernelClone = clone $kernel;
$output .= "开始内核<br/>";
$output .= renderKernelTable($kernel->getMatrix());
$output .= "使用 NORMALIZE_KERNEL_VALUE 缩放。<br/>";
$kernel->scale(2, \Imagick::NORMALIZE_KERNEL_VALUE);
$output .= renderKernelTable($kernel->getMatrix());
$kernel = clone $kernelClone;
$output .= "按百分比缩放<br/>";
$kernel->scale(2, \Imagick::NORMALIZE_KERNEL_PERCENT);
$output .= renderKernelTable($kernel->getMatrix());
$matrix2 = [
[-1, -1, 1],
[ -1, false, 1],
[1, 1, 1],
];
$kernel = \ImagickKernel::fromMatrix($matrix2);
$output .= "按相关性缩放<br/>";
$kernel->scale(1, \Imagick::NORMALIZE_KERNEL_CORRELATE);
$output .= renderKernelTable($kernel->getMatrix());
return $output;
?>