o
    e                     @   s@   d Z ddlmZmZ dadd ZdZed ZG dd	 d	eZdS )
an   Read/Write images using SimpleITK.

Backend: `Insight Toolkit <https://itk.org/>`_

.. note::
    To use this plugin you have to install its backend::

        pip install imageio[itk]

The ItkFormat uses the ITK or SimpleITK library to support a range of
ITK-related formats. It also supports a few common formats (e.g. PNG and JPEG).

Parameters
----------
None

   )Format
has_moduleNc                   C   s^   zdd l atjatjaW tS  ty.   zdd latjatj	aW Y tS  ty-   tdw w )N    zitk could not be found. Please try   python -m pip install itk or   python -m pip install simpleitk or refer to   https://itkpythonpackage.readthedocs.io/ for further instructions.)
Zitk_itkZimread_read_functionZimwrite_write_functionImportError	SimpleITKZ	ReadImageZ
WriteImage r
   r
   ID:\Projects\ConvertPro\env\Lib\site-packages\imageio/plugins/simpleitk.pyload_lib   s"   
r   )z.giplz.iplz.mhaz.mhdz.nhdrZniahdrz.nrrdz.niiz.nii.gzz.imgz.img.gzz.vtkZhdf5ZlsmmncZmnc2Zmghr   Zpic)	z.bmpz.jpegz.jpgz.pngz.tiffz.tifz.dicomz.dcmz.gdcmc                   @   sD   e Zd ZdZdd Zdd ZG dd dejZG dd	 d	ejZd
S )	ItkFormatz$See :mod:`imageio.plugins.simpleitk`c                 C   ,   |j tv rdS tdstdr|j tv S d S NTzitk.ImageIOBaser	   	extensionITK_FORMATSr   ALL_FORMATSselfrequestr
   r
   r   	_can_read]   s
   

zItkFormat._can_readc                 C   r   r   r   r   r
   r
   r   
_can_writeg   s
   

zItkFormat._can_writec                   @   s6   e Zd ZdddZdd Zdd Zdd	 Zd
d ZdS )zItkFormat.ReaderNc                 K   sN   t st  d}|d ur||f7 }|d ur||f7 }t| j g|R  | _d S )Nr
   )r   r   r   r   get_local_filename_img)r   Z
pixel_typeZfallback_onlykwargsargsr
   r
   r   _openp   s   

zItkFormat.Reader._openc                 C   s   dS )N   r
   r   r
   r
   r   _get_lengthz      zItkFormat.Reader._get_lengthc                 C      d S Nr
   r!   r
   r
   r   _close}   r#   zItkFormat.Reader._closec                 C   s$   |dkr
d}t |t| ji fS )Nr   z.Index out of range while reading from itk file)
IndexErrorr   ZGetArrayFromImager   r   index	error_msgr
   r
   r   	_get_data   s   zItkFormat.Reader._get_datac                 C      d}t |Nz5The itk plugin does not support meta data, currently.RuntimeErrorr(   r
   r
   r   _get_meta_data      zItkFormat.Reader._get_meta_data)NN)__name__
__module____qualname__r   r"   r&   r+   r0   r
   r
   r
   r   Readero   s    

	r5   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
zItkFormat.Writerc                 C   s   t st  d S d S r%   )r   r   r!   r
   r
   r   r      s   
zItkFormat.Writer._openc                 C   r$   r%   r
   r!   r
   r
   r   r&      r#   zItkFormat.Writer._closec                 C   s   t |}t|| j  d S r%   )r   ZGetImageFromArrayr   r   r   )r   ZimmetaZ_itk_imgr
   r
   r   _append_data   s   
zItkFormat.Writer._append_datac                 C   r,   r-   r.   )r   r6   r*   r
   r
   r   set_meta_data   r1   zItkFormat.Writer.set_meta_dataN)r2   r3   r4   r   r&   r7   r8   r
   r
   r
   r   Writer   s
    r9   N)	r2   r3   r4   __doc__r   r   r   r5   r9   r
   r
   r
   r   r   Z   s    
r   )	r:   corer   r   r   r   r   r   r   r
   r
   r
   r   <module>   s   