
    ёi                     |    S SK Jr  S SKrS SKJr  / rS rS rSS jr	S r
SS jrSS	 jrSS
 jrS r " S S5      rg)    )StringION)Imagec                 :   U[        [        U R                  S   U R                  S   5      5      -  n[        [	        U R                  S   U-  5      5      [        [	        U R                  S   U-  5      5      4nU R                  U[        R                  5      n U $ )z
Resize an image so that the shorter edge has length target_size.
img: the input image to be resized.
target_size: the target resized image size.
r      )floatminsizeintroundresizer   	ANTIALIAS)imgtarget_sizepercentresized_sizes       W/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/utils/image_util.pyresize_imager      s     E#chhqk388A;"?@@GE#((1+'()E#((1+'()L **\5??
3CJ    c                 j    [        U R                  5      S:X  a  U SS2SS2SSS24   $ U SS2SSS24   $ )zo
Return the flipped image.
Flip an image along the horizontal direction.
im: input image, (K x H x W) ndarrays
   N)lenshape)ims    r   flipr   &   s:     288}!Q"*~!TrT'{r   c                    U(       a  [        XR                  S   5      [        XR                  S   5      pT[        R                  " SXE45      nX@R                  S   -
  S-  nXPR                  S   -
  S-  nXpR                  S   -   XR                  S   -   pXSS2Xy2X24'   OU R	                  S5      n [        XR                  S   5      [        XR                  S   5      pT[        R                  " XE45      nX@R                  S   -
  S-  nXPR                  S   -
  S-  nXpR                  S   -   XR                  S   -   pXXy2X24'   U(       a  XA-
  S-  nXQ-
  S-  nOJ[        R
                  R                  SXA-
  S-   5      n[        R
                  R                  SXQ-
  S-   5      nXq-   X-   pU(       a  USS2Xy2X24   nO	XgU	2X24   nU(       d.  [        R
                  R                  S5      S:X  a  [        U5      nU$ )a!  
Return cropped image.
The size of the cropped image is inner_size * inner_size.
im: (K x H x W) ndarrays
inner_size: the cropped image size.
color: whether it is color image.
test: whether in test mode.
  If False, does random cropping and flipping.
  If True, crop the center of images.
r      r   Nfloat32r   )maxr   npzerosastyperandomrandintr   )r   
inner_sizecolortestheightwidth	padded_imstartYstartXendYendXpics               r   crop_imgr0   2   s    
HHQK(
HHQK(  HHa/0	88A;&!+((1+%*hhqk)6HHQK+?d13!V[&+-.YYy!
HHQK(
HHQK(  HHf_-	88A;&!+((1+%*hhqk)6HHQK+?d.0&+v{*+%*$)""1f&9A&=>""1e&81&<=$f&9$6;34tV[01ryy((+q03iJr   c                     [         R                  " [        R                  " [	        U 5      5      5      n[        UR                  5      S:X  a  [         R                  " US5      nU$ )Nr   )r   r   r   )r    arrayr   openr   r   r   	transpose)jpeg_stringnp_arrays     r   decode_jpegr7   b   sD    xx

8K#89:H
8>>a<<)4Or   c                 r    U R                  S5      n U(       + n[        XXE5      nXa-  nUR                  5       $ )z
Does data augmentation for images.
If is_train is false, cropping the center region from the image.
If is_train is true, randomly crop a region from the image,
and random does flipping.
im: (K x H x W) ndarrays
r   )r"   r0   flatten)r   img_mean	crop_sizeis_trainr&   r'   r/   s          r   preprocess_imgr=   i   s8     
9	B<D
2%
.COC;;=r   c                 ~   [         R                  " U 5      S   nX-
  S-  nU(       aO  X-  S-  UR                  S   :X  d   eUR                  SX5      nUSS2XUU-   2XUU-   24   R	                  S5      nU$ X-  UR                  S   :X  d   eUR                  X5      nUXUU-   2XUU-   24   R	                  S5      nU$ )z
Return the loaded meta file.
Load the meta image, which is the mean of the images in the dataset.
The mean image is subtracted from every input image so that the expected mean
of each input image is zero.
	data_meanr   r   r   Nr   )r    loadr   reshaper"   )	meta_pathmean_img_sizer;   r&   meanborders         r   	load_metarF   x   s     779k*D'1,F,q0DJJqMAAA||A}<v**Fi5G,GG

&
 	 K ,

1===||M9i''92D)DD

&
 	 Kr   c                 R    [         R                  " U 5      nUR                  5         U$ )zO
Load image and return.
img_path: image path.
is_color: is color image or not.
)r   r3   r@   )img_pathis_colorr   s      r   
load_imagerJ      s      **X
CHHJJr   c                    [         R                  " U S   R                  5      n[         R                  " U5      nUSS S-  nSUS   US   -
  4nSUS   US   -
  4n[         R                  " S[        S9nSnU H"  nU H  n	XXS   -   XS   -   4Xg'   US-  nM     M$     [         R
                  " US5      [         R                  " U* S-  US-  /5      -   US	'   [         R
                  " US
5      n[         R                  " S[        U 5      -  US   US   US   4[         R                  S9n
SnU  HE  nU H#  nXS   US   2US   US   2SS24   X'   US-  nM%     XS-
  U2SS2SSS2SS24   XS-
  U& MG     U
$ )z
image : iterable of (H x W x K) ndarrays
crop_dims: (height, width) tuple for the crops.
Returned data contains ten crops of input image, namely,
four corner patches and the center patch as well as their
horizontal reflections.
r   Nr   g       @r   )      )dtype)r   r   rM   )r   r   
   r   r   rL   )	r    r2   r   emptyr
   tileconcatenater   r   )r   	crop_dimsim_shape	im_center	h_indices	w_indicescrops_ixcurrijcropsixr   crops                 r   
oversampler_      s    xxA%H#I!s"I HQK)A,./IHQK)A,./Ixxc*HDAA!$4aA,6FGHNAID   '')V,r~~
c	9s?+0 HQK wwx(H HH	c#h	!ilHRLAjjE 
BD7T!W,d1gQ.?BCEI!GB  #6B;4R4#:;1fr	 
 Lr   c                   8    \ rS rSr S	S jrS rS rS rS rSr	g)
ImageTransformer   Nc                 v    X@l         U R                  U5        U R                  U5        U R                  U5        g N)rI   set_transposeset_channel_swapset_mean)selfr4   channel_swaprD   rI   s        r   __init__ImageTransformer.__init__   s1     !9%l+dr   c                 Z    Ub"  U R                   (       a  S[        U5      :X  d   eXl        g Nr   )rI   r   r4   rh   orders     r   re   ImageTransformer.set_transpose   s$    }}CJ&r   c                 Z    Ub"  U R                   (       a  S[        U5      :X  d   eXl        g rm   )rI   r   ri   rn   s     r   rf   !ImageTransformer.set_channel_swap   s%    }}CJ&!r   c                     Ubc  UR                   S:X  a'  US S 2[        R                  [        R                  4   nO,U R                  (       a  [	        UR
                  5      S:X  d   eXl        g )Nr   r   )ndimr    newaxisrI   r   r   rD   )rh   rD   s     r   rg   ImageTransformer.set_mean   sP    yyA~Arzz2::56 ==tzz?a///	r   c                     U R                   b  UR                  U R                   5      nU R                  b  XR                  S S 2S S 24   nU R                  b  XR                  -  nU$ rd   )r4   ri   rD   )rh   datas     r   transformerImageTransformer.transformer   sZ    >>%>>$..1D())1a/0D99 IIDr   )ri   rI   rD   r4   )NNNT)
__name__
__module____qualname____firstlineno__rj   re   rf   rg   ry   __static_attributes__ r   r   ra   ra      s    EI"	r   ra   )TT)T)ior   numpyr    PILr   __all__r   r   r0   r7   r=   rF   rJ   r_   ra   r   r   r   <module>r      sI      
	-`0&R' 'r   