+
    ùäûjÜ  ã                   ót   € ^ RI HtHtHt ^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHt  ! R R	]4      tR# )
é    )ÚAnyÚDictÚOptionalN)ÚTensor)ÚIntensityAugmentationBase2D)Úrgb_to_grayscale)ÚKORNIA_CHECK)Ú_to_device_nonblockingc                   ó\   a a€ ] tR t^t oRtRV3R lV 3R llltRV3R lR lltRtVtV ;t	# )	ÚRandomGrayscaleu•  Convert images to grayscale (channel count kept), applied per sample with probability ``p`` (default 0.1).

``output = RandomGrayscale(...)(input)`` turns selected images ``(B, C, H, W)`` into grayscale values while
retaining their channel count: RGB uses luminance weights and other channel counts default to equal weights.

.. image:: _static/img/RandomGrayscale.png

See the Convention block on :class:`~kornia.augmentation.IntensityAugmentationBase2D`.

Works for multispectral imagery too (e.g. satellite data with 4-13+ bands): for a non-RGB
channel count the grayscale is the weighted average across *all* channels, broadcast back to
the input channel count. This makes the augmentation usable outside the 3-channel RGB regime.

Args:
    rgb_weights: Per-channel weights applied when reducing to grayscale â€” one weight per input
        channel (three, for the usual RGB case). If ``None``, RGB inputs use the standard
        luminance weights and multispectral inputs weight every band equally. Weights are applied
        as given and are not normalized, so weights that do not sum to one rescale the output.
    p: probability of applying the transformation to each sample.
    same_on_batch: apply the same transformation across the batch.
    keepdim: whether to keep the output shape the same as input (True) or broadcast it
                    to the batch form (False).

Shape:
    - Input: ``(C, H, W)`` or ``(B, C, H, W)``, Optional: ``(B, 3, 3)``
    - Output: ``(B, C, H, W)``

Convention:
    - this operation is range-independent: it does not clamp the input into ``[0, 1]``.
    - the channel count is preserved: the single weighted average is broadcast back over the input's
      channels, so every output channel of a sample carries the same value.
    - a three-channel input uses the RGB luminance weights by default; any other channel count
      defaults to an equal weight per channel, which makes the output the plain mean over channels.
      ``rgb_weights`` replaces those defaults.
    - the result is not clamped; its range follows the weighted channel reduction and the supplied
      ``rgb_weights``.

.. note::
    For 3-channel RGB inputs this uses :func:`kornia.color.rgb_to_grayscale`; multispectral
    inputs use a weighted channel average.

See Also:
    - :class:`RandomChannelDropout`: removes selected channels instead of computing grayscale.

Examples:
    >>> rng = torch.manual_seed(0)
    >>> inputs = torch.randn((1, 3, 3, 3))
    >>> aug = RandomGrayscale(p=1.0)
    >>> aug(inputs)
    tensor([[[[-1.1344, -0.1330,  0.1517],
              [-0.0791,  0.6711, -0.1413],
              [-0.1717, -0.9023,  0.0819]],
    <BLANKLINE>
             [[-1.1344, -0.1330,  0.1517],
              [-0.0791,  0.6711, -0.1413],
              [-0.1717, -0.9023,  0.0819]],
    <BLANKLINE>
             [[-1.1344, -0.1330,  0.1517],
              [-0.0791,  0.6711, -0.1413],
              [-0.1717, -0.9023,  0.0819]]]])

To apply the exact augmenation again, you may take the advantage of the previous parameter state:
    >>> input = torch.randn(1, 3, 32, 32)
    >>> aug = RandomGrayscale(p=1.0)
    >>> (aug(input) == aug(input, params=aug._params)).all()
    tensor(True)

c          
      óF   <€ V ^8„  d   QhRS[ S[,          RS[RS[RS[RR/# )é   Úrgb_weightsÚsame_on_batchÚpÚkeepdimÚreturnN)r   r   ÚboolÚfloat)ÚformatÚ__classdict__s   "€ÚgC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\intensity\grayscale.pyÚ__annotate__ÚRandomGrayscale.__annotate__c   s:   ø€ ÷ 'ñ 'Ù#¡FÕ+ð'ÙCGð'ÙTYð'Ùjnð'à	ñ'ó    c                ó6   <€ \         SV `  W2VR 7       Wn        R# ))r   r   r   N)ÚsuperÚ__init__r   )Úselfr   r   r   r   Ú	__class__s   &&&&&€r   r   ÚRandomGrayscale.__init__c   s   ø€ ô 	‰Ñ˜1À7ÐÔKØ&Ör   c          
      ót   <€ V ^8„  d   QhRS[ RS[S[S[ 3,          RS[S[S[3,          RS[S[ ,          RS[ /# )r   ÚinputÚparamsÚflagsÚ	transformr   )r   r   Ústrr   r   )r   r   s   "€r   r   r   i   sL   ø€ ÷ 6ñ 6Ùð6Ù%)©#©v¨+Õ%6ð6Ù?CÁCÉÀH½~ð6ÙZbÑciÕZjð6á	ñ6r   c                óD  aa€ VP                   R,          oRVP                  ^,
          ,          pS^8X  d   \        WP                  R7      pM»V P                  oSf8   \        P
                  ! S3RS,          VP                  VP                  R7      oMC\        SP                  4       S8H  VV3R l4       \        SVP                  VP                  4      oVSP                  ! . VOSN^N^N5!  ,          P                  RRR7      pVP                  ! . VOSN^N^N5!  # )	é   ©r   g      ð?)ÚdeviceÚdtypec                  ó2   <€ R SP                  4        RS  R2# )z.rgb_weights needs one weight per channel: got z for Ú.)Únumel)Únum_channelsÚweightss   €€r   Ú<lambda>Ú1RandomGrayscale.apply_transform.<locals>.<lambda>z   s    ø€ ÐLÈWÏ]É]Ë_ÐL]Ð]bÐcoÐbpÐpqÑrr   T)r   éýÿÿÿ)é   )ÚshapeÚndimr   r   ÚtorchÚfullr+   r,   r	   r/   r
   ÚviewÚsumÚrepeat)	r   r#   r$   r%   r&   ÚleadÚgrayr0   r1   s	   &&&&&  @@r   Úapply_transformÚRandomGrayscale.apply_transformi   sÿ   ù€ ð —{‘{ 2•ˆØ�u—z‘z A•~Õ&ˆØ˜1Ôä# E×7GÑ7GÔH‰Dð ×&Ñ&ˆGØŠÜŸ*š* l _°c¸LÕ6HÐQV×Q]ÑQ]Ðej×epÑepÔq‘äØ—M‘M“O |Ñ3Ýrôô 1°¸%¿,¹,ÈÏÉÓT�Ø˜GŸLšLÐC¨$ÐC°ÐC¸aÐCÀÓCÕC×HÑHÈÐUYÐHÓZˆDà�{Š{Ð5˜DÐ5 ,Ð5°Ð5°1Ó5Ð5r   r*   )NFgš™™™™™¹?F)N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r?   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r    r   s   @@r   r   r      s%   ù‡ € ñC÷J'õ '÷6÷ 6ò 6r   r   )Útypingr   r   r   r8   r   Ú&kornia.augmentation._2d.intensity.baser   Úkornia.colorr   Úkornia.core.checkr	   Úkornia.core.utilsr
   r   © r   r   Ú<module>rO      s.   ð÷$ 'Ñ &ã Ý å NÝ )Ý *Ý 4ôb6Ð1ö b6r   