Пример #1
0
def image_gather_channels(image_list: List[Image],
                          im: Image = None,
                          subimages=0) -> Image:
    """Gather a list of subimages back into an image using the channel_iterator
    
    If the template image is not given then it will be formed assuming that the list has
    been generated by image_scatter_channels with subimages = number of channels

    :param image_list: List of subimages
    :param im: Output image
    :param subimages: Number of image partitions on each axis (2)
    :return: list of subimages
    """

    if im is None:
        nchan = len(image_list)
        _, npol, ny, nx = image_list[0].shape
        im_shape = nchan, npol, ny, ny
        im = create_image_from_array(
            numpy.zeros(im_shape, dtype=image_list[0].data.dtype),
            image_list[0].wcs, image_list[0].polarisation_frame)

    assert image_is_canonical(im)

    if subimages == 0:
        subimages = len(image_list)

    for i, slab in enumerate(image_channel_iter(im, subimages=subimages)):
        slab.data[...] = image_list[i].data[...]

    return im
Пример #2
0
    def test_channelise(self):
        m31cube = create_test_image(
            polarisation_frame=PolarisationFrame('stokesI'),
            frequency=numpy.linspace(1e8, 1.1e8, 128))

        for subimages in [128, 16, 8, 2, 1]:
            for slab in image_channel_iter(m31cube, subimages=subimages):
                assert slab.data.shape[0] == 128 // subimages
Пример #3
0
def image_scatter_channels(im: Image, subimages=None) -> List[Image]:
    """Scatter an image into a list of subimages using the channels

    :param im: Image
    :param subimages: Number of channels
    :return: list of subimages

    See also
        :py:func:`rascil.processing_components.image.iterators.image_channel_iter`
    """

    assert image_is_canonical(im)

    image_list = list()
    if subimages is None:
        subimages = im.shape[0]

    for slab in image_channel_iter(im, subimages=subimages):
        image_list.append(slab)

    assert len(image_list) == subimages, "Too many subimages scattered"

    return image_list