简体   繁体   中英

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. 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

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 the WritableRaster class. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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