Example #1
0
def runCellCoordinateTransformation(parameter):
    """Transform points by resampling applying the elastix transformation and then re-resample again"""
    
    im = parameter.Resampling.DataFiles;
    if im is None:    
        im = parameter.DataSource.ImageFile;
        
    cf = parameter.ImageProcessing.CellCoordinateFile;
    pa = parameter.Alignment;
    pr = parameter.Resampling;
    
    # downscale points to referenece image size
    points = resamplePoints(cf, im, resolutionData = pr.ResolutionData, resolutionReference = pr.ResolutionReference, orientation = pr.Orientation);
    
    # transform points
    points = points[:,[1,0,2]]; # account for (y,x, z) array representaton here
    points = transformPoints(points, alignmentdirectory = pa.AlignmentDirectory, transformparameterfile = None, read = True, tmpfile = None, outdirectory = None, indices = False);
    points = points[:,[1,0,2]]; # account for (y,x, z) array representaton here
    
    # upscale ppints back to original size
    points = resamplePointsInverse(points, im, resolutionData = pr.ResolutionData, resolutionReference = pr.ResolutionReference, orientation = pr.Orientation);
    
    tf = parameter.ImageProcessing.CellTransformedCoordinateFile;
    if tf is None:
        return points;
    else:
        io.writePoints(tf, points);
        return tf;
Example #2
0
def runCellCoordinateTransformationToReference(parameter):
    """Transform points by resampling and applying the elastix transformation in the reference data"""
    
    im = parameter.Resampling.DataFiles;
    if im is None:    
        im = parameter.DataSource.ImageFile;
    
    cf = parameter.ImageProcessing.CellCoordinateFile;
    pa = parameter.Alignment;
    pr = parameter.Resampling;
    
    # downscale points to referenece image size
    points = resamplePoints(cf, im, resolutionData = pr.ResolutionData, resolutionReference = pr.ResolutionReference, orientation = pr.Orientation);
    
    # transform points
    #points = points[:,[1,0,2]];
    points = transformPoints(points, alignmentdirectory = pa.AlignmentDirectory, transformparameterfile = None, read = True, tmpfile = None, outdirectory = None, indices = True);
    #points = points[:,[1,0,2]];
    
    tf = parameter.ImageProcessing.CellTransformedCoordinateFile;
    if tf is None:
        return points;
    else:
        io.writePoints(tf, points);
        return tf;
Example #3
0
def runCellCoordinateTransformationToReference(parameter):
    """Transform points by resampling and applying the elastix transformation in the reference data"""

    im = parameter.Resampling.DataFiles
    if im is None:
        im = parameter.DataSource.ImageFile

    cf = parameter.ImageProcessing.CellCoordinateFile
    pa = parameter.Alignment
    pr = parameter.Resampling

    # downscale points to referenece image size
    points = resamplePoints(cf,
                            im,
                            resolutionData=pr.ResolutionData,
                            resolutionReference=pr.ResolutionReference,
                            orientation=pr.Orientation)

    # transform points
    #points = points[:,[1,0,2]];
    points = transformPoints(points,
                             alignmentdirectory=pa.AlignmentDirectory,
                             transformparameterfile=None,
                             read=True,
                             tmpfile=None,
                             outdirectory=None,
                             indices=True)
    #points = points[:,[1,0,2]];

    tf = parameter.ImageProcessing.CellTransformedCoordinateFile
    if tf is None:
        return points
    else:
        io.writePoints(tf, points)
        return tf
Example #4
0
def runCellCoordinateTransformation(parameter):
    """Transform points by resampling applying the elastix transformation and then re-resample again"""

    im = parameter.Resampling.DataFiles
    if im is None:
        im = parameter.DataSource.ImageFile

    cf = parameter.ImageProcessing.CellCoordinateFile
    pa = parameter.Alignment
    pr = parameter.Resampling

    # downscale points to referenece image size
    points = resamplePoints(cf,
                            im,
                            resolutionData=pr.ResolutionData,
                            resolutionReference=pr.ResolutionReference,
                            orientation=pr.Orientation)

    # transform points
    points = points[:, [1, 0, 2]]
    # account for (y,x, z) array representaton here
    points = transformPoints(points,
                             alignmentdirectory=pa.AlignmentDirectory,
                             transformparameterfile=None,
                             read=True,
                             tmpfile=None,
                             outdirectory=None,
                             indices=False)
    points = points[:, [1, 0, 2]]
    # account for (y,x, z) array representaton here

    # upscale ppints back to original size
    points = resamplePointsInverse(points,
                                   im,
                                   resolutionData=pr.ResolutionData,
                                   resolutionReference=pr.ResolutionReference,
                                   orientation=pr.Orientation)

    tf = parameter.ImageProcessing.CellTransformedCoordinateFile
    if tf is None:
        return points
    else:
        io.writePoints(tf, points)
        return tf
Example #5
0
def runCellCoordinateResampling(parameter):
    """Transform points by resampling"""
    
    im = parameter.Resampling.DataFiles;
    if im is None:    
        im = parameter.DataSource.ImageFile;
        
    cf = parameter.ImageProcessing.CellCoordinateFile;
    pr = parameter.Resampling;
    
    # downscale points to referenece image size
    points = resamplePoints(cf, im, resolutionData = pr.ResolutionData, resolutionReference = pr.ResolutionReference, orientation = pr.Orientation);
        
    tf = parameter.ImageProcessing.CellTransformedCoordinateFile;
    if tf is None:
        return points;
    else:
        io.writePoints(tf, points);
        return tf;
Example #6
0
def runCellCoordinateResampling(parameter):
    """Transform points by resampling"""

    im = parameter.Resampling.DataFiles
    if im is None:
        im = parameter.DataSource.ImageFile

    cf = parameter.ImageProcessing.CellCoordinateFile
    pr = parameter.Resampling

    # downscale points to referenece image size
    points = resamplePoints(cf,
                            im,
                            resolutionData=pr.ResolutionData,
                            resolutionReference=pr.ResolutionReference,
                            orientation=pr.Orientation)

    tf = parameter.ImageProcessing.CellTransformedCoordinateFile
    if tf is None:
        return points
    else:
        io.writePoints(tf, points)
        return tf
parameter.Resampling.ResolutionReference = (25, 25, 25)

#Orientation of the Data set wrt reference
#(-axis will invert the orientation, for other hemisphere use (-1, 2, 3), to exchnge x,y use (2,1,3) etc)
parameter.Resampling.Orientation = (1, 2, 3)

#centers
centers = io.readPoints(os.path.join(basedirectory, 'cells.csv'))
print("Center shape: (%d, %d)" % centers.shape)

datasize = (2560, 2160, 1728)
# takes (y,x,z)
print(datasize)

rcenters = resamplePoints(centers, datasize,
                          parameter.Resampling.ResolutionData,
                          parameter.Resampling.ResolutionReference,
                          parameter.Resampling.Orientation)
print("Reshaped centers shape: (%d, %d)" % rcenters.shape)

if verbose:
    datares = io.readData(os.path.join(basedirectory, 'autofluo_resample.tif'))
    #print "Shape raw: " + str(dataraw.shape)
    print("Shape res: " + str(datares.shape))

    #Plot.plotOverlayPoints(dataraw*0.01, centers)er();

    Plot.plotOverlayPoints(datares * 0.01, rcenters)

io.writePoints(os.path.join(basedirectory, 'cells_resampled.csv'), rcenters)

#save pixel image:
#Resolution of the Reference / Atlas (in um/ pixel)
parameter.Resampling.ResolutionReference = (25, 25, 25);

#Orientation of the Data set wrt reference
#(-axis will invert the orientation, for other hemisphere use (-1, 2, 3), to exchnge x,y use (2,1,3) etc)
parameter.Resampling.Orientation = (1,2,3);

#centers
centers = io.readPoints(os.path.join(basedirectory, 'cells.csv'))
print "Center shape: (%d, %d)" % centers.shape


datasize = (2560, 2160, 1728); # takes (y,x,z)
print datasize

rcenters = resamplePoints(centers, datasize, parameter.Resampling.ResolutionData, parameter.Resampling.ResolutionReference, parameter.Resampling.Orientation)
print "Reshaped centers shape: (%d, %d)" % rcenters.shape

if verbose:
    datares = io.readData(os.path.join(basedirectory, 'autofluo_resample.tif'));
    #print "Shape raw: " + str(dataraw.shape)
    print "Shape res: " + str(datares.shape)
    
    #Plot.plotOverlayPoints(dataraw*0.01, centers)er();

    Plot.plotOverlayPoints(datares*0.01, rcenters)
    
io.writePoints(os.path.join(basedirectory, 'cells_resampled.csv'), rcenters)

#save pixel image:
import iDISCO.Analysis.Voxelization as vox;
    "resolutionSink"   : (12, 15, 5),

    #Orientation of the Data set wrt reference as (x=1,y=2,z=3)
    #(-axis will invert the orientation, for other hemisphere use (-1, 2, 3), to exchnge x,y use (2,1,3) etc)
    "orientation" : (1,2,3),
    
    #number of processes to use in parallel:
    "processes" : 4,     
    };


#centers
points = io.readPoints(os.path.join(baseDirectory, 'Synthetic/cells.csv'));
print("points shape: (%d, %d)" % points.shape)

respoints = resamplePoints(points, dataSize, shiftPoints = True, **resamplingParameter);
print("Reshaped centers shape: (%d, %d)" % respoints.shape)

if verbose:
    dataraw = io.readData(os.path.join(baseDirectory, 'Data/Synthetic/test_iDISCO_\d{3}.tif'));
    datares = io.readData(os.path.join(baseDirectory, 'Synthetic/test_iDISCO_resample.tif'));
    print("Shape raw: " + str(dataraw.shape))
    print("Shape res: " + str(datares.shape))
    
    plot.plotOverlayPoints(dataraw*0.01, points);
    plot.plotOverlayPoints(datares*0.01, respoints);


#check inverse:
resipoints = resamplePointsInverse(respoints, dataSize, **resamplingParameter);
diff = points - resipoints;
    "resolutionSink"   : (12, 15, 5),

    #Orientation of the Data set wrt reference as (x=1,y=2,z=3)
    #(-axis will invert the orientation, for other hemisphere use (-1, 2, 3), to exchnge x,y use (2,1,3) etc)
    "orientation" : (1,2,3),
    
    #number of processes to use in parallel:
    "processes" : 4,     
    };


#centers
points = io.readPoints(os.path.join(baseDirectory, 'Synthetic/cells.csv'));
print "points shape: (%d, %d)" % points.shape

respoints = resamplePoints(points, dataSize, shiftPoints = True, **resamplingParameter);
print "Reshaped centers shape: (%d, %d)" % respoints.shape

if verbose:
    dataraw = io.readData(os.path.join(baseDirectory, 'Data/Synthetic/test_iDISCO_\d{3}.tif'));
    datares = io.readData(os.path.join(baseDirectory, 'Synthetic/test_iDISCO_resample.tif'));
    print "Shape raw: " + str(dataraw.shape)
    print "Shape res: " + str(datares.shape)
    
    plot.plotOverlayPoints(dataraw*0.01, points);
    plot.plotOverlayPoints(datares*0.01, respoints);


#check inverse:
resipoints = resamplePointsInverse(respoints, dataSize, **resamplingParameter);
diff = points - resipoints;