Creating and drawing huge (Buffered) images in Java - java

I'm working on an application which draws out a matrix - using Java 2D - which can become quite large, for example 30000 x 30000 pixels.
At this moment I've experimented a bit with BufferedImage but creating such a huge BufferedImage causes out of memory exceptions, even when enlarging the heap.
Now I was thinking splitting the image up into several images/regions, and when I'm done in a certain region write it to disk and create a new region/BufferedImage and continue drawing.
I'm interested in thoughts of other people on how they would handle this. I've been away from Java for a while so any concrete examples are welcome.

I contribute to a new/small open source project which may be quite well suited to your needs.
The project is Glimpse. Its intended to aid in construction of 2D data visualizations in Java with a focus on handling large data sets well and making it easy to provide real-time interactivity to allow easy exploration of data.
It utilizes OpenGL to take advantage of hardware features on modern GPUs like texture memory and shaders to achieve the above goals. So if you're set on using Java2D then this won't work for you. However, Glimpse panels can be placed side-by-side with other Swing components, so it's easy to drop into your existing Swing GUI. The only caveat it that you'll need a decent graphics card.
The image is an example of a large matrix of data whose coloring is being dynamically adjusted via the color scale on the right (the matrix data is stored in a GPU texture and the dynamic re-coloring is accomplished via a custom shader). The source for this example is HeatMapExample.java. There's lots of other examples like that which provide starting points for working with Glimpse's other features.
You can learn more at glimpse.metsci.com. There's an intro video on the front page, along with Java WebStart examples. The source is hosted on GitHub.

if you just want to generate the image on disk, then look at pngj - it can generate big png images with no problems because it writes lines of pixels to disk as they are available. the api is a little png-specific, but it's not too complex (it might help to read a little background on the png image format before using it).

Related

The use of image processing to extract data from a diagram

I have a data flow diagram (a diagram that looks like a flow chart). It has a set of specific geometrical components like rectangles, circles, ellipses and arrows.
What I'm trying to achieve is to detect these shapes and be able to know which component is connected to which component (through the lines) and finally read the text inside each one to extract data from the diagram and do further processing. It is also notable to mention that the diagram will not be drawn by hand but computer generated so we don't have to worry about angles and ratios being inaccurate.
I'm currently working in Java and I was wondering if this is going to be possible since Java is not the best language when it comes to image processing (correct me if I'm wrong). And if it's possible I'd you guys to point out where I should start looking.
I think Java is fine, and it has many libraries to process images. ImageJ is just one example. Personally, I like to use Python, so I write scripts in this language using Java API of the DMelt platform. Look at the documentation of this projecst, wiki. Here is a link to a few examples.
Doing this in Java wasn't a great idea because mainly the lack of online resources. After a good amount of research, I found that the best and the easiest approach was the use of C# and Emgu CV which is a cross platform .Net wrapper to the OpenCV image processing library.
This example helped me to get started with detecting basic geometrical shapes like Lines, Rectangles and Triangles.

Adding Text to Screen with OpenGL

Currently, I am working on a OpenGL project and here is the screenshoot what I did
The question is, I want to add texts(degrees) to compass and want to do that with pure OpenGl methods. I found TextRenderer class however, couldn't manage to download it and use it. How to use TextRenderer class in my Java project? If there is any other way of adding text besides TextRenderer, would love to hear it.
My second and most important question is about merging swing/awt methods with OpenGL and using multiple objects. I wrote the program with only using one GL2 object and worked perfectly, is it sensible to use multiple openGL objects on the same frame? Furthermore, using swing methods and openGL methods together is a good idea?
I want to add texts(degrees) to compass and want to do that with pure OpenGl methods.
Unless you can live with not very pleasantly looking center stroke fonts, you have no choice but to use help from some other library or API.
Theoretically OpenGL can collaborate with OpenVG, but so far overall support for OpenVG is very poor, and OpenGL interoperability even worse. But say you had a proper working OpenVG – OpenGL interoperability working, then OpenVG was the way to go.
Practically you have to something different. A very fruitful approach is to use a font renderer library (like FreeType) together with some layout engine (like Pango) to produce an outline stroke list of the text to be rendered, which in turn can be either rendered directly using some extension by NVidia (http://www.opengl.org/registry/specs/NV/path_rendering.txt available only on the most recent NVidia GPUs) or manually tesselated into triangles, either on the CPU or by a combination of GPU Geometry and Tesselation Shaders. A huge drawback of drawing glyphs as tesselated filled outlines with OpenGL primitives is, that they will look very dirty (due to aliasing) if the used framebuffer doesn't have a multisample format (full screen antialiasing)
The next best thing is rendering the text to an image and copying that to the GPU and overlay that over the scene by rendering a textured quad. You should apply all text transformations already when rendering the quad, so that the font hinting system can make the proper adjustments on the transformed glyphs before rasterizing them.
Another approach is using texture mapped fonts. I implemented two TMF engines myself so far, but personally I advise against using this approach these days, as TMFs are resource hogs. A 200kiB TTF font can blow up to several megabytes of texture data. Maybe one day I or somebody else implements a TrueType or OpenType rendering engine with OpenCL, CUDA or Compute Shader, but until then rendering text with OpenGL is dirty business.
It boils down to
Crisp Look
Memory Efficient
Computationally Efficient
→ choose 2
After doing little research, I ve figured out how to install it and use it correctly.
Firstly, go to that web site and download suitable version of jogl for your os in case you dont have any library:
http://jogamp.org/deployment/autobuilds/master/jogl-b1011-2013-06-19_05-41-38/
Then, download that jar file and add it to your user library.
http://www.java2s.com/Code/Jar/j/Downloadjogl20jar.htm
That file contains the TextRenderer class.
If you dont know how to make one, use that link:
http://riccardotramma.com/2011/04/setup-eclipse-to-develop-opengl-glut-apps-in-java-cc-on-windows-mac/
Then, follow the instructions: http://download.java.net/media/jogl/jogl-2.x-docs/com/sun/opengl/util/awt/TextRenderer.html
It's very easy to use, I perfectly added numbers to my compass. However, not efficient as far as I can tell.

What is a good Java lib for image transformations and backbuffer rendering without need of front buffer for server side programming?

I'm trying to find a simple library to fit my needs, but because I am really unaware of Java libs (I use to do everything from scratch in any programming language that I work with) and the exactly thing that I need is complicated for a Google search query, it would be greatly appreciated any recomendation.
What I am trying to achieve is to do some image manipulation in server side using the sumitted info from a web browser. Is not simple scale or crop, but to be able to rotate, scale and crop every single sprite and draw it in the exactly order to compose the final hight resolution image in a backbuffer then save it in bmp and make some copies in lower resolution as png.
I have no problem with the interface from client side to the server, also I have experience in game programming, so I know how to work with double buffering. What I need is a library that let me do all these images transformation and backbuffer drawing without the need of a front buffer and graphics hardware, because the output will not be the screen, and to be able to access every pixel argb from memory, able to save in various image formats and as a plus but not requiered able to render text from different font.
Thanks for any reply and any recomendations to improve my question will be apreciated too (I am new around here).
A couple of libraries you may find helpful for server side image processing in Java:
JH Labs image filters : http://www.jhlabs.com/ip/filters/index.html
imgscalr image scaling library: https://github.com/thebuzzmedia/imgscalr
Also don't forget the good old BufferedImage API that is already in Java: it has quick a decent range of functionality for basic image manipulation (cropping etc.)
http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html

java image loading with effects

I wanted to load java images with some effects like we have in power point like blinds or appear in Java swing when user clicks on the image.
I have these specific questions in mind:
1.Is there a way to do this in Java?
2.Also how will this behave when the image to load is huge like 25 Mega Pixel?
3.If we are dealing with large images being switched, what mechanism should be used for incorporating images in the application?
Thanks,
Sandeep
1.Is there a way to do this in Java?
Yes, but it won't be with a single command or anything like that. Unless you find a library for this, you'll have to code it up manually.
To do animations like these I suggest you have a look at SwingWorkers.
2.Also how will this behave when the image to load is huge like 25 Mega Pixel?
25 mega pixel is quite large. It depends on your computer of course but if you code it reasonable well it should work fine.
3.If we are dealing with large images being switched, what mechanism should be used for incorporating images in the application?
Unless you really want the program to zoom into the details of the image, I suggest you shrink them immediately after loading, so your drawing-routines can work with them efficiently.
You can experiment with your target images using ImageJ. I routinely use it to manipulate images having scores of megapixels containing 8-, 16- and 32-bit data.

Java Graphics library

I'm looking for a high-level java graphic library for creating artistic text, watermarks, resize, crop, image identification and manipulation.
ImageMagic is a good example of such library, but its java ports are somewhat problematic (they either run imagemagic through JNI or via commandline and are hellish to deploy to servers).
Ideally I'd like to have similar functionality to ImageMagic, but pure Java and open-source, free to use.
Has anyone seen something like that?
This is for a server-side component. A service that manipulates images of various web formats (png, jpg, gif etc).
Java has its own libraries, of course (Graphics2D) but I'm looking for something of higher level.
Here are several use cases:
Resize and crop images. If it has "smart resize" or "smart crop" that'll be cool, for example seam carving resize, or cropping by points of interest in the photo
Drawing artistic text on images. Using fonts, colors, text effects (3d text, charcoal and other effects)
Embedding watermarks.
Layering images, using images as background, masking with images etc.
Image identification such as - number of colors, stdev etc.
As mentioned, Java in its Graphics2D supports all of the above but is too low level so I'm looking for something that's nicer to work with.
Thanks!
Java Advanced Imaging ( JAI ) sounds like what you want. From the website:
The Java Advanced Imaging API provides
a set of object-oriented interfaces
that support a simple, high-level
programming model which lets you
manipulate images easily.
I found it relatively simple to work with. And the performance was better than spinning off ImageMagic processes.
Use ImageJ. In addition to being a neat program, it can be used as a library.
The Apache SVG Batik library can
be used to display some vectorial
drawing in SVG.
The eclipse project
contains a library called Graphical
Editing Framework (GEF) shipped with
a painting and layout plug-in called
Draw2D. see
http://whf.poac.ac.cn/codeopen/jiaocheng/java2s/Code/Java/SWT-JFace-Eclipse/2D.htm.
Raw Java2D makes it quite easy to do resizing and cropping (just make sure that you reduce in powers of 2, the backend doesn't handle this automatically). I only found JAI useful for my usage to do color quantization... the rest of the pipeline seemed unnecessary for basic functions.

Categories

Resources