Code covered by the BSD License  

Highlights from
Carving a Dinosaur

4.88889

4.9 | 9 ratings Rate this file 60 Downloads (last 30 days) File Size: 20.1 KB File ID: #26160
image thumbnail

Carving a Dinosaur

by

 

21 Dec 2009 (Updated )

This is a demo of reconstructing a 3D shape from multiple images using space-carving.

| Watch this File

File Information
Description

This is a demo of reconstructing a 3D shape from multiple images using a simple space-carving approach. This technique is usually used when you need a 3D model of a small artefact which can be placed on a turntable, allowing dozens, even hundreds of images to be captured from around the object. It has been used pretty successfully by museums and the like to create online virtual galleries.

Each image is just used as a mask or silhouette. A lump of voxel "clay" is placed in the middle of the scene and from each image we simply look and see what is outside the object silhouette. Anything outside is carved away. Obviously, this requires us to know where the camera was relative to the object when the picture was taken, which is a whole separate problem.

This technique has been refined over the last decade and can be done in some computationally and memory efficient ways. My approach is neither of these - I went for simplicity over efficiency since my only aim was to explain the technique and show it in MATLAB.

Acknowledgements

The dinosaur images used here were provided by Wolfgang Niem at the University of Hannover.

The camera data used in this example was provided by Dr A. W. Fitzgibbon and Prof A. Zisserman from the University of Oxford Robotics Research Group.

The images and camera data can both be downloaded from the Visual Geometry Group web-pages at the University of Oxford Robotics Research Group. They are not included with the demo code.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (28)
06 Mar 2014 Asri Khalid

great info and coding

16 Dec 2013 dongdong

thank you for the source code

25 Sep 2013 Siti Syazalina

Thanks..
I'm trying with my own data, but it has problem on making voxels I guess, & I dont know what to do..

Error using spacecarving.findmodel (line 39)
Nothing left after initial search! Check your camera matrices.

Error in space_carving_demo (line 105)
[xlim,ylim,zlim] = findmodel( cameras );

24 Sep 2013 Ben Tordoff

im(:,:,1) is the red channel of the RGB image, im(:,:,3) is the blue. S is therefore true (1) for pixels whose color contains more red than blue and false (0) otherwise.

Nearly every color contains some red and some blue and this is just a quick and dirty way to find those that are closer to red than blue.

24 Sep 2013 Siti Syazalina

Hi Ben,
Can you please explain what's the meaning for this code?
% Initial segmentation based on more red than blue
S = im(:,:,1) > (im(:,:,3)-2);
More red than blue? If other colors?

07 Aug 2013 maryam  
26 Jul 2013 Sam

Hello Ben,
I want to do the same for other object. But for that I want to know Is your provided code is useful for other objects if I provide 36 images of that object and the camera matrix for the particular ?

Thanks

Sam

24 Jul 2013 Sam  
16 May 2013 wei zhang

very helpful!

21 Apr 2013 Ian

Hello Ben,

I've been trying to upload my own data to this program, but it always says the camera matrices are incorrect at the find model cell block. I thought this may be because I was using only 7 images (10 degrees apart) but when I run this program (with the dinosaur images), but edit the line;

cameras = loadcameradata( datadir);

to

cameras = loadcameradata( datadir, 1:7 );

As you described in the loadcameradata function, it doesnt work with 7 images, and the find model function fails. I was wondering if you could provide any help or suggestions?

Many thanks

Adam

04 Apr 2013 Elizabeth

Hello everyone,

I wish to use this program, but upload my own images. Has anyone successful done this? Im struggling with generating the intrinsic and extrinsic parameters.

Thanks!

15 Mar 2013 kevin  
14 Jan 2013 Ben Tordoff

I'm afraid I cannot upload the data since it doesn't belong to me. As mentioned in the description you can download it from the Visual Geometry Group at the University of Oxford.

14 Jan 2013 Hooi Thing

Hi I couldn't find the dino_Ps.mat file and receive the following error. Can you upload the MAT file? Thanks

Error using load
Unable to read file DinosaurData\dino_Ps.mat: No such file or directory.

Error in spacecarving.loadcameradata (line 32)
rawP = load( fullfile( dataDir, 'dino_Ps.mat') );

28 Nov 2012 Hung Nguyen  
11 Nov 2012 Andrew

Great work and very interesting!!

One small thing I noticed just more for the aesthetics of the final result where you colour the surface of your 3D model, you need to have an inverse cosine (or acos in Matlab) to compute the angle between the camera view vector and vertex normals when doing the dot product. At the moment the variable 'angles' is actually not the angle but the cosine of the angle between the two vectors. Therefore putting acos in front of the dot product significantly improves the colouring of the surface.

Thanks for the great submission.

Andy

31 Oct 2012 win kong

Hi Ben,
I'm having problem in getting the 3x4 matrix in dino_ps.mat.
How can I get the calibration parameters?

Thanks in advance

Win

20 Sep 2012 salon  
27 Jul 2012 mariem123

Hi Ben,

I was wondering why there is the " Get real value" part in your algorithm. I do not really get what is here for.

Cheers,

Marie

05 Jul 2012 Ben Tordoff

I believe you are correct, P{1,1} relates to image 1, however it's been a long time since I've worked on this. If you type

>> edit spacecarving.loadcameradata

you can see how the camera data is read and decomposed and which images are loaded where.

Cheers.
Ben

04 Jul 2012 mariem123

I have an other question for today ^^
Is P{1,1}( cell (1,1) of the file dino_ps.mat ) the Projection matrix relative to the image viff.001.ppm for example ?

Is P{1,2}( cell (1,1) of the file dino_ps.mat ) the Projection matrix relative to the image viff.002.ppm as well, and so on ?

Cheers

Marie

03 Jul 2012 mariem123

Hi Ben, thank for the reply.

How did you do to get the P matrix? Did you write it manually yourseld or is there any toolbox which did it for you ?

02 Jul 2012 Ben Tordoff

Hi Marie, the matrices are "projection matrices", containing both the internal (K) and external (R, t) camera parameters. These are roughly P = K*[R t] where K is the 3x3 matrix of internal (aka intrinsic) parameters, R is a 3x3 rotation matrix giving the camera orientation and t a 3x1 translation vector. Hence the output, P, is 3x4.

However, these are estimated matrices and will contain noise. In order to draw the scenes I do an approximate decomposition back into K, R and t, but I make no claims that I'm doing it the most accurate way!

Cheers
Ben

02 Jul 2012 mariem123

Hi Ben, great job !

I have a question for you about the dino_ps.mat you're using in the demo.
What are the coefficients in the matrix as it is a matrix 3*4 ? ( I guess there are the intrinsic and extrinsic parameters but which ones are there ?)

Cheers. Marie

22 Jun 2012 Habibullah

Hi Ben, thanks for reply

Due to your suggestion.
I replaced the '~' with 'num_voxels' and it works fine.

Thanks for the great work and share

Cheers. Habib

05 Mar 2012 Ben Tordoff

Hi Habibullah, are you by any chance using a version of MATLAB older than R2009a (which is when the '~' syntax was introduced)?

If so, you may still be able to get it to work by replacing the '~' with a real variable name, but bear in mind this hasn't been developed or tested on releases older than R2009b.

Cheers. Ben

04 Mar 2012 Habibullah

This is very interesting!
However I cannot run it because this error:
??? Error: File: space_carving_demo.m Line: 197 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.

The line 197 is below:
[~,mykeep] = carve( myvoxels, cameras(ii) );

Any help thanks

22 Jan 2010 Mike  
Updates
22 Jan 2010

Removed third party data from package

Contact us