ó
    EñiT>  ã                   ó¦   • S r SSKrSSKJr  SSKrSSKJr  SSKJr  SSKrSSK	J
r
  SSKJr  / SQrS	 rS
 rS r " S S5      rS r " S S\5      rg)zEData structures to hold collections of images, with optional caching.é    N)Úglob)ÚSequence)Úcopy)ÚImage)ÚTiffFile)Ú
MultiImageÚImageCollectionÚconcatenate_imagesÚimread_collection_wrapperc                 ó¸   • U  Vs/ s H  o[         R                  S4   PM     nn [         R                  " U5      nU$ s  snf ! [         a    [        S5      ef = f)a$  Concatenate all images in the image collection into an array.

Parameters
----------
ic : an iterable of images
    The images to be concatenated.

Returns
-------
array_cat : ndarray
    An array having one more dimension than the images in `ic`.

See Also
--------
ImageCollection.concatenate
MultiImage.concatenate

Raises
------
ValueError
    If images in `ic` don't have identical shapes.

Notes
-----
``concatenate_images`` receives any iterable object containing images,
including ImageCollection and MultiImage, and returns a NumPy array.
.zImage dimensions must agree.)ÚnpÚnewaxisÚconcatenateÚ
ValueError)ÚicÚimageÚ
all_imagesÚ	array_cats       ÚR/home/mande/repo/quber/.venv/lib/python3.13/site-packages/skimage/io/collection.pyr
   r
      s`   € ñ8 79Ó9²b¨UœŸ
™
 C˜Ô(±b€JÐ9ð9Ü—N’N :Ó.ˆ	ð Ðùò :øô ó 9ÜÐ7Ó8Ð8ð9ús   …>¦A ÁAc                 óœ   • [         R                  " SU 5       Vs/ s H$  oR                  5       (       a  [        U5      OUPM&     nnU$ s  snf )aý  Convert string to list of strings and ints that gives intuitive sorting.

Parameters
----------
s : string

Returns
-------
k : a list of strings and ints

Examples
--------
>>> alphanumeric_key('z23a')
['z', 23, 'a']
>>> filenames = ['f9.10.png', 'e10.png', 'f9.9.png', 'f10.10.png',
...              'f10.9.png']
>>> sorted(filenames)
['e10.png', 'f10.10.png', 'f10.9.png', 'f9.10.png', 'f9.9.png']
>>> sorted(filenames, key=alphanumeric_key)
['e10.png', 'f9.9.png', 'f9.10.png', 'f10.9.png', 'f10.10.png']
z([0-9]+))ÚreÚsplitÚisdigitÚint)ÚsÚcÚks      r   Úalphanumeric_keyr   ;   sA   € ô, 02¯xªx¸
ÀAÔ/FÓGÒ/F¨!—9‘9—;‘;ŒˆQŒ AÒ	%Ñ/F€AÐGØ€Hùò 	Hs   š+A	c                 ó  • [        U [        5      =(       a    [        R                  U ;   n[        U [        5      (       + n[        U [        5      n[        S U  5       5      nU=(       d    U=(       a    U=(       a    UnU$ )zhHelping function. Returns True if pattern contains a tuple, list, or a
string separated with os.pathsep.c              3   óB   #   • U  H  n[        U[        5      v •  M     g 7f©N)Ú
isinstanceÚstr)Ú.0Úpats     r   Ú	<genexpr>Ú#_is_multipattern.<locals>.<genexpr>\   s   é € ÐD²m¨s”j ¤c×*Ð*²mùs   ‚)r"   r#   ÚosÚpathsepr   Úall)Úinput_patternÚhas_str_ospathsepÚnot_a_stringÚhas_iterableÚhas_stringsÚis_multipatterns         r   Ú_is_multipatternr1   U   sl   € ô # =´#Ó6×V¼2¿:¹:ÈÑ;VÐÜ! -´Ó5Ô5€LÜ˜m¬XÓ6€LÜÑD±mÓDÓD€Kà'÷ Ø×5˜×5¨+ð ð Ðó    c                   óx   • \ rS rSrSr SS jr\S 5       r\S 5       rS r	S r
S	 rS
 rS rS rSS jrS rSrg)r	   éd   a   Load and manage a collection of image files.

Parameters
----------
load_pattern : str or list of str
    Pattern string or list of strings to load. The filename path can be
    absolute or relative.
conserve_memory : bool, optional
    If True, :class:`skimage.io.ImageCollection` does not keep more than one in
    memory at a specific time. Otherwise, images will be cached once they are loaded.

Other parameters
----------------
load_func : callable
    ``imread`` by default. See Notes below.
**load_func_kwargs : dict
    Any other keyword arguments are passed to `load_func`.

Attributes
----------
files : list of str
    If a pattern string is given for `load_pattern`, this attribute
    stores the expanded file list. Otherwise, this is equal to
    `load_pattern`.

Notes
-----
Note that files are always returned in alphanumerical order. Also note that slicing
returns a new :class:`skimage.io.ImageCollection`, *not* a view into the data.

ImageCollection image loading can be customized through
`load_func`. For an ImageCollection ``ic``, ``ic[5]`` calls
``load_func(load_pattern[5])`` to load that image.

For example, here is an ImageCollection that, for each video provided,
loads every second frame::

  import imageio.v3 as iio3
  import itertools

  def vidread_step(f, step):
      vid = iio3.imiter(f)
      return list(itertools.islice(vid, None, None, step)

  video_file = 'no_time_for_that_tiny.gif'
  ic = ImageCollection(video_file, load_func=vidread_step, step=2)

  ic  # is an ImageCollection object of length 1 because 1 video is provided

  x = ic[0]
  x[5]  # the 10th frame of the first video

Alternatively, if `load_func` is provided and `load_pattern` is a
sequence, an :class:`skimage.io.ImageCollection` of corresponding length will
be created, and the individual images will be loaded by calling `load_func` with the
matching element of the `load_pattern` as its first argument. In this
case, the elements of the sequence do not need to be names of existing
files (or strings at all). For example, to create an :class:`skimage.io.ImageCollection`
containing 500 images from a video::

  class FrameReader:
      def __init__ (self, f):
          self.f = f
      def __call__ (self, index):
          return iio3.imread(self.f, index=index)

  ic = ImageCollection(range(500), load_func=FrameReader('movie.mp4'))

  ic  # is an ImageCollection object of length 500

Another use of `load_func` would be to convert all images to ``uint8``::

  def imread_convert(f):
      return imread(f).astype(np.uint8)

  ic = ImageCollection('/tmp/*.png', load_func=imread_convert)

Examples
--------
>>> import imageio.v3 as iio3
>>> import skimage.io as io

# Where your images are located
>>> data_dir = os.path.join(os.path.dirname(__file__), '../data')

>>> coll = io.ImageCollection(data_dir + '/chess*.png')
>>> len(coll)
2
>>> coll[0].shape
(200, 200)

>>> image_col = io.ImageCollection([f'{data_dir}/*.png', '{data_dir}/*.jpg'])

>>> class MultiReader:
...     def __init__ (self, f):
...         self.f = f
...     def __call__ (self, index):
...         return iio3.imread(self.f, index=index)
...
>>> filename = data_dir + '/no_time_for_that_tiny.gif'
>>> ic = io.ImageCollection(range(24), load_func=MultiReader(filename))
>>> len(image_col)
23
>>> isinstance(ic[0], np.ndarray)
True
Nc                 ól  • / U l         [        U5      (       a  [        U[        5      (       a  UR	                  [
        R                  5      nU H'  nU R                   R                  [        U5      5        M)     [        U R                   [        S9U l         O‹[        U[        5      (       aB  U R                   R                  [        U5      5        [        U R                   [        S9U l         O4[        U[        5      (       a  Ub  [        U5      U l         O[        S5      eUc"  SSKJn  X`l        U R#                  5       U l        O'X0l        ['        U R                   5      U l        SU l        U(       a  SnOU R$                  nX l        SU l        X@l        [0        R2                  " U[4        S9U l        g)z'Load and manage a collection of images.)ÚkeyNzInvalid pattern as input.é   ©Úimread©Údtype)Ú_filesr1   r"   r#   r   r(   r)   Úextendr   Úsortedr   r   ÚlistÚ	TypeErrorÚ_ior9   Ú	load_funcÚ_find_imagesÚ
_numframesÚlenÚ_frame_indexÚ_conserve_memoryÚ_cachedÚload_func_kwargsr   ÚemptyÚobjectÚdata)ÚselfÚload_patternÚconserve_memoryrB   rI   Úpatternr9   Úmemory_slotss           r   Ú__init__ÚImageCollection.__init__Ð   s<  € ð ˆŒÜ˜L×)Ñ)Ü˜,¬×,Ñ,Ø+×1Ñ1´"·*±*Ó=�Û'�Ø—‘×"Ñ"¤4¨£=Ö1ñ (ä  §¡Ô2BÑCˆD�KÜ˜¤c×*Ñ*Ø�K‰K×Ñœt LÓ1Ô2Ü  §¡Ô2BÑCˆD�KÜ˜¤h×/Ñ/°IÑ4IÜ˜|Ó,ˆD�KäÐ7Ó8Ð8àÑÝ#à#ŒNØ"×/Ñ/Ó1ˆD�Oà&ŒNÜ! $§+¡+Ó.ˆDŒOØ $ˆDÔæØ‰LàŸ?™?ˆLà /ÔØˆŒà 0ÔÜ—H’H˜\´Ñ8ˆ�	r2   c                 ó   • U R                   $ r!   )r<   ©rM   s    r   ÚfilesÚImageCollection.filesø   s   € à�{‰{Ðr2   c                 ó   • U R                   $ r!   )rG   rU   s    r   rO   ÚImageCollection.conserve_memoryü   s   € à×$Ñ$Ð$r2   c                 óä  • / nU R                    HÐ  nUR                  5       R                  S5      (       aU  [        US5       n[	        U5      nU[        [        UR                  5      5       Vs/ s H  oRU4PM     sn-  nS S S 5        M|   [        R                  " U5      nUR                  S5        Sn  UR                  U5        UR                  X%45        US-  nM+     Xl        [        U5      $ s  snf ! , (       d  f       Mù  = f! [         a     GM
  f = f! [         a     Of = f[        US5      (       d  GM2  UR                  (       d  GMF  UR                  R                  5         GMc  )N)z.tiffz.tifÚrbr   r7   Úfp)r<   ÚlowerÚendswithÚopenr   ÚrangerE   Úpagesr   ÚseekÚOSErrorÚEOFErrorÚappendÚhasattrr\   ÚcloserF   )rM   ÚindexÚfnameÚfÚimgÚiÚims          r   rC   ÚImageCollection._find_images   s5  € ØˆØ—[”[ˆEØ�{‰{‹}×%Ñ%Ð&7×8Ñ8Ü˜% Ô&¨!Ü" 1›+�CØ´%¼¸C¿I¹I»Ô2GÓHÒ2G¨Q a›jÑ2GÑHÑH�E÷ 'Ñ&ðÜŸš EÓ*�BØ—G‘G˜A”Jð �ØðØŸ™ œ
ð —L‘L % Ô,Ø˜‘F�Añ ñ !ð* "ÔÜ�5‹zÐùò% I÷ 'Ö&ûô ó Ûðûô $ó Ùðúô ˜2˜t×$Ô$¨¯¯ªØ—E‘E—K‘K—MsB   Á-C9Á/C4
Á<C9Â'DÂ7DÃ4C9Ã9
D	Ä
DÄDÄ
D*Ä)D*c                 óø  • [        US5      (       a  UR                  5       n[        U[        [        45      (       d  [        S5      e[        U[        5      (       aò  U R                  U5      nU[        U R                  5      -  nU R                  (       a  XR                  :w  d  U R                  U   cŠ  U R                  nU R                  (       a:  U R                  U   u  pEUb  XSS'    U R                  " U40 UD6U R                  U'   O-U R                  " U R                  U   40 UD6U R                  U'   Xl
        U R                  U   $ [!        U R"                  5      U   n[%        U 5      nU R                  (       aL  U V	s/ s H  o�R                  U	   S   PM     sn	Ul        U V	s/ s H  o�R                  U	   PM     sn	Ul        O$U V	s/ s H  o�R&                  U	   PM     sn	Ul        [        U5      Ul        U R                  (       ax  U R                  U;   aG  UR)                  U R                  5      Ul
        [*        R$                  " U R                  5      Ul        U$ [*        R,                  " S[.        S9Ul         U$ U R                  U   Ul        U$ ! [
         a>  nS[        U5      ;   a)  US	 U R                  " U40 UD6U R                  U'    SnAGNªe SnAff = fs  sn	f s  sn	f s  sn	f )	a”  Return selected image(s) in the collection.

Loading is done on demand.

Parameters
----------
n : int or slice
    The image number to be returned, or a slice selecting the images
    and ordering to be returned in a new ImageCollection.

Returns
-------
img : ndarray or :class:`skimage.io.ImageCollection`
    The `n`-th image in the collection, or a new ImageCollection with
    the selected images.
Ú	__index__z+slicing must be with an int or slice objectNÚimg_numz%unexpected keyword argument 'img_num'r   r7   r:   )rf   rp   r"   r   Úslicer@   Ú_check_imgnumrE   rL   rO   rH   rI   rF   rB   r#   rV   r`   rD   r   r<   rh   r   rJ   rK   )
rM   ÚnÚidxÚkwargsri   rq   ÚeÚfidxÚnew_icrl   s
             r   Ú__getitem__ÚImageCollection.__getitem__  sk  € ô" �1�k×"Ñ"Ø—‘“ˆAä˜!œc¤5˜\×*Ñ*ÜÐIÓJÐJä�aœ×ÑØ×"Ñ" 1Ó%ˆAØ”c˜$Ÿ)™)“nÑ$ˆCà×$×$¨¯l©lÓ):ÀÇ	Á	È#ÁÑ@VØ×.Ñ.�Ø×$×$Ø%)×%6Ñ%6°qÑ%9‘N�EØÑ*Ø,3˜yÑ)ð"Ø)-¯ª¸Ñ)HÀÑ)H˜Ÿ	™	 #šð &*§^¢^°D·J±J¸q±MÑ%LÀVÑ%L�D—I‘I˜c‘NØ ”à—9‘9˜S‘>Ð!ô ˜Ÿ™Ó)¨!Ñ,ˆDÜ˜$“ZˆFà× × ÙBFÓ GÂ$¸Q×!2Ñ!2°1Ñ!5°aÔ!8Á$Ñ G�”ÙEIÓ&JÂTÀ×'8Ñ'8¸Ô';ÁTÑ&J�Õ#á9=Ó >º°A§¡¨Q¤¹Ñ >�”ä # D£	ˆFÔà×#×#Ø—<‘< 4Ó'Ø%)§Z¡Z°·±Ó%=�F”NÜ"$§'¢'¨$¯)©)Ó"4�F”Kð
 ˆMô #%§(¢(¨1´FÑ";�F•Kð ˆMð #Ÿi™i¨™o�”ØˆMøôG %ó "ØBÄcÈ!ÃfÓLØ & yÐ 1Ø-1¯^ª^¸EÑ-LÀVÑ-L˜DŸI™I cŸNà!ûð"üò( !HùÚ&Jùâ >s0   Ã, J" ÆK-Æ.K2ÇK7Ê"
K*Ê,2K%Ë$K%Ë%K*c                 óf   • U R                   nU* Us=::  a  U:  a	  O  OX-  nU$ [        SU S35      e)z+Check that the given image number is valid.zThere are only z images in the collection)rD   Ú
IndexError)rM   rt   Únums      r   rs   ÚImageCollection._check_imgnumc  s=   € à�o‰oˆØˆ4�1�?�sŽ?Ø‘ˆAð ˆô ˜¨s¨eÐ3LÐMÓNÐNr2   c              #   óN   #   • [        [        U 5      5       H	  nX   v •  M     g7f)zIterate over the images.N)r`   rE   )rM   rl   s     r   Ú__iter__ÚImageCollection.__iter__l  s   é € ä”s˜4“yÖ!ˆAØ‘'ŒMò "ùs   ‚#%c                 ó   • U R                   $ )zNumber of images in collection.)rD   rU   s    r   Ú__len__ÚImageCollection.__len__q  s   € à�‰Ðr2   c                 ó,   • [        U R                  5      $ r!   )r#   rV   rU   s    r   Ú__str__ÚImageCollection.__str__u  s   € Ü�4—:‘:‹Ðr2   c                 óN   • [         R                  " U R                  5      U l        g)z”Clear the image cache.

Parameters
----------
n : None or int
    Clear the cache for this image only. By default, the
    entire cache is erased.

N)r   Ú
empty_likerL   )rM   rt   s     r   ÚreloadÚImageCollection.reloadx  s   € ô —M’M $§)¡)Ó,ˆ�	r2   c                 ó   • [        U 5      $ )aA  Concatenate all images in the collection into an array.

Returns
-------
ar : np.ndarray
    An array having one more dimension than the images in `self`.

See Also
--------
skimage.io.concatenate_images

Raises
------
ValueError
    If images in the :class:`skimage.io.ImageCollection` do not have identical
    shapes.
)r
   rU   s    r   r   ÚImageCollection.concatenate„  s   € ô$ " $Ó'Ð'r2   )rH   rG   r<   rF   rD   rL   rB   rI   ©TNr!   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rR   ÚpropertyrV   rO   rC   rz   rs   r�   r„   r‡   r‹   r   Ú__static_attributes__© r2   r   r	   r	   d   sg   † ñiðX =Aô&9ðP ñó ðð ñ%ó ð%òò4GòRòò
òô
-õ(r2   r	   c                 ó   ^ • SU 4S jjnU$ )Nc                 ó   >• [        XTS9$ )a¯  Return an `ImageCollection` from files matching the given pattern.

Note that files are always stored in alphabetical order. Also note that
slicing returns a new ImageCollection, *not* a view into the data.

See `skimage.io.ImageCollection` for details.

Parameters
----------
load_pattern : str or list
    Pattern glob or filenames to load. The path can be absolute or
    relative.  Multiple patterns should be separated by a colon,
    e.g. ``/tmp/work/*.png:/tmp/other/*.jpg``.  Also see
    implementation notes below.
conserve_memory : bool, optional
    If True, never keep more than one in memory at a specific
    time.  Otherwise, images will be cached once they are loaded.

)rO   rB   )r	   )rN   rO   r9   s     €r   Úimread_collectionÚ4imread_collection_wrapper.<locals>.imread_collectionš  s   ø€ ô( ØÀVñ
ð 	
r2   )Tr—   )r9   rš   s   ` r   r   r   ™  s   ø€ ÷
ð0 Ðr2   c                   ó@   ^ • \ rS rSrSrSU 4S jjr\S 5       rSrU =r	$ )r   iµ  aŒ  A class containing all frames from multi-frame TIFF images.

Parameters
----------
load_pattern : str or list of str
    Pattern glob or filenames to load. The path can be absolute or
    relative.
conserve_memory : bool, optional
    Whether to conserve memory by only caching the frames of a single
    image. Default is True.

Notes
-----
`MultiImage` returns a list of image-data arrays. In this
regard, it is very similar to `ImageCollection`, but the two differ in
their treatment of multi-frame images.

For a TIFF image containing N frames of size WxH, `MultiImage` stores
all frames of that image as a single element of shape `(N, W, H)` in the
list. `ImageCollection` instead creates N elements of shape `(W, H)`.

For an animated GIF image, `MultiImage` reads only the first frame, while
`ImageCollection` reads all frames by default.

Examples
--------
# Where your images are located
>>> data_dir = os.path.join(os.path.dirname(__file__), '../data')

>>> multipage_tiff = data_dir + '/multipage.tif'
>>> multi_img = MultiImage(multipage_tiff)
>>> len(multi_img)  # multi_img contains one element
1
>>> multi_img[0].shape  # this element is a two-frame image of shape:
(2, 15, 10)

>>> image_col = ImageCollection(multipage_tiff)
>>> len(image_col)  # image_col contains two elements
2
>>> for frame in image_col:
...     print(frame.shape)  # each element is a frame of shape (15, 10)
...
(15, 10)
(15, 10)
c                 óD   >• SSK Jn  Xl        [        TU ]  " X4SU0UD6  g)zLoad a multi-img.r7   r8   rB   N)rA   r9   Ú	_filenameÚsuperrR   )rM   ÚfilenamerO   r;   Úimread_kwargsr9   Ú	__class__s         €r   rR   ÚMultiImage.__init__ä  s"   ø€ åà!ŒÜ‰Ò˜ÑV¸fÐVÈÓVr2   c                 ó   • U R                   $ r!   ©rž   rU   s    r   r    ÚMultiImage.filenameë  s   € à�~‰~Ðr2   r¥   r�   )
r�   r‘   r’   r“   r”   rR   r•   r    r–   Ú__classcell__)r¢   s   @r   r   r   µ  s#   ø† ñ,÷\Wð ñó ör2   r   )r”   r(   r   r   Úcollections.abcr   r   Únumpyr   ÚPILr   Útifffiler   Ú__all__r
   r   r1   r	   r   r   r—   r2   r   Ú<module>r­      sU   ðÙ Kã 	Ý Û 	Ý $Ý ã Ý å ò€ò!òHò4÷r(ñ r(òj	ô88�õ 8r2   