예제 #1
0
def test_explore(): 
    I = Image(make_data_int16())
    J = Image(make_data_int16())
    IM = IconicMatcher(I.array, J.array, I.toworld, J.toworld)
    T = np.eye(4)
    T[0:3,3] = np.random.rand(3)
    simi, params = IM.explore(ux=[-1,0,1],uy=[-1,0,1])
예제 #2
0
def _test_similarity_measure(simi, val):
    I = Image(make_data_int16())
    J = Image(I.array.copy())
    IM = IconicMatcher(I.array, J.array, I.toworld, J.toworld)
    IM.set_field_of_view(subsampling=[2,1,3])
    IM.set_similarity(simi)
    assert_almost_equal(IM.eval(np.eye(4)), val)
예제 #3
0
def affine_register(source, 
                    target, 
                    similarity='cr',
                    interp='pv',
                    subsampling=None,
                    normalize=None, 
                    search='affine',
                    graduate_search=False,
                    optimizer='powell'):
    
    """
    Three-dimensional affine image registration. 
    
    Parameters
    ----------
    source : image object 
       Source image array 
    target : image object
       Target image array
    similarity : str
       Cost-function for assessing image similarity.  One of 'cc', 'cr',
       'crl1', 'mi', je', 'ce', 'nmi', 'smi', 'custom'.  'cr'
       (correlation ratio) is the default.  See ``routines.pyx``
    interp : str
       Interpolation method.  One of 'pv': Partial volume, 'tri':
       Trilinear, 'rand': Random interpolation.  See
       ``register.iconic_matcher.py`
    subsampling : None or sequence of integers length 3
       subsampling of image in voxels, where None (default) results 
       in [1,1,1], See ``register.iconic_matcher.py``
    normalize : None or ?
       Passed to ``matcher.set_similarity`` in
       ``register.iconic_matcher.py`` - used where?
    search : str
       One of 'affine', 'rigid', 'similarity'; default 'affine'
    graduate_search : {False, True}
       Run registration by doing first 'rigid', then 'similarity', then
       'affine' - if True
    optimizer : str
       One of 'powell', 'simplex', 'conjugate_gradient'
       
    Returns
    -------
    T : source-to-target affine transformation 
        Object that can be casted to a numpy array. 

    """
    matcher = IconicMatcher(source.get_data(), 
                            target.get_data(), 
                            source.get_affine(),
                            target.get_affine())
    if subsampling == None: 
        matcher.set_field_of_view(fixed_npoints=64**3)
    else:
        matcher.set_field_of_view(subsampling=subsampling)
    matcher.set_interpolation(method=interp)
    matcher.set_similarity(similarity=similarity, normalize=normalize)

    # Register
    print('Starting registration...')
    print('Similarity: %s' % matcher.similarity)
    print('Normalize: %s' % matcher.normalize) 
    print('Interpolation: %s' % matcher.interp)

    T = None
    if graduate_search or search=='rigid':
        T = matcher.optimize(method=optimizer, search='rigid')
    if graduate_search or search=='similarity':
        T = matcher.optimize(method=optimizer, search='similarity', start=T)
    if graduate_search or search=='affine':
        T = matcher.optimize(method=optimizer, search='affine', start=T)
    return T
예제 #4
0
"""
Example of running affine matching on the 'sulcal2000' database
"""

##rootpath = 'D:\\data\\sulcal2000'
rootpath = '/neurospin/lnao/Panabase/roche/sulcal2000'
        
print('Scanning data directory...')

# Get data
print('Fetching image data...')
I = load_image(join(rootpath,'nobias_anubis'+'.nii'))
J = load_image(join(rootpath,'ammon_TO_anubis'+'.nii'))

# Setup registration algorithm
matcher = IconicMatcher(I.get_data(), J.get_data(), 
                        I.get_affine(), J.get_affine()) ## I: source, J: target

# Params
size = 5
nsimu = 1
depth = 10

import pylab as pl

# Simulations 
for i in range(nsimu): 

    # Select random block
    x0 = np.random.randint(I.array.shape[0]-size)
    y0 = np.random.randint(I.array.shape[1]-size)
    z0 = np.random.randint(I.array.shape[2]-size)