Exemplo n.º 1
0
def test():
    """Test voxelization module"""
    
    import iDISCO.Analysis.Voxelization as self
    reload(self)
    
    import iDISCO.Analysis.VoxelizationCode as vox
    import numpy
    
    
    points = numpy.random.rand(200,3) * 10;
    
    #use cython code
    vi = vox.voxelizeSphere(points, 20,20,20, 5,5,5);
    
    import iDISCO.Visualization.Plot as Plot

    Plot.plotTiling(vi)
    
    #use voxelize
    vi = self.voxelize(points, dataSize = (20,20,20), average = (5,5,5));
    
    Plot.plotTiling(vi)
    
    
    #weighted voxelization 
    points = numpy.random.rand(10,3) * 10;    
    weights = numpy.random.rand(10);
    
    #use voxelize
    vi = self.voxelize(points, dataSize = (20,20,20), average = (5,5,5));
    viw =  self.voxelize(points, dataSize = (20,20,20), average = (5,5,5), weights = weights);
    
    Plot.plotTiling(vi)
    Plot.plotTiling(viw)
Exemplo n.º 2
0
def test():
    """Test voxelization module"""
    import ClearMap.Analysis.Voxelization as self
    reload(self)

    import ClearMap.Analysis.VoxelizationCode as vox
    import numpy


    points = numpy.random.rand(200,3) * 10;

    #use cython code
    vi = vox.voxelizeSphere(points, 20,20,20, 5,5,5);

    import ClearMap.Visualization.Plot as Plot

    Plot.plotTiling(vi)

    #use voxelize
    vi = self.voxelize(points, dataSize = (20,20,20), size = (5,5,5));

    Plot.plotTiling(vi)


    #weighted voxelization
    points = numpy.random.rand(10,3) * 10;
    weights = numpy.random.rand(10);

    #use voxelize
    vi = self.voxelize(points, dataSize = (20,20,20), size = (5,5,5));
    viw =  self.voxelize(points, dataSize = (20,20,20), size = (5,5,5), weights = weights);

    Plot.plotTiling(vi)
    Plot.plotTiling(viw)
Exemplo n.º 3
0
def voxelize(points, dataSize = None, sink = None, voxelizeParameter = None,  method = 'Spherical', size = (5,5,5), weights = None):
    """Converts a list of points into an volumetric image array
    
    Arguments:
        points (array): point data array
        dataSize (tuple): size of final image
        sink (str, array or None): the location to write or return the resulting voxelization image, if None return array
        voxelizeParameter (dict):
            ========== ==================== ===========================================================
            Name       Type                 Descritption
            ========== ==================== ===========================================================
            *method*   (str or None)        method for voxelization: 'Spherical', 'Rectangular' or 'Pixel'
            *size*     (tuple)              size parameter for the voxelization
            *weights*  (array or None)      weights for each point, None is uniform weights                          
            ========== ==================== ===========================================================      
    Returns:
        (array): volumetric data of smeared out points
    """
    
    if dataSize is None:
        dataSize = tuple(int(math.ceil(points[:,i].max())) for i in range(points.shape[1]));
    elif isinstance(dataSize, basestring):
        dataSize = io.dataSize(dataSize);
    
    points = io.readPoints(points);
        
    if method.lower() == 'spherical':
        if weights is None:
            data = vox.voxelizeSphere(points.astype('float'), dataSize[0], dataSize[1], dataSize[2], size[0], size[1], size[2]);
        else:
            data = vox.voxelizeSphereWithWeights(points.astype('float'), dataSize[0], dataSize[1], dataSize[2], size[0], size[1], size[2], weights);
           
    elif method.lower() == 'rectangular':
        if weights is None:
            data = vox.voxelizeRectangle(points.astype('float'), dataSize[0], dataSize[1], dataSize[2], size[0], size[1], size[2]);
        else:
            data = vox.voxelizeRectangleWithWeights(points.astype('float'), dataSize[0], dataSize[1], dataSize[2], size[0], size[1], size[2], weights);
    
    elif method.lower() == 'pixel':
        data = voxelizePixel(points, dataSize, weights);
        
    else:
        raise RuntimeError('voxelize: mode: %s not supported!' % method);
    
    return io.writeData(sink, data);
Exemplo n.º 4
0
def voxelize(points, dataSize = None, sink = None, voxelizeParameter = None,  method = 'Spherical', size = (5,5,5), weights = None):
    """Converts a list of points into an volumetric image array

    Arguments:
        points (array): point data array
        dataSize (tuple): size of final image
        sink (str, array or None): the location to write or return the resulting voxelization image, if None return array
        voxelizeParameter (dict):
            ========== ==================== ===========================================================
            Name       Type                 Descritption
            ========== ==================== ===========================================================
            *method*   (str or None)        method for voxelization: 'Spherical', 'Rectangular' or 'Pixel'
            *size*     (tuple)              size parameter for the voxelization
            *weights*  (array or None)      weights for each point, None is uniform weights
            ========== ==================== ===========================================================
    Returns:
        (array): volumetric data of smeared out points
    """

    if dataSize is None:
        dataSize = tuple(int(math.ceil(points[:,i].max())) for i in range(points.shape[1]));
    elif isinstance(dataSize, basestring):
        dataSize = io.dataSize(dataSize);

    points = io.readPoints(points);

    if method.lower() == 'spherical':
        if weights is None:
            data = vox.voxelizeSphere(points.astype('float'), dataSize[0], dataSize[1], dataSize[2], size[0], size[1], size[2]);
        else:
            data = vox.voxelizeSphereWithWeights(points.astype('float'), dataSize[0], dataSize[1], dataSize[2], size[0], size[1], size[2], weights);

    elif method.lower() == 'rectangular':
        if weights is None:
            data = vox.voxelizeRectangle(points.astype('float'), dataSize[0], dataSize[1], dataSize[2], size[0], size[1], size[2]);
        else:
            data = vox.voxelizeRectangleWithWeights(points.astype('float'), dataSize[0], dataSize[1], dataSize[2], size[0], size[1], size[2], weights);

    elif method.lower() == 'pixel':
        data = voxelizePixel(points, dataSize, weights);

    else:
        raise RuntimeError('voxelize: mode: %s not supported!' % method);

    return io.writeData(sink, data);