How to Fourier transform an Android camera image? - java

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,

Related

Convert image to sketch and then cartoonify?

My aim is to let the user take a selfie from my app and then apply different image processing algorithms to convert it in a cartoon type image. I followed the algo written here, and then also used the method written just below the chosen answer to convert black and white sketch to colored image that should look like cartoon. Every thing is ok except that after applying Gaussian Blur , the image becomes too hazy and unclear. Here is the image output:
Any advice how I can make it more clear? Like shown in this link. I know they used Photoshop , but I want to achieve it with Java and Android.
PS: I found all the image processing methods from here. Plus the method mentioned here (the one below the chosen answer), what could be the ideal values in the arguments?
cartoonifying image
If you have a basic knowledge of C++, you can port this app for your need.
This application works real time. If you want to non-real time,than you can use bilateral filter against two medianBlurs at the bottom of function. That will give better results, but bad performance. But you need to use OpenCV in your application. If you want to make application with more functions, I will suggest you to do it.

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 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's the best way to analyse the colours in an image (Java)?

I don't have much experience doing image analysis so I thought I'd ask more enlightened individuals :)
Basically what I want to do is analyse an image and work out what the most common colours are (these will be averages obviously).
Does anybody know of an effective way to do this? If at all possible I'd like to avoid using any third party libraries, but everything will be considered at least.
Like I said, I don't have much experience with image analysis so please be patient with me if I don't understand your answers properly!
I've tried Google but there doesn't seem to be anything resembling what I'm after. Maybe my Google-Fu just isn't good enough today.
I'd really appreciate any pointers you guys could give!
Thanks,
Tom
A rough idea of how you might be able to do this:
You could use java.awt.image.PixelGrabber to grab a 2D array of RGB ints from the image, pixel by pixel.
When you have this array populated, you can go through and sort however you want (sounds like it would be memory-intensive), and perform simple functions to order them, count them, etc.
Then you could look at java.awt.Color and, using the Color(int, int, int) constructor, create boxes with those colors (as visual placeholders) with the number of occurrences appearing below it.
To get the hex values for the color, you can use a String like so:
String rgb = Integer.toHexString(color.getRGB());
rgb = rgb.substring(2, rgb.length());
(substring is necessary, otherwise you'd get 8 characters)
Hopefully this gets you on the right track!
Resources: Color Class, Image Class
Consider a "color cube" with RGB instead of XYZ. Split the cube into subcubes, but make them all overlap. Ensure they are all the same size. An easy to remember/calculate cube-pattern would be one that goes from 0-127, 64-191, 128-255 in all directions, making for a total of 27 cubes. For each cube, find what colors in the image fall into them.
As you make the cubes smaller and smaller, the results will change less and less and begin to converge on the most popular color ranges. Once you have that convergence, take the average of the range to get the "actual color".
That's about as much detail as I can go into with my boss hovering around the cubefarm :-)
I know your trying to avoid third party libraries, but do take a look at OpenCV. They have some good stuff w.r.t image manipulation and analysis. Maybe that can work for you.

java double[][] - display as image

just wondering if there is a simple way in java to display the contents of say 16x16 array of doubles [0..1] as a greyscale image (ala matlab)? using an unfamiliar matrix library, so I'd like to check that I'm on the right track. don't really care if it is slow or ugly, or if it requires external library - it's just there for a quick look, so as long as it works, I'm fine.
Take a look at java.awt.MemoryImageSource.
The javadoc gives an example of how to use this class similar to what you need.
The Component.createImage(ImageProducer) method can then convert this into an Image that you can display in swing components with an ImageIcon.

Java image with double value pixel

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

Categories