Based on @ford's answer. This one will extract it to the my_dirname folder. So that we can properly clear the empty folders without affected currently existing files.
tar xzf images.tgz --transform='s/.*\///' -C my_dirname
find my_dirname -type d -empty -delete