java double[][] - display as image - java

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.

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 to Fourier transform an Android camera image?

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,

How to improve the image quality before the image processing start in javacv or opencv?

I have an image with 400x400 image to identify different components from it. But when I try to identify components using that most of time it doesn't provide correct answers. So I need to know whether there are some kind of methods in javacv or opencv to improve the quality of the image or increase the size of the image without effecting to its quality ?
This is the sample image that I use. (This is the maximum size that I can get and I can't use any photo editing softwares in the project, because it's dynamically generated image.)
In my image processing I need to identify squares and rectangles that connects those squares. And specially I need to get the width and height of those using pixel values.
You can scale it to any size, if you can vectorize it... and in your case vestorization is quite simple as you have some simple geometrical objects in image.
So, in my view your approach should be like this:
detect edges in the image with a high threshold (as you have very distinct objects)
vectorize them
scale them to any size
You should also look at the following link: Increasing camera capture resolution in OpenCV.
If you stick to image processing the easiest way to do it is to apply an equalizeHist(). This will increase contrast and will improve subsequent steps.
But, and this is a biiiig 'but', why are you doing it? Just reading this post, I saw another solution, and a quick google proved me I am right:
Kabeja is a Java library for parsing, processing and converting
Autodesk's DXF format. You can use Kabeja from the CommandLine or
embed into your application. All parsed data are accessible with the
DOM-like API.
That means you can extract directly all the data you want from that image in a text format. Probably something like "at position x, y there is a transistor, or whatever." So why would you render that file into an image, then analyse that image to extract the components?
If you do it for school (I know that many school projects are like this) I would recommend you to find a real problem to solve, and propose it to your teacher. You will be happier to do something that is not complete nonsense.
vectorizing the image is best option I guess as suggested by mocap.
you can also use enhancement tools like sharpening, saturating etc.

Java Image Editor which renders output as source code?

Alex explained what I'm looking for much better than I have:
You want an existing program that
allows you to draw a picture, captures
what you do as you draw, and writes
each action as a Java command. When
you click the "Drawl Oval" tool and
click at 0,0 and then at 50,50, it
would generate the line
g.drawOval(0,0,50,50).
If anybody knows of a program such as this, let me know. Thanks.
Original question:
I've been working with Java and custom drawing using the java.awt.Graphics library lately, but find it is taking too much time to write manually. Is there any simple graphics editor (like mspaint) which generates source code?
Example:
Drawing this:
Would generate:
public void update(Graphics g) {
g.translate(0, 0);
g.drawOval(0, 0, 50, 50);
}
Thanks.
If they are vectors, you could use an SVG Editor (eg, Inkscape) along with Kirill's SVG to Java2D Transcoder to simplify this. It isn't perfect, but Kirill is very responsive in responding to requests for enhancement.
It's unclear what you are asking. Two guesses:
You want an existing program that allows you to draw a picture, captures what you do as you draw, and writes each action as a Java command. When you click the "Drawl Oval" tool and click at 0,0 and then at 50,50, it would generate the line g.drawOval(0,0,50,50).
I do not know of any such tool. But the above might help you reword your question so that others can share their knowledge.
You want a program that takes an existing bitmap and converts it into a series of commands that will replicate the bitmap. Other than simply outputting pixels, such a tool is nearly impossible to write; attempting to decompose an arbitrary picture into simple drawing commands is very hard.
In this case, I would recommend simply importing the bitmap as a JPG, PNG, whatever, and using drawImage() instead of using Graphics calls.
While not what you were looking for, I should mention that XPM (X Pixmap) format is basically a subset of C programming language. XPM2 simplified it more by removing the trappings of C syntax. XPM3 brought them back again.
In a sense XPM image converters are source code generators and translators.
You are looking for something similar to output Java AWT, but for many real images or photographs it would be complicated to do analysis on the image to find oval,etc and create the code for drawing them with lines and shapes (well unless the image had filters applied to simplify it, or was an SVG as someone pointed out). It would probably have to convert to a bitmap of some form and keep it in an array in the generated Java source.

An easy way (tool?) to compare images pixel for pixel in different formats?

Well I've written a basic lossless jpeg joiner thing in java now but I'd like to compare the files it produces with the original files.
I can only compare so much in a hex editor, does anyone know of an easy way, software or java based (preferably software as I dont feel like any more coding for now!) that I can compare two images and produce a "difference map" of where the pixels aren't the same?
Thanks.
Thanks for the suggestions.
I tried the Gimp approach first which works well except when the difference between the images are very small. I couldn't find an "enhance differences" option to make the differences obvious and the histogram also only gives a rough representation of the differences.
In the end I used ImageMagick something I'd installed a while ago and forgot all about. Creating a difference/comparison image is as easy as typing:
compare first.jpg second.png difference.gif
in the command line.
It's all nicely explained here.
TortoiseIDiff is a free image diff viewer:
http://tortoisesvn.tigris.org/TortoiseIDiff.html
It is part of TortoiseSVN, but can be used without Subversion.
Depending on your project, not all files which are under version
control are text files. Most likely you will have images too, for
example screenshots and diagrams for the documentation/helpfile.
For those files it's not possible to use a common file diff tool,
because they only work with text files and diff line-by-line. Here is
where the Tortoise Image Diff tool (TortoiseIDiff) comes to the
rescue. It can show two images side-by-side, or even show the images
over each other alpha blended.
You could do a lot worse than Perceptual Diff.
The best approach would be to use Pix for windows (comes with the DirectX SDK). Supports Bitmap, PNG and Jpeg...Enjoy!
Use an image editor like Photoshop or the Gimp or whatever, which has multiple layers. Create an image where each source image in a separate layer.
At this point, you can visually compare the images by toggling the top layer's visibility off and on.
In most decent editors, you can also set the top layer to "difference" mode. Now each image pixel's value is the absolute difference of the pixel values in the underlying images. You can use e.g. a histogram tool to see if the images are identical. If they're identical, then all the pixel values will be exactly 0.
For stuff like this, I love the netpbm/pbmplus toolkit. You can use djpeg and pnmtoplainpnm to convert each image into a simple ASCII format. You then just read both files and emit a new image which shows where pixels differ. You could, for example, compute the Euclidean distance in RGB space between old and new pixels and emit a white pixel for zero difference, light gray for a small difference, darker for larger differences, and so on. The ASCII format is simple and is well documented on the man pages, and all the standard viewer programs can view it directly.
The latest version of Araxis Merge will do image diffs ( http://www.araxis.com/merge/topic_comparing_image_files.html ).
Unfortunately it's not a free app so whether or not you're willing to pay for it is another thing...
There's also a convenient web app called Resemble.js, which analyzes and compares images pixel by pixel. The different pixels in the images (if any) are highlighted with pink or yellow color depending on your preference.

Categories