code: def replace_luminance(self, luminance):
          
          if self.is_empty():
              return
  
          if luminance.shape != self.channels[0].shape:
              if ((luminance.shape[0] * 1.0 / luminance.shape[1]) ==
                      (self.channels[0].shape[0] * 1.0 / self.channels[0].shape[1])):
                  if luminance.shape[0] > self.channels[0].shape[0]:
                      self.resize(luminance.shape)
                  else:
                      raise NameError("Luminance smaller than the image !")
              else:
                  raise NameError("Not the good shape !")
  
          mode = self.mode
          if mode.endswith("A"):
              self.convert("YCbCrA")
              self.channels[0] = luminance
              self.convert(mode)
          else:
              self.convert("YCbCr")
              self.channels[0] = luminance
              self.convert(mode)
docs: Replace the Y channel of the image by the array *luminance*. If the
          image is not in YCbCr mode, it is converted automatically to and
          from that mode.