2008/01/19

A very easy way to view dependencies: GraphViz

There is a wonderful and powerful tool called GraphViz that is able to draw graphs very easily. When I visited its website for the first time I thought it was very difficult to use, and this is completely false, so I will show how easy it can be.

This tool can do very powerful and complex graphs, but for the impatients (like me), that want to understand quickly how it works and be able to use it in another context (e.g. to show JAR dependencies in a Java application), I will show a very minimal example. Let's go.

First, you must download and install GraphViz. It is very easy to install. For Windows you have an installer, and for Linux you can use your favourite installer (at least Graphviz it's present in the Ubuntu Gutsy repositories, I don't know the other distributions).

Now, we will write a minimal text file with the dependencies we want to draw. Use your favourite editor and write a text file called 'sample.dot' with this content:

digraph g {
node1 -> node2
node2 -> node3
node2 -> node4
}

Now, you simply have to call the executable dot, from the GraphViz tool:

dot -Tpng -osample.png sample.dot

Pretty simple, isn't it ? We say we want to generate a PNG image (-T is the type of output file) and write it to an output file 'sample.png' from our graph file 'sample.dot'.

And the result is this:


Now, you can take a look at the documentation to know how to customize your graphs: you can specify colours, widths and shapes of your nodes, etc.

And one last advice: if the names of your nodes have spaces or special characters (like ':' or '\'), double quote them in the '.dot' file or you will get errors. So our last file would look like this:

digraph g {
"node1" -> "node2"
"node2" -> "node3"
"node2" -> "node4"
}

That's all. Enjoy making images of your dependencies!

2007/10/21

Lossless digital zoom in digital cameras

These last two weeks I've been on my honeymoon holidays...really really nice. I have been quite disconnected from computing or technological news, but I learned a useful feature of my digital camera that was absolutely unknown to me: the lossless digital zoom. Let me explain a little bit...

I have had several digital cameras and many of them had digital zoom. As this nice article explains, the digital zoom makes the illusion of having a longer optical zoom by making larger a small part of the original image the optical zoom gets (through interpolation). The result is a softened image (with less definition), not so clear as a normal one and not very useful in general. That's why I always disabled the digital zoom of my cameras. But, these holidays I discovered a great trick some modern cameras use to be able to enhance your optical zoom with a special kind of digital zoom that has no degradation...Is that magic ? No, but it's amazing anyway.

The trick is called "Smart zoom" by Sony and "Safe zoom" by Canon, but it's implemented by other cameras and it's pretty simple to implement. If you have a camera with many megapixels but you make a picture with less resolution than the maximum, your camera can actually make a picture with the maximum resolution and then crop it to the small part you have selected (by zooming with the digital zoom). In other words, the camera traditionally has had to make a large image from the small part selected by the digital zoom, and it had to "invent" the information it didn't have by interpolation; but now, it doesn't have to "invent" this information, because it actually has them (just selecting a larger resolution for the image). This article explains it much better than me, so read it (specially the "Smart zoom" part). This special zoom has limitations, it only can work if the image resolution you select is smaller than the maximum and the factor of zoom without degradation is not unlimited (in my camera I can "only" double the optical zoom range when I select a 1600x1200 resolution)...but it's enough for me.

The technique is equivalent to make a picture with a maximum resolution with the optical zoom and crop it yourself at home to the size of image you really wanted from the beginning, but it has some advantages:
  • You don't need to do this process at home (the camera does it for you), so this saves your time
  • You save space in your camera, because what is saved is the cropped image, not the lareg one (at maximum resolution)
  • You can choose the composition of the picture while you do it (I prefer it)
So...I have enabled the digital zoom in my camera again, it's worth it.



Powered by ScribeFire.