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 = np.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 = np.concatenate((data, cimage), axis=3) #print cimage.shape return io.writeData(sink, cimage)
def resamplePointsInverse(pointSource, pointSink=None, dataSizeSource=None, dataSizeSink=None, orientation=None, resolutionSource=(4.0625, 4.0625, 3), resolutionSink=(25, 25, 25), **args): """Resample points from the coordinates of the resampled image to the original data The resampling of points here corresponds to he resampling of an image in :func:`resampleDataInverse` Arguments: pointSource (str or array): image to be resampled pointSink (str or None): destination of resampled image orientation (tuple): orientation specified by permuation and change in sign of (1,2,3) dataSizeSource (str, tuple or None): size of the data source dataSizeSink (str, tuple or None): target size of the resampled image resolutionSource (tuple): resolution of the source image (in length per pixel) resolutionSink (tuple): resolution of the resampled image (in length per pixel) Returns: (array or str): data or file name of inversely resampled points Notes: * resolutions are assumed to be given for the axes of the intrinsic orientation of the data and reference as when viewed by matplotlib or ImageJ * orientation: permuation of 1,2,3 with potential sign, indicating which axes map onto the reference axes, a negative sign indicates reversal of that particular axes * only a minimal set of information to detremine the resampling parameter has to be given, e.g. dataSizeSource and dataSizeSink """ orientation = fixOrientation(orientation) #datasize of data source if isinstance(dataSizeSource, basestring): dataSizeSource = io.dataSize(dataSizeSource) dataSizeSource, dataSizeSink, resolutionSource, resolutionSink = resampleDataSize( dataSizeSource=dataSizeSource, dataSizeSink=dataSizeSink, resolutionSource=resolutionSource, resolutionSink=resolutionSink, orientation=orientation) points = io.readPoints(pointSource) dataSizeSinkI = orientDataSizeInverse(dataSizeSink, orientation) #resolutionSinkI = orientResolutionInverse(resolutionSink, orientation); #scaling factors scale = [ float(dataSizeSource[i]) / float(dataSizeSinkI[i]) for i in range(3) ] #print scale rpoints = points.copy() #invert axis inversion and permutations if not orientation is None: #invert permuation iorientation = inverseOrientation(orientation) per = orientationToPermuation(iorientation) rpoints = rpoints[:, per] for i in range(3): if iorientation[i] < 0: rpoints[:, i] = dataSizeSinkI[i] - rpoints[:, i] #scale points for i in range(3): rpoints[:, i] = rpoints[:, i] * scale[i] return io.writePoints(pointSink, rpoints)
import ClearMap.IO.IO as io import os import ClearMap.Visualization.Plot as plt import ClearMap.Analysis.Label as lbl import numpy as np sampleName = 'LowNIC' #execfile('/d2/studies/ClearMap/IA_iDISCO/' + sampleName + '/parameter_file_' + sampleName + '.py') execfile( '/d2/studies/ClearMap/Alex_Acute_iDISCO/3RB_HighNIC/parameter_file_template_3RB.py' ) baseDirectory = '/d2/studies/ClearMap/Alex_Acute_iDISCO/NIC_HeatMaps/FiguresForPaper/' region = 'MSC' points = io.readPoints(TransformedCellsFile) data = plt.overlayPoints(AnnotationFile, points.astype(int), pointColor=None) io.writeData( os.path.join(BaseDirectory, sampleName + '_Annotations_Points_Overlay_newAtlas2.tif'), data) data = data[:, :, :, 1:] io.writeData( os.path.join(BaseDirectory, sampleName + '_Points_Transformed_newAtlas2.tif'), data) label = io.readData(AnnotationFile) label = label.astype('int32') labelids = np.unique(label) outside = np.zeros(label.shape, dtype=bool)
def resamplePointsInverse(pointSource, pointSink = None, dataSizeSource = None, dataSizeSink = None, orientation = None, resolutionSource = (4.0625, 4.0625, 3), resolutionSink = (25, 25, 25), **args): """Resample points from the coordinates of the resampled image to the original data The resampling of points here corresponds to he resampling of an image in :func:`resampleDataInverse` Arguments: pointSource (str or array): image to be resampled pointSink (str or None): destination of resampled image orientation (tuple): orientation specified by permuation and change in sign of (1,2,3) dataSizeSource (str, tuple or None): size of the data source dataSizeSink (str, tuple or None): target size of the resampled image resolutionSource (tuple): resolution of the source image (in length per pixel) resolutionSink (tuple): resolution of the resampled image (in length per pixel) Returns: (array or str): data or file name of inversely resampled points Notes: * resolutions are assumed to be given for the axes of the intrinsic orientation of the data and reference as when viewed by matplotlib or ImageJ * orientation: permuation of 1,2,3 with potential sign, indicating which axes map onto the reference axes, a negative sign indicates reversal of that particular axes * only a minimal set of information to detremine the resampling parameter has to be given, e.g. dataSizeSource and dataSizeSink """ orientation = fixOrientation(orientation); #datasize of data source if isinstance(dataSizeSource, basestring): dataSizeSource = io.dataSize(dataSizeSource); dataSizeSource, dataSizeSink, resolutionSource, resolutionSink = resampleDataSize(dataSizeSource = dataSizeSource, dataSizeSink = dataSizeSink, resolutionSource = resolutionSource, resolutionSink = resolutionSink, orientation = orientation); points = io.readPoints(pointSource); dataSizeSinkI = orientDataSizeInverse(dataSizeSink, orientation); #resolutionSinkI = orientResolutionInverse(resolutionSink, orientation); #scaling factors scale = [float(dataSizeSource[i]) / float(dataSizeSinkI[i]) for i in range(3)]; #print scale rpoints = points.copy(); #invert axis inversion and permutations if not orientation is None: #invert permuation iorientation = inverseOrientation(orientation); per = orientationToPermuation(iorientation); rpoints = rpoints[:,per]; for i in range(3): if iorientation[i] < 0: rpoints[:,i] = dataSizeSinkI[i] - rpoints[:,i]; #scale points for i in range(3): rpoints[:,i] = rpoints[:,i] * scale[i]; return io.writePoints(pointSink, rpoints);