Esempio n. 1
0
def overlayPoints(dataSource,
                  pointSource,
                  sink=None,
                  pointColor=[1, 0, 0],
                  x=all,
                  y=all,
                  z=all):
    """Overlay points on 3D data and return as color image
    
    Arguments:
        dataSouce (str or array): volumetric image data
        pointSource (str or array): point data to be overlayed on the image data
        pointColor (array): RGB color for the overlayed points
        x, y, z (all or tuple): sub-range specification
    
    Returns:
        (str or array): image overlayed with points
        
    See Also:
        :func:`overlayLabel`
    """
    data = io.readData(dataSource, x=x, y=y, z=z)
    points = io.readPoints(pointSource, x=x, y=y, z=z, shift=True)
    #print data.shape

    if not pointColor is None:
        dmax = data.max()
        dmin = data.min()
        if dmin == dmax:
            dmax = dmin + 1
        cimage = numpy.repeat((data - dmin) / (dmax - dmin), 3)
        cimage = cimage.reshape(data.shape + (3, ))

        if data.ndim == 2:
            for p in points:  # faster version using voxelize ?
                cimage[p[0], p[1], :] = pointColor
        elif data.ndim == 3:
            for p in points:  # faster version using voxelize ?
                cimage[p[0], p[1], p[2], :] = pointColor
        else:
            raise RuntimeError(
                'overlayPoints: data dimension %d not suported' % data.ndim)

    else:
        cimage = vox.voxelize(points, data.shape, voxelizationMethod='Pixel')
        cimage = cimage.astype(data.dtype) * data.max()
        data.shape = data.shape + (1, )
        cimage.shape = cimage.shape + (1, )
        cimage = numpy.concatenate((data, cimage), axis=3)

    #print cimage.shape
    return io.writeData(sink, cimage)
Esempio n. 2
0
def overlayPoints(dataSource, pointSource, sink = None, pointColor = [1,0,0], x = all, y = all, z = all):
    """Overlay points on 3D data and return as color image
    
    Arguments:
        dataSouce (str or array): volumetric image data
        pointSource (str or array): point data to be overlayed on the image data
        pointColor (array): RGB color for the overlayed points
        x, y, z (all or tuple): sub-range specification
    
    Returns:
        (str or array): image overlayed with points
        
    See Also:
        :func:`overlayLabel`
    """
    data = io.readData(dataSource, x = x, y = y, z = z);
    points = io.readPoints(pointSource, x = x, y = y, z = z, shift = True);
    #print data.shape
    
    if not pointColor is None:
        dmax = data.max(); dmin = data.min();
        if dmin == dmax:
            dmax = dmin + 1;
        cimage = numpy.repeat( (data - dmin) / (dmax - dmin), 3);
        cimage = cimage.reshape(data.shape + (3,));    
    
        if data.ndim == 2:
            for p in points: # faster version using voxelize ?
                cimage[p[0], p[1], :] = pointColor;
        elif data.ndim == 3:
            for p in points: # faster version using voxelize ?
                cimage[p[0], p[1], p[2], :] = pointColor;
        else:
            raise RuntimeError('overlayPoints: data dimension %d not suported' % data.ndim);
    
    else:
        cimage = vox.voxelize(points, data.shape, method = 'Pixel');
        cimage = cimage.astype(data.dtype) * data.max();
        data.shape = data.shape + (1,);
        cimage.shape =  cimage.shape + (1,);
        cimage = numpy.concatenate((data, cimage), axis  = 3);
    
    #print cimage.shape    
    return io.writeData(sink, cimage);