Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

general bug fixes

git-svn-id: file://localhost/Volumes/Storage/SVNRepository/Research/RANSAC@49 876389e7-766b-4580-87e5-4a53071d1477
  • Loading branch information...
commit 019598f0ee0f51e9a69c0ced230e2ea703718ec7 1 parent 44bcb1d
zuliani authored
View
25 CreateRANSACtoolbox.m
@@ -16,7 +16,7 @@
destination_dir = strcat(root_dir, '/Research/RANSAC-toolbox');
author = 'Marco Zuliani';
email = 'marco.zuliani@gmail.com';
-year = '2010';
+year = '2011';
license = 'GPL';
addpath(path, './Development')
@@ -69,7 +69,7 @@
fprintf('\nToolbox path: %s', toolbox_dirname);
fprintf('\nArchive filename: %s', archive_filename);
-% copy the files bby performing an export to the target dir
+% copy the files by performing an export to the target dir
if isOctave
system(sprintf("svn export %s %s",'../RANSAC/', toolbox_dirname));
else
@@ -91,12 +91,12 @@
% remove the autosaved files and other trash
switch computer
- case {'GLNX86', 'MAC', 'MACI', 'GLNXA64', 'SOL64', 'i386-apple-darwin10.4.0'}
+ case {'GLNX86', 'MAC', 'MACI', 'GLNXA64', 'SOL64', 'i386-apple-darwin10.8.0'}
trash = '\.m~$|^[\.DS_Store]$';
case {'PCWIN', 'PCWIN64'}
trash = '\.asv$';
otherwise
- error('Unknown platform')
+ error('Unknown platform (check the OS version is correct)')
end;
f = get_file_list(toolbox_dirname, trash, true);
@@ -112,12 +112,12 @@
% take care of the damn CR LR
switch computer
- case {'GLNX86', 'MAC', 'MACI', 'GLNXA64', 'SOL64', 'i386-apple-darwin10.4.0'}
+ case {'GLNX86', 'MAC', 'MACI', 'GLNXA64', 'SOL64', 'i386-apple-darwin10.8.0'}
cmd = 'dos2unix -q';
case {'PCWIN', 'PCWIN64'}
cmd = 'unix2dos';
otherwise
- error('Unknown platform')
+ error('Unknown platform (check the OS version is correct)')
end;
for h = 1:numel(f)
system(sprintf('%s %s', cmd, f(h).filename));
@@ -133,14 +133,17 @@
mkdir(toolbox_doc_dirname);
copyfile(RANSAC4Dummies_filename, toolbox_doc_dirname);
+% change directory
+current_dir = pwd();
+cd(destination_dir)
+
switch computer
- case {'GLNX86', 'MAC', 'MACI', 'GLNXA64', 'SOL64', 'i386-apple-darwin10.4.0'}
- % eval(sprintf('!tar -czvf %s.tgz %s/', archive_filename, toolbox_dirname));
+ case {'GLNX86', 'MAC', 'MACI', 'GLNXA64', 'SOL64', 'i386-apple-darwin10.8.0'}
if isOctave
# note that the traditional zip command does not work
# we would get the following error:
# error: zip: zip failed with exit status = 12
- str = sprintf('zip -r %s.zip %s', archive_filename, toolbox_dirname);
+ str = sprintf('zip -r %s.zip RANSAC', archive_filename);
[status, output] = system(str);
else
zip(sprintf('%s.zip', archive_filename), toolbox_dirname);
@@ -148,5 +151,7 @@
case {'PCWIN', 'PCWIN64'}
zip(sprintf('%s.zip', archive_filename), toolbox_dirname);
otherwise
- error('Unknown platform')
+ error('Unknown platform (check the OS version is correct)')
end;
+
+cd(current_dir)
View
4 Examples/test_RANSAC_RST.m
@@ -46,7 +46,9 @@
% scaling is in [1-As, 1+As]
As = 0.5;
s = 1 + (As * (rand()-0.5));
-phi = pi*(rand()-0.5);
+% angle is in [-Aphi Aphi]
+Aphi = 30;
+phi = Aphi*pi*(rand()-0.5);
T = rand(2, 1);
C = s*cos(phi);
View
129 Examples/test_RANSAC_affine.m
@@ -0,0 +1,129 @@
+% NAME:
+% test_RANSAC_affine.m
+%
+% DESC:
+% test to estimate the parameters of an affine transformation
+
+close all
+clear
+% clc
+
+%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Parameters
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% number of points
+N = 200;
+% inilers percentage
+p = 0.75;
+% noise
+sigma = 1;
+
+% set RANSAC options
+options.epsilon = 1e-6;
+options.P_inlier = 1-1e-4;
+options.sigma = sigma;
+options.est_fun = @estimate_affine;
+options.man_fun = @error_affine;
+options.mode = 'MLESAC';
+options.Ps = [];
+options.notify_iter = [];
+options.min_iters = 1000;
+options.fix_seed = false;
+options.reestimate = true;
+options.stabilize = false;
+
+%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Data Generation
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% make it pseudo-random
+seed = 34545;
+rand('twister', seed);
+randn('state', seed);
+
+% generate an RST transformation
+% scaling is in [1-As, 1+As]
+As = 0.5;
+s = 1 + (As * (rand()-0.5));
+phi = pi*(rand()-0.5);
+T = rand(2, 1);
+gamma = 0.05*randn(1);
+
+C = s*cos(phi);
+S = s*sin(phi);
+H = [C C*gamma-S T(1); S S*gamma+C T(2); 0 0 1];
+
+% generate a set of points correspondences
+Ni = round(p*N);
+No = N-Ni;
+
+% inliers
+L = 256;
+% random Gaussian distribution
+% X1i = 512*randn(2, Ni);
+% gridded distribution
+s = linspace(-L, L, ceil(sqrt(Ni)));
+[x y] = ndgrid(s, s);
+X1i(1, :) = transpose(x(:));
+X1i(2, :) = transpose(y(:));
+X1i = X1i(:, 1:Ni);
+X2i = homo2cart(H*cart2homo(X1i));
+
+% outliers
+X1o = L*2*(rand(2, No) - 0.5);
+X2o = L*2*(rand(2, No) - 0.5);
+
+X1 = [X1i X1o];
+X2 = [X2i X2o];
+
+% scrample (just in case...)
+[dummy ind] = sort(rand(1, N));
+X1 = X1(:, ind);
+X2 = X2(:, ind);
+
+% and add some noise
+X1 = X1 + sigma*randn(2, N);
+X2 = X2 + sigma*randn(2, N);
+
+%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% RANSAC
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% form the input data pairs
+X = [X1; X2];
+% run RANSAC
+[results, options] = RANSAC(X, options);
+
+%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Results Visualization
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+R = [results.Theta(1) -results.Theta(2); ...
+ results.Theta(2) results.Theta(1)];
+T = results.Theta(3:4);
+
+X1_map = R*X1 + repmat(T, 1, size(X1,2));
+X2_map = R\(X2 - repmat(T, 1, size(X1,2)));
+
+figure;
+
+subplot(1,2,1)
+hold on
+plot(X2_map(1, results.CS), X2_map(2, results.CS), 'sg', 'MarkerFaceColor', 'g')
+plot(X1(1, :), X1(2, :), '+r')
+
+axis equal tight
+xlabel('x');
+ylabel('y');
+
+legend('Estimate Inliers', 'Data Points')
+
+subplot(1,2,2)
+hold on
+plot(X1_map(1, results.CS), X1_map(2, results.CS), 'sg', 'MarkerFaceColor', 'g')
+plot(X2(1, :), X2(2, :), '+r')
+
+axis equal tight
+xlabel('x');
+ylabel('y');
+
+legend('Estimate Inliers', 'Data Points')
View
9 HowToGeneratePackage.txt
@@ -1,11 +1,10 @@
-Construction of the RANSAC package for Matlab
----------------------------------------
+Construction of the RANSAC package for Matlab/Octave
+---------------------------------------------
--. Launch Matlab and cd to the directory containing the revisioned version of the RANSAC toolbox
--. Add the directory containing the add_license.m function to the path (e.g. addpath('~/Research/Misc/add_license/'))
+-. Launch Matlab/Octave and cd to the directory containing the revisioned version of the RANSAC toolbox
-. Execute the script SetPathLocal.m
-. Make sure the directory RANSAC-toolbox exists in the right place (check also the parameters)
--. MAke sure the programs dos2unix and unix2dos are present in the path
+-. Make sure the programs dos2unix and unix2dos are present in the path
-. Launch the script CreateRANSACToolbox.m after having checked the parameters
-. Copy the files RANSAC_XX-XXX-XXXX -> RANSAC.zip inside the web site folders
-. Update the version of the package in the web page (in the form dd-mmm-yyyy)
View
16 Models/Affine/error_affine.m
@@ -33,19 +33,19 @@
% HISTORY
%
-% 1.0.0 - 27/08/06 initial version
+% 1.0.0 - 12/12/10 initial version
% compute the squared symmetric reprojection error
E = [];
if ~isempty(Theta) && ~isempty(X)
+
+ N = size(X, 2);
- X12(1, :) = Theta(1)*X(1, :) + Theta(3)*X(2, :) + Theta(5);
- X12(2, :) = Theta(2)*X(1, :) + Theta(4)*X(2, :) + Theta(6);
-
- det = Theta(1)*Theta(4)-Theta(2)*Theta(3);
- dy = Theta(6) - X(4, :);
- X21(1, :) = (dy*Theta(3) - Theta(4)*Theta(5) + Theta(4)*X(3, :))/det;
- X21(2, :) = -(dy*Theta(1) - Theta(2)*Theta(5) + Theta(2)*X(3, :))/det;
+ X12 = zeros(2, N);
+ [X12(1, :) X12(2, :)] = mapping_affine(X(1, :), X(2, :), true, Theta);
+
+ X21 = zeros(2, N);
+ [X21(1, :) X21(2, :)] = mapping_affine(X(3, :), X(4, :), false, Theta);
E1 = sum((X(1:2, :)-X21).^2, 1);
E2 = sum((X(3:4, :)-X12).^2, 1);
View
15 Models/Affine/estimate_affine.m
@@ -1,13 +1,14 @@
-function [Theta, k] = estimate_RST(X, s)
+function [Theta, k] = estimate_affine(X, s)
-% [Theta k] = estimate_RST(X, s)
+% [Theta k] = estimate_affine(X, s)
%
% DESC:
-% estimate the parameters of an RST trasformation via least squares.
-% Note that Theta = [s*cos(phi); s*sin(phi); tx; ty] where:
-% s is the scaling factor
-% phi is the rotation angle
-% tx, ty is the translation
+% estimate the parameters of an affine trasformation via least squares.
+%
+% X2 = A * X1 + b
+%
+% where Theta = [a11; a21; a12; a22; b1; b2];
+
%
% VERSION:
% 1.0.0
View
68 Models/Affine/mapping_affine.m
@@ -0,0 +1,68 @@
+function [xd yd] = mapping_affine(xs, ys, mode, Theta)
+
+% [xd yd] = mapping_affine(xs, ys, mode, Theta)
+%
+% DESC:
+% Apply the affine mapping to the source points (xs, ys)
+%
+% AUTHOR
+% Marco Zuliani - marco.zuliani@gmail.com
+%
+% VERSION:
+% 1.0.0
+%
+% INPUT:
+% xs, ys = source points
+% mode = true for forward mapping, false for backward mapping
+% Theta = parameters of the mapping function
+%
+% OUTPUT:
+% xd, yd = destination points
+%
+% SEE ALSO: imcanvas
+
+% HISTORY
+% 1.0.0 - 09/28/08 - Initial version
+% 1.0.1 - 11/26/10 - Adapted for RANSAC
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% check for the input parameters
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% preliminary operations
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% recover translation
+a11 = Theta(1);
+a21 = Theta(2);
+
+a12 = Theta(3);
+a22 = Theta(4);
+
+b1 = Theta(5);
+b2 = Theta(6);
+
+xs = transpose(xs(:));
+ys = transpose(ys(:));
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% mapping
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+if mode
+ % forward mapping
+ xd = b1 + a11*xs + a12*ys;
+ yd = b2 + a21*xs + a22*ys;
+else
+ % backward mapping
+ dx = xs-b1;
+ dy = ys-b2;
+ det = a11*a22 - a12*a21;
+ xd = ( a22*xs - a12*ys)/det;
+ yd = (-a21*xs + a11*ys)/det;
+end;
+
+% make sure the points are returned as row vectors
+xd = transpose(xd(:));
+yd = transpose(yd(:));
+
+return;
View
17 Models/RST/RSTLS.m
@@ -5,9 +5,6 @@
% DESC:
% computes the RST transformation between the point pairs X1, X2
%
-% AUTHOR
-% Marco Zuliani - marco.zuliani@gmail.com
-%
% VERSION:
% 1.0.1
%
@@ -22,6 +19,16 @@
% phi = rotation angle
% T = translation vector
+
+% AUTHOR:
+% Marco Zuliani, email: marco.zuliani@gmail.com
+% Copyright (C) 2011 by Marco Zuliani
+%
+% LICENSE:
+% This toolbox is distributed under the terms of the GNU GPL.
+% Please refer to the files COPYING.txt for more information.
+
+
% HISTORY
% 1.0.0 08/27/08 - intial version
% 1.0.1 06/09/09 - implemented closed form for the LS estimation
@@ -48,7 +55,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% normalize the input
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-if normalization
+if (normalization) && (N > 2)
% fprintf('\nNormalizing...')
[X1, T1] = normalize_points(X1);
[X2, T2] = normalize_points(X2);
@@ -136,7 +143,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% de-normalize the parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-if normalization
+if (normalization) && (N > 2)
H = T2\H*T1;
end;
H = H/H(9);
View
3  RANSAC_update.m
@@ -70,6 +70,9 @@ function RANSAC_update()
version_web(4) = '-';
version_web(8) = '-';
+version = strtrim(version);
+version_web = strtrim(version_web);
+
version_num = datenum(version, 'dd-mmm-yyyy');
try
version_num_web = datenum(version_web, 'dd-mmm-yyyy');
View
2  README.txt
@@ -85,6 +85,8 @@ of templates for bibtex:
Updates History
---------------
+- August 2011: General fixes. Added affine model.
+
- 18 October 2009: Fixed a bug in get_minimal_sample_set.m to handle
the tabu indices. Improved RST estimation routines. Major improvement
in the manual/tutorial
View
7 SetPathLocal.m
@@ -78,4 +78,11 @@ function SetPathLocal(base)
warning('off','MATLAB:dispatcher:pathWarning');
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% if Octave take care of the windows server
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+if (exist('OCTAVE_VERSION') ~= 0)
+ setenv("GNUTERM", "x11")
+end;
+
return
View
2  VERSION.txt
@@ -1 +1 @@
-05-Dec-2010
+06-Aug-2011
Please sign in to comment.
Something went wrong with that request. Please try again.