我应该如何用Java进行图像处理?
我正在制作一个小程序,可以让用户裁剪出图像的一部分并保存它。对于裁剪,我将实现一个“魔杖”式的工具。我可以在 Matlab 中完成所有这些工作,但我在弄清楚 Java 库时遇到了一些麻烦。以下是我需要执行的一些任务:
- 通过 (x,y) 随机访问图像中的像素并返回单个对象(java.awt.Color、ARGB int、short[],等等 - 只要我不单独处理通道)
- 从布尔值[][]创建一个alpha通道
- 创建一个初始化为绿色的N乘M图像
有专业人士可以帮助我吗?只需从你的头脑中提取一些代码片段就可以了。
非常感谢,
尼尔
I'm making an applet that lets users crop out a piece of an image and save it. For cropping, I'm going to implement a "magic wand"-esque tool. I can do all this in Matlab but i'm having some trouble figuring out the Java libraries. Here are a few tasks I need to perform:
- Randomly access pixels in an image by (x,y) and return a single object (java.awt.Color, ARGB int, short[], whatever -- as long as I'm not dealing with channels individually)
- Create an alpha channel from a boolean[ ][ ]
- Create a N by M image that's initialized to green
Any pros out there who can help me? Just some code snippets off the top of your head would be fine.
Many thanks,
Neal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您想要使用 Java2D 库。具体来说,您希望使用库中的 BufferedImage 类来处理图像。您可以访问各个像素并执行上面指定的所有操作。 Sun/Oracle 有一个很好的教程来帮助您开始正确的方向。该教程的第二部分介绍了如何创建 Alpha 通道。哦,要访问单个像素,您需要使用
WritableRaster
类。所以你可以做这样的事情。希望这能让你开始。You want to use the Java2D libraries. Specifically, you want to use the
BufferedImage
class from the library to deal with your images. You can access individual pixels and do all of the things you have specified above. Sun/Oracle has a good tutorial to get you started in the right direction. The second part in that tutorial goes over creating an alpha channel. Oh, and to access individual pixels, you want to use theWritableRaster
class. So you can do something like this. Hope this gets you started.ImageJ
是一个成熟的开源图像处理框架,支持宏、插件和许多其他功能。ImageJ
is a mature, open-source image processing framework that supports macros, plugins and a host of other features.Marvin 是一个可以帮助您的 Java 图像处理框架。它提供了过滤、特征提取、形态分析、转换、分割等算法。此外,其架构支持使用相同算法的实时视频处理。
Marvin is a Java image processing framework that can help you. It provides algorithms for filtering, feature extraction, morphological analysis, tranformations, segmentation and so forth. Moreover, its architecture supports real-time video processing with the same algorithms.