将whiteboard cleaner脚本转换为php

时间:2014-12-07 14:47:30

标签: php imagemagick imagemagick-convert

我尝试使用imagick扩展程序将此Imagemagick whiteboard cleaning script转换为纯PHP,以避免使用exec之类的产生进程。

原始bash脚本:

#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

我在最初的Convolve形态学核心矩阵中苦苦挣扎,其他一切看起来都有效:

<?php

$channel = null;

$convolveKernel = array(15, 100, 0);
$negateGreys = false;

$blurRadius = 0;
$blurSigma = 1;

$levelBlack = 60; // 60%
$levelGamma = 0.1;
$levelWhite = 91; // 91%

$image = new Imagick($file);

try {
    $image->convolveImage($convolveKernel, $channel);
    $image->negateImage($negateGreys, $channel);
    $image->normalizeImage($channel);
    $image->blurImage($blurRadius, $blurSigma, $channel);
    $image->levelImage($levelBlack, $levelGamma, $levelWhite, $channel);

    header('Content-type: image/jpeg');
    echo $image;
} catch (ImagickException $e) {
    echo $e->getMessage();
}

我收到异常"The kernel must contain a square number of elements",但我也想知道黑白级别值的比例 - 这些是0-100,0-255还是0-65535?< / p>

1 个答案:

答案 0 :(得分:0)

PECL Imagick扩展doesn't implement(或使用)MagickWand的MagickMorphologyImage,它是原始命令中-morphology Convolve DoG:15,100,0标志的接口。

要使用convolveImage,您需要likely need to use an odd-numbered matrix

  

内核是一个矩阵,指定为以逗号分隔的整数列表(没有空格),从顶行开始从左到右排序。目前,只支持奇数内核,因此指定内核中的条目数必须为3 2 = 9,5 2 = 25,7 2 = 49等。

但是我不认为你能够重新创建它(至少不像原版那样高质量),因为原始标志使用计算的卷积Difference of GaussiansDoG),您无法使用更简单,更原始的卷积重新创建。