266

I am using both the JAI media apis and ImageMagick?

ImageMagick has some scalability issues and the JNI based JMagick isn't attractive either. JAI has poor quality results when doing resizing operations compared to ImageMagick.

Does anyone know of any excellent tools either open source or commercial that are native java and deliver high quality results?

Daniel Honig
  • 4,268
  • 6
  • 26
  • 24
  • 5
    JMagick has almost no documentation except for the javadocs. I've just spent two hours searching for something that should have been pretty easy to do. – Alex Ciminian Aug 04 '10 at 16:30
  • Indeed. I chose to just go out of process and use ImageMagick using apache exec as a means of managing the process. This worked fine. I might have gone so far as to build an image server just for this purpose. Its hard to find something with the quality and functionality of ImageMagick. – Daniel Honig Aug 05 '10 at 20:18
  • See this answer on a duplicate question: http://stackoverflow.com/a/2407269/11236 – ripper234 Nov 28 '11 at 15:46
  • 189
    It's ridiculous that questions like this get closed as off-topic. Over 100000 viewings, it's clearly a question people are asking. Sometimes people do not know exactly everything they are going to do in advance, and would appreciate other peoples "opinionated" responses on the best general framework. Too much grandiose moderation on SO! – user467257 Jun 17 '14 at 11:46
  • 15
    What's wrong if people discuss pros and cons of ways of a key aspect of Java programming? Isn't what SO supposed to do? IMHO, such questions should be carefully moderated and maintained to provide a good reference to developers starting afresh on the particular topic. – Raúl Apr 17 '15 at 12:13
  • 26
    Yup. Top result in Google for `java image processing library` but closed... as usual. Moderation is going overboard on SO these days. – Stijn de Witt Dec 04 '15 at 15:25
  • Nobody mentioned Apache Commons Imaging Library. Just a note here. – Shukant Pal Nov 25 '18 at 02:20

11 Answers11

138

I know this question is quite old, but as new software comes out it does help to get some new links to projects that might be interesting for folks.

imgscalr is pure-Java image resizing (and simple ops like padding, cropping, rotating, brighten/dimming, etc.) library that is painfully simple to use - a single class consists of a set of simple graphics operations all defined as static methods that you pass an image and get back a result.

The most basic example of using the library would look like this:

BufferedImage thumbnail = Scalr.resize(image, 150);

And a more typical usage to generate image thumbnails using a few quality tweaks and the like might look like this:

import static org.imgscalr.Scalr.*;

public static BufferedImage createThumbnail(BufferedImage img) {
    // Create quickly, then smooth and brighten it.
    img = resize(img, Method.SPEED, 125, OP_ANTIALIAS, OP_BRIGHTER);

    // Let's add a little border before we return result.
    return pad(img, 4);
}

All image-processing operations use the raw Java2D pipeline (which is hardware accelerated on major platforms) and won't introduce the pain of calling out via JNI like library contention in your code.

imgscalr has also been deployed in large-scale productions in quite a few places - the inclusion of the AsyncScalr class makes it a perfect drop-in for any server-side image processing.

There are numerous tweaks to image-quality you can use to trade off between speed and quality with the highest ULTRA_QUALITY mode providing a scaled result that looks better than GIMP's Lancoz3 implementation.

abagh0703
  • 841
  • 1
  • 12
  • 26
Riyad Kalla
  • 10,604
  • 7
  • 53
  • 56
  • 1
    @Riyad Kalla it seems interesting thanks... But I don't get it can it be used in commercial projects? – user592704 Jan 07 '13 at 05:29
  • 5
    @user592704 Absolutely, imgscalr is licensed under the Apache 2 license; the same license everything at the Apache Foundation is licensed under. You can take it and do what you want with it in open source or commercial products. imgscalr is actually already deployed in a number of commercial web apps in production. – Riyad Kalla Jan 08 '13 at 00:00
  • imgscalr is great, except is doesn't have it's own IO routines (if I'm wrong here please please correct me). It depends on IOImage or JAI to create a BufferedImage. But IOImage doesn't support JPEG images with certain metadata, and JAI doesn't support JPEG images with a CMYK color scheme. So if you're working with uncontrolled images the technoglogies that imagscalr depend on are all buggy. :( – David Parks Feb 04 '13 at 07:49
  • 2
    @DavidParks You are correct, imgscalr is meant to take over once you have that BufferedImage instance (decoded image data), not before. I didn't want to even consider going down the path of trying to do my own decoders/encoders as those pipelines have long since been hardware accelerated under the covers by the Java2D team -- trying to redo all that work bug-free and efficiently would be a herculean undertaking. – Riyad Kalla Feb 05 '13 at 15:54
  • I found that the image quality really suffers with imgscalr. Resizing image to 7x smaller (by area) shouldn't cause the size to drop by 17x. I got better results with Thumbnailator actually. The only problem is that it doesn't handle PNG well. – juminoz Jun 21 '13 at 07:29
  • @juminoz You need to tell imgscalr what you want (quality or speed) -- if you pass it ULTRA_QUALITY and use the AA filter, the image will look as good as anything GIMP or Mac Preview can produce. If you pass it no arguments, it will use BALANCED or SPEED in which case, you are right, quality will suffer -- that is by design. – Riyad Kalla Jun 22 '13 at 14:15
  • @RiyadKalla We ran a test at highest quality for imgscalr and the quality is still not good enough when comparing to other open source or commercial ones. In fact, it's not even in the top half on the list. – juminoz Jun 23 '13 at 06:08
  • @juminoz Please file a bug or email the example and the code you used to generate it (including loading/saving the file) -- a lot of times the JPG compression settings passed to the Java encoder are to blame, regardless of how good of quality BufferedImage imgscalr creates. I've helped a number of folks with quality problems before, maybe I can help here? – Riyad Kalla Jun 24 '13 at 13:39
  • which formats are supports? – gstackoverflow Dec 04 '14 at 06:49
  • 1
    @gstackoverflow imgscalr operates on the raw BufferedImage instances (decoded image data) -- so something else (typically the ImageIO library) needs to decode the encoded image data to a BufferedImage and then re-encode it to a new image once imgscalr is done operating on it -- put another way "imgscalr doesn't care about file format, you have already decoded the image before you hand it to imgscalr" – Riyad Kalla Dec 04 '14 at 17:24
  • @Riyad Kalla does this list is actual https://docs.oracle.com/javase/7/docs/api/javax/imageio/package-summary.html ? – gstackoverflow Dec 04 '14 at 18:42
  • @gstackoverflow If you use ImageIO to decode/encode your images and a stock JDK install, then yes, that is what ImageIO supports out of the box. There are other plugins you can add to ImageIO via 3rd party JARs (I've seen some for JPEG2000 support for example) but yes, more or less, that is what you will get in default Java. – Riyad Kalla Dec 06 '14 at 16:31
  • 1
    ImgScalr is only good for basic image manipulation. If it comes to image loading and processing. it lacks the complexicit. – MarekM Feb 10 '15 at 09:50
  • ImgScalr 4.2 supports rotating only in multiples of 90 degrees. It can't rotate at arbitrary angles. – M. Leonhard May 25 '19 at 00:08
94

There's ImageJ, which boasts to be the

world's fastest pure Java image processing program

It can be used as a library in another application. It's architecture is not brilliant, but it does basic image processing tasks.

Community
  • 1
  • 1
Ivan
  • 7,436
  • 1
  • 21
  • 21
  • 3
    I use ImageJ as a library in a number of image processing applications. It's a very decent Java library. It integrates nicely with Java2D too, so you can mix and match the 2 quite easily. – hohonuuli Sep 20 '10 at 17:12
  • 5
    At the time I used ImageJ its API was pretty awkward.It's more an application for which you can write plugins than a library. And as far I remember, trying do develop new GUI in that old AWT code base was a pain. – Ivan Sep 21 '10 at 08:28
  • 8
    I just wasted half a day trying to do a simple image rotation, scale, and crop. It's 2019 and ImageJ's documentation is not usable. – M. Leonhard May 24 '19 at 23:33
33

Another good alternative: Marvin

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Joseph
  • 331
  • 3
  • 2
10

I'm not a Java guy, but OpenCV is great for my needs. Not sure if it fits yours. Here's a Java port, I think: http://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html

rafalmag
  • 1,791
  • 1
  • 17
  • 24
kenny
  • 21,522
  • 8
  • 49
  • 87
9

Processing is new but very, very good.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
fmsf
  • 36,317
  • 49
  • 147
  • 195
  • 1
    I am aware of processing, but are folks really using it in the, I'd like to go run X transformation on my library of X jpeg's sort of fashion? – Daniel Honig Mar 03 '09 at 06:48
  • I've used it and seems really powerfull and worth betting in – fmsf Mar 06 '09 at 03:31
  • 2
    Actually the core libraries (which could be used for embedding functionality) are LGPL. But nobody asked what the license is. http://wiki.processing.org/w/FAQ#Is_Processing_Open_Source.3F_How_.27bout_some_code.3F – Benjamin Atkin Mar 19 '12 at 05:15
  • This does not look like its based on java but javascript. – mjs May 27 '22 at 11:38
5

Try to use Catalano Framework.

Keypoints:

  • Architecture like AForge.NET/Accord.NET.
  • Run in the both environments with the same code, desktop and Android.
  • Contains several filters in parallel.
  • Development is on full steam.

The Catalano Framework is a framework for scientific computing for Java and Android. The project started as an initial port of the many features of the AForge.NET and Accord.NET frameworks for .NET, but is steadily growing with more advanced features which are now being shared between those projects.

Example:

FastBitmap fb = new FastBitmap(bitmap);

Grayscale g = new Grayscale();
g.applyInPlace(fb);

Threshold t = new Threshold(120);
t.applyInPlace(fb);

bitmap = fb.toBitmap();

//Show the result
Diego Catalano
  • 689
  • 9
  • 16
  • 9
    `The best framework in Java is Catalano Framework` that sounds like you are advertising your own product. Your framework might be great, but you should disclose your affiliation with it, as stated in the [FAQs](https://meta.stackexchange.com/questions/57497/limits-for-self-promotion-in-answers#answer-59302). – Matthias Braun Feb 25 '14 at 18:21
  • @MatthiasBraun OK, I agree with you, I didn't know about it. I edited the answer. – Diego Catalano Mar 01 '14 at 14:29
  • 1
    The Catalano Framework has moved to https://github.com/DiegoCatalano/Catalano-Framework – HairOfTheDog Feb 14 '20 at 19:22
4

imo the best approach is using GraphicsMagick Image Processing System with im4java as a comand-line interface for Java.

There are a lot of advantages of GraphicsMagick, but one for all:

  • GM is used to process billions of files at the world's largest photo sites (e.g. Flickr and Etsy).
kajo
  • 5,631
  • 4
  • 31
  • 29
3

http://im4java.sourceforge.net/ - if you're running linux forking a new process isn't expensive.

rjohnston
  • 7,153
  • 8
  • 30
  • 37
Amanjit Gill
  • 105
  • 1
  • 2
  • Watch out for out of memory errors though... – Claes Mogren Oct 06 '10 at 08:42
  • forking is expensive. It can use a lot of memory. See the person's quote from an article at the bottom of http://www.coderanch.com/t/419196/java/java/there-any-way-execute-Linux (The article is: http://developers.sun.com/solaris/articles/subprocess/subprocess.html) – Plaudit Design Aug 25 '11 at 17:50
  • @Plaudit checkout gm4java, it creates a pool of GM process in interactive mode and doesn't need to fork every time to convert an image. http://kennethxu.blogspot.com/2013/04/integrate-java-and-graphicsmagick.html – Kenneth Xu Apr 17 '13 at 03:19
2

For commercial tools, you might want to try Snowbound.

http://www.snowbound.com/

My experience with them is somewhat dated, but I found their Java Imaging API to be a lot easier to use than JAI and a lot faster.

Their customer support and code samples were very good too.

Clayton
  • 920
  • 1
  • 6
  • 13
2

RoboRealm vision software list mentions JHLabs and NeatVision among lots of other non-Java based libraries.

rics
  • 5,494
  • 5
  • 33
  • 42
1

I cannot say that it is the "best" library, but I think you can try this: http://algart.net/java/AlgART/ It is an open-source Java library, supporting generalized "smart" arrays and matrices with elements of different types (from 1 bit to 64-bit floating point), including 2D-, 3D- and multidimensional image processing and other algorithms, working with arrays and matrices. Unfortunately right now it consists not enough demo and examples, but, on the other hand, it contains a lot of JavaDocs. It lay in the base of commercial software (SIMAGIS) during several years, but now it is open-source.

Daniel
  • 11
  • 2
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Matthias Dec 26 '13 at 14:01
  • You are right, I've edited the first comment. – Daniel Dec 26 '13 at 16:06