使用 GIMP 方案编写矩阵转换
我想用 DrRacket(R5RS 但不仅如此)写一些漂亮的数学(Racket 标签有点空)。
我真的很想编写一些矩阵的东西,例如:
(3 3 3) (5 3 4) (4 4 4) -> (5 3 4) (5 5 5) (5 3 4)
以及其他类似的东西来设置一些漂亮的 gimp 过滤器...
有些人指出,这可以通过列表内的列表来完成,但我在这里想不出一个实际的例子...
我期待您的回复。 此致,Andreas_P
I want to write some nice Math with DrRacket(R5RS but not only) (Racket Tag is a bit empty).
I would really like to code some matrix stuff like:
(3 3 3) (5 3 4)
(4 4 4) -> (5 3 4)
(5 5 5) (5 3 4)
And other stuff like this to set up some nice gimp filters...
Some folks pointed out, this could be done via lists inside lists, but I can't think of a practical example here...
I am looking forward to your reply.
Yours sincerely, Andreas_P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些注意事项:
1)Scheme“内置于核心”是什么意思? GIMP 现在拥有原生 Python-fu 和 Script-fu
2) 赢得 Google AI Challenge 的 Lisp 是 Common Lisp,而不是 Scheme
3) 我不确定,但 Script-fu 控制台声明 TinyScheme,因此我希望它能够就更完整的方案实现而言,在几乎没有库支持的情况下,这确实是必不可少的
无论如何,我尝试了一些关于矩阵“方案方式”的示例。为了简单起见,它们对输入数据缺乏任何控制,但对于简单的示例,它们在 DrRacket 上运行良好。
现在对数据进行简单测试,如其他答案所示:
A few notes:
1) what do you mean with Scheme "is built in within the core"? GIMP now has a native Python-fu along with Script-fu
2) the Lisp that won Google AI Challenge is Common Lisp, not Scheme
3) I am not sure, but the Script-fu console states TinyScheme, thus I would expect it to be really essential, with little library support, with respect to more complete Scheme implementations
Anyway, I tried a few example on matrices "the Scheme way". For the sake of simplicity, they lack any control on the input data, but for simple examples they work fine on DrRacket.
And now a simple test on the data as in the other answer:
HHi,我强烈建议您使用Python 而不是Scheme 来编写GIMP 脚本,除非您想为了娱乐目的而学习Scheme。
Python 的原则之一是不要让语言成为你和问题之间的障碍,编写你自己的矩阵操作代码是微不足道的。如果您想要高性能操作,您可以使用第三方库,例如 NumPy(甚至来自 GIMP 环境内部)来获取它。
因此,对于允许标量乘法和加一的 Matrix 类,可以简单地编写:
Python 交互式控制台上的示例:
实现更多操作同样简单,并且,为了调用 GIMP 的 API 函数,在这个示例类中,您可以只使用 m。值,这只是一个按顺序包含所有矩阵值的列表 - 这是 GIMP PDB 函数使用它们的方式。 (例如pdb.gimp_drawable_transform_matrix或pdb.plug_in_convmatrix。(我想你已经在帮助菜单下找到了GIMP的API浏览器 - 在Scheme和Python中也有相同的功能,只需将名称中的“-”替换为“_” )
HHi, I'd highly recommend you to use Python instead of Scheme for writing GIMP scripts, unless you want to learn Scheme for recreational purposes.
One of the tenets in Python is to not allow the language to stay between you and your problem, and writing your own Matrix manipulation code is trivial. If you want high performance ops, you can use a third party library such as NumPy (even from inside GIMP environment) to get it.
So, for a Matrix class that would allow scallar multiplication and adding one could simply write:
Example on Python's interactive console:
Implementing more operations is equally simple, and, for calling GIMP's API functions, with this example class, you can just use m.values, that is simply a list with all the matrix values in sequence - which is the way GIMP PDB's functions use them. (Such as pdb.gimp_drawable_transform_matrix or pdb.plug_in_convmatrix. (I suppose you've found GIMP's API browser under the help menu - the same functions are available in Scheme and in Python, just replace the "-" in the names for "_")