def detectCellShape(img, peaks, detectCellShapeParameter = None, threshold = None, save = None, verbose = False, subStack = None, out = sys.stdout, **parameter): """Find cell shapes as labeled image Arguments: img (array): image data peaks (array): point data of cell centers / seeds detectCellShape (dict): ============ =================== =========================================================== Name Type Descritption ============ =================== =========================================================== *threshold* (float or None) threshold to determine mask, pixel below this are background if None no mask is generated *save* (tuple) size of the box on which to perform the *method* *verbose* (bool or int) print / plot information about this step ============ =================== =========================================================== verbose (bool): print progress info out (object): object to write progress info to Returns: array: labeled image where each label indicates a cell """ threshold = getParameter(detectCellShapeParameter, "threshold", threshold); save = getParameter(detectCellShapeParameter, "save", save); verbose = getParameter(detectCellShapeParameter, "verbose", verbose); if verbose: writeParameter(out = out, head = 'Cell shape detection:', threshold = threshold, save = save); # extended maxima timer = Timer(); if threshold is None: imgmask = None; else: imgmask = img > threshold; imgpeaks = voxelizePixel(peaks, dataSize = img.shape, weights = numpy.arange(1, peaks.shape[0]+1)); imgws = watershed(-img, imgpeaks, mask = imgmask); #imgws = watershed_ift(-img.astype('uint16'), imgpeaks); #imgws[numpy.logical_not(imgmask)] = 0; if not save is None: writeSubStack(save, imgws.astype('int32'), subStack = subStack); if verbose > 1: #plotTiling(img) plotOverlayLabel(img * 0.01, imgws, alpha = False); #plotOverlayLabel(img, imgmax.astype('int64'), alpha = True) if verbose: out.write(timer.elapsedTime(head = 'Cell Shape:') + '\n'); return imgws
def detectCellShape(img, peaks, detectCellShapeParameter=None, threshold=None, save=None, verbose=False, subStack=None, out=sys.stdout, **parameter): """Find cell shapes as labeled image Arguments: img (array): image data peaks (array): point data of cell centers / seeds detectCellShape (dict): ============ =================== =========================================================== Name Type Descritption ============ =================== =========================================================== *threshold* (float or None) threshold to determine mask, pixel below this are background if None no mask is generated *save* (tuple) size of the box on which to perform the *method* *verbose* (bool or int) print / plot information about this step ============ =================== =========================================================== verbose (bool): print progress info out (object): object to write progress info to Returns: array: labeled image where each label indicates a cell """ threshold = getParameter(detectCellShapeParameter, "threshold", threshold) save = getParameter(detectCellShapeParameter, "save", save) verbose = getParameter(detectCellShapeParameter, "verbose", verbose) if verbose: writeParameter(out=out, head='Cell shape detection:', threshold=threshold, save=save) # extended maxima timer = Timer() if threshold is None: imgmask = None else: imgmask = img > threshold imgpeaks = voxelizePixel(peaks, dataSize=img.shape, weights=numpy.arange(1, peaks.shape[0] + 1)) imgws = watershed(-img, imgpeaks, mask=imgmask) #imgws = watershed_ift(-img.astype('uint16'), imgpeaks); #imgws[numpy.logical_not(imgmask)] = 0; if not save is None: writeSubStack(save, imgws.astype('int32'), subStack=subStack) if verbose > 1: #plotTiling(img) plotOverlayLabel(img * 0.01, imgws, alpha=False) #plotOverlayLabel(img, imgmax.astype('int64'), alpha = True) if verbose: out.write(timer.elapsedTime(head='Cell Shape:') + '\n') return imgws
def findCenterOfMaxima(img, imgmax = None, label = None, findCenterOfMaximaParameter = None, save = None, verbose = False, subStack = None, out = sys.stdout, **parameter): """Find center of detected maxima weighted by intensity Arguments: img (array): image data findCenterOfMaximaParameter (dict): ========= ==================== =========================================================== Name Type Descritption ========= ==================== =========================================================== *save* (str or None) saves result of labeling the differnet maxima if None, do the lableling is not saved *verbose* (bool or int) print / plot information about this step ========= ==================== =========================================================== subStack (dict or None): sub-stack information verbose (bool): print progress info out (object): object to write progress info to Returns: array: coordinates of centers of maxima, shape is (n,d) where n is number of maxima and d the dimension of the image """ save = getParameter(findCenterOfMaximaParameter, "save", save); verbose = getParameter(findCenterOfMaximaParameter, "verbose", verbose); if verbose: writeParameter(out = out, head = 'Center of Maxima:', save = save); timer = Timer(); #center of maxima if label is None: imglab, nlab = sm.label(imgmax); else: imglab = label; nlab = imglab.max(); #print 'max', imglab.shape, img.shape #print imglab.dtype, img.dtype if not save is None: writeSubStack(save, imglab, subStack = subStack); if nlab > 0: centers = numpy.array(sm.center_of_mass(img, imglab, index = numpy.arange(1, nlab))); if verbose > 1: #plotOverlayLabel(img * 0.01, imglab, alpha = False); #plotTiling(img) imgc = numpy.zeros(img.shape); for i in range(centers.shape[0]): imgc[centers[i,0], centers[i,1], centers[i,2]] = 1; plotOverlayLabel(img, imgc, alpha = False); #plotOverlayLabel(img, imgmax.astype('int64'), alpha = True) #return centers, imglab, mask #cintensity = numpy.array([img[centers[i,0], centers[i,1], centers[i,2]] for i in range(centers.shape[0])]); if verbose: out.write(timer.elapsedTime(head = 'Cell Centers')); #return ( centers, cintensity ); return centers; else: if verbose: out.write('Cell Centers: No Cells found !'); #return ( numpy.zeros((0,3)), numpy.zeros(0) ); #return empty set o coordinates return numpy.zeros((0,3));
def findExtendedMaxima(img, findExtendedMaximaParameter = None, hMax = None, size = 5, threshold = None, save = None, verbose = None, subStack = None, out = sys.stdout, **parameter): """Find extended maxima in an image Effectively this routine performs a h-max transfrom, followed by a local maxima search and thresholding of the maxima. Arguments: img (array): image data findExtendedMaximaParameter (dict): =========== =================== =========================================================== Name Type Descritption =========== =================== =========================================================== *hMax* (float or None) h parameter for the initial h-Max transform if None, do not perform a h-max transform *size* (tuple) size for the structure element for the local maxima filter *threshold* (float or None) include only maxima larger than a threshold if None keep all localmaxima *save* (str or None) file name to save result of this operation if None do not save result to file *verbose* (bool or int) print / plot information about this step =========== =================== =========================================================== subStack (dict or None): sub-stack information verbose (bool): print progress info out (object): object to write progress info to Returns: array: binary image with True pixel at extended maxima See Also: :func:`hMaxTransform`, :func:`localMax` """ hMax = getParameter(findExtendedMaximaParameter, "hMax", hMax); size = getParameter(findExtendedMaximaParameter, "size", size); threshold = getParameter(findExtendedMaximaParameter, "threshold", threshold); save = getParameter(findExtendedMaximaParameter, "save", save); verbose = getParameter(findExtendedMaximaParameter, "verbose", verbose); if verbose: writeParameter(out = out, head = 'Extended Max:', hMax = hMax, size = size, threshold = threshold, save = save); timer = Timer(); ## extended maxima imgmax = hMaxTransform(img, hMax); #imgmax = regionalMax(imgmax, regionalMaxStructureElement); imgmax = localMax(imgmax, size); #thresholding if not threshold is None: imgmax = numpy.logical_and(imgmax, img >= threshold); if verbose > 1: #plotTiling(img) plotOverlayLabel(img * 0.01, imgmax.astype('int64'), alpha = False); #plotOverlayLabel(img, imgmax.astype('int64'), alpha = True) if not save is None:# writeSubStack(save, imgmax.astype('int8'), subStack = subStack) if verbose: out.write(timer.elapsedTime(head = 'Extended Max') + '\n'); return imgmax