gpt4 book ai didi

image - 数学 : Add text to imported image/graphic as a label

转载 作者:行者123 更新时间:2023-12-04 05:06:08 25 4
gpt4 key购买 nike

我已经搜索了几个小时......但我不知所措!

我已经导入了一个图像 int Mathematica -> 尺寸为 2x2cm 的 72DPI。

我正在尝试使用以下文本字符串“标记”图像:
- 具有字体颜色“fontColor”
- 有黑色轮廓,所以它与任何底层颜色形成对比
- 位于导入图像的右下角
- 以厘米为单位的尺寸 h/w
- 可选地位于具有白色背景的文本框中

这是我走了多远:

数学代码:

image = Import["myimg.jpg"];
inchFactor = 2.54;(* 1 inch = 2.54cm *)
docRes = 72;
pixelConverter = docRes/inchFactor/2;

myText = First[
First[ImportString[
ExportString[
Style["glorious label string here", Bold, FontSize -> 15,
FontFamily -> "Verdana"], "PDF"], "PDF",
"TextMode" -> "Outlines"]]];

myTextGraphic =
Graphics[{EdgeForm[Directive[Black, Thickness[0.01]]], White,
myText}, Background -> White,
ImageSize -> {10*pixelConverter, 2*pixelConverter}];
myTextGraphic = Rasterize[myTextGraphic];

combined = SetAlphaChannel[myTextGraphic, myTextGraphicAlphaVersion];

我为文本字符串的黑色轮廓找到了上述方法(PDF 包装器)。

我正在使用仅使用黑色/白色的版本将 AlphaChannel 添加到文本字符串的图形中。

然后我尝试将图像与 Overlay 结合起来。

由于这些似乎都不适用于输出的图像大小和定位,因此我恳请帮助。
没有必要“修复”那些凌乱的代码。

也许你可以给我指一个脚本或教程——我真正想要的是添加一个文本字符串或文本框并将其定位到底层图像。

非常感谢!

最佳答案

看看这个。还有其他方法。

img = Import["http://todayinsci.com/H/Hilbert_David/HilbertDavidThm.jpg"];

Column[{
img,
Text[Style["Professor Hilbert", Red]]
}]

imgCtr = Round[ImageDimensions[img]/2];

overlay = Framed[Graphics[{Text[Style["Professor Hilbert", Red, 9], imgCtr]},ImageSize-> {66, 14}], FrameStyle -> Green]

Overlay[{img, overlay}, Alignment -> Center]

关于image - 数学 : Add text to imported image/graphic as a label,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15509139/

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