The last of 3 posts presenting algorithms for the ellipsoid method of Khachiyan for 2D point clouds. This version in Matlab will return: 1) the ellipse radius in x, 2) the ellipse radius in y, 3) the centre in x, 4) the centre in y, and 5) orientation of the ellipse, and coordinates of the ellipse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The second of 3 posts presenting algorithms for the ellipsoid method of Khachiyan for 2D point clouds. This version in python will return: 1) the ellipse radius in x, 2) the ellipse radius in y
x is a 2xN array [x,y] points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The first of 3 posts presenting algorithms for the ellipsoid method of Khachiyan for 2D point clouds. This version in R will return: 1) the ellipse radius in x, 2) the ellipse radius in y, 3) the centre in x, 4) the centre in y, and 5) orientation of the ellipse, and coordinates of the ellipse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sometimes you want a least-squares polynomial fit to data but to constrain it so it passes through a certain point. Well ...
Inputs: x, y (data); x0 and y0 are the coordinates of the point you want it to pass through, and n is the degree of polynomial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is based on Computational Statistics Toolbox by W. L. and A. R. Martinez, which has a similar algorithm in 2D. It uses John d'Errico's inhull function
Inputs: N = number of data points which you want to be uniformly distributed over XP, YP, ZP which represent the vertices of the region in 3 dimensions
Outputs: x,y,z are the coordinates of generated points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here is a function to generate a 3D matrix of 1/frequency noise
Inputs are 1)rows, 2) cols (self explanatory I hope), 3) dep (the 3rd dimension - number of images in the stack) and 4) factor, which is the degree of autocorrelation in the result. The larger this value, the more autocorrelation an the bigger the 'blobs' in 3D
Enjoy!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For computational geometry problems there is a rather splendid tool called the Multi Parametric Toolbox for Matlab
Here are a few examples of using this toolbox for a variety of purposes using 3D convex polyhedra represented as polytope arrays. In the following examples, P is always a domain bounded 3D polytope array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% return a vector of the number of sides in each polytope
[H,K]=double(P);
[numsides, Cncols] = cellfun(@size, H);
% return a vector of polytope radii
[xyz,Rad] = chebyball(P);
% find the extrema of each polytope in P
for ip=1:length(P)
E(ip)=extreme(P(ip));
end
%Slice through a 3-dimensional volume. Here, I'm slicing through 3D polytope array P to return the number of polytopes in each slice (N) and the mean diameter of polytopes in each slice (M). Slices are made at arbitrary values in the space [0,1]
% Here I reduce each 3D polytope in array P by factor fct to give new polytope array Q
Q = [];
for ip=1:length(P)
E=extreme(P(ip));
ey=E(:,2); ex=E(:,1); ez=E(:,3);
ex = fct*ex+(1-fct)*mean(ex); % expand x by factor fct
ey = fct*ey+(1-fct)*mean(ey); % expand y
ez = fct*ez+(1-fct)*mean(ez); % expand y
Er=[ex,ey,ez];
Q = [Q,hull(Er)];
end
% Finally, here's a piece of code which will a) convert a 3D polytope array into a 3D matrix, then b) display slices of that volume (left side, back, and the centre line in both the x and y orientation) % first, slice P at small increments and build up matrix im
1. How to reconstruct the three-dimensional shape of an object in a scene in a very inexpensive way using shadow-casting 2. How to write and execute a matlab script from a bash script
The script relies heavily on the GUI-style interfacing tools of Zenity and acts as an interface and wrapper for the algorithm as implemented by these guys. It will also write and execute a matlab script for visualising the outputs.
This script should live in a directory with the following compiled programs, all available here: 1. ccalib (performs the camera calibration to retrieve the intrinsic parameters of camera and desk) 2. find_light (performs the light calibration to find light-source coordinates) 3. desk_scan (does the 3d reconstruction) 4. merge (merges 2 3d reconstructions, e.g. from different angles)
and the following matlab script: 1. selectdata.m (available here)
When the makefile is run, it creates the compiled programs in the ./bin directory. It's important to consult the README in the main folder as well as within the 'desk_scan' folder to have a clear idea of what the program does and what the input parameters mean.
My program will check if the camera calibration and light calibration files exist in the folder and if not will carry them out accordingly then several reconstructions are carried out, and the outputs merged. Finally matlab is called from the command line to run 'p_lightscan_data.m' to visualize the results.
when the script finishes there will be the following output files: 1. xdim.txt - max dimension to scan to 2. params - camera calibration parameters 3. data - camera calibration data 4. light.txt - light calibration parameters 5. sample.pts - [x,y,z] of object, in coordinates relative to light source 6. sample_lightscan1.tif - filled colour contour plot of reconstructed object 7. sample_lightscan2.tif - mesh plot of reconstructed object
I've tried to keep it flexible. It will run only the elements it needs to. For example, if the camera or lighting has been carried out before for a different object it will pick up on that. Also, the program can be invoked by passing it two arguments (path to folder where sample images are, and what sequence of contrasts to use for the reconstruction), which avoids having to input with the graphical menus. Example usage: 1. bash shadowscan.sh 2. bash shadowscan.sh /home/daniel/Desktop/shadow_scanning/sample/bottle 30.35.40.45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if no arguments, IMAGES and CNTRST will be empty otherwise will be filled with the arguments
defined args && IMAGES=${args[0]} # first = sample image location e.g. /home/daniel/Desktop/shadow_scanning/sample/
defined args && CNTRST=${args[1]} # second = contrst values - no more than four! e.g. 30.35.40.45
# if IMAGES empty, display flash info, and prompt user to direct program to folder
if [ -z $IMAGES ] ; then
zenity --info --title="SHADOWSCAN" --text "This program will create a 3D reconstruction of an object using images of the object scanned by a shadow. It is a bash/matlab wrapper program for code created by http://www.cs.columbia.edu/~pblaer/projects/photo/ which implements the shadow-casting algorithm of Jean-Yves Bouguet and Pietro Perona (http://www.vision.caltech.edu/bouguetj/ICCV98/)"
# folder where sample images are
IMAGES=$(zenity --file-selection --directory --title="Select directory where sample images are")
fi
if [ ! -f ./param ] # if param does not exist, do cam calib
This program will read an image, convert it to greyscale, crop it to a square, and calculate it's spatial (1D) autocorrelation function (correlogram), printing it to screen.
It uses OpenCV image processing libraries - see here and here
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This program to sends a command to serial device, receives data from the device, converts it to numeric format, and graphs the data in real time. It is written in Python using wxPython for the display.
The device is connected to /dev/ttyS0 with a baud rate of 19200, 8-bit data, no parity, and 1 stopbit. You need to edit the line 'serial.Serial' with the relevant parameters to use this code for your device. Editing 'DATA_LENGTH' will change the rate at which the graph scrolls forward. Also, you'd need to change the 'command' that the device understands as 'send me data' (here it is the s character - line 'input'). Knowledge of the format of the returned data is also essential (here I turn ascii into 2 integers) line 'struct.unpack' - see here for help). Otherwise this should work with any device. Tested on Ubuntu 9.10 and 10.4 using serial port and USB-serial converters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters