【发布时间】:2018-04-05 00:46:25
【问题描述】:
我正在尝试使用 SVG 过滤器找到图像的边缘点。问题是没有成功。下面是我尝试过的代码。
<svg width="100%" height="495">
<defs>
<filter id="blobby" color-interpolation-filters="sRGB">
<feColorMatrix type="saturate" values="0"/>
<feComponentTransfer>
<feFuncR type="discrete" tableValues="0 0 0 0 0 1"/>
<feFuncG type="discrete" tableValues="0 0 0 0 0 1"/>
<feFuncB type="discrete" tableValues="0 0 0 0 0 1"/>
</feComponentTransfer>
<feMorphology operator="erode" radius="0"/>
<feGaussianBlur stdDeviation="10"/>
<feComponentTransfer>
<feFuncR type="discrete" tableValues="0 0 0 0 0 1"/>
<feFuncG type="discrete" tableValues="0 0 0 0 0 1"/>
<feFuncB type="discrete" tableValues="0 0 0 0 0 1"/>
</feComponentTransfer>
</filter>
</defs>
<g filter="url(#blobby)">
<image xlink:href="https://i.stack.imgur.com/dreFV.jpg" />
</g>
</svg>
如果我将图像标签放在 svg 之外,它可以工作。但是这样我不能在 svg 有 html 时保存它。而且我不想要这种格式。我希望有上面的 svg 格式。
img {
width: 400px;
}
.blob {
background-color: white;
padding: 40px;
filter: url(#blobby);
}
/* Hide the SVG element */
svg {
width: 0px;
height: 0px;
position: absolute;
left: -999px;
}
<svg>
<defs>
<filter id="blobby" color-interpolation-filters="sRGB">
<!-- Convert to greyscale -->
<feColorMatrix type="saturate" values="0"/>
<!-- Threshhold to black or white -->
<feComponentTransfer>
<feFuncR type="discrete" tableValues="0 0 0 0 0 1"/>
<feFuncG type="discrete" tableValues="0 0 0 0 0 1"/>
<feFuncB type="discrete" tableValues="0 0 0 0 0 1"/>
</feComponentTransfer>
<!-- Morphology filter to "erode" (shrink) the white areas -->
<feMorphology operator="erode" radius="8"/>
<!-- Blur to cause image to "spread" -->
<feGaussianBlur stdDeviation="10"/>
<!-- High contrast to threshhold again -->
<feComponentTransfer>
<feFuncR type="discrete" tableValues="0 0 0 0 0 1"/>
<feFuncG type="discrete" tableValues="0 0 0 0 0 1"/>
<feFuncB type="discrete" tableValues="0 0 0 0 0 1"/>
</feComponentTransfer>
</filter>
</defs>
<g>
<img src="https://s3-us-west-2.amazonaws.com/fabric-canvas/Bros-1.jpg"/>
<br>
<div class="blob">
<img src="https://s3-us-west-2.amazonaws.com/fabric-canvas/Bros-1.jpg"/>
</div>
</g>
</svg>
预期的输出是:
提前致谢。
【问题讨论】:
标签: image canvas svg edge-detection svg-filters