bigfelreg
index
/.automount/ioasun3/root/disk/users/kybic/work/python_volumes/bigfelreg.py

 Module representing the next generation of
Fast Elastic Registration Algorithm
as described in the corresponding chapter of my thesis.
 
When this works, I will remove the routines from other modules
which have thus become superflous.
 
Jan Kybic, April 2001
$Id: bigfelreg.html,v 1.1 2002/08/26 14:11:15 jkybic Exp $

 
Modules
                      
BIGsplines
Image
ImageDraw
ImageFont
MA
bigoptimize
bigsplines
bigtools
copy
copy_reg
math
multiarray
new
operator
pickle
string
time
types

 
Classes
                      
bigoptimize.EvaluableProblem
DProjProblem
MultigridableWarpingProblemBase
MultigridableWarpingProblemSQ
MultigridableWarpingProblemSprings
MultigridableWarpingProblemWI
WarpingProblemS
MultigridableWarpingProblemSDataPart
MWPSequencePlugin
MWPSpringPlugin
MWPWarpIndexPlugin
WarpableImageS

 
class DProjProblem(bigoptimize.EvaluableProblem)
            Implements a task of evaluating the distance between two
deformations, one given by a WarpableImageS object and second
by a table of values. Suitable for minimization using optimizerGdesQ
and similar.
 
Implements the interface of EvaluableProblem.
 
  
__init__(self, wi, tbl, mask=None)
 wi is a WarpableImageS, tbl a table as returned from
WarpableImageS.getDeformation
dHerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
gerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
getE(self, c)
 Calculate the criterion for a particular c
getEg(self, c)
getEgDh(self, x) from bigoptimize.EvaluableProblem
getInitialX(self)
 Return the initial state of the deformation.
It is a private copy of the array, it will not change with time
getX(self)
 Currently homonyme for getInitialX(). Returns the last value
used for the calculation
numDh(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
numg(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
setX(self, x)
 Sets the deformation parameters to x. This functions is
automatically called whenever new calculation of E or g is needed.

 
class MWPSequencePlugin
            This is an auxiliary plug-in class to be used in derivatives of
MultigridableWarpingProblemBase.
It returns a sequence of images illustrating the optimization.
It accepts parameters:
fileseqmask - the full filename including a printf-style placeholder
           for image number, for example 'regseq%04d.tiff'
imgsize - target size of a single image, we currently make
          a sequence of images about 2*imgsize+10
 
  
__init__(self, par=None, datapart=None)
canReduce(self)
getE(self, x)
getEg(self, x)
getReduced(self, datapart=None)
 Returns a reduced version of the plugin.
makeimg(self, x)
 Creates an image corresponding to current state.
 
For second and subsequent evaluation, if the criterion increases,
previous images are being used (to reconsider)

 
class MWPSpringPlugin
            This is a auxiliary plug-in class to be used in derivatives of
MultigridableWarpingProblemBase. It represents the landmark
spring constraints.
 
New parameters in par are springfactor, springpos, springtarget
The added part of the criterion is:
 
Espring=Sum springfactor(i)*||g(springpos(i))-springtarget(i)||^2
 
springpos,springtarget and springfactor should be arrays with first
dimension equal to N, the number of springs.
 
  
__init__(self, par=None, datapart=None)
canReduce(self)
getE(self, x)
 Calculate the contribution of the springs. Note that it is
crucial that the DataPart is evaluated before the spring part,
so that the deformation is already set. That's why x is not
used in this function
getEg(self, x)
 See comment at getE
getReduced(self, datapart=None)
 Returns a reduced version of the spring plug-in.

 
class MWPWarpIndexPlugin
            This is an auxiliary plug-in class to be used in derivatives of
MultigridableWarpingProblemBase. It returns the trajectory of the
optimization process: the values of the energy and the warping index.
It accepts parameters:
trueg - (the true deformation as returned by getDefS),
reslist - a list of tuples (imgsize,crate,E,wi)
wimask  - the mask as returned for example by
bigregister.calculateThresholdedMask
 
When on the parameter 'measuretime' is set, none of the above is
calculated and the reslist contains the list of times as returned by
time.clock()
 
  
__init__(self, par=None, datapart=None)
canReduce(self)
evalwi(self, x)
 Evaluates the state of the optimization and appends it to
the self.par.reslist list
 
For second and subsequent evaluation, if the criterion increases,
values from previous (successful) evaluation are used instead.
getE(self, x)
getEg(self, x)
getReduced(self, datapart=None)
 Returns a reduced version of the warpindex plugin.
reduceMask(self, m)
 Take a binary mask m and reduce it by half

 
class MultigridableWarpingProblemBase(bigoptimize.EvaluableProblem)
            This is the basis versions of a WarpingProblemS.
Additional plug-in criteria parts can be added.
 
The object of a created class supports the following
interface methods:
__init__(self,par=None)
getInitialX,getE,getEg,setX
canReduce,getReduced,getXstate,getXcopy,updateFine
 
These interface methods must be supported by the first (DataPart)
client object, the auxiliary ones only need to support
 
getE,getEg,canReduce,getReduced
 
The auxiliary criterion objects will get an additional keyword argument
datapart for their __init__ and getReduced() methods and
should access the current state
through this pointer.
 
The possible parameters object par attributes are refimg,
testimg, testw, and many others
 
  
__init__(self, par=None)
canReduce(self)
 Relay the call to all members and accumulate
dHerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
gerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
getE(self, x)
 Relay the call to all members and accumulate
getEg(self, x)
 Relay the call to all members and accumulate
getEgDh(self, x) from bigoptimize.EvaluableProblem
getInitialX(self)
 Gets the initial value of X. We only relay this call
to the first (data part) member
getReduced(self)
 Returns an object of my own class, containing reduced
versions of myself and the auxiliary criterion parts.
getX(self)
 Gets the value of X. We only relay this call
to the first (data part) member
getXcopy(self)
 Relay the call to the data part
getXstate(self)
 Relay the call to the data part
numDh(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
numg(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
setX(self, x)
 Relay the call to the data part
setXstate(self, x)
 Relay the call to the data part
updateFine(self, xc0, cp)
 Relay the call to the data part

 
class MultigridableWarpingProblemSDataPart(WarpingProblemS)
            Implements the multigridable version of WarpingProblemS.
 
The added methods are canReduce(), getReduced(), updateFine()
 
When reducing, we will alternatively coarsen the image and
the deformation grid, or coarsen both at the same time (default).
 
Remark: For the moment, we consider only uniform coarsening
of the deformation grid
 
If grmask is nonzero, gradient mask is automatically computed at
each level with this percentage of active pixels.
 
It is not intended to be run independently. Instead it will be
a part of a WarpingProblemS object, together with other parts
of the criteria.
 
  
__init__(self, par=None)
 The par members refimg and testimg
are either an array or a MSplineSignal.
Alternatively, you can specify testw
(a WarpableImageS) directly
canReduce(self)
 True if any coarsening is possible
canReduceDef(self)
 Returns true if the deformation can be further coarsened
canReduceImg(self)
 True if Img can be reduced
dHerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
gerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
getE(self, c) from WarpingProblemS
getEg(self, c) from WarpingProblemS
getEgDh(self, x) from bigoptimize.EvaluableProblem
getGradientMask(self, pct=10)
  Calculates a mask of refimg, such that it contains 'pct'
pixels with the highest gradient values
 
NOTE: This is not very efficient, as we generate the WarpableImageS
first
getInitialX(self) from WarpingProblemS
getReduced(self)
 Returns a reduced version of the MultigridableWarpingProblemS
the particular reducing method can be chosen by the parameters
getReducedAlternate(self)
 Returns a reduced version of the MultigridableWarpingProblemS,
alternatively reducing the image size and the deformation
grid size.
getReducedDef(self)
 Returns a reduced version of the MultigridableWarpingProblemS
with reduced deformation grid.
getReducedImg(self)
 Returns a reduced version of the MultigridableWarpingProblemS
with reduced images and possibly also the deformation grid,
if needed
getReducedImgAndDef(self)
 Reduce both image and deformation grid
getX(self) from WarpingProblemS
getXcopy(self)
 Get a copy of the current state, to be used with updateFine()
getXstate(self)
 Get the current state (no copy), to be used with updateFine()
numDh(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
numg(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
setX(self, x) from WarpingProblemS
setXstate(self, x)
 Converse of getXstate() or getXcopy()
updateFine(self, xc0, cp)
 Update yourself from the result of coarse level computation.
xc0 is the coarse grid value received from cp.getXcopy()
(a private copy) before the coarse grid representation.
It might or might not be an array.
cp is the coarse level MultigridableWarpingProblemS in its
final state. The new fine value is
xforig+Expand(xc1-xc0)

 
class MultigridableWarpingProblemSQ(MultigridableWarpingProblemBase)
            WarpingProblem including the sequence plugin
 
  
__init__(self, par=None) from MultigridableWarpingProblemBase
canReduce(self) from MultigridableWarpingProblemBase
dHerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
gerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
getE(self, x) from MultigridableWarpingProblemBase
getEg(self, x) from MultigridableWarpingProblemBase
getEgDh(self, x) from bigoptimize.EvaluableProblem
getInitialX(self) from MultigridableWarpingProblemBase
getReduced(self) from MultigridableWarpingProblemBase
getX(self) from MultigridableWarpingProblemBase
getXcopy(self) from MultigridableWarpingProblemBase
getXstate(self) from MultigridableWarpingProblemBase
numDh(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
numg(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
setX(self, x) from MultigridableWarpingProblemBase
setXstate(self, x) from MultigridableWarpingProblemBase
updateFine(self, xc0, cp) from MultigridableWarpingProblemBase

 
class MultigridableWarpingProblemSprings(MultigridableWarpingProblemBase)
            WarpingProblem including the spring regulatization
 
  
__init__(self, par=None) from MultigridableWarpingProblemBase
canReduce(self) from MultigridableWarpingProblemBase
dHerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
gerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
getE(self, x) from MultigridableWarpingProblemBase
getEg(self, x) from MultigridableWarpingProblemBase
getEgDh(self, x) from bigoptimize.EvaluableProblem
getInitialX(self) from MultigridableWarpingProblemBase
getReduced(self) from MultigridableWarpingProblemBase
getX(self) from MultigridableWarpingProblemBase
getXcopy(self) from MultigridableWarpingProblemBase
getXstate(self) from MultigridableWarpingProblemBase
numDh(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
numg(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
setX(self, x) from MultigridableWarpingProblemBase
setXstate(self, x) from MultigridableWarpingProblemBase
updateFine(self, xc0, cp) from MultigridableWarpingProblemBase

 
class MultigridableWarpingProblemWI(MultigridableWarpingProblemBase)
            WarpingProblem including the warping index calculation
 
  
__init__(self, par=None) from MultigridableWarpingProblemBase
canReduce(self) from MultigridableWarpingProblemBase
dHerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
gerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
getE(self, x) from MultigridableWarpingProblemBase
getEg(self, x) from MultigridableWarpingProblemBase
getEgDh(self, x) from bigoptimize.EvaluableProblem
getInitialX(self) from MultigridableWarpingProblemBase
getReduced(self) from MultigridableWarpingProblemBase
getX(self) from MultigridableWarpingProblemBase
getXcopy(self) from MultigridableWarpingProblemBase
getXstate(self) from MultigridableWarpingProblemBase
numDh(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
numg(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
setX(self, x) from MultigridableWarpingProblemBase
setXstate(self, x) from MultigridableWarpingProblemBase
updateFine(self, xc0, cp) from MultigridableWarpingProblemBase

 
class WarpableImageS
            contains n-dimensional image to be warped.
 
Reimplementation of bigregister.WarpableImage using MSplineSignal
 
The ratio between the image size and the control grid size
is now constrained to be an integer 'crate' (actually a vector)
The deformation is a list of MSplineSignals, 'defs', one element for
each component . It coincides with 'imgs' at zero and goes 'crate'
times slower.
 
  
__init__(self, imgs, defs=None, par=None, c=None, mask=None)
 imgs is supposed to be MSplineSignal or an array,
defs is either None, or a MSplineSignalList
If imgs is an array, we convert it.
The deformation defaults to identity, or it can be given
by the MSplineSignal defs or the matrix c
 
If mask is not None it determines which pixel values are
going to be evaluated. It should have the same size as
the image imgs. For the moment, only the calculation
of the warped image is affected.
cRateIsEven(self)
 True if all elements of crate are even
getCAsArray(self)
 Unpacks the coefficients of the deformation to an array
getContrib(self, x)
 Returns an array of the size of self.defs.l[0].c which contains
the spline values of the corresponding spline functions at point x
getDefS(self)
 Return pointer the defs  MSplineSignalList
getDeformation(self)
 Get the deformation function at all points, caching the
results.
 
NOTE: mask could have been used here, but it is not,
as evalfract does not support it anyway.
getDeformationAtPoints(self, pts)
 Gets target position of multiple points pts of size (n,dim),
(which is the transpose of what interpoldef wants)
It returns the diplacements in the same format (n,dim)
getDerivatives(self)
 get all first derivatives of the image
getExpandedDef(self)
 Returns an equivalent version of WarpableImageS with twice
expanded deformation grid. crate is divided by two
getImageS(self)
 Return pointer to imgs
getReducedDef(self)
 Returns an equivalent version of WarpableImageS with twice
reduced deformation grid. crate is multiplied by two
getReducedImg(self)
 Returns an equivalent version of WarpableImageS with twice
reduced image and correspondingly modified deformation structure
getReducedImgAndDef(self)
 Returns an equivalent version of WarpableImageS with twice
reduced image and twice reduced deformation grid.
crate stays constant
getWarped(self, g=None)
 Get the warped image as an array
getWarpedOther(self, img)
 Warp an image img
with the same deformation as myself, expanding appropriately
getWarpingIndex(self, c, mask=None)
 Calculates the warping index (average geometric error) between
the current deformation and the deformation given by c.
The mask here is positive, i.e. 1 means consider, 0 do not consider
getWarpingIndexDefS(self, defs, par, mask=None)
 Calculates the warping index (average geometric error) between
the current deformation and deformation given by defs and
par (from which crate, degc are taken)
getWarpingIndexG(self, g0, mask=None)
 Calculates the warping index (average geometric error) between
the current deformation and deformation given by g 
and mask
setCFromArray(self, c)
 Sets the internal representation of a deformation from an
array c
setDefS(self, defs)
 Set a new defs, invalidating the deformation
setIdentity(self)
setMask(self, mask)
setProjection(self, g0, mask=None)
 Given a conforming deformation table g0, set coefficients
of the deformation so that it is as close as possible (in the
warping index sense) to g0

 
class WarpingProblemS(bigoptimize.EvaluableProblem)
            Implements the accelerated variant of the single-scale
warping problem. Mostly compatible with bigregister.WarpingProblem
 
Accepts two images: reference and test. Reference is an array,
test is a MSplineSignal which will be embedded in
ReducWarpableImageS.
 
The criterion is SSD per pixel.
 
Implements the interface of EvaluableProblem.
 
  
__init__(self, refimg, testimg=None, testw=None, par=None, mask=None)
 refimg is an array, testimg a MSplineSignal
or an array. Alternatively, you can specify testw
(a WarpableImageS) directly
dHerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
gerr(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
getE(self, c)
 Calculate the criterion for a particular c
getEg(self, c)
 Calculate the criterion and its gradient for some c
getEgDh(self, x) from bigoptimize.EvaluableProblem
getInitialX(self)
 Return the initial state of the deformation.
It is a private copy of the array, it will not change with time
getX(self)
 Currently homonyme for getInitialX(). Returns the last value
used for the calculation
numDh(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
numg(self, x, h=9.9999999999999995e-07) from bigoptimize.EvaluableProblem
setX(self, x)
 Sets the deformation parameters to x. This functions is
automatically called whenever new calculation of E or g is needed.

 
Functions
                      
alltrue = reduce(...)
array(...)
array(sequence, typecode=None, copy=1, savespace=0) will return a new array formed from the given (potentially nested) sequence with type given by typecode.  If no typecode is given, then the type will be determined as the minimum type required to hold the objects in sequence.  If copy is zero and sequence is already an array, a reference will be returned.  If savespace is nonzero, the new array will maintain its precision in operations.
choose(...)
choose(a, (b1,b2,...))
cross_correlate(...)
cross_correlate(a,v)
cumproduct = accumulate(...)
cumsum = accumulate(...)
fromstring(...)
fromstring(string, count=None, typecode='l') returns a new 1d array initialized from the raw binary data in string.  If count is not equal to None, the new array will have count elements, otherwise it's size is determined by the size of string.
product = reduce(...)
repeat(...)
repeat(a, n, axis=0)
reshape(...)
reshape(a, (d1, d2, ..., dn)).  Change the shape of a to be an n-dimensional array with dimensions given by d1...dn.  One dimension is allowed to be None.  This dimension will be set to whatever value will make the size of the new array equal the size of the old one.  Note: the size specified for the new array must be exactly equal to the size of the  old one or an error will occur.  This returns a completely new array with the data of the old one copied.  Use a.shape=(...) for no data copying.
searchsorted = binarysearch(...)
binarysearch(a,v)
sometrue = reduce(...)
sum = reduce(...)
take(...)
take(a, indices, axis=0).  Selects the elements in indices from array a along the given axis.
test_MROptimizerState()
test_MultigridableWarpingProblem()
test_Springs()
test_WarpableImageS()
test_WarpingProblemS()
test_bigimage()
test_preserve()
test_registerUltrasound()
test_updateFine()
zeros(...)
zeros((d1,...,dn),typecode,savespace) will return a new array of shape (d1,...,dn) and type typecode (default 'l') with all it's entries initialized to zero.  If savespace (default 0) is nonzero the array will be a spacesaver array.

 
Constants
                      ArrayType = <type 'array'>
Complex = 'D'
Complex0 = 'F'
Complex16 = 'F'
Complex32 = 'F'
Complex64 = 'D'
Complex8 = 'F'
Float = 'd'
Float0 = 'f'
Float16 = 'f'
Float32 = 'f'
Float64 = 'd'
Float8 = 'f'
Int = 'l'
Int0 = '1'
Int16 = 's'
Int32 = 'i'
Int8 = '1'
LittleEndian = 1
PrecisionError = 'PrecisionError'
PyObject = 'O'
UnsignedInt8 = 'b'
arraytype = <type 'array'>
e = 2.7182818284590451
pi = 3.1415926535897931