def merge(oim, order):
    """
    Merges a three dimensional volume into a single plane.
    """
    if not type(order) == bool:
        if not oim.ndim == 3:
            raise Exception('original image must be three dimensional')
        if not len(order) == oim.shape[0]:
            raise Exception('length of order must match first image dimension')
        return oim[order].transpose((1, 0, 2)).reshape([oim.shape[1], -1])
    else:
        return oim
