Applying a coloured overlay to an image in either PIL or Imagemagik

前端 未结 3 1827
自闭症患者
自闭症患者 2020-12-15 08:04

I am a complete novice to image processing, and I am guessing this is quite easy to do, but I just don\'t know the terminology.

Basically, I have a black and white im

3条回答
  •  一个人的身影
    2020-12-15 08:51

    See my gist https://gist.github.com/Puriney/8f89b43d96ddcaf0f560150d2ff8297e

    Core function via opencv is described as below.

    def mask_color_img(img, mask, color=[0, 255, 255], alpha=0.3):
        '''
        img: cv2 image
        mask: bool or np.where
        color: BGR triplet [_, _, _]. Default: [0, 255, 255] is yellow.
        alpha: float [0, 1]. 
    
        Ref: http://www.pyimagesearch.com/2016/03/07/transparent-overlays-with-opencv/
        '''
        out = img.copy()
        img_layer = img.copy()
        img_layer[mask] = color
        out = cv2.addWeighted(img_layer, alpha, out, 1 - alpha, 0, out)
        return(out)
    

    Add colored and transparent overlay on either RGB or gray image can work:

提交回复
热议问题