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:

https://addons.mozilla.org/pt-BR/firefox/addon/video-downloadhelper/

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


Where:

-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 img2dcm.py -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.


Notes


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: http://www.ciceromoraes.com.br/?p=430
BlogItalia - La directory italiana dei blog Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.