code: def _compute_luts(
      tiles_x_im: torch.Tensor,
      num_bins: int = 256,
      clip: float = 40.0,
      diff: bool = False,
  ) -> torch.Tensor:
      r"""Compute luts for a batched set of tiles.
  
      Same approach as in OpenCV (https://github.com/opencv/opencv/blob/master/modules/imgproc/src/clahe.cpp)
  
      Args:
          tiles_x_im: set of tiles per image to apply the lut. (B, GH, GW, C, TH, TW)
          num_bins: number of bins. default: 256
          clip: threshold value for contrast limiting. If it is 0 then the clipping is disabled.
          diff: denote if the differentiable histagram will be used. Default: False
  
      Returns:
          Lut for each tile (B, GH, GW, C, 256).
      """
      if tiles_x_im.dim() != 6:
          raise AssertionError("Tensor must be 6D.")
  
      b, gh, gw, c, th, tw = tiles_x_im.shape
      pixels: int = th * tw
      tiles: torch.Tensor = tiles_x_im.view(
          -1, pixels
      )  # test with view  # T x (THxTW)
      if not diff:
          if torch.jit.is_scripting():
              histos = torch.stack(
                  [
                      _torch_histc_cast(
                          tile, bins=num_bins, min=0, max=1
                      )
                      for tile in tiles
                  ]
              )
          else:
              histos = torch.stack(
                  list(map(_my_histc, tiles, [num_bins] * len(tiles)))
              )
      else:
          bins: torch.Tensor = torch.linspace(
              0, 1, num_bins, device=tiles.device
          )
          histos = histogram(tiles, bins, torch.tensor(0.001)).squeeze()
          histos *= pixels
  
      if clip > 0.0:
          max_val: float = max(clip * pixels // num_bins, 1)
          histos.clamp_(max=max_val)
          clipped: torch.Tensor = pixels - histos.sum(1)
          residual: torch.Tensor = torch.remainder(clipped, num_bins)
          redist: torch.Tensor = (clipped - residual).div(num_bins)
          histos += redist[None].transpose(0, 1)
          # trick to avoid using a loop to assign the residual
          v_range: torch.Tensor = torch.arange(
              num_bins, device=histos.device
          )
          mat_range: torch.Tensor = v_range.repeat(histos.shape[0], 1)
          histos += mat_range < residual[None].transpose(0, 1)
  
      lut_scale: float = (num_bins - 1) / pixels
      luts: torch.Tensor = torch.cumsum(histos, 1) * lut_scale
      luts = luts.clamp(0, num_bins - 1)
      if not diff:
          luts = (
              luts.floor()
          )  # to get the same values as converting to int maintaining the type
      luts = luts.view((b, gh, gw, c, num_bins))
      return luts
  
file_path: kornia/kornia/enhance/equalization.py
imports: import math
  from typing import Tuple
  import torch
  import torch.nn.functional
  from kornia.utils.helpers import _torch_histc_cast
  from kornia.utils.image import perform_keep_shape_image
  from .histogram import histogram
label_desc: Use image node_id 4 for calling a global function with example usage: _compute_luts(tiles_x_im, num_bins, clip, diff) and returns: luts