Esempio n. 1
0
 def splice(self, image, mask, gan_out):
     if mask.shape[-1] > 0:
         mask = (np.sum(mask, -1, keepdims=True) < 1)
         mask = 1 - mask  # invert mask for blending
         mask = mask.astype('uint8') * 255
         mask = GaussianBlur(mask, (29, 29), 0)
         # mask_img = np.zeros([mask.shape[0], mask.shape[1],3]).astype('uint8')
         # for i in range(3):
         #     mask_img[:,:,i] = mask
         mask_img = mask.astype(float) / 255
         # proper blending courtesy of https://www.learnopencv.com/alpha-blending-using-opencv-cpp-python/
         fg_o = gan_out.astype(float)
         bg_o = image.astype(float)
         fg = np.zeros([mask.shape[0], mask.shape[1], 3]).astype(float)
         bg = np.zeros([mask.shape[0], mask.shape[1], 3]).astype(
             float
         )  # create foreground and background images with proper rgb channels
         cover = image
         for i in range(3):
             # Multiply the fg with the mask matte
             fg[:, :, i] = multiply(mask_img, fg_o[:, :, i])
             # Multiply the bg with ( 1 - mask_img )
             bg[:, :, i] = multiply(1.0 - mask_img, bg_o[:, :, i])
             # Add the masked fg and bg.
             cover[:, :, i] = add(fg[:, :, i], bg[:, :, i])
     else:
         #error case, return image
         cover = image
     return cover
Esempio n. 2
0
def field_flattening(image, filter_type="gaussian", ksize=31, sigma=101):
    """
    Function that will field flatten a single channel image
    """
    if filter_type == "gaussian":
        blurred_image = GaussianBlur(image.astype(np.uint8),
                                     ksize=(ksize, ksize),
                                     sigmaX=sigma)
    if filter_type == "median":
        blurred_image = medianBlur(image.astype(np.uint8), ksize=ksize)

    flat_image = np.divide(image.astype(float), blurred_image.astype(float))

    flat_image[np.isnan(flat_image)] = 0
    flat_image = (min_max_rescaling(flat_image)) * 255

    return flat_image