class_docstr: Randomly adjust image color balance. Operates on raw arrays (not tensors).
  
  Parameters
  ----------
  magnitude : float
      randomly choose color balance enhancement factor on [max(0, 1-magnitude), 1+magnitude]
  p : float
      probability to apply saturation
class_docstr_tok: ["Randomly","adjust","image","color","balance",".","Operates","on","raw","arrays","(","not","tensors",")",".","Parameters","--","--","--","--","--","magnitude",":","float","randomly","choose","color","balance","enhancement","factor","on","[","max","(","0",",","1-magnitude",")",",","1+magnitude","]","p",":","float","probability","to","apply","saturation"]
code: def generate_code(self):
      my_range = Compiler.get_iterator()
      p = self.p
      magnitude = self.magnitude
  
      def saturation(images, *_):
          def blend(img1, img2, ratio):
              return (
                  (ratio * img1 + (1 - ratio) * img2)
                  .clip(0, 255)
                  .astype(img1.dtype)
              )
  
          apply_saturation = np.random.rand(images.shape[0]) < p
          magnitudes = np.random.uniform(
              max(0, 1 - magnitude), 1 + magnitude, images.shape[0]
          )
          for i in my_range(images.shape[0]):
              if apply_saturation[i]:
                  r, g, b = (
                      images[i, :, :, 0],
                      images[i, :, :, 1],
                      images[i, :, :, 2],
                  )
                  l_img = (0.2989 * r + 0.587 * g + 0.114 * b).astype(
                      images[i].dtype
                  )
                  l_img3 = np.zeros_like(images[i])
                  for j in my_range(images[i].shape[-1]):
                      l_img3[:, :, j] = l_img
                  images[i] = blend(images[i], l_img3, magnitudes[i])
  
          return images
  
      saturation.is_parallel = True
      return saturation
  
imports: import numpy
  from dataclasses import replace
  from ..pipeline.allocation_query import AllocationQuery
  from ..pipeline.operation import Operation
  from ..pipeline.state import State
  from ..pipeline.compiler import Compiler
label_desc: Use image node_id 2 for calling the RandomSaturation obj's underlying member method code with example usage: obj.generate_code() and returns: saturation, images, unknown