microscopestitching/stitching.py
def stitch(images):
    """Stitch regular spaced images.

    Parameters
    ----------
    images : ImageCollection or list of tuple(path, row, column)
        Each image-tuple should contain path, row and column. Row 0,
        column 0 is top left image.

        Example:
        >>> images = [('1.png', 0, 0), ('2.png', 0, 1)]

    Returns
    -------
    tuple (stitched, offset)
        Stitched image and registered offset (y, x).
    """
    if type(images) != ImageCollection:
        images = ImageCollection(images)
    calc_translations_parallel(images)
    _translation_warn(images)

    yoffset, xoffset = images.median_translation()

    if xoffset != yoffset:
        warn('yoffset != xoffset: %s != %s' % (yoffset, xoffset))

    # assume all images have the same shape
    y, x = imread(images[0].path).shape
    height = y*len(images.rows) + yoffset*(len(images.rows)-1)
    width = x*len(images.cols) + xoffset*(len(images.cols)-1)

    # last dimension is number of images on top of each other
    merged = np.zeros((height, width, 2), dtype=np.int)
    for image in images:
        r, c = image.row, image.col
        mask = _merge_slice(r, c, y, x, yoffset, xoffset)
        # last dim is used for averaging the seam
        img = _add_ones_dim(imread(image.path))
        merged[mask] += img

    # average seam, possible improvement: use gradient
    merged[..., 0] /= merged[..., 1]

    return merged[..., 0].astype(np.uint8), (yoffset, xoffset)
def stitch(images):
    if type(images) != ImageCollection:
        images = ImageCollection(images)
    calc_translations_parallel(images)
    _translation_warn(images)

    yoffset, xoffset = images.median_translation()

    if xoffset != yoffset:
        warn('yoffset != xoffset: %s != %s' % (yoffset, xoffset))

    # assume all images have the same shape
    y, x = imread(images[0].path).shape
    height = y*len(images.rows) + yoffset*(len(images.rows)-1)
    width = x*len(images.cols) + xoffset*(len(images.cols)-1)

    # last dimension is number of images on top of each other
    merged = np.zeros((height, width, 2), dtype=np.int)
    for image in images:
        r, c = image.row, image.col
        mask = _merge_slice(r, c, y, x, yoffset, xoffset)
        # last dim is used for averaging the seam
        img = _add_ones_dim(imread(image.path))
        merged[mask] += img

    # average seam, possible improvement: use gradient
    merged[..., 0] /= merged[..., 1]

    return merged[..., 0].astype(np.uint8), (yoffset, xoffset)
def stitch ( images ) : if type ( images ) != ImageCollection : images = ImageCollection ( images ) calc_translations_parallel ( images ) _translation_warn ( images ) yoffset , xoffset = images . median_translation ( ) if xoffset != yoffset : warn ( 'yoffset != xoffset: %s != %s' % ( yoffset , xoffset ) ) # assume all images have the same shape y , x = imread ( images [ 0 ] . path ) . shape height = y * len ( images . rows ) + yoffset * ( len ( images . rows ) - 1 ) width = x * len ( images . cols ) + xoffset * ( len ( images . cols ) - 1 ) # last dimension is number of images on top of each other merged = np . zeros ( ( height , width , 2 ) , dtype = np . int ) for image in images : r , c = image . row , image . col mask = _merge_slice ( r , c , y , x , yoffset , xoffset ) # last dim is used for averaging the seam img = _add_ones_dim ( imread ( image . path ) ) merged [ mask ] += img # average seam, possible improvement: use gradient merged [ ... , 0 ] /= merged [ ... , 1 ] return merged [ ... , 0 ] . astype ( np . uint8 ) , ( yoffset , xoffset )
Stitch regular spaced images.

    Parameters
    ----------
    images : ImageCollection or list of tuple(path, row, column)
        Each image-tuple should contain path, row and column. Row 0,
        column 0 is top left image.

        Example:
        >>> images = [('1.png', 0, 0), ('2.png', 0, 1)]

    Returns
    -------
    tuple (stitched, offset)
        Stitched image and registered offset (y, x).
Stitch regular spaced images .