Sunday 2 September 2012

Converting a Video of Computed Tomography into a 3d Mesh

 Obs.: Please, watch this video before to read the article.

CT scan is an excellent technology for research in a lot of areas. unfortunately is a extensive service to be contracted.

If you are a researcher in egyptian archaeology or facial reconstruction this article will help you to learn a way to get CT scan in a easy way.

An archaeological example of the use of the technique

Describing the Technique

The technique consists in download a video of Youtube or Vimeo or whatever i movies site on the internet.

A example of Firefox add-on that can be used to download a video is DownloaHelper, and you can download it here:

If you use other browser is possibly have a version of DownloadHelper for it or you can use other solution. 

For this example was downloaded a CT scan video in the site the Virtual Pig Head.

A .MOV video was downloaded directly for this page, dispensing the use of DownloadHelper in this case.

OBS.: If you like dinosaurs or articles about CT scan, you cannot let to visit Witmer's lab site. It can be nteresting to found a got material for your research or pleasure.

Once a video was acquired it was seen that it have a lot of labels in the screen.

To erase it was used he video editor Kdenlive. The solution was to create some black areas over the bigger labels.

 So, a new video was generated without that labels. To convert this video in a image sequence you can use FFMPEG, a command line software that converts video in a serie of different formats.:

$ ffmpeg -i Video.mpeg -sameq sequencia/%04d.jpg


-i Video.mpeg is the input file.

-sameq preserves the same quality of the frame in the jpg output file.

sequence/%04d.jpg sequence is the directory where the file will be created and %04d.jpg means that the result files will be a sequence with four zeros like 0001.jpg, 0002.jpg, 0003.jpg.

Obs.: The signal $ only means that the command have to be written in a terminal. 

Ok, now you already have the jpg sequence, but InVesalius (the CT scan software) uses DICOM files to convert images in 3D meshes.

A DICOM file is not only a image file, but a imagem file with the data of pacient, distance of the slices, and etc.

So, to convert an image in a DICOM file you'll need a specific application called IMG2DCM, tha can be download here. With this command line application you'll convert image files like Tif, Png and Jpg in a sequence of .Dcm (DICOM) files and if necessary you can setup the information about the pacient, the distance of slices and etc. 

To do the conversion is quite easy:

$ python -i sequence_directory -o output_directory -t jpg

To open the DICOM files and convert it in a 3D mesh you can use InVesalius, that is a power opensource in area of CT scan.

How appears in the screenshot when the reconstruction is made the names os the muscles that was in the video was reconstructed too. It isn't a problem, because they will be deleted in the 3D editor after. 

We can importing the .STL file exported from InVesalius in Blender 3D.

The .STL files comes big and with a lot of subdivisions. You need to simplify it with Remesh, for example, to edit the mesh with tranquility.

Blender has a sculpt mode, where you can to polish the little warts that was created when had the texts with the name of the muscles.

Because the labels, the right ear came incomplete.

You can solve it mirroring the model and complete the lacking area.

This video shows a good technic to make this.

When the jpg sequence was converted in a DICOM sequence the data of distance of the slices wasn't setup. Because this the pig's face was generated stretched. After polished the warts and mirrored the ear we can rescale the face to correct the proportions (with a clean mesh).

Usually artists remodel a complex mesh with less subdivision using a technique called retopo.

But, this article is geared for scientific and archaeological solutions. So, the texturing of the model will be configured in the complex mesh, without make retopo.

The final step is rendering the images and make the animation, like you saw in the start of the article.

If you wanna, you can download the textured .OBJ file here.

Facial forensic reconstruction of a skull reconstructed of a video
The video used to reconstruct the mummy of the start of the article (and above) can be watched here.


1) A situation that gave a lot of pride for the writer of this article was the citation of Mr. Witmer in his Facebook page:

This is a good demonstration that people that like to share information generate big amount of solutions. The most important is the technique was describet and all have a chance to learn and make a solution better.

2) The original post  that motivated this article was written in portuguese:


  1. excellent work ..
    Congratulations for the great contribution

  2. Thank you for the great contribution.
    I was able to do the exact same thing until the InVesalius part. DICOM Images generated by img2dcm makes InVesalius hanging forever at opening whereas it can smoothly open freely available DICOM datasets. Do you have any hint why ? That would be helpful


  3. Thank you for the words Michael!

    What operating system are you using? Because the InVesalius are with a bug on Ubuntu/Debian package. The developers will solve soon.

    Unfortunately I dont know other option with a good reconstruction for CT-Scan. Maybe you can use Imagej.

    I wait your answer.

    A big hug!

  4. Indeed I was running Debian binaries. I gave it a try under Win 7 : same problem. Other softwares such as 3DSlicer or VolView cannot open the generated DICOM files either.
    I guess the problem is rather coming from img2dcm than from the segmentation softs. Probably a flaw in the headers ?


  5. How do I get the to work. When I try to run it is says "
    Traceback (most recent call last):
    File "", line 26, in
    import gdcm
    ImportError: No module named gdcm
    Can you explain to me like you would a child, how do I make this work? THANKS!

    1. Hi Natre!

      You have to install the libgdcm. What operating system are you using?

      A big huh!

    2. Hi I have the same problem I use Archeos an Ubuntu based Linux OS. I try using apt-get command to install the missing lib probably I'm using a wrong lib name.
      could you help me?
      regards Franco


BlogItalia - La directory italiana dei blog Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.