code: def _apply_gamma_correction(dicom_dataset):
      d_min = 0
      d_max = 255
      bpp = dicom_dataset.BitsAllocated
      spp = dicom_dataset.SamplesPerPixel
      if "WindowCenter" in dicom_dataset:
          win_center = float(dicom_dataset.WindowCenter)
      else:
          win_center = (1 << bpp) / 2
      if "WindowWidth" in dicom_dataset:
          win_width = float(dicom_dataset.WindowWidth)
      else:
          win_width = 1 << bpp
      ################ NCTB #######
      if "PhotometricInterpretation" in dicom_dataset:
          photo_interpretation = dicom_dataset.PhotometricInterpretation
      else:
          photo_interpretation = "MONOCHROME2"
  
      if "RescaleSlope" in dicom_dataset:
          rescale_slope = float(dicom_dataset.RescaleSlope)
      else:
          rescale_slope = 1.0
  
      if "RescaleIntercept" in dicom_dataset:
          rescale_intercept = float(dicom_dataset.RescaleIntercept)
      else:
          rescale_intercept = 0
      ############################
      win_max = win_center + 0.5 * win_width - 0.5
      win_min = win_max - win_width - 0.5
      range = max(win_max - win_min, 1)
      factor = (d_max - d_min) / range
      img = np.array(dicom_dataset.pixel_array)
      dtype = img.dtype
      if photo_interpretation == "MONOCHROME1":
          img = (1 << bpp) - (img * rescale_slope + rescale_intercept)
          img = img.astype(dtype)
      else:
          img = (img * rescale_slope + rescale_intercept).astype(dtype)
      dest = np.zeros_like(img).astype(np.uint8)
      dest[img <= win_min] = d_min
      dest[img > win_max] = d_max
      dest[(win_min < img) & (img <= win_max)] = (
          img[(win_min < img) & (img <= win_max)] - win_min
      ) * factor + d_min
      if spp == 1:
          rgb_img = np.stack([dest, dest, dest], axis=2)
      else:
          rgb_img = dest
      return rgb_img
  
file_path: nnabla/python/src/nnabla/utils/image_utils/backend_events/dicom_backend.py
imports: from __future__ import absolute_import, division
  import numpy
  import pydicom
  from .common import _imread_before, _imread_after
  from .image_utils_backend import ImageUtilsBackend
label_desc: Use image node_id 1 for calling a global function with example usage: _apply_gamma_correction(dicom_dataset) and returns: rgb_img