Found this way to take an image of just the partitions and not the empty space at the end of the disk:

dd if=/dev/sdX of=filename.img bs=1M count=<size in MB>