What's the best Java library to use if I want to import graphics in some custom format (basically an array of bytes with a specified height, width, bytes per pixel and depth) and then work on it? Image resizing and cutting functionality would be useful if it was included. Should support saving to some lossless format too.
Ones I've found so far are too high level to import the raw data (or maybe it was hidden too deep...)
I've found SWT more than adequate. It allows images to be manipulated
at the pixel level. See this article and the Image Analyzer example.
For more take a look at SWT Home
Related
I basically have an matrix of bytes. Each row (meaning byte[]) represents an image. How do I create a movie out of that (any format - avi, mpeg, whatever), and save it as a file?
Each image can be one of the following:
int JPEG Encoded formats.
int NV16 YCbCr format, used for video.
int NV21 YCrCb format used for images, which uses the NV21 encoding format.
int RGB_565 RGB format used for pictures encoded as RGB_565.
int YUY2 YCbCr format used for images, which uses YUYV (YUY2) encoding format.
int YV12 Android YUV format: This format is exposed to software decoders and applications.
I can choose the format to whatever I like, as long as I get to create the movie.
public void createMovie(byte[][] images) {
// and ideas on what to write here?
}
I don't need the actual implementation, just let me know the idea and what external libraries I need (if I need any).
I also need to edit some of the images (the byte stream) before I create the movie (to add some text). How can I do that?
The solution needs to be "Java only"! No external programs, no external commands (but I can use external jars).
Thanks!
The solution seems to be to use Mencoder (or at least, that seems to be a semi-popular choice).
Here's a link that specifically addresses images-to-movies capabilities in Mencoder.
As for rendering text onto the frames before encoding them as part of the video, you can use Java2D's image manipulation libraries to simply draw text on top of the images beforehand For example:
Load up the images into BufferedImage objects via the ImageIO library's .read method
Use Graphics2D's .drawString method to render the text
That's one way to do it, and this FAQ should get you started in that direction with Java2D, font rendering, etc., and offer pointers to further resources.
The ImageIO library also allows you to read/write a number of image formats, effectively allowing you to transcode images from, say, .jpg -> BufferedImage -> .png, or any which way you need to do it, if you want to store the image files temporarily during the conversion process, and/or convert all the images to a single format when importing them for the conversion project, etc.
Depending on how many output formats you want to support, you'll probably do something like
public void createMovie(BufferedImage[] frames, String destinationFormat)
...where "destinationFormat" is something like "m4v", "mpeg2", "h.264", "gif", etc.
Have you heard about JMF (Java Media Framework), from the sample you can find this example : Generating a Movie File from a List of (JPEG) Images
You can try making a gif with this gif encoder.
I wrote an MJPEG reader and writer for playing videos inside of Java applets. MJPEG is not the most advanced video format but it is very easy to manipulate. The code is part of my computer vision library BoofCV, but you could just rip out this one class for your own purposes.
Download this file: CreateMJpeg.java
Look at main function. Where it reads in jpeg images put your byte[] data, but you will need to convert it to jpeg's first.
You can convert it into a jpeg using the standard java library
Run modified code and enjoy your movie
Sorry its not in a more user friendly format, but at least you don't need to mess with JNI like some other solutions.
I have a play framework application which I want to be able to produce a product label from. I have the label design in illustrator. It consists of a black circle, white writing with a QR code in the middle, also has curved text.
I want to create a high resolution PDF and/or image file of this design on the fly. All most all of the drawing stuff I find for java relates to swing.
Anyone done this?
The basic class which allows creating an image programatically is BufferedImage and the corresponding Graphics2D class. You are not forced to use it with Swing. You can easily convert it to common graphic formats like PNG. Then you can save it as an image file or place it in a generated(e.g. with iText) PDF.
http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html
In other words - yes, it can be done.
But if I ware you I would consider exporting the design from Illustrator to a file and use it as a resource in your application. But if you need to scale it programatically you ought to consider using SVG format to avoid loosing quality. Java does not have build-in support for vector images so you should look at
Apache Batik
I basically have an matrix of bytes. Each row (meaning byte[]) represents an image. How do I create a movie out of that (any format - avi, mpeg, whatever), and save it as a file?
Each image can be one of the following:
int JPEG Encoded formats.
int NV16 YCbCr format, used for video.
int NV21 YCrCb format used for images, which uses the NV21 encoding format.
int RGB_565 RGB format used for pictures encoded as RGB_565.
int YUY2 YCbCr format used for images, which uses YUYV (YUY2) encoding format.
int YV12 Android YUV format: This format is exposed to software decoders and applications.
I can choose the format to whatever I like, as long as I get to create the movie.
public void createMovie(byte[][] images) {
// and ideas on what to write here?
}
I don't need the actual implementation, just let me know the idea and what external libraries I need (if I need any).
I also need to edit some of the images (the byte stream) before I create the movie (to add some text). How can I do that?
The solution needs to be "Java only"! No external programs, no external commands (but I can use external jars).
Thanks!
The solution seems to be to use Mencoder (or at least, that seems to be a semi-popular choice).
Here's a link that specifically addresses images-to-movies capabilities in Mencoder.
As for rendering text onto the frames before encoding them as part of the video, you can use Java2D's image manipulation libraries to simply draw text on top of the images beforehand For example:
Load up the images into BufferedImage objects via the ImageIO library's .read method
Use Graphics2D's .drawString method to render the text
That's one way to do it, and this FAQ should get you started in that direction with Java2D, font rendering, etc., and offer pointers to further resources.
The ImageIO library also allows you to read/write a number of image formats, effectively allowing you to transcode images from, say, .jpg -> BufferedImage -> .png, or any which way you need to do it, if you want to store the image files temporarily during the conversion process, and/or convert all the images to a single format when importing them for the conversion project, etc.
Depending on how many output formats you want to support, you'll probably do something like
public void createMovie(BufferedImage[] frames, String destinationFormat)
...where "destinationFormat" is something like "m4v", "mpeg2", "h.264", "gif", etc.
Have you heard about JMF (Java Media Framework), from the sample you can find this example : Generating a Movie File from a List of (JPEG) Images
You can try making a gif with this gif encoder.
I wrote an MJPEG reader and writer for playing videos inside of Java applets. MJPEG is not the most advanced video format but it is very easy to manipulate. The code is part of my computer vision library BoofCV, but you could just rip out this one class for your own purposes.
Download this file: CreateMJpeg.java
Look at main function. Where it reads in jpeg images put your byte[] data, but you will need to convert it to jpeg's first.
You can convert it into a jpeg using the standard java library
Run modified code and enjoy your movie
Sorry its not in a more user friendly format, but at least you don't need to mess with JNI like some other solutions.
I need to to clip variablesized images into puzzle shaped pices like this(not squares): http://www.fernando.com.ar/jquery-puzzle/
I have considered the posibility of doing this with a php library like Cairo or GD, but have little to no experience with these librays, and see no immidiate soulution for creating a clipping mask dynamicaly scalable for different sized images.
I'm looking for guidance/tips on which serverside programing language to use to accomplish this task, and preferably an approach to this problem.
You can create an image using GD with the size of the puzzle piece. and then copy the full image on that image with the right cropping to get the right part of the image.
Then you can just dynamically color in every part of the piece you want to remove with a distinct color (eg #0f0) and then use imagecolorallocatealpha to make that color transparent. Do it for each piece and you have your server side image pieces.
However, if I where you I would create the clipping mask of each puzzle peace in advance in the distinct color. That would make two images per connection (one with the "circle" connecter sticking out and one where this circle connector fits into). That way you can just copy these masks onto the image to create nice edges quickly.
GD is quite complicated, I've heard very good things about Image Magick for which there is a PHP version and lots of documentation on php.net. However, not all web servers would have this installed by default.
http://www.php.net/manual/en/book.imagick.php
If you choose to do it using PHP with GD then the code here may help:
http://php.amnuts.com/index.php?do=view&id=15&file=class.imagemask.php
Essentially what you need to do with GD is to start with a mask at a particular size and then use the imagecopyresampled function to copy the mask image resource to a larger or smaller size. To see what I mean, check out the _getMaskImage method class shown at the url above. A working example of the output can be seen at:
http://php.amnuts.com/demos/image-mask/
The problem with doing it via GD, as far as I can tell, is that you need to do it a pixel at a time if you want to achieve varying opacity levels, so processing a large image could take a few seconds. With ImageMagick this may not be the case.
Given:
two images of the same subject matter;
the images have the same resolution, colour depth, and file format;
the images differ in size and rotation; and
two lists of (x, y) co-ordinates that correlate the images.
I would like to know:
How do you transform the larger image so that it visually aligns to the second image?
(Optional.) What are the minimum number of points needed to get an accurate transformation?
(Optional.) How far apart do the points need to be to get an accurate transformation?
The transformation would need to rotate, scale, and possibly shear the larger image. Essentially, I want to create (or find) a program that does the following:
Input two images (e.g., TIFFs).
Click several anchor points on the small image.
Click the several corresponding anchor points on the large image.
Transform the large image such that it maps to the small image by aligning the anchor points.
This would help align pictures of the same stellar object. (For example, a hand-drawn picture from 1855 mapped to a photograph taken by Hubble in 2000.)
Many thanks in advance for any algorithms (preferably Java or similar pseudo-code), ideas or links to related open-source software packages.
This is called Image Registration.
Mathworks discusses this, Matlab has this ability, and more information is in the Elastix Manual.
Consider:
Open source Matlab equivalents
IRTK
IRAF
Hugin
you can use the javax.imageio or Java Advanced Imaging api's for rotating, shearing and scaling the images once you found out what you want to do with them.
For a C++ implementation (without GUI), try the old KLT (Kanade-Lucas-Tomasi) tracker.
http://www.ces.clemson.edu/~stb/klt/