Actually I'm working with BufferedImages, that provide me pixel values in int type.
Do you know a Java object to represent an image that the pixel value in double or float type?
I'm not sure exactly what your end goal is, but you could look into java.awt.image.ColorModel
. Either that or you could do your processing on a float[][]/double[][] and then round if you need to do something with your BufferedImage.
I do know of an implementation off the top of my head, but you can use the SampleModel/WritableRaster to access bands independently and create your own backing however you like. It likely won't be much fun though. Although, I'd question the "access component (??) as a double/float" requirement (unless you're doing something fun like OpenGL 8-bit floats ... which don't map to Java floats anyway :-)
You can use Java Advanced Imaging API (JAI).
JAI introduces two new data classes, which extend the Java 2D DataBuffer image data class: DataBufferFloat and DataBufferDouble.
http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/J2D-concepts.doc.html#52401
Related
What I have is: for each of the colors r, g and b, a two-dimensional array of integers in the [0,255] range. What I want is: create a BMP out of this array and send it to the client. The problem is, I cannot use java.awt.Color, BufferedImage, etc., since these are off-limits in the App Engine. The App Engine does offer an image manipulation service which, however, is meant for images I already have, not for creating images from scratch.
I am considering teaching myself how to 'manually' create a BMP, but this does seem like a lot of work. Should I do this, or is there an easier way?
The BMP format is pretty simple compared to JPG or PNG for example.
It has lots of header fields and bits, but you don't need to calculate/fill all. Basically what you need to do is create/write the BMP header which is less than 100 bytes (~56 if I remember well). Only a few fields you need to set, e.g. image size in pixels, image type (e.g. bits/bytes per pixel) etc. You can use the image type which is identical to yours: 3 bytes per pixel (r, g and b components).
Once you have this, the image data follows which you can just write as you have, one thing to keep in mind is that BMP stores images upside-down, and it may have line padding to be a multiple of 4 bytes for example.
That's all! Note that I haven't mentioned java.awt.Image or java.awt.Color because they are not needed to create simple BMPs.
I consider posting full code out of "scope" as you haven't posted any.
Here's an example Java implementation, use it or modify/tweak it to your needs:
http://www.javaworld.com/article/2077561/learn-java/java-tip-60--saving-bitmap-files-in-java.html
There are also many other Java implementations, don't be afraid to search.
This is a question I've been mulling over for a couple of evenings now, and I'm not really any closer to an answer. I'd like to take the Fourier transform of an image that's just been taken on a camera on an Android device. Now the way I see it, there are 3 options for doing this:
Transform the byte[] array which is returned from the camera, then change the result to an image which can be displayed. This seems the most direct method but I can't find any libraries which can transform byte arrays.
Convert the byte array to an int[] or other number array and run a transform from one of the mathematical libraries like JTransform. Then convert to an image from the number array.
Convert the camera image to a RenderedImage object and use the DFTDescriptor class in the Java Advanced Imaging library to perform the transform. Not sure how well this would run on phone processors AND the documentation for JAI isn't exactly the clearest...
Or have I missed some other glaringly obvious way that merits a *hit head with hand*?
I'd be really grateful if someone could shine some light on this. I seem to be going in circles with it!
Thanks.
My suggestion is that you use Piotr Wendykier's JTransform library (as per your option 2). Amongst other possibilities it specifically supplies a 2D DFT transform, which should fit your requirement nicely.
Cheers,
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 is a mature, open-source image processing framework that supports macros, plugins and a host of other features.
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.
What is a Java type which can hold a PNG implement and provide access to it's pixel buffer?
BufferedImage img = ImageIO.read(new File("my.png"));
int color = img.getRGB(23,12);
I would take a look at Java Advanced Imaging, it handle multiple types of image files.
Take a look ImageIO and its numerous static helpers for reading and writing bytes/streams containing an image.
If you want to do pixel based operations on the entire image, I've found calling the getRGB() method every time to be fairly slow. In that case, you might want to try and get access to the actual pixel array holding the image data using something like:
byte[] pixel_array = ((DataBufferByte)img.getRaster().getDataBuffer()).getData()
There may be a more flexible way that doesn't make any presumptions on the array data type.
I have a Serializable object which is supposed to hold a java.awt.Image as its member. How should I go about serializing it?
(Edited from a not so clear first version, sorry.)
ImageIcon implements Serializable and it can be used to wrap an Image class
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ImageIcon.html
javax.swing.ImageIcon, as a part of Swing, does not guarantee to have compatible serialised form between versions. However, you can cheat and look at its readObject and writeObject code - find width and height, grab the pixels with PixelGrabber. I'm not entirely sure that covers the colour model correctly. The obvious alternative is to write a real image format with javax.imageio.
None that I know of. I believe you need to write your own serializer for it to basically save out the width, height and pixel values... Or write it out to the stream as a PNG or something