gpt4 book ai didi

wolfram-mathematica - 提取粗线轮廓

转载 作者:行者123 更新时间:2023-12-05 00:05:39 26 4
gpt4 key购买 nike

如何以矢量形式绘制如下粗线的轮廓?我所说的矢量形式是指一些不是 Raster 或 Image 的 Graphics 基元集合。

Graphics[{AbsoluteThickness[100], JoinForm["Round"], CapForm["Round"],
Line[{{0, 0}, {0, 1}, {1, 1}}]}, ImageSize -> 200]


(来源: yaroslavvb.com)

文档有以下用于提取文本轮廓的示例,但我还没有找到修改它以获取 Line 轮廓的方法。对象
ImportString[ExportString[Style["M8", FontFamily -> "Times", FontSize -> 72],"PDF"], "TextMode" -> "Outlines"]

我已经 also triedRasterize在线对象上并从 alpha channel 中减去一个稍小的版本。这会产生光栅化伪影,并且对于 ImageSize->500 来说每个形状 5 秒太慢了。

也问过数学组

更新
我已经尝试通过您从 MorphologicalPerimeter 获得的点拟合样条曲线. ListCurvePathPlot理论上是这样,但它打破了像素“楼梯”模式。为了平滑楼梯,需要找到曲线周围点的顺序。 FindCurvePath看起来很有希望,但返回了 splinter 曲线的列表。 FindShortestTour理论上也可以这样做,但它在 20x20 像素图像中的轮廓上花了一秒钟。 ConvexHull在圆形零件上做得很好,但切断了非凸面部分。

我最终得到的解决方案是在周边点上构建最近邻图并使用版本 8 函数 FindEulerianCycle找到形状周围像素的顺序,然后使用 MovingAverage平滑楼梯,然后是 ListCurvePathPlot创建样条对象。它并不完美,因为仍然存在“楼梯”模式的残余,而平均太多会平滑重要的角落。更好的方法可能是将形状分解为多个凸形,使用 ConvexHull ,然后重新组合。同时,这是我正在使用的
getSplineOutline[pp_, smoothLen_: 2, interOrder_: 3] := (
(* need to negate before finding perimeter to avoid border *)

perim = MorphologicalPerimeter@ColorNegate@pp;
points =
Cases[ArrayRules@SparseArray@ImageData[perim],
HoldPattern[{a_Integer, b_Integer} -> _] :> {a, b}];
(* raster coordinate system is upside down, flip the points *)

points = {1, -1} (# - {0, m}) & /@ points;
(* make nearest neighbor graph *)

makeEdges[point_] := {Sort[{point, #}]} & /@
Nearest[DeleteCases[points, point], point];
edges = Union[Flatten[makeEdges /@ points, 2]];
graph = Graph[UndirectedEdge @@@ edges];
tour = FindEulerianCycle[graph] // First;
smoothed = MovingAverage[tour[[All, 1]], smoothLen];
g = ListCurvePathPlot[smoothed, InterpolationOrder -> interOrder];
Cases[g, BSplineCurve[___], Infinity] // First
);

scale = 200;
pp = Graphics[{AbsoluteThickness[scale/2], JoinForm["Round"],
CapForm["Round"], Line[{{0, 0}, {0, 1}, {1, 1}}]},
ImageSize -> scale];
Graphics[getSplineOutline[pp, 3, 3]]


(来源: yaroslavvb.com)

最佳答案

很遗憾EdgeForm[] (如文档中所述)不适用于 Line对象。所以我们能做的最好的事情就是不使用 Line[]或使用某种黑客。我能想到的最简单的是

Graphics[{AbsoluteThickness[100], JoinForm["Round"], CapForm["Round"],
Line[{{0, 0}, {0, 1}, {1, 1}}], AbsoluteThickness[99], White,
Line[{{0, 0}, {0, 1}, {1, 1}}]}, ImageSize -> 200]

alt text

关于wolfram-mathematica - 提取粗线轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4425582/

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