%Code written by Namrata Vaswani. A small part of the code (a little bit of the level set part) is taken from code written by Yogesh Rathi
%Please cite
%Namrata Vaswani, Yogesh Rathi, Anthony Yezzi, Allen Tannenbaum, PF-MT with an Interpolation Effective Basis for Tracking Local Contour Deformations, Accepted to IEEE Trans. Image Processing, 2008
%when using this code
% A shorter version of this work appeared in
%Namrata Vaswani, Anthony Yezzi, Yogesh Rathi, Allen Tannenbaum, Time-varying Finite Dimensional Basis for Tracking Contour Deformations, IEEE Conf. on Decision and Control (CDC), 2006.
- Unzip utils.zip netlab.zip and DeformPFMT.zip
- Add utils and netlab into MATLAB path
runsims
- generates simulated data and then first runs deform PF-MT and then runs affine PF-MT and compares results.
- to run on real data, comment out the data generation part.
- this is deform PF-MT with Radial-Angle Parameterization
- To just run Deform PF-MT with Radial-Angle Parameterization (earlier called it Geometric Basis)
- T = 20, gendata_2obj_geom, mcpf2_geom
- I recommend using this one first - since it is much easier to handle.
- To run Deform PF-MT with with Arclength Parameterization (earlier called it Parametric Basis)
- T = 20, gendata_2obj, mcpf2
IMPORTANT THINGS
- u0,v0, u2 need to be specified - I am not learning the intensities but forcing a certain pre-decided intensity.
- Also, I am assuming a 3 region model with intensities u0, u2 and v0. Two types of object
objecttype = 1 means u0 is intensity inside object, u2,v0 are intensities outside object
objecttype = 2 means u0, u2 are two intensities inside object, v0 is intensity outside object
In the simulated sequence, objectclass=1 segments the grey object. objectclass=2 segments the white object.
- If set M=2 can track both object contours simultaneously.
- initialize.m is the code used to approximately initialize the contour in the first frame.
******************************************************************************************
IMPORTANT FILES (RADIAL-ANGLE PARAMETERIZATION - also called GEOMETRIC BASIS)
setparamssim_geom: setting of most parameters. Some others get set in mcpf2_geom (beginning) or in mcevidencesample5
gendata_2obj_geom: generates the simulated sequences as described in the paper.
mcpf2_geom: runs the PF. Calls
- setparamssim_geom: sets parameters. Replace by appropriate setparamssim for your sequence (either by learning or by tweeking)
- mcsamplet1_geom: initializes the PF at t=1. Calls a script called initialize
- initialize: reads in a circle image (for simulated data) or asks the user to enter an approximate contour for the first frame in the sequence(modify this for your application)
PF LOOP: for each t calls:
- mcsystemsample2_geom: generates samples from the system model and performs the GD iterations (number of gradient descent iterations is set as impsampiters).
- mcevidencesample5 : weighting and resampling steps. The current weighting is by a combination of region based (Chan-Vese) and edge based (Condensation) likelihoods.
- displaying routines
learn_geom: learning the system model parameters. Need to write a similar code for affine parameter learning also.
******************************************************************************************
IMPORTANT FILES (ARCLENGTH PARAMETERIZATION also called PARAMETRIC BASIS)
gendata_2obj:
Generates the 2 object sequences
mcpf2:
Main PF file
setparamssim:
Called both in gendata_2obj and in mcpf2 - sets all parameters
mcsystemsample2:
a) Generates prediction particles using the "system model" for the state [C,Cvel_basis,knotloc_moved]
Cvel_basis = K-dim velocity at the K control points corresponding the K knot locations knotloc_moved
b) the code inside "if impsample" runs impsampiters iterations of gradient descent to minimize the Chan-Vese energy functional - the code in get_velocity_chanvese to get the velocity - the code needs to be modified/corrected a bit...
For now impsampiters set to 0, but try setting it to 2 or 3 - helps lock the contour onto the object better than with just K-dim prediction.
Also, in mcsystemsample2.m - may need to remove the deformindx part of the code or set deformindx = []
mcevidencesample5:
a) Weights each particle by observation likelihood. observation likelihood = likelihood of contour C given current image
b) "resamples" particles to eliminate low weight particles
detectneedchange
Detects the need to change knot locations (increase or decrease K)
changeknots
Re-allocates Knew knotlocations to the contour
mcsamplet1
initialization: reads in a binary circle image as initial contour - adds noise to it to generate n=15 different contour particles, also allocates knots to each contour and also generates n=15 velocity particles.
initialize
reads in the binary circle image - change this file to read in your first contour.
PARAMETERS OF INTEREST - MAY NEED TO CHANGE THEM
a,signoise, v0, u0, u2, n, deformindx set M=1
sig2obsedge, dmax, rho
In mcevidencesample5, change the
- "if object1" part of the code
- weight given to edgewt term in logw = edgewt + ...
In mcpf2.m, change
signoise, n
initialize.m
******************************************************************************************
10/20/07:
Replaced
xc = round(mean(nar_x));
yc = round(mean(nar_y));
by
if ~isempty(nar_x)
xc = round(mean(nar_x));
yc = round(mean(nar_y));
else
xc = inf; yc = inf; disp('empty nar_x, nar_y in Find_Narrow_band')
end
******************************************************************************************
THINGS TO MODIFY: 1,3 below are MOST IMPORTANT (I plan to get to these now, if I get it done will send them to you)
1. get_basis_fns_theta: WORST PIECE OF CODE, VERY SLOW. Can be made much faster by using MATLAB's spline function or interp1q. Make it even faster if generate the interpolation functions once and keep using them until K changes.
2. Changing K has not been implemented for arclength parameterization. Has been done for radial angle, see mcpf2.m
3. u0: Simple and efficient way to set: use the mean intensity inside the most likely contour or compute a weighted mean of intensities inside all contours. Similarly for v0.
4. Learning code: learn_geom.m - still working on it.
5. Change any of the above or other parameters: setparamssim_geom, mcpf2_geom (beginning) or mcevidencesample5
6. Current GD iter step does GD only for Chan-Vese energy, not for the edge based (Condensation) term. Correct thing to do: also include GD to minimize Condensation energy. If C_{obs} is the observed contour obtained by searching along the normals, then move a "few" iterations towards C_{obs}.
IGNORE EVERYTHING BELOW
IF YOU WANT TO WRITE CODE FOR ANGLE BASED INTERPOLATION: has been done I think
file to change: mcsystemsample2.m
OLDER VERSION
- CHANGING K and DETECTING NEED TO CHANGE K IN sYSTEMsAMPLE.M
- TRACKS ONE OF 2 OBJECTS DEPENDING ON OBSERVATION MODEL
pf: Main PF file
setparamssim: Called both in gendata_2obj and in mcpf - sets all parameters
systemsample2: Generates
evidencesample5:
gendata_2obj uses systemsample.m to generate sample contours
评论3