I'm currently working with JavaFX 2.2 und Batik. I have an application with a pane on which you can drag multiple SVG pictures.
This is all working out, and the svg code of each picture is stored in each object, so I can get that, too.
However now I want to take a "screenshot" of this pane and its current SVG-children and export it as an svg-file.
To me, there are two possibilities:
1) export it with the takeSnapshot() function as a .png-file and convert it to svg
2) or create a new svg-file from all the small svg-files with paying attention to the position of each svg-picture-object.
Is the latter possible? Or does anyone know, whether batik can do this png to svg conversion?
Thanks a lot for your help! :)
With approach 1) you would loose all vector information and end up effectively with a bitmap. The result would typically be larger (in terms of disk space) and loose quality when it is scaled.
So approach 2) is clearly better. Batik implements SVG DOM so that manipulation of the individual documents should not be to difficult.
Related
Currently we have a requirement where we have an image depicting the blueprint of the mall (red specifies the booked up areas and white specifies the available areas) and the image is available in a raster (JPEG) format.
We would like to drag and drop some icons onto the available areas of the image (in white). There should also be zoom in and zoom out functionality to be given for the above image as well
Since the JPEG has a lossy scaling, zooming after a certain limit can result in a jagged image. One proposed solution is to convert the image to SVG (Scalable Vector graphics).
Going with the expanded form of SVG, it simply tells us that image is:
s=>scalable (i.e. you can zoom to any level without compromising the quality)
v=>vectorized (i.e co-ordinates are available)
So by simply looking at the XML format of the image, we can predict whether to allow dropping an object at fill=red or fill=white where red and white are the two colors in the image. This might not be appropriate solution, but I'm just guessing it this way
Now the problems I see with this approach is:
Converting an image with some open source tool (InkSpace) - if we trace it with ink-space, which uses portace inside it to trace the image, it can handle only black and white colors.
Note-: Most of the tools comes with some license.
Problem with inkspace is that it embeds the image into the SVG map and does not create the co-ordinates. If you trace it with inkspace, it only creates the outline of the image.
Converting it with some online utility - Not recommended in our case, but doing so results in a large size of the SVG image. For a 700 KB file, the SVG generated is about 39 MB, which when opened up on a browser crashes the browser.
Most of the time when the image is converted to an SVG, it becomes way too large a big factor to worry about. There are utilities available like Gzip to compress files, but this is a two way route - first you convert, then you compress.
Using delinate (which employs a portace and autotrace engines in it) - the quality of the image produced is not good.
Using Java code - Again the quality suffers. Java graphics are not fully developed to handle the conversion (size is again way too large)
Converting the image to PDF, then to SVG - this also embeds the image into the SVG file, which is useless as no co-ordinates are available
Does anybody got any idea on this ,how to deal with this situation?,Can we handle the drag and drop on raster(jpeg,png...etc) images itself?
Thanks
Dishant Anand
Looking for tips/tools to make this happen (using PDF/Velocity Templates/Java):
I have an image that has large dimension (4000 x 2000) and that image is obviously not viewable in a PDF. I can modify the size of the image to fit into the PDF.
But what I want to do is to view the actual size of the image in the PDF. I want to be able to scroll the image from left to right.
How can I keep the true size of the image, without destroying the set container size of the PDF?
That's not quite a basic PDF feature, but it might be implementable using some embedded scripts inside the PDF, assuming that the user has a PDF viewer capable of running scripts.
Now, a PDF is not supposed to be used as a dynamic document where you can scroll. How would that work on paper after printing? If you want scrollable documents, then you should stick to HTML. I strongly advise you not to try to do this.
If, however, you still want to go down this route, then here are a couple of suggestions:
As I said, you could do it with embedded JavaScript, but then it depends on how you're generating the PDF: FOP, iText, another PDF writer library, or just plain println concatenation, since few libraries support embedding JavaScript.
You could just make the image fit into the page, but keep its original resolution, so that you end up with a high resolution page that the user can zoom in and scroll. This way you leave the scrolling to the PDF viewer itself, you'll just have to let the user know that the image has a higher resolution and should be magnified. And frankly 4000px isn't that large, it's not even enough to keep up with today's standard printer DPIs.
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.
I'm working on application in Java that will maintain database of song lyrics in plain text and print out some songbooks/chordbooks(that is create PDF file from selected songs). I was planing that the Java application will generate source code for pdflatex and after compiling this source user will get PDF file.
Lately I've run into a lot of problems because of latex limitation: fixed memory size (some pictures will also be drawn to PDF) - error when exceeded, no way to query end of line or and of page dynamically, it's very hard to override latex placement algorithm in a complex way,... see also some my other questions regarding latex. I come to conclusion that latex is not good option for automated PDF generation.
So I need replacement. I need to be able to typeset:
Chords over lyrics when the lyrics are in variable char width so I need to be able to measure text width
Chord diagrams that means I'll have to draw quite complex pictures
Each song on separate double page
Different fonts etc.
Thanks for all answers
Here are some PDF open source APIs
http://java-source.net/open-source/pdf-libraries
This has been asked many time, You might want to look at this post
IText is a free library which offers lots of capabilities for creating PDFs programmatically.
Rather than try to manage/calculate the complexities of the desired layout, you could try Docmosis. It will let you layout a document as a template using doc or odt formats. This means if you could make a doc or odt look like you want, you can turn it into a template and get Docmosis to render it as a PDF. Text and images can be placed inside or outside tables which makes layout fairly easy to manage.
ConTeXt is another TeX system, but it is easier to control the layout than with LaTeX. For drawing you could use PGF/TikZ or MetaPost. Support for both is available in ConTeXt. With ConTeXt's built in Lua scripting you could draw the chords automatically, assuming you have them stored in some sort of data structure.
why not just use lilypond with latex? it's meant for typesetting music.
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.