如何使用 Java 或 clojure 中的 ImageJ 进行批量图像处理?
我想使用 ImageJ 对几千张图像进行一些处理。
有没有办法采用任何通用 imageJ 插件并将其自动应用于数百张图像?
例如,假设我想拍摄一千张图像并对每张图像应用极坐标变换——
可以在此处找到 ImageJ 的极坐标变换插件:
http://rsbweb.nih.gov/ij/plugins/polar-transformer.html
太棒了!让我们使用它吧。来自:
我发现我可以使用以下内容应用插件:
(defn x-polar
[imageP]
(let [thread (Thread/currentThread)
options ""]
(.setName thread "Run$_polar-transform")
(Macro/setOptions thread options)
(IJ/runPlugIn imageP "Polar_Transformer" "")))
这很好,因为它可以抑制每个图像都会弹出的对话框。但是运行它总是会弹出一个包含转换后的图像的窗口,而我想要的只是返回转换后的图像。
做我想做的事情的最愚蠢的方法是关闭出现的窗口并返回它正在显示的图像。
做了我想要的,但绝对是迟钝的:
(defn x-polar
[imageP]
(let [thread (Thread/currentThread)
options ""]
(.setName thread "Run$_polar-transform")
(Macro/setOptions thread options)
(IJ/runPlugIn imageP "Polar_Transformer" "")
(let [return-image (IJ/getImage)]
(.hide return-image)
return-image)))
我显然错过了一些关于如何在编程上下文中使用 imageJ 插件的内容。 有谁知道执行此操作的正确方法?
谢谢, ——罗伯特·麦金太尔
I want to use ImageJ to do some processing of several thousand images.
Is there a way to take any general imageJ plugin and apply it to hundreds of images automatically?
For example, say I want to take my thousand images and apply a polar transformation to each---
A polar transformation plugin for ImageJ can be found here:
http://rsbweb.nih.gov/ij/plugins/polar-transformer.html
Great! Let's use it. From:
I find that I can apply a plugin using the following:
(defn x-polar
[imageP]
(let [thread (Thread/currentThread)
options ""]
(.setName thread "Run$_polar-transform")
(Macro/setOptions thread options)
(IJ/runPlugIn imageP "Polar_Transformer" "")))
This is good because it suppresses the dialog which would otherwise pop up for every image. But running this always brings up a window containing the transformed image, when what I want is to simply return the transformed image.
The stupidest way to do what I want is to just close the window that comes up and return the image which it was displaying.
Does what I want but is absolutely retarded:
(defn x-polar
[imageP]
(let [thread (Thread/currentThread)
options ""]
(.setName thread "Run$_polar-transform")
(Macro/setOptions thread options)
(IJ/runPlugIn imageP "Polar_Transformer" "")
(let [return-image (IJ/getImage)]
(.hide return-image)
return-image)))
I'm obviously missing something about how to use imageJ plugins in a programming context.
Does anyone know the right way to do this?
Thanks,
--Robert McIntyre
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,在编写 ImageJ 插件时没有考虑到编程用途是很常见的,并且没有一种真正优雅的方法可以在不更改插件代码的情况下解决这个问题。 (您已经发现周围有一些不满意的方法:))因此,在您的立场上,我只需按以下方式更改
Polar_Transformer.java
中的代码:http://gist.github.com/452826
...这大致符合 斐济插件设计指南,同时仍然尝试对原始代码进行最小的更改。然后,您只需创建 PlugIn 对象并对其调用 exec(...) 即可提供您想要的选项。 (我还没有真正测试过该补丁,但你明白了。)
我希望这有一些帮助 - 不过,我看到你的问题是前一段时间,所以我想你可能同时找到了一些其他解决方法。
Unfortunately, it's very common for ImageJ plugins to be written without programmatic use in mind, and there's not really an elegant way of getting around that without changing the code of the plugin. (You've already discovered that there are unsatisfactory ways around it :)) So, in your position I would just change the code in
Polar_Transformer.java
in the following way:http://gist.github.com/452826
... which is vaguely along the lines suggested in the Fiji PlugIn Design Guidelines, while still trying to just make minimal changes to the original code. Then you can just create the PlugIn object and call
exec(...)
on it supplying the options you want. (I haven't really tested that patch, but you get the idea.)I hope that's of some help - I see that your question was some time ago, though, so I guess you may have found some other workaround in the mean time.