+
    AiT>                         R t ^ RIt^ RIHt ^ RIt^ RIHt ^ RIHt ^ RIt^ RI	H
t
 ^ RIHt . ROtR	 tR
 tR t ! R R4      tR t ! R R]4      tR# )zEData structures to hold collections of images, with optional caching.N)glob)Sequence)copy)Image)TiffFile
MultiImageImageCollectionc                    V  Uu. uF  q\         P                  R3,          NK  	  pp \         P                  ! V4      pV# u upi   \         d    \        R4      hi ; i)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   &   S/var/www/html/photoedit/myenv/lib/python3.14/site-packages/skimage/io/collection.pyconcatenate_imagesr      sc    8 799bU

C((bJ99NN:.	  :  97889s   !AA Ac                    \         P                  ! RV 4       Uu. uF%  qP                  4       '       d   \        V4      MTNK'  	  ppV# u upi )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    , 02xx
A/FG/F!99;;QA	%/FAGH 	Hs   +A	c                N   \        V \        4      ;'       d    \        P                  V 9   p\        V \        4      '       * p\        V \        4      p\
        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      pT;'       g    T;'       d    T;'       d    TpV# )zhHelping function. Returns True if pattern contains a tuple, list, or a
string separated with os.pathsep.c              3   B   "   T F  p\        V\        4      x  K  	  R # 5iN)
isinstancestr).0pats   & r   	<genexpr>#_is_multipattern.<locals>.<genexpr>\   s     Dmsjc**ms   FT)r    r!   ospathsepr   all)input_patternhas_str_ospathsepnot_a_stringhas_iterablehas_stringsis_multipatterns   &     r   _is_multipatternr/   U   s     #=#6VV2::;V!-55LmX6L#DmD###DmDDK'  5555+      c                      a  ] tR t^dt o RtRR lt]R 4       t]R 4       tR t	R t
R tR	 tR
 tR tRR ltR tRtV tR# )r   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                   . V n         \        V4      '       d   \        V\        4      '       d    VP	                  \
        P                  4      pV F'  pV P                   P                  \        V4      4       K)  	  \        V P                   \        R7      V n         M\        V\        4      '       dF   V P                   P                  \        V4      4       \        V P                   \        R7      V n         M6\        V\        4      '       d   Ve   \        V4      V n         M\        R4      hVf#   ^RIHp W`n        V P#                  4       V n        M'W0n        \'        V P                   4      V n        RV n        V'       d   ^pMV P$                  pW n        RV n        W@n        \0        P2                  ! V\4        R7      V n        R# )z'Load and manage a collection of images.)keyNzInvalid pattern as input.imreaddtype)_filesr/   r    r!   r   r&   r'   extendr   sortedr   r   list	TypeError_ior5   	load_func_find_images
_numframeslen_frame_index_conserve_memory_cachedload_func_kwargsr
   emptyobjectdata)selfload_patternconserve_memoryr>   rE   patternr5   memory_slotss   &&&&,   r   __init__ImageCollection.__init__   s<    L)),,,+11"**='""4=1 ( 2BCDKc**KKtL12 2BCDKh//I4I|,DK788##N"//1DO&N!$++.DO $DL??L / 0HH\8	r0   c                    V P                   # r   )r8   rI   s   &r   filesImageCollection.files   s    {{r0   c                    V P                   # r   )rC   rQ   s   &r   rK   ImageCollection.conserve_memory   s    $$$r0   c           	        . pV P                    F  pVP                  4       P                  R4      '       da   \        VR4      ;_uu_ 4       p\	        V4      pT\        \        VP                  4      4       Uu. uF  qRV3NK  	  up,          pRRR4       K   \        P                  ! V4      pVP                  ^ 4       ^ p  TP                  T4       TP                  Y%34       T^,          pK0  	  Wn        \        V4      # u upi   + '       g   i     EK  ; i  \         d     EK  i ; i  \         d     Mi ; i\        TR4      '       g   EKH  TP                  '       g   EK]  TP                  P                  4        EKz  ).tiffrbNfp)rW   z.tif)r8   lowerendswithopenr   rangerA   pagesr   seekOSErrorEOFErrorappendhasattrrY   closerB   )rI   indexfnamefimgiims   &      r   r?   ImageCollection._find_images   s6   [[E{{}%%&788%&&!"1+C%CII2GH2GQaj2GHHE '&E*BGGAJ 
 LL%,FA% !* "5z% I '&&   $  2t$$EEKKMsB   -D	8D	D	'DD1D		DD.-D.1D?>D?c                l   \        VR4      '       d   VP                  4       p\        V\        \        34      '       g   \        R4      h\        V\        4      '       Ed   V P                  V4      pV\        V P                  4      ,          pV P                  '       d   WP                  8w  g   V P                  V,          f   V P                  pV P                  '       d@   V P                  V,          w  rEVe   WSR&    V P                  ! V3/ VB V P                  V&   M1V P                  ! V P                  V,          3/ VB V P                  V&   Wn
        V P                  V,          # \!        V P"                  4      V,          p\%        V 4      pV P                  '       dW   V U	u. uF  qP                  V	,          ^ ,          NK  	  up	Vn        V U	u. uF  qP                  V	,          NK  	  up	Vn        M'V U	u. uF  qP&                  V	,          NK  	  up	Vn        \        V4      Vn        V P                  '       d}   V P                  V9   dH   VP)                  V P                  4      Vn
        \*        P$                  ! V P                  4      Vn        V# \*        P,                  ! ^\.        R7      Vn         V# V P                  V,          Vn        V#   \
         d@   pR\        T4      9   d*   TR T P                  ! T3/ TB T P                  T&    Rp?ELh Rp?ii ; iu up	i u up	i u up	i )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'r6   )rc   rm   r    r   slicer<   _check_imgnumrA   rH   rK   rD   rE   rB   r>   r!   rR   r]   r@   r   r8   re   r
   rF   rG   )
rI   nidxkwargsrf   rn   efidxnew_icri   s
   &&        r   __getitem__ImageCollection.__getitem__  s   " 1k""A!c5\**IJJa""1%Ac$))n$C$$$ll):		#@V..$$$%)%6%6q%9NE*,3y)")-)H)H		# &*^^DJJqM%LV%LDIIcN 99S>! )!,D$ZF   BF G$Q!2!21!5a!8!8$ GEI&JT'8'8';';T&J#9= >AQ > #D	F###<<4'%)ZZ%=FN"$''$))"4FK
 M #%((1F";FK M #iioMG % "Bc!fL &y 1-1^^E-LV-LDIIcN!"( !H&J >s0    K )"L'L,?L1L$%3LLL$c                r    V P                   pV) Tu;8:  d   V8  d   M M
W,          pV# \        RV R24      h)z+Check that the given image number is valid.zThere are only z images in the collection)r@   
IndexError)rI   rq   nums   && r   rp   ImageCollection._check_imgnumc  s=    oo41?s?A  se3LMNNr0   c              #  X   "   \        \        V 4      4       F  pW,          x  K  	  R# 5i)zIterate over the images.N)r]   rA   )rI   ri   s   & r   __iter__ImageCollection.__iter__l  s     s4y!A'M "s   (*c                    V P                   # )zNumber of images in collection.)r@   rQ   s   &r   __len__ImageCollection.__len__q  s    r0   c                ,    \        V P                  4      # r   )r!   rR   rQ   s   &r   __str__ImageCollection.__str__u  s    4::r0   c                P    \         P                  ! V P                  4      V n        R# )zClear 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_likerH   )rI   rq   s   &&r   reloadImageCollection.reloadx  s     MM$)),	r0   c                    \        V 4      # )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   rQ   s   &r   r   ImageCollection.concatenate  s    $ "$''r0   )rD   rC   r8   rB   r@   rH   r>   rE   TNr   )__name__
__module____qualname____firstlineno____doc__rN   propertyrR   rK   r?   rw   rp   r~   r   r   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r   d   si     iV&9P   % %4GR

-( (r0   c                    a  RV 3R llpV# )Tc                   < \        WSR7      # )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.

)rK   r>   )r   )rJ   rK   r5   s   &&r   imread_collection4imread_collection_wrapper.<locals>.imread_collection  s    ( V
 	
r0   )T )r5   r   s   f r   imread_collection_wrapperr     s    
0 r0   c                   J   a a ] tR tRt oRtRV 3R llt]R 4       tRtVt	V ;t
# )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                F   < ^RI Hp Wn        \        SV `  ! W3RV/VB  R# )zLoad a multi-img.r4   r>   N)r=   r5   	_filenamesuperrN   )rI   filenamerK   r7   imread_kwargsr5   	__class__s   &&&&, r   rN   MultiImage.__init__  s"    !VfVVr0   c                    V P                   # r   r   rQ   s   &r   r   MultiImage.filename  s    ~~r0   r   r   )r   r   r   r   r   rN   r   r   r   r   __classcell__)r   r   s   @@r   r   r     s*     ,\W   r0   )r   r   r   r   )r   r&   r   r   collections.abcr   r   numpyr
   PILr   tifffiler   __all__r   r   r/   r   r   r   r   r0   r   <module>r      sU    K 	  	 $    !H4r( r(j	88 8r0   