• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • Imagick::forwardFourierTransformImage()

    (No version information available, might only be in Git)

    Description

    说明

    publicImagick::forwardFourierTransformimage(bool $magnitude): bool

    将图像的discrete Fourier变换(DFT)作为幅度/相位或实/虚图像对来实现。

    参数

    $magnitude

    If true, return as magnitude / phase pair otherwise a real / imaginary image pair.

    返回值

    成功时返回TRUE

    范例

    Example #1 Imagick::forwardFourierTransformImage()

    <?php
    //Utility function for forwardTransformImage
    function createMask() {
        $draw = new \ImagickDraw();
        $draw->setStrokeOpacity(0);
        $draw->setStrokeColor('rgb(255, 255, 255)');
        $draw->setFillColor('rgb(255, 255, 255)');
        //Draw a circle on the y-axis, with it's centre
        //at x, y that touches the origin
        $draw->circle(250, 250, 220, 250);
        $imagick = new \Imagick();
        $imagick->newImage(512, 512, "black");
        $imagick->drawImage($draw);
        $imagick->gaussianBlurImage(20, 20);
        $imagick->autoLevelImage();
        return $imagick;
    }
    function forwardFourierTransformImage($imagePath) {
        $imagick = new \Imagick(realpath($imagePath));
        $imagick->resizeimage(512, 512, \Imagick::FILTER_LANCZOS, 1);
        $mask = createMask();
        $imagick->forwardFourierTransformImage(true);
        @$imagick->setimageindex(0);
        $magnitude = $imagick->getimage();
        @$imagick->setimageindex(1);
        $imagickPhase = $imagick->getimage();
        if (true) {
            $imagickPhase->compositeImage($mask, \Imagick::COMPOSITE_MULTIPLY, 0, 0);
        }
        if (false) {
            $output = clone $imagickPhase;
            $output->setimageformat('png');
            header("Content-Type: image/png");
            echo $output->getImageBlob();
        }
        $magnitude->inverseFourierTransformImage($imagickPhase, true);
        $magnitude->setimageformat('png');
        header("Content-Type: image/png");
        echo $magnitude->getImageBlob();
    }
    ?>
    

    以上例程的输出类似于:

    For fuzz, percentage or float values do not seem to work. The value is based on the intensity of the image colors. 
    The documentation states: "The amount of fuzz. For example, set fuzz to 10 and the color red at intensities of 100 and 102 respectively are now interpreted as the same color." 
    For those of us who are not graphics geeks, your color intensity might be something like 65535. In which case, to get just 10% fuzz, you need to set it to 6550. 
    You likely will not see any effect if you are using low numbers or floats, like 100, 20, or 0.8. 
    For example: 
    $im = new Imagick();
    $transparentColor = new ImagickPixel('transparent');
    $greenscreen = '#00FF08';  // Super bright green
    $im->readImage("cartoon_dog.png");  // Cartoony dog with a black outline and a #00FF08 (super bright green) background. 
    // Replace the green background with transparent.
    // Leaves significant green lines around the outline of the dog, which is unacceptable.
    $im->floodFillPaintImage($transparentColor, 30, $greenscreen, 0, 0, false, Imagick::CHANNEL_ALPHA);
    // Works as intended - removes all of the green background. 
    $im->floodFillPaintImage($transparentColor, 30000, $greenscreen, 0, 0, false, Imagick::CHANNEL_ALPHA);
    Credit to the discussion here: 
    https://php5.kiev.ua/php7/imagick.painttransparentimage.html