o
    h                     @   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.)
itk_itkimread_read_functionimwrite_write_functionImportError	SimpleITK	ReadImage
WriteImage r   r   T/var/www/html/scripts/venv/lib/python3.10/site-packages/imageio/plugins/simpleitk.pyload_lib   s"   
r   )z.giplz.iplz.mhaz.mhdz.nhdrniahdrz.nrrdz.niiz.nii.gzz.imgz.img.gzz.vtkhdf5lsmmncmnc2mghr   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"   
pixel_type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}   r0   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   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.RuntimeErrorr6   r   r   r   _get_meta_data      zItkFormat.Reader._get_meta_data)NN)__name__
__module____qualname__r,   r/   r3   r9   r>   r   r   r   r   Readero   s    

	rC   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 r2   )r   r   r.   r   r   r   r,      s   
zItkFormat.Writer._openc                 C   r1   r2   r   r.   r   r   r   r3      r0   zItkFormat.Writer._closec                 C   s   t |}t|| j  d S r2   )r   GetImageFromArrayr
   r#   r&   )r"   immeta_itk_imgr   r   r   _append_data   s   
zItkFormat.Writer._append_datac                 C   r:   r;   r<   )r"   rF   r8   r   r   r   set_meta_data   r?   zItkFormat.Writer.set_meta_dataN)r@   rA   rB   r,   r3   rH   rI   r   r   r   r   Writer   s
    rJ   N)	r@   rA   rB   __doc__r$   r%   r   rC   rJ   r   r   r   r   r   Z   s    
r   )	rK   corer   r   r   r   r   r    r   r   r   r   r   <module>   s   