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;
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
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;
def runCellDetection(parameter): """Detect cells in data""" timer = Timer() pp = parameter.StackProcessing ps = parameter.DataSource # run segmentation if parameter.ImageProcessing.Method == "SpotDetection": detectCells = iDISCO.ImageProcessing.SpotDetection.detectCells centers, intensities = parallelProcessStack( ps.ImageFile, x=ps.XRange, y=ps.YRange, z=ps.ZRange, processes=pp.Processes, chunksizemax=pp.ChunkSizeMax, chunksizemin=pp.ChunkSizeMin, chunkoverlap=pp.ChunkOverlap, optimizechunks=pp.OptimizeChunks, optimizechunksizeincrease=pp.OptimizeChunkSizeIncrease, segmentation=detectCells, parameter=parameter.ImageProcessing) else: if haveIlastik: #ilastik does parallel processing so do sequential processing here detectCells = iDISCO.ImageProcessing.IlastikClassification.detectCells centers, intensities = sequentiallyProcessStack( ps.ImageFile, x=ps.XRange, y=ps.YRange, z=ps.ZRange, chunksizemax=pp.ChunkSizeMax, chunksizemin=pp.ChunkSizeMin, chunkoverlap=pp.ChunkOverlap, segmentation=detectCells, parameter=parameter.ImageProcessing) else: raise RuntimeError( "No Ilastik installed use SpotDectection instead!") timer.printElapsedTime("Main") if not parameter.ImageProcessing.Parameter.ThresholdSave is None: iid = intensities > parameter.ImageProcessing.Parameter.ThresholdSave centers = centers[iid, :] if not parameter.ImageProcessing.PointFile is None: io.writePoints(parameter.ImageProcessing.PointFile, centers) if not parameter.ImageProcessing.IntensityFile is None: io.writePoints(parameter.ImageProcessing.IntensityFile, intensities) return centers, intensities
def runCellDetection(parameter): """Detect cells in data""" timer = Timer(); pp = parameter.StackProcessing; ps = parameter.DataSource; # run segmentation if parameter.ImageProcessing.Method == "SpotDetection": detectCells = iDISCO.ImageProcessing.SpotDetection.detectCells; centers, intensities = parallelProcessStack(ps.ImageFile, x = ps.XRange, y = ps.YRange, z = ps.ZRange, processes = pp.Processes, chunksizemax = pp.ChunkSizeMax, chunksizemin = pp.ChunkSizeMin, chunkoverlap = pp.ChunkOverlap, optimizechunks = pp.OptimizeChunks, optimizechunksizeincrease = pp.OptimizeChunkSizeIncrease, segmentation = detectCells, parameter = parameter.ImageProcessing); else: if haveIlastik: #ilastik does parallel processing so do sequential processing here detectCells = iDISCO.ImageProcessing.IlastikClassification.detectCells; centers, intensities = sequentiallyProcessStack(ps.ImageFile, x = ps.XRange, y = ps.YRange, z = ps.ZRange, chunksizemax = pp.ChunkSizeMax, chunksizemin = pp.ChunkSizeMin, chunkoverlap = pp.ChunkOverlap, segmentation = detectCells, parameter = parameter.ImageProcessing); else: raise RuntimeError("No Ilastik installed use SpotDectection instead!"); timer.printElapsedTime("Main"); if not parameter.ImageProcessing.Parameter.ThresholdSave is None: iid = intensities > parameter.ImageProcessing.Parameter.ThresholdSave; centers = centers[iid,:]; if not parameter.ImageProcessing.PointFile is None: io.writePoints(parameter.ImageProcessing.PointFile, centers); if not parameter.ImageProcessing.IntensityFile is None: io.writePoints(parameter.ImageProcessing.IntensityFile, intensities); return centers, intensities;
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
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;
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.Alignment.MovingImage = os.path.join( basedirectory, 'autofluo_for_cfos_resample.tif') parameter.Alignment.FixedImage = os.path.join(basedirectory, 'cfos_resample.tif') parameter.Alignment.FixedImageMask = None #elastix parameter files for alignment #parameter.Alignment.AffineParameterFile = os.path.join(parameter.Alignment.AlignmentDirectory, ''); #parameter.Alignment.BSplineParameterFile = os.path.join(parameter.Alignment.AlignmentDirectory, 'ElastixParameterBSpline.txt');# #parameter.Alignment.BSplineParameterFile = None; runInitializeElastix(parameter) pts = runCellCoordinateTransformation(parameter) io.writePoints(os.path.join(basedirectory, 'cells_to_autofluo.csv'), pts) ## Visualize cfos to auto points parameter.ImageProcessing.CellCoordinateFile = pts parameter.ImageProcessing.CellTransformedCoordinateFile = None pts2 = runCellCoordinateResampling(parameter) ds = dataSize(os.path.join(basedirectory, 'autofluo_for_cfos_resample.tif')) voximg = vox.voxelizePixel(pts2, ds) io.writeDataStack( os.path.join(basedirectory, 'points_transformed_cfos_to_auto.tif'), voximg) #pts0 = io.readPoints(os.path.join(basedirectory, 'cells.csv'));
parameter.ImageProcessing.Parameter.ThresholdSave = 30 iid = intensities > parameter.ImageProcessing.Parameter.ThresholdSave centersSave = centers[iid, :] if verbose: imgc = numpy.zeros(img.shape) for i in range(centersSave.shape[0]): imgc[centersSave[i, 0], centersSave[i, 1], centersSave[i, 2]] = 1 plt.plotOverlayLabel(img * 0.01, imgc, alpha=False) # result file for cell coordinates (csv, vtk or ims) parameter.ImageProcessing.CellCoordinateFile = os.path.join( basedirectory, 'Test/ImageProcessing/cells.csv') io.writePoints(parameter.ImageProcessing.CellCoordinateFile, centersSave) ############################################################################## # Test Ilastik ############################################################################## import os import numpy from iDISCO.Parameter import * from iDISCO.IO import IO as io from iDISCO.Visualization import Plot as plt from iDISCO.ImageProcessing import SpotDetection as ip from iDISCO.ImageProcessing import IlastikClassification as ip
#moving and reference images parameter.Alignment.MovingImage = os.path.join(basedirectory, 'autofluo_for_cfos_resample.tif'); parameter.Alignment.FixedImage = os.path.join(basedirectory, 'cfos_resample.tif'); parameter.Alignment.FixedImageMask = None; #elastix parameter files for alignment #parameter.Alignment.AffineParameterFile = os.path.join(parameter.Alignment.AlignmentDirectory, ''); #parameter.Alignment.BSplineParameterFile = os.path.join(parameter.Alignment.AlignmentDirectory, 'ElastixParameterBSpline.txt');# #parameter.Alignment.BSplineParameterFile = None; runInitializeElastix(parameter); pts = runCellCoordinateTransformation(parameter); io.writePoints(os.path.join(basedirectory, 'cells_to_autofluo.csv'), pts); ## Visualize cfos to auto points parameter.ImageProcessing.CellCoordinateFile = pts; parameter.ImageProcessing.CellTransformedCoordinateFile = None; pts2 = runCellCoordinateResampling(parameter) ds = dataSize(os.path.join(basedirectory, 'autofluo_for_cfos_resample.tif')); voximg = vox.voxelizePixel(pts2, ds); io.writeDataStack(os.path.join(basedirectory, 'points_transformed_cfos_to_auto.tif'), voximg) #pts0 = io.readPoints(os.path.join(basedirectory, 'cells.csv'));
#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) }; alignmentDirectory = os.path.join(baseDirectory, 'Synthetic/elastix'); # downscale points to referenece image size points = resamplePoints(pointsFile, dataFile, **resamplingParameter); # transform points points = transformPoints(points, transformDirectory = alignmentDirectory, indices = False, resultDirectory = None); # save io.writePoints(transformedPointsFile, points); if verbose: refdata = io.readData(os.path.join(baseDirectory, 'Synthetic/test_iDISCO_reference.tif')); plot.plotOverlayPoints(0.01 * refdata, points) ############################################################################## # Test Voxelization ##############################################################################
iid = intensities > parameter.ImageProcessing.Parameter.ThresholdSave ; centersSave = centers[iid,:]; if verbose: imgc = numpy.zeros(img.shape); for i in range(centersSave.shape[0]): imgc[centersSave[i,0], centersSave[i,1], centersSave[i,2]] = 1; plt.plotOverlayLabel(img * 0.01, imgc, alpha = False); # result file for cell coordinates (csv, vtk or ims) parameter.ImageProcessing.CellCoordinateFile = os.path.join(basedirectory, 'Test/ImageProcessing/cells.csv'); io.writePoints(parameter.ImageProcessing.CellCoordinateFile, centersSave); ############################################################################## # Test Ilastik ############################################################################## import os import numpy from iDISCO.Parameter import *