+
    [°³jôb  ã                   ó  € R t ^ RIHtHtHt ^ RIt^ RIt^ RIHtH	t	  ]P                  P                  tRt R t ! R R4      t ^ RIHt ]R,          t ^ RIt]P"                  P.                  ]P0                  ,          t]P4                  R8¼  dS   ]P4                  R8¼  d   ]P4                  R8:  d   ^ R	IHt M^ R	IHt  ]].]3,          t]]P                  .]3,          tR
 t!R t"R t#R R lt$^]PJ                  3R lt&R!R lt'R!R lt(R R lt)R R lt*R"R lt+R#R lt, ! R R4      t-R t.R t/])R^€RR3R lt0R#   ] d    ]P                  t ELi ; i  ] d    ]t ELi ; i  ]]3 d    ]t Lói ; i  ]  d    ]t]t L¡i ; i)$aû  
Perceptual image hashing library

Example:

>>> from PIL import Image
>>> import imagehash
>>> hash = imagehash.average_hash(Image.open('test.png'))
>>> print(hash)
d879f8f89b1bbf
>>> otherhash = imagehash.average_hash(Image.open('other.bmp'))
>>> print(otherhash)
ffff3720200ffff
>>> print(hash == otherhash)
False
>>> print(hash - otherhash)
36
>>> for r in range(1, 30, 5):
...     rothash = imagehash.average_hash(Image.open('test.png').rotate(r))
...     print('Rotation by %d: %d Hamming difference' % (r, hash - rothash))
...
Rotation by 1: 2 Hamming difference
Rotation by 6: 11 Hamming difference
Rotation by 11: 13 Hamming difference
Rotation by 16: 17 Hamming difference
Rotation by 21: 19 Hamming difference
Rotation by 26: 21 Hamming difference
>>>
)Úabsolute_importÚdivisionÚprint_functionN)ÚImageÚImageFilterz4.3.2c                óô   € RP                  R ^V P                  4       ,           4       4      p\        \        P                  ! \        V4      ^,          4      4      pRP                  \        V^4      VR7      # )z?
internal function to make a hex string out of a binary array.
Ú c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5i©N©Ústr)Ú.0Úbs   & ÚS/home/luca/screen-checking/.venv/lib/python3.14/site-packages/imagehash/__init__.pyÚ	<genexpr>Ú'_binary_array_to_hex.<locals>.<genexpr>V   s   é € Ð8Ñ&7 ”c˜!—f�fÓ&7ùó   ‚z{:0>{width}x}©Úwidth)ÚjoinÚflattenÚintÚnumpyÚceilÚlenÚformat)ÚarrÚ
bit_stringr   s   &  r   Ú_binary_array_to_hexr   R   s\   € ð �g‰gÑ8 a¨#¯+©+«-Ö&7Ó8Ó8€Ü	ŒU�ZŠZœ˜J›¨!Õ+Ó,Ó	-€Ø×Ñœs :¨qÓ1¸ÐÓ?Ð?ó    c                   óT   a € ] tR t^[t o RtR tR tR tR tR t	R t
R tR	 tR
tV tR# )Ú	ImageHashzF
Hash encapsulation. Can be used for dictionary keys and comparisons.
c                ó   € Wn         R # r
   ©Úhash)ÚselfÚbinary_arrays   &&r   Ú__init__ÚImageHash.__init__`   s   € à†)r   c                óH   € \        V P                  P                  4       4      # r
   )r   r$   r   ©r%   s   &r   Ú__str__ÚImageHash.__str__d   s   € Ü	˜dŸi™i×/Ñ/Ó1Ó	2Ð2r   c                ó,   € \        V P                  4      # r
   )Úreprr$   r*   s   &r   Ú__repr__ÚImageHash.__repr__g   s   € Ü	ˆd�i‰i‹Ðr   c                óz  € Vf   \        R4      hV P                  P                  VP                  P                  8w  d6   \        RV P                  P                  VP                  P                  4      h\        P
                  ! V P                  P                  4       VP                  P                  4       8g  4      # )NzOther hash must not be None.z&ImageHashes must be of the same shape.)Ú	TypeErrorr$   ÚsizeÚshaper   Úcount_nonzeror   ©r%   Úothers   &&r   Ú__sub__ÚImageHash.__sub__j   s}   € à
‚]Ü	Ð1Ó	2Ð2Ø	‡Y�Y‡^�^�u—z‘z—‘Ô&Ü	Ð;¸T¿Y¹Y¿_¹_ÈeÏjÉj×N^ÑN^Ó	_Ð_Ü	×	Ò	˜TŸY™Y×.Ñ.Ó0°E·J±J×4FÑ4FÓ4HÑHÓ	IÐIr   c                óœ   € Vf   R# \         P                  ! V P                  P                  4       VP                  P                  4       4      # ©NF©r   Úarray_equalr$   r   r6   s   &&r   Ú__eq__ÚImageHash.__eq__r   s7   € à
‚]Ù
Ü	×	Ò	˜4Ÿ9™9×,Ñ,Ó.°·
±
×0BÑ0BÓ0DÓ	EÐEr   c                ó¦   € Vf   R# \         P                  ! V P                  P                  4       VP                  P                  4       4      '       * # r;   r<   r6   s   &&r   Ú__ne__ÚImageHash.__ne__x   s:   € à
‚]Ù
Ü×Ò˜tŸy™y×0Ñ0Ó2°E·J±J×4FÑ4FÓ4HÓIÔ	IÐIr   c           	     ó¾   € \        \        V P                  P                  4       4       UUu. uF  w  rV'       g   K  ^V^,          ,          NK!  	  upp4      # u uppi )é   )ÚsumÚ	enumerater$   r   )r%   ÚiÚvs   &  r   Ú__hash__ÚImageHash.__hash__~   sC   € ä	¤Y¨t¯y©y×/@Ñ/@Ó/BÔ%CÔIÑ%C™T˜QÄqŒjˆa�!�a•%�jˆjÑ%CÒIÓ	JÐJùÓIs
   ¬A
½A
c                ó.   € V P                   P                  # r
   )r$   r3   r*   s   &r   Ú__len__ÚImageHash.__len__‚   s   € à	�‰�‰Ðr   r#   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r'   r+   r/   r8   r>   rA   rI   rL   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r!   r!   [   s;   ø‡ € ñòò3òòJòFòJòK÷ð r   r!   )ÚLiteral)ÚCallablec                óÈ  € \        \        P                  ! \        V 4      ^,          4      4      pRP	                  \        V ^4      W,          R7      p\        ^ \        V4      V4       Uu. uF  q2W3V,            NK  	  pp\        P                  ! V UUu. uF&  qU Uu. uF  p\        \        V4      4      NK  	  upNK(  	  upp4      p\        V4      # u upi u upi u uppi )aY  
Convert a stored hash (hex, as retrieved from str(Imagehash))
back to a Imagehash object.

Notes:
1. This algorithm assumes all hashes are either
                bidimensional arrays with dimensions hash_size * hash_size,
                or onedimensional arrays with dimensions binbits * 14.
2. This algorithm does not work for hash_size < 2.
ú{:0>{width}b}r   )	r   r   Úsqrtr   r   ÚrangeÚarrayÚboolr!   )ÚhexstrÚ	hash_sizer&   rG   Úbit_rowsÚrowÚdÚ
hash_arrays   &       r   Úhex_to_hashre   ¦   s´   € ô ”—’œC ›K¨!�OÓ,Ó-€à×&Ñ&¤s¨6°2£¸iÕ>SÐ&ÓT€Ü49¸!¼SÀÓ=NÐPYÔ4ZÓ[Ñ4Z¨q˜! 	�MÓ*Ñ4Z€Ð[Ü�kŠkÁ(ÔKÁ(¸3°#Ó6±#¨QœD¤ Q£žL±#Ô6Á(ÒKÓL€Ü�*ÓÐùò \ùÚ6ùÓKs   Á+CÂC
ÂCÂ:C
ÃC
c           
      ó4  € \        \        V 4      ^,          V,          4      pRP                  \        V ^4      W!,          R7      p\        P                  ! V Uu. uF  p\        \        V4      4      NK  	  up.4      V) V,          R p\        V4      # u upi )é   rZ   r   N)r   r   r   r   r]   r^   r!   )r_   Úhashsizer`   r&   rc   rd   s   &&    r   Úhex_to_flathashri   º   s   € ä”�V“˜q• HÕ-Ó.€Ø×&Ñ&¤s¨6°2£¸iÕ>RÐ&ÓS€Ü�kŠk±,Ó?±,¨QœD¤ Q£žL±,Ñ?Ð@ÓAÀ9À*ÈxÕBWÐBXÐY€Ü�*ÓÐùò @s   ÁBc                óx   € V P                  R4      pV Uu. uF  p\        V4      NK  	  pp\        V4      # u upi )a¬  
Convert a stored multihash (hex, as retrieved from str(ImageMultiHash))
back to an ImageMultiHash object.

This function is based on hex_to_hash so the same caveats apply. Namely:

1. This algorithm assumes all hashes are either
                bidimensional arrays with dimensions hash_size * hash_size,
                or onedimensional arrays with dimensions binbits * 14.
2. This algorithm does not work for hash_size < 2.
Ú,)Úsplitre   ÚImageMultiHash)r_   rl   ÚxÚhashess   &   r   Úhex_to_multihashrp   Â   s:   € ð 
�‰�cÓ	€Ù#(Ó
)¡5˜aŒ;�qŽ>¡5€Ð
)Ü�vÓÐùò *s   –7c           	     óÂ  € . pW^,          ,          p\        V 4      V8w  d   Rp\        VP                  V4      4      h\        V^,          4       Fi  pW^,          V^,          ^,            p\	        RV,           ^4      pTP                  \        ^4       Uu. uF  qW^V,          ,          ^ 8„  NK  	  up4       Kk  	  \        \        P                  ! V4      4      # u upi )a  
Convert a stored hash (hex, as retrieved from str(Imagehash))
back to a Imagehash object. This method should be used for
hashes generated by ImageHash up to version 3.7. For hashes
generated by newer versions of ImageHash, hex_to_hash should
be used instead.
zExpected hex string size of {}.Ú0x)	r   Ú
ValueErrorr   r\   r   Úappendr!   r   r]   )r_   r`   r   ÚcountÚemsgrG   ÚhrH   s   &&      r   Úold_hex_to_hashrx   Ô   s·   € ð 
€Ø	 1•nÕ	%€ÜˆƒK�5ÔØ	*€$Ü�4—;‘;˜uÓ%Ó&Ð&Ü
�˜•
Ö
€QØ��U�1�q•5˜1•9Ð€!Ü	ˆ$��(�BÓ€!Ø‡*�*¤E¨!¤HÓ-¡H˜q�!�Q•$�h˜Œl¡HÑ-Ö.ñ ô 	”%—+’+˜cÓ"Ó#Ð#ùò .s   ÂC
c                óÌ   € V^8  d   \        R4      hV P                  R4      P                  W3\        4      p \        P
                  ! V 4      pV! V4      pW48„  p\        V4      # )aŽ  
Average Hash computation

Implementation follows https://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html

Step by step explanation: https://web.archive.org/web/20171112054354/https://www.safaribooksonline.com/blog/2013/11/26/image-hashing-with-python/ # noqa: E501

@image must be a PIL instance.
@mean how to determine the average luminescence. can try numpy.median instead.
ú,Hash size must be greater than or equal to 2ÚL©rs   ÚconvertÚresizeÚ	ANTIALIASr   Úasarrayr!   )Úimager`   ÚmeanÚpixelsÚavgÚdiffs   &&&   r   Úaverage_hashr†   é   sc   € ð �„MÜÐAÓBÐBð 
�‰�sÓ	×	"Ñ	" IÐ#9¼9Ó	E€ô �-Š-˜Ó
€ÙˆFƒ|€ð 	‰€ä�$‹Ðr   c                óŽ  € V^8  d   \        R4      h^ RIpW,          pV P                  R4      P                  WD3\        4      p \
        P                  ! V 4      pVP                  P                  VP                  P                  V^ R7      ^R7      pVRV1RV13,          p\
        P                  ! V4      pWx8„  p	\        V	4      # )ú£
Perceptual Hash computation.

Implementation follows https://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html

@image must be a PIL instance.
rz   Nr{   )Úaxis)rs   Úscipy.fftpackr}   r~   r   r   r€   ÚfftpackÚdctÚmedianr!   )
r�   r`   Úhighfreq_factorÚscipyÚimg_sizerƒ   rŒ   Ú
dctlowfreqÚmedr…   s
   &&&       r   Úphashr“     s²   € ð �„MÜÐAÓBÐBãØÕ'€Ø	�‰�sÓ	×	"Ñ	" HÐ#7¼Ó	C€Ü
�-Š-˜Ó
€Ø‡}�}×Ñ˜Ÿ™×*Ñ*¨6¸Ð*Ó:ÀÐÓC€Ø�*�9�*˜j˜y˜jÐ(Õ)€Ü‡|‚|�JÓ€ØÑ€Ü�$‹Ðr   c                ó2  € ^ RI pW,          pV P                  R4      P                  WD3\        4      p \        P
                  ! V 4      pVP                  P                  V4      pVRV1^V^,           13,          pVP                  4       pWx8„  p	\        V	4      # )rˆ   Nr{   )
rŠ   r}   r~   r   r   r€   r‹   rŒ   r‚   r!   )
r�   r`   rŽ   r�   r�   rƒ   rŒ   r‘   r„   r…   s
   &&&       r   Úphash_simpler•     sˆ   € ó ØÕ'€Ø	�‰�sÓ	×	"Ñ	" HÐ#7¼Ó	C€Ü
�-Š-˜Ó
€Ø‡}�}×Ñ˜Ó €Ø�*�9�*˜a 	¨A¥˜oÐ-Õ.€Ø‡�Ó€ØÑ€Ü�$‹Ðr   c                óò   € V^8  d   \        R4      hV P                  R4      P                  V^,           V3\        4      p \        P
                  ! V 4      pVR,          VRRR13,          8„  p\        V4      # )z½
Difference Hash computation.

following https://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html

computes differences horizontally

@image must be a PIL instance.
rz   r{   ºNNNN)r—   ºé   NNéÿÿÿÿr|   ©r�   r`   rƒ   r…   s   &&  r   Údhashrœ   0  sm   € ð �„MÜÐAÓBÐBà	�‰�sÓ	×	"Ñ	" I°¥M°9Ð#=¼yÓ	I€Ü
�-Š-˜Ó
€àˆu�˜˜q # 2 #˜v�Ñ&€Ü�$‹Ðr   c                óÌ   € V P                  R4      P                  W^,           3\        4      p \        P                  ! V 4      pVR,          VRR1R3,          8„  p\        V4      # )z»
Difference Hash computation.

following https://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html

computes differences vertically

@image must be a PIL instance.
r{   r—   N)r˜   r—   rš   )r}   r~   r   r   r€   r!   r›   s   &&  r   Údhash_verticalrž   F  sX   € ð 
�‰�sÓ	×	"Ñ	" I¸1­}Ð#=¼yÓ	I€Ü
�-Š-˜Ó
€àˆu�˜˜s ˜s A˜v�Ñ&€Ü�$‹Ðr   c                óR  € ^ RI pVe   W"^,
          ,          ^ 8X  g   Q R4       hMD^\        \        P                  ! \	        V P
                  4      4      4      ,          p\        Wa4      p\        \        P                  ! V4      4      p\        \        P                  ! V4      4      pW^,
          ,          ^ 8X  g   Q R4       hW‡8:  g   Q R4       hWx,
          p	V P                  R4      P                  W"3\        4      p \        P                  ! V 4      R,          p
V'       dG   VP                  V
RVR7      p\        V4      pV^ ;;,          ^ ,          uu&   VP                  VR4      p
VP                  W£V	R7      pV^ ,          p\        P                  ! V4      pWÍ8„  p\        V4      # )	aD  
Wavelet Hash computation.

based on https://www.kaggle.com/c/avito-duplicate-ads-detection/

@image must be a PIL instance.
@hash_size must be a power of 2 and less than @image_scale.
@image_scale must be power of 2 and less than image size. By default is equal to max
                                power of 2 for an input image.
@mode (see modes in pywt library):
                                'haar' - Haar wavelets, by default
                                'db4' - Daubechies wavelets
@remove_max_haar_ll - remove the lowest low level (LL) frequency using Haar wavelet.
Nzimage_scale is not power of 2zhash_size is not power of 2zhash_size in a wrong ranger{   g     ào@Úhaar)Úlevel)Úpywtr   r   Úlog2Úminr3   Úmaxr}   r~   r   r€   Úwavedec2ÚlistÚwaverec2r�   r!   )r�   r`   Úimage_scaleÚmodeÚremove_max_haar_llr¢   Úimage_natural_scaleÚll_max_levelr¡   Ú	dwt_levelrƒ   ÚcoeffsÚdwt_lowr’   r…   s   &&&&&          r   Úwhashr±   Y  s]  € ó  ØÒØ	 a�Õ	(¨AÔ	-ÐNÐ/NÓNÑ	-àœ3œuŸzšz¬#¨e¯j©j«/Ó:Ó;Õ;ÐÜÐ'Ó3€+ä”E—J’J˜{Ó+Ó,€ä	ŒU�ZŠZ˜	Ó"Ó	#€Ø •]Õ# qÔ(ÐGÐ*GÓGÐ(ØÔÐ;Ð;Ó;ÐØÕ!€à	�‰�sÓ	×	"Ñ	" KÐ#=¼yÓ	I€Ü
�-Š-˜Ó
 Õ
%€÷ Ø�=‰=˜ ¨|ˆ=Ó<€&Ü�‹<€&Øˆ‡)ˆq….ƒ)Ø�=‰=˜ Ó(€&ð �-‰-˜¨Iˆ-Ó
6€Ø�!�9€ô ‡|‚|�GÓ€Ø‰€Ü�$‹Ðr   c           
     óš  € \         P                  ! V P                  R4      4      P                  4       pV P                  R4      P	                  4        Uu. uF'  p\         P                  ! V4      P                  4       NK)  	  upw  rEpV^ 8  pVP                  4       pV^U8  p\         P                  ! V( V4      P                  4       p	\         P                  ! V( V( 4      p
\         P                  ! W¥^ª8  4      p\         P                  ! W¥^ª8„  4      p\        ^V
P                  4       4      p\         P                  ! ^ ^ÿ^4      pVP                  4       '       d#   \         P                  ! WK,          VR7      w  ppM&\         P                  ! \        V4      ^,
          4      pVP                  4       '       d#   \         P                  ! WL,          VR7      w  ppM&\         P                  ! \        V4      ^,
          4      p^V,          p\        V^,
          \        VV,          4      4      \        V^,
          \        V	V,          4      4      .p\!        V4      \!        V4      ,            FC  pVP#                  \        V^,
          \        VV,          R,          V,          4      4      4       KE  	  . pV FY  pT\%        V4       Uu. uF9  pV^VV,
          ^,
          ,          ,          ^VV,
          ,          ,          ^ 8„  NK;  	  up,          pK[  	  \'        \         P                  ! V4      P)                  RV34      4      # u upi u upi )a  
Color Hash computation.

Computes fractions of image in intensity, hue and saturation bins:

* the first binbits encode the black fraction of the image
* the next binbits encode the gray fraction of the remaining image (low saturation)
* the next 6*binbits encode the fraction in 6 bins of saturation, for highly saturated parts of the remaining image
* the next 6*binbits encode the fraction in 6 bins of saturation, for mildly saturated parts of the remaining image

@binbits number of bits to use to encode each pixel fractions
r{   ÚHSV)Úbinsg      ð?rš   )r   r€   r}   r   rl   r‚   Úlogical_andr¥   rE   ÚlinspaceÚanyÚ	histogramÚzerosr   r¤   r   r§   rt   r\   r!   Úreshape)r�   ÚbinbitsÚ	intensityrH   rw   ÚsÚ
mask_blackÚ
frac_blackÚ	mask_grayÚ	frac_grayÚmask_colorsÚmask_faint_colorsÚmask_bright_colorsÚcÚhue_binsÚh_faint_countsÚ_Úh_bright_countsÚmaxvalueÚvaluesÚcountsÚbitarrayrG   s   &&                     r   Ú	colorhashrÎ   ‹  sŽ  € ô  �]Š]˜5Ÿ=™=¨Ó-Ó.×6Ñ6Ó8€Ø05·±¸eÓ0D×0JÑ0JÔ0LÓMÑ0L¨1ŒE�MŠM˜!Ó×$Ñ$Ö&Ñ0LÑM�€€qà˜(Ñ"€Ø�o‰oÓ€à�‰\€Ü×Ò 
˜{¨IÓ6×;Ñ;Ó=€ä× Ò  * ¨y¨jÓ9€Ü×&Ò& {¸Ñ4DÓEÐÜ×'Ò'¨¸Ñ5EÓFÐäˆˆK�O‰OÓÓ€ä�NŠN˜1˜c 5Ó)€Ø×Ñ×ÒÜ—o’o aÕ&:ÀÔJÑ€.‘!ä—;’;œs 8›}¨qÕ0Ó1€.Ø×Ñ×ÒÜ—’ qÕ'<À8ÔLÑ€/‘1ä—K’K¤ H£°Õ 1Ó2€/ð ˆw�J€Üˆx˜!�|œS ¨hÕ!6Ó7Ó8¼#¸hÈ½lÌCÐPYÐ\dÕPdÓLeÓ:fÐ
g€Ü�NÓ#¤d¨?Ó&;×;Ð;€VØ‡-�-”�H˜q•L¤# f¨xÕ&7¸"Õ&<¸qÕ&@Ó"AÓBÖCñ <ð €Û
€QØ
Ì5ÐQXÌ>ÓZÉ>Àaˆq�Q˜ 1� q�Õ)Õ*¨Q°¸1µÕ-=Õ=ÀÔAÉ>ÑZÕZ‚(ñ ä”%—-’- Ó)×1Ñ1°2°w°-Ó@ÓAÐAùòE NùòB [s   Á-MË?Mc                   óp   a € ] tR tRt o RtR tR tR tRR ltR t	R	 t
R
 tRR ltRR ltRR ltRtV tR# )rm   iÁ  z½
This is an image hash containing a list of individual hashes for segments of the image.
The matching logic is implemented as described in Efficient Cropping-Resistant Robust Image Hashing
c                ó   € Wn         R # r
   ©Úsegment_hashes)r%   ro   s   &&r   r'   ÚImageMultiHash.__init__Ç  s   € àÖr   c                ó0   € Vf   R# V P                  V4      # r;   ©Úmatchesr6   s   &&r   r>   ÚImageMultiHash.__eq__Ë  s   € à
‚]Ù
Ø	�‰�eÓ	Ðr   c                ó.   € V P                  V4      '       * # r
   rÕ   r6   s   &&r   rA   ÚImageMultiHash.__ne__Ñ  s   € à�\‰\˜%Ó Ô	 Ð r   Nc                óþ   € V P                  WV4      w  rE\        V P                  4      pV^ 8X  d   V# V\        V P                  ^ ,          4      ,          p^ \        V4      V,          ,
          pWH,           p	Wi,
          # )é    )Ú	hash_diffr   rÒ   Úfloat)
r%   r7   Úhamming_cutoffÚbit_error_raterÖ   Úsum_distanceÚmax_differenceÚmax_distanceÚtie_breakerÚmatch_scores
   &&&&      r   r8   ÚImageMultiHash.__sub__Õ  sq   € àŸ.™.¨ÀÓOÑ€'Ü�t×*Ñ*Ó+€.Ø�„\Ø
ÐØœ3˜t×2Ñ2°1Õ5Ó6Õ6€,Ø”U˜<Ó(¨<Õ7Õ8€+ØÕ%€+Ø	Õ	%Ð%r   c                óœ   € \        \        ;QJ d"    . R  V P                   4       F  NK  	  54      # ! R  V P                   4       4      4      # )c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir
   r#   )r   Úsegments   & r   r   Ú*ImageMultiHash.__hash__.<locals>.<genexpr>á  s   é € ÐEÑ1D g”D˜—M�MÓ1Dùr   )r$   ÚtuplerÒ   r*   s   &r   rI   ÚImageMultiHash.__hash__à  s8   € Ü	�eŒeÑE°×1DÒ1DÓE�eÓ	FÐFˆeÑE°×1DÒ1DÓEÓEÓ	FÐFr   c                óF   € R P                  R V P                   4       4      # )rk   c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir
   r   )r   rn   s   & r   r   Ú)ImageMultiHash.__str__.<locals>.<genexpr>ä  s   é € Ð6Ñ"5˜Q”#�a—&�&Ó"5ùr   )r   rÒ   r*   s   &r   r+   ÚImageMultiHash.__str__ã  s   € Ø	�‰Ñ6 $×"5Ò"5Ó6Ó	6Ð6r   c                ó,   € \        V P                  4      # r
   )r.   rÒ   r*   s   &r   r/   ÚImageMultiHash.__repr__æ  s   € Ü	ˆd×!Ñ!Ó	"Ð"r   c                ó$  a€ Vf*   Vf   Rp\        V P                  ^ ,          4      V,          p. pV P                   F;  o\        V3R lVP                   4       4      pWR8”  d   K*  VP                  V4       K=  	  \        V4      \	        V4      3# )a  
Gets the difference between two multi-hashes, as a tuple. The first element of the tuple is the number of
matching segments, and the second element is the sum of the hamming distances of matching hashes.
NOTE: Do not order directly by this tuple, as higher is better for matches, and worse for hamming cutoff.
:param other_hash: The image multi hash to compare against
:param hamming_cutoff: The maximum hamming distance to a region hash in the target hash
:param bit_error_rate: Percentage of bits which can be incorrect, an alternative to the hamming cutoff. The
default of 0.25 means that the segment hashes can be up to 25% different
g      Ð?c              3   ó6   <"  € T F  pSV,
          x € K  	  R # 5ir
   © )r   Úother_segment_hashÚsegment_hashs   & €r   r   Ú+ImageMultiHash.hash_diff.<locals>.<genexpr>ü  s"   øé € ð á7Ðð Ð%×%Ò%Û7ùs   ƒ)r   rÒ   r¤   rt   rE   )r%   Ú
other_hashrÞ   rß   Ú	distancesÚlowest_distancerö   s   &&&&  @r   rÜ   ÚImageMultiHash.hash_diffé  s�   ø€ ð ÒØÒØ€NÜ˜×+Ñ+¨AÕ.Ó/°.Õ@€>à€)Ø×)Ô)€lÜô à(×7Ò7óó €?ð Ô&ÙØ×Ñ�OÖ$ñ *ô 
ˆY‹œ˜Y›Ð	'Ð'r   c                ó2   € V P                  WV4      w  rVWR8¬  # )aé  
Checks whether this hash matches another crop resistant hash, `other_hash`.
:param other_hash: The image multi hash to compare against
:param region_cutoff: The minimum number of regions which must have a matching hash
:param hamming_cutoff: The maximum hamming distance to a region hash in the target hash
:param bit_error_rate: Percentage of bits which can be incorrect, an alternative to the hamming cutoff. The
default of 0.25 means that the segment hashes can be up to 25% different
)rÜ   )r%   rø   Úregion_cutoffrÞ   rß   rÖ   rÈ   s   &&&&&  r   rÖ   ÚImageMultiHash.matches  s   € ð �~‰~˜j¸.ÓI�*€'Ø	Ñ	!Ð!r   c                ó.   a aa€ \        VVVV 3R lR7      # )a’  
Returns the hash in a list which is the best match to the current hash
:param other_hashes: A list of image multi hashes to compare against
:param hamming_cutoff: The maximum hamming distance to a region hash in the target hash
:param bit_error_rate: Percentage of bits which can be incorrect, an alternative to the hamming cutoff.
Defaults to 0.25 if unset, which means the hash can be 25% different
c                 ó*   <€ SP                  V SS4      # r
   )r8   )rø   rß   rÞ   r%   s   &€€€r   Ú<lambda>Ú+ImageMultiHash.best_match.<locals>.<lambda>  s   ø€ ˜$Ÿ,™, z°>À>ÔRr   )Úkey)r¤   )r%   Úother_hashesrÞ   rß   s   f&ffr   Ú
best_matchÚImageMultiHash.best_match  s   ú€ ô 
ØÞRô
ð r   rÑ   )NN)r™   NN)rN   rO   rP   rQ   rR   r'   r>   rA   r8   rI   r+   r/   rÜ   rÖ   r  rS   rT   rU   s   @r   rm   rm   Á  sB   ø‡ € ñò
òò!ô	&òGò7ò#ô(ô8"÷ò r   rm   c                ó�  € \        4       p\        4       p\        P                  ! \        P                  ! V 4      4      p\	        V^ ,          4      pVP                  V4       VP                  4       p \        4       pV F@  pVw  ršV	^,
          V
3V	^,           V
3Wš^,
          3Wš^,           3.pVP                  V4       KB  	  VP                  W4       V'       g    V# \        4       pV FW  pW,          '       d6   VP                  V4       VP                  V4       VP                  V4       KF  VP                  V4       KY  	  KÖ  )aK  
Finds a region and returns a set of pixel coordinates for it.
:param remaining_pixels: A numpy bool array, with True meaning the pixels are remaining to segment
:param segmented_pixels: A set of pixel coordinates which have already been assigned to segment. This will be
updated with the new pixels added to the returned segment.
)	Úsetr   Ú	transposeÚnonzerorê   ÚaddÚcopyÚupdateÚdifference_update)Úremaining_pixelsÚsegmented_pixelsÚ	in_regionÚnot_in_regionÚavailable_pixelsÚstartÚ
new_pixelsÚtry_nextÚpixelrn   ÚyÚ
neighbourss   &&          r   Ú_find_regionr  !  s  € ô ‹U€Ü“€ä—O’O¤E§M¢MÐ2BÓ$CÓDÐÜ	Ð Õ"Ó	#€Ø
‡�ˆuÔØ�n‰nÓ€ØÜ‹U€(ã€eØ
�4€1àˆ…UˆA€JØˆ…UˆA€JØˆA�€JØˆA�€Jð	€:ð ‡?�?�:Öñ ð ×ÑÐ-Ô=ç	Øð 	Ðô ‹u€*ã€eØ×ÔØ‡M�M�%ÔØ‡N�N�5ÔØ×Ñ˜Öà×Ñ�eÖó r   c                ó  € V P                   w  r4W8„  p\        P                  ! V P                   R\        R7      p. p\	        4       pTP                  \        V4       U	u. uF  p	RV	3NK	  	  up	4       TP                  \        V4       U	u. uF  q™R3NK  	  up	4       TP                  \        V4       U	u. uF  q“V	3NK  	  up	4       TP                  \        V4       U	u. uF  q™V3NK  	  up	4       \        P                  ! WV4      P                  4       '       dR   \        P                  ! WV4      p
\        W¨4      p\        V4      V8”  d   VP                  V4       V F  pRWl&   K	  	  K{  \        P                  ! V4      p\        V4      W4,          8  dR   \        P                  ! WÖ4      p
\        W¨4      p\        V4      V8”  d   VP                  V4       V F  pRWl&   K	  	  Kg  V# u up	i u up	i u up	i u up	i )aÑ  
Finds all the regions within an image pixel array, and returns a list of the regions.

Note: Slightly different segmentations are produced when using pillow version 6 vs. >=7, due to a change in
rounding in the greyscale conversion.
:param pixels: A numpy array of the pixel brightnesses.
:param segment_threshold: The brightness threshold to use when differentiating between hills and valleys.
:param min_segment_size: The minimum number of pixels for a segment.
T)ÚdtypeFrš   )r4   r   Úfullr^   r  r  r\   Úbitwise_andr·   r  r   rt   Úinvert)rƒ   Úsegment_thresholdÚmin_segment_sizeÚ	img_widthÚ
img_heightÚthreshold_pixelsÚunassigned_pixelsÚsegmentsÚalready_segmentedÚzr  rè   ÚpixÚthreshold_pixels_is   &&&           r   Ú_find_all_segmentsr+  M  sÀ  € ð  Ÿ™Ñ€àÑ.ÐÜ—Z’Z §¡¨d¼$Ô?Ðà€Ü“UÐð ×Ñ¬E°*Ô,=Ó>Ñ,= q˜B ›7Ñ,=Ñ>Ô?Ø×Ñ¬E°)Ô,<Ó=Ñ,< q˜r›7Ñ,<Ñ=Ô>Ø×Ñ´5¸Ô3DÓEÑ3D¨a q›>Ñ3DÑEÔFØ×Ñ´E¸)Ô4DÓEÑ4D¨q˜z›?Ñ4DÑEÔFô ×ÒÐ)Ó=×AÑA×CÒCÜ×&Ò&Ð'7ÓKÐÜÐ)Ó=€'äˆƒ\Ð$Ô$Ø‡?�?�7ÔÛ€cØ!ÐÓó ô —l’lÐ#3Ó4ÐÜ
ÐÓ 	Õ 6Ô6Ü×&Ò&Ð'9ÓMÐÜÐ)Ó=€'äˆƒ\Ð$Ô$Ø‡?�?�7ÔÛ€cØ!ÐÓó ð 	€ùò5 ?ùÚ=ùÚEùÚEs   ÁG-Â
G2Â5G7Ã G<iô  i,  c                óÒ  € V P                  4       pV P                  R4      P                  WU3\        4      p V P	                  \
        P                  ! 4       4      P	                  \
        P                  ! 4       4      p \        P                  ! V 4      P                  \        P                  4      p\        WsV4      pV'       g&   R
V^,
          V^,
          30p	VP                  V	4       V'       d   \        VR RR7      RV p. p
V FÓ  pVP                  w  rÍ\!        V4      V,          p\!        V4      V,          p\#        R V 4       4      V,          p\#        R V 4       4      V,          p\%        R V 4       4      ^,           V,          p\%        R	 V 4       4      ^,           V,          pVP'                  VVVV34      pV
P                  V! V4      4       KÕ  	  \)        V
4      # )a©  
Creates a CropResistantHash object, by the algorithm described in the paper "Efficient Cropping-Resistant Robust
Image Hashing". DOI 10.1109/ARES.2014.85
This algorithm partitions the image into bright and dark segments, using a watershed-like algorithm, and then does
an image hash on each segment. This makes the image much more resistant to cropping than other algorithms, with
the paper claiming resistance to up to 50% cropping, while most other algorithms stop at about 5% cropping.

Note: Slightly different segmentations are produced when using pillow version 6 vs. >=7, due to a change in
rounding in the greyscale conversion. This leads to a slightly different result.
:param image: The image to hash
:param hash_func: The hashing function to use
:param limit_segments: If you have storage requirements, you can limit to hashing only the M largest segments
:param segment_threshold: Brightness threshold between hills and valleys. This should be static, putting it between
peak and through dynamically breaks the matching
:param min_segment_size: Minimum number of pixels for a hashable segment
:param segmentation_image_size: Size which the image is resized to before segmentation
r{   c                 ó   € \        V 4      # r
   )r   )r½   s   &r   r  Ú%crop_resistant_hash.<locals>.<lambda>¨  s   € ¬C°¬Fr   T)r  ÚreverseNc              3   ó2   "  € T F  q^ ,          x € K  	  R# 5i©rÛ   Nrô   ©r   Úcoords   & r   r   Ú&crop_resistant_hash.<locals>.<genexpr>°  ó   é € Ð,¡G˜5�A�hŠh£Gùó   ‚c              3   ó2   "  € T F  q^,          x € K  	  R# 5i©r™   Nrô   r2  s   & r   r   r4  ±  r5  r6  c              3   ó2   "  € T F  q^ ,          x € K  	  R# 5ir1  rô   r2  s   & r   r   r4  ²  ó   é € Ð-¡W˜E�Q�xŠx£Wùr6  c              3   ó2   "  € T F  q^,          x € K  	  R# 5ir8  rô   r2  s   & r   r   r4  ³  r:  r6  )rÛ   rÛ   )r  r}   r~   r   Úfilterr   ÚGaussianBlurÚMedianFilterr   r]   ÚastypeÚfloat32r+  rt   Úsortedr3   rÝ   r¤   r¥   Úcroprm   )r�   Ú	hash_funcÚlimit_segmentsr   r!  Úsegmentation_image_sizeÚ
orig_imagerƒ   r&  Úfull_image_segmentro   rè   Úorig_wÚorig_hÚscale_wÚscale_hÚmin_yÚmin_xÚmax_yÚmax_xÚbounding_boxs   &&&&&&               r   Úcrop_resistant_hashrQ  }  s›  € ð6 �j‰j‹l€à	�‰�sÓ	×	"Ñ	"Ð$;Ð#UÔW`Ó	a€à	�‰”k×.Ò.Ó0Ó	1×	8Ñ	8¼×9QÒ9QÓ9SÓ	T€Ü
�+Š+�eÓ
×
#Ñ
#¤E§M¡MÓ
2€ä˜vÐ:JÓK€÷ 	ØÐ!8¸1Õ!<Ð>UÐXYÕ>YÐ ZÐ[ÐØ
‡/�/Ð$Ô%÷ Ü�HÑ"2¸DÔAÀ/À>ÐR€(ð €Û€WØ—?‘?�.€&Ü�&‹MÐ3Õ3€'Ü�&‹MÐ3Õ3€'Ü
Ñ,¡GÓ,Ó
,¨wÕ
6€%Ü
Ñ,¡GÓ,Ó
,¨wÕ
6€%ÜÑ-¡WÓ-Ó-°Õ1°WÕ
<€%ÜÑ-¡WÓ-Ó-°Õ1°WÕ
<€%à—‘ %¨°°uÐ!=Ó>€,Ø‡-�-‘	˜,Ó'Ö(ñ ô$ 	�vÓÐr   )r    Údb4)é   rS  )rS  é	   rÛ   )rS  rT  r™   )é   )rU  rg   )rU  Nr    T)rS  )1rR   Ú
__future__r   r   r   Úsysr   ÚPILr   r   Ú
ResamplingÚLANCZOSr   ÚAttributeErrorÚ__version__r   r!   ÚtypingrW   Ú	WhashModeÚImportErrorr   Únumpy.typingÚNDArrayÚbool_r§   Úversion_inforX   Úcollections.abcrÝ   ÚMeanFuncÚHashFuncr2   re   ri   rp   rx   r‚   r†   r“   r•   rœ   rž   r±   rÎ   rm   r  r+  rQ  rô   r   r   Ú<module>rg     sº  ðñ÷< AÑ @ã 
ã ß "ðØ×Ñ×%Ñ%€ð €ð òF@÷)ñ )ðZåØ�]Õ#€ðãØ�<‰<×Ñ §¡Õ,€ð
 ×Ñ�vÔØ×Ñ˜	Ô! c×&6Ñ&6¸)Ô&Cæå&ðØ�w�i Ð&Õ'€(Ø�u—{‘{�m YÐ.Õ/€(òò(òô$$ð* #$¨%¯*©*ô ô8ô.ô(ô,ô&/ôd3B÷l]ñ ]ò@)òX-ðd ØØØØöAøðk ô ð �_‰_ƒðûðH ô Øƒðûð 	˜Ð$ô Ø‚ðûð 	ô Ø€(Ø‚(ðúsG   žD< ÁE Á+E& Ã"E7 Ä<EÅEÅ	E#Å"E#Å&E4Å3E4Å7FÆF