【问题标题】:convert whiteboard cleaner script to php将白板清洁器脚本转换为 php
【发布时间】:2015-02-05 06:31:15
【问题描述】:

我正在尝试使用 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?

【问题讨论】:

    标签: php imagemagick imagemagick-convert


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-06-23
      • 2021-10-24
      • 2018-01-07
      • 2014-04-21
      • 2011-01-20
      • 1970-01-01
      • 2016-09-09
      • 2016-11-12
      • 2015-11-16
      相关资源
      最近更新 更多