gpt4 book ai didi

php - 使用 Imagick PHP 勾勒透明图像时如何用边框颜色填充封闭区域

转载 作者:搜寻专家 更新时间:2023-10-31 20:56:53 28 4
gpt4 key购买 nike

我想在具有 20 像素边框的透明背景中勾勒出一个对象的轮廓。但是,我想用边框颜色填充封闭区域。

$image = new Imagick('./img/hinata.png');
$mask = clone $image;
$mask->separateImageChannel(Imagick::CHANNEL_ALPHA);
$mask->negateImage(true);
$mask->edgeImage(20);
$mask->opaquePaintImage("white","blue",65000,false);
//// TODO: I don't know how to fill the holes
$mask->transparentPaintImage("black",0.0,0,false);
$image->compositeImage($mask,Imagick::COMPOSITE_DEFAULT,0,0);

我引用了这个问题: Outline a transparent image using imagick PHP

这是图片: enter image description here

这是我想要实现的: enter image description here

这不是我想要实现的: enter image description here

最佳答案

这就是我在 ImageMagick 命令行中的做法。

Make the background under the transparency blue.

Extract the alpha channel.

Dilate the alpha channel.

Use connected components to fill in any "holes" smaller than some threshold in area.

Replace the old alpha channel with the new one


输入:from here

enter image description here

convert cartoon_girl.png -background blue -alpha background \
\( -clone 0 -alpha extract \
-morphology dilate diamond:12 \
-define connected-components:mean-color=true \
-define connected-components:area-threshold=500 \
-connected-components 8 \) \
-alpha off -compose copy_opacity -composite \
result.png


enter image description here

不幸的是,据我所知,Imagick 不支持连接组件。所以唯一的其他方法是在每个“洞”内的某个点使用洪水填充。这意味着您必须在每个孔内选择 x,y 坐标,以用于在进行扩张后进行洪水填充。参见 https://www.php.net/manual/en/imagick.floodfillpaintimage.php

convert cartoon_girl.png -background blue -alpha background \
\( -clone 0 -alpha extract \
-morphology dilate diamond:12 \
-fuzz 80% -fill white \
-draw "color 100,310 floodfill" \
-draw "color 200,235 floodfill" -alpha off \) \
-alpha off -compose copy_opacity -composite \
result2.png


enter image description here

关于php - 使用 Imagick PHP 勾勒透明图像时如何用边框颜色填充封闭区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57655087/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com