o
    :ήc                     @   sR   d dl ZddlmZ ddlmZ dgZejdde 		ddd	d
dZ	dS )    N   )utils)exposuremontageF)multichannel_outputmean)channel_axisc                   s  |dur
t | } n
t | dt jf } | jdkrtd| j\} }|r0dd |D \}	}
ntt t | }	}
|rNt	|D ]}t
| | | |< qB|dkrX| jdd	}t || j}|t j |	    |
  |f| jd
}t	|D ]
}|| |d|f< q~fddt	|	D } fddt	|
D }t| D ]\}}||
 }||
 }|||| || ddf< q|dur|S |d S )a	  Create a montage of several single- or multichannel images.

    Create a rectangular montage from an input array representing an ensemble
    of equally shaped single- (gray) or multichannel (color) images.

    For example, ``montage(arr_in)`` called with the following `arr_in`

    +---+---+---+
    | 1 | 2 | 3 |
    +---+---+---+

    will return

    +---+---+
    | 1 | 2 |
    +---+---+
    | 3 | * |
    +---+---+

    where the '*' patch will be determined by the `fill` parameter.

    Parameters
    ----------
    arr_in : (K, M, N[, C]) ndarray
        An array representing an ensemble of `K` images of equal shape.
    fill : float or array-like of floats or 'mean', optional
        Value to fill the padding areas and/or the extra tiles in
        the output array. Has to be `float` for single channel collections.
        For multichannel collections has to be an array-like of shape of
        number of channels. If `mean`, uses the mean value over all images.
    rescale_intensity : bool, optional
        Whether to rescale the intensity of each image to [0, 1].
    grid_shape : tuple, optional
        The desired grid shape for the montage `(ntiles_row, ntiles_column)`.
        The default aspect ratio is square.
    padding_width : int, optional
        The size of the spacing between the tiles and between the tiles and
        the borders. If non-zero, makes the boundaries of individual images
        easier to perceive.
    multichannel : boolean, optional
        If True, the last `arr_in` dimension is threated as a color channel,
        otherwise as spatial. This argument is deprecated: specify
        `channel_axis` instead.
    channel_axis : int or None, optional
        If None, the image is assumed to be a grayscale (single channel) image.
        Otherwise, this parameter indicates which axis of the array corresponds
        to channels.



    Returns
    -------
    arr_out : (K*(M+p)+p, K*(N+p)+p[, C]) ndarray
        Output array with input images glued together (including padding `p`).

    Examples
    --------
    >>> import numpy as np
    >>> from skimage.util import montage
    >>> arr_in = np.arange(3 * 2 * 2).reshape(3, 2, 2)
    >>> arr_in  # doctest: +NORMALIZE_WHITESPACE
    array([[[ 0,  1],
            [ 2,  3]],
           [[ 4,  5],
            [ 6,  7]],
           [[ 8,  9],
            [10, 11]]])
    >>> arr_out = montage(arr_in)
    >>> arr_out.shape
    (4, 4)
    >>> arr_out
    array([[ 0,  1,  4,  5],
           [ 2,  3,  6,  7],
           [ 8,  9,  5,  5],
           [10, 11,  5,  5]])
    >>> arr_in.mean()
    5.5
    >>> arr_out_nonsquare = montage(arr_in, grid_shape=(1, 3))
    >>> arr_out_nonsquare
    array([[ 0,  1,  4,  5,  8,  9],
           [ 2,  3,  6,  7, 10, 11]])
    >>> arr_out_nonsquare.shape
    (2, 6)
    N.   zkInput array has to be 3-dimensional for grayscale images, or 4-dimensional with a `channel_axis` specified.c                 S   s   g | ]}t |qS  )int).0sr
   r
   </tmp/pip-target-vg8gfxp4/lib/python/skimage/util/_montage.py
<listcomp>o   s    zmontage.<locals>.<listcomp>r   )r      r   )axis)dtypec                    s2   g | ]}t    |     |   qS r
   slicer   n)n_padn_rowsr
   r   r      
    c                    s2   g | ]}t   |    |    qS r
   r   r   )n_colsr   r
   r   r      r   ).r   )npasarraynewaxisndim
ValueErrorshaper   ceilsqrtranger   rescale_intensityr   
atleast_1dastyper   empty	enumerate)arr_infillr$   
grid_shapepadding_widthmultichannelr   n_imagesn_chan
ntiles_row
ntiles_coliarr_outidx_chan
slices_row
slices_col	idx_imageimageidx_sridx_scr
   )r   r   r   r   r   	   sJ   Y
)r   FNr   F)
numpyr   _sharedr    r   __all__channel_as_last_axisdeprecate_multichannel_kwargr   r
   r
   r
   r   <module>   s    
