
    ⨽g                     F    d Z ddlmZmZ dad ZdZedz   Z G d de      Zy)	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                      	 dd l at        j                  at        j                  at        S # t        $ rE 	 dd lat        j                  at        j                  aY t        S # t        $ r t        d      w xY ww xY 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     b/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/imageio/plugins/simpleitk.pyload_libr      sx    ,,$ K#  	$!^^N"ooO K  
	,	 	
	s   $, 	A:$A!!A66A:)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                   p    e Zd ZdZd Zd Z G d dej                        Z G d dej                        Zy)		ItkFormatz$See :mod:`imageio.plugins.simpleitk`c                 z    |j                   t        v ryt        d      st        d      r|j                   t        v S y NTzitk.ImageIOBaser   	extensionITK_FORMATSr   ALL_FORMATSselfrequests     r   	_can_readzItkFormat._can_read]   s<    
 +'(J{,C$$33 -Dr   c                 z    |j                   t        v ryt        d      st        d      r|j                   t        v S y r    r!   r%   s     r   
_can_writezItkFormat._can_writeg   s:    +'(J{,C$$33 -Dr   c                   ,    e Zd ZddZd Zd Zd Zd Zy)ItkFormat.ReaderNc                     t         s
t                d}|||fz  }|||fz  }t        | j                  j	                         g| | _        y )Nr   )r   r   r
   r'   get_local_filename_img)r&   
pixel_typefallback_onlykwargsargss        r   _openzItkFormat.Reader._openp   sR    
D%% ,],,D&t||'F'F'HP4PDIr   c                      y)N   r   r&   s    r   _get_lengthzItkFormat.Reader._get_lengthz   s    r   c                      y Nr   r7   s    r   _closezItkFormat.Reader._close}       r   c                 h    |dk7  rd}t        |      t        j                  | j                        i fS )Nr   z.Index out of range while reading from itk file)
IndexErrorr   GetArrayFromImager/   r&   index	error_msgs      r   	_get_datazItkFormat.Reader._get_data   s5    zL	 ++ ))$))4b88r   c                     d}t        |      Nz5The itk plugin does not support meta data, currently.RuntimeErrorr@   s      r   _get_meta_datazItkFormat.Reader._get_meta_data       OIy))r   )NN)__name__
__module____qualname__r4   r8   r;   rC   rH   r   r   r   Readerr,   o   s    	Q			9	*r   rM   c                   $    e Zd Zd Zd Zd Zd Zy)ItkFormat.Writerc                 &    t         st                y y r:   )r   r   r7   s    r   r4   zItkFormat.Writer._open   s    
 r   c                      y r:   r   r7   s    r   r;   zItkFormat.Writer._close   r<   r   c                 v    t         j                  |      }t        || j                  j	                                y r:   )r   GetImageFromArrayr   r'   r.   )r&   immeta_itk_imgs       r   _append_datazItkFormat.Writer._append_data   s)    --b1HHdll&E&E&GHr   c                     d}t        |      rE   rF   )r&   rU   rB   s      r   set_meta_datazItkFormat.Writer.set_meta_data   rI   r   N)rJ   rK   rL   r4   r;   rW   rY   r   r   r   WriterrO      s    			I	*r   rZ   N)	rJ   rK   rL   __doc__r(   r*   r   rM   rZ   r   r   r   r   r   Z   s/    .44* *>* *r   r   )	r[   corer   r   r   r   r#   r$   r   r   r   r   <module>r]      s?   $ &8,  
 
B* B*r   