'How to increase a shadow on an Image with PIL

here's my issue. I'm trying to add a shadow on a image, i have the image of the shadow where every pixels are 1 or 0 in RGB. Only the Alpha number is different. The lowest alpha, the darker is the shadow. I did this

def print_shadow(im, shadow):
  im_pix = np.array(im)
  shadow_pix = np.array(shadow)
  shadow_pix[:, :, :3] = 1
  shadow_pix = np.multiply(shadow_pix, -1)
  shadow_pix = np.add(255, shadow_pix)
  shadow_pix = np.divide(shadow_pix, 255)
  im_pix = np.multiply(im_pix, shadow_pix)
  im_pix = np.array(im_pix).astype(np.uint8)
  return Image.fromarray(im_pix)

This function work perfectly but we're comming to the issue. I tried to add a factor to make the shadow darker or brigther. I tried to add a line (line 4)

def print_shadow(im, shadow, factor):
  im_pix = np.array(im)
  shadow_pix = np.array(shadow)
  shadow_pix[:, :, :3] = 1
  shadow_pix = np.divide(shadow_pix, factor)
  shadow_pix = np.multiply(shadow_pix, -1)
  shadow_pix = np.add(255, shadow_pix)
  shadow_pix = np.divide(shadow_pix, 255)
  im_pix = np.multiply(im_pix, shadow_pix)
  im_pix = np.array(im_pix).astype(np.uint8)
  return Image.fromarray(im_pix)

But it doesn't just increase the darkness of the shadow. Tt puts like a dark filter on the whole image, even where there's no shadow. Can someone help me ? I don't understand what's happening



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source