Itf usefull sometimes to convert between these two formats. For example if you want to make some changes on a raw image file (img) with VirtualBox.

To convert a .img file to a .vdi file:

batpig ~ # VBoxManage convertfromraw -format VDI filename.img filename.vdi
Converting from raw image file="filename.img" to file="filename.vdi"...
Creating dynamic image with size 3251654656 bytes (3102MB)...

or

batpig ~ # VBoxManage convertdd filename.img filename.vdi
Converting from raw image file="filename.img" to file="filename.vdi"...
Creating dynamic image with size 3251654656 bytes (3102MB)...

Now you can attach you vdi to VirtualBox and make changes.
After that, we want to go back to ram image file.
Simply clone you vdi like that:

batpig ~ # VBoxManage clonehd filename.vdi filename1.img --format RAW
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'RAW'. UUID: 00a18442-9e53-4e73-9be9-8069ca92569c

And your done.