a
    "DfG	                     @   s8   d dl ZddlmZ G dd deZejdfddZdS )    N   )	normalizec                   @   s4   e Zd ZdZd	ddZedd ZejfddZ	dS )
Nchannel2RGBzzConvert nchannel array to rgb by PCA.

    Parameters
    ----------
    pca: sklearn.decomposition.PCA
        PCA.

    Nc                 C   s   || _ d| _d S )N)NN)_pca_min_max_value)selfpca r	   \/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/imgviz/nchannel.py__init__   s    zNchannel2RGB.__init__c                 C   s   | j S )zPCA for N channel to 3.)r   )r   r	   r	   r
   r      s    zNchannel2RGB.pcac           
      C   s  ddl }|jdksJ dt|jtjs2J d|j\}}}|d|}| jdu rt|j	j
ddd| _| j|}n| j|}|||d}|tjkr| jdu rtj|d	d
tj|d	d
f| _| j\}}	t|||	}|d  tj}nt|tjsJ ||}|S )a\  Convert nchannel array to rgb by PCA.

        Parameters
        ----------
        nchannel: numpy.ndarray, (H, W, C), float
            N channel image.
        dtype: numpy.dtype
            Dtype (default: numpy.uint8).

        Returns
        -------
        dst: numpy.ndarray, (H, W, 3), numpy.uint8
            Visualized image.

        r   N   znchannel.ndim must be 3znchannel.dtype must be floatingi  )Zn_componentsZrandom_state)r   r   )Zaxis   )Zsklearn.decompositionndimnpZ
issubdtypedtypeZfloatingshapeZreshaper   decompositionZPCAZfit_transformZ	transformuint8r   ZnanminZnanmaxr   roundZastype)
r   nchannelr   ZsklearnHWDdstZ	min_valueZ	max_valuer	   r	   r
   __call__   s2    




zNchannel2RGB.__call__)N)
__name__
__module____qualname____doc__r   propertyr   r   r   r   r	   r	   r	   r
   r      s
   	

r   c                 C   s   t || |S )a`  Convert nchannel array to rgb by PCA.

    Parameters
    ----------
    nchannel: numpy.ndarray, (H, W, C), float
        N channel image.
    dtype: numpy.dtype
        Dtype (default: numpy.uint8).
    pca: sklearn.decomposition.PCA
        PCA.

    Returns
    -------
    dst: numpy.ndarray, (H, W, 3), numpy.uint8
        Visualized image.

    )r   )r   r   r   r	   r	   r
   nchannel2rgbK   s    r!   )numpyr    r   objectr   r   r!   r	   r	   r	   r
   <module>   s   E