简体   繁体   English

我该如何用Java进行图像处理?

[英]How should I do image processing in Java?

I'm making an applet that lets users crop out a piece of an image and save it. 我正在创建一个applet,让用户可以裁剪出一段图像并保存。 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. 我可以在Matlab中完成所有这些工作但是我在搞清楚Java库时遇到了一些麻烦。 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) 通过(x,y)随机访问图像中的像素并返回单个对象(java.awt.Color,ARGB int,short [],无论如何 - 只要我不单独处理通道)
  • Create an alpha channel from a boolean[ ][ ] 从布尔[] []创建一个alpha通道
  • Create a N by M image that's initialized to green 创建一个初始化为绿色的N×M图像

Any pros out there who can help me? 有谁可以帮助我的专业人士? Just some code snippets off the top of your head would be fine. 只需要一些代码片段就可以了。

Many thanks, 非常感谢,

Neal 尼尔

You want to use the Java2D libraries. 您想要使用Java2D库。 Specifically, you want to use the BufferedImage class from the library to deal with your images. 具体来说,您希望使用库中的BufferedImage类来处理图像。 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. Sun / Oracle提供了一个很好的教程 ,可以帮助您开始正确的方向。 The second part in that tutorial goes over creating an alpha channel. 该教程的第二部分将介绍如何创建alpha通道。 Oh, and to access individual pixels, you want to use the WritableRaster class. 哦,要访问单个像素,您需要使用WritableRaster类。 So you can do something like this. 所以你可以做这样的事情。 Hope this gets you started. 希望这能让你开始。

WritableRaster imageRaster = Bufferedimg.getRaster();
//use java random generation to get a random x and y coordinate, then call this to access the pixel
imageRaster.getPixel(x, y,(int[])null);

ImageJ是一个成熟的开源图像处理框架,支持宏,插件和许多其他功能

Marvin is a Java image processing framework that can help you. Marvin是一个可以帮助您的Java图像处理框架。 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. 此外,其架构支持使用相同算法的实时视频处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM