Esempio n. 1
0
def process_subimage(subimage_list,kernel_width,sigma_range,sigma_domain,filter_itr):
    """
    input:
        kernel_width : size of kernel
        subimage_list: list of inpainted regions of image
        sigma_range  : variation across intensity
        sigma_domain : variation across distance
        filter_itr   : inpainting iterations on damaged regions
    output:
        inpainted subimages with restored damaged regions
    """
    logger.debug("processing damaged regions")
    for element in range(len(subimage_list)):
        subimage = subimage_list[element][0]
        for i in range(filter_itr):
            subimage = common_cv.apply_bilateral_filter(subimage,kernel_width,sigma_range,sigma_domain)
        subimage_list[element][0] = subimage
    logger.info("Processing done for damaged regions")
    return subimage_list   
Esempio n. 2
0
def draw_freehand(event,x,y,flags,param):
    """
    input:
        event : captures every mouse event
        x,y   : x,y coordinate of pixel under curser
    action:
        adds the selected damaged pixel coordinates in a set
        set is used to avoid redundant values

    """
    global ix,iy,is_drawing
    if event == cv.EVENT_LBUTTONDOWN:
        logger.debug("down")
        is_drawing = True
        #ix,iy = x,y
    elif event == cv.EVENT_MOUSEMOVE:
        logger.debug("move")
        if is_drawing == True:
            cv.circle(img,(x,y),1,(0,0,255),-1)
    elif event == cv.EVENT_LBUTTONUP:
        is_drawing = False
    if is_drawing:
        image_global_points.add((y,x))
Esempio n. 3
0
def apply_bilateral_filter(img, diameter, sigma_intensity, sigma_domain):
    '''
    Input : 
        img => Input damaged image
        diameter => kernel size, window size
        sigma_intensity => variance for range
        sigma_domain => variance for domain
    Ouput : Bilateral inpainted filtered image
    '''
    row = img.shape[0]
    col = img.shape[1]
    filtered_img = np.copy(img)
    r = diameter // 2
    # calculating x,y distance from center pixel locations for w1(x,y)
    x, y = np.meshgrid(np.arange(2 * r + 1) - r, np.arange(2 * r + 1) - r)
    # Applying gaussian for domain w1(x,y)
    kernel_s = gaussian((x * x + y * y), sigma_domain)
    logger.info("Calculated Gaussian for w1(x,y) of domain")
    for x in range(r, row - r):
        for y in range(r, col - r):

            if img.ndim == 3:
                logger.debug("Image type is RGB")
                # Identifying k*k size neighbourhood for all channels with center pixel location x,y
                tmp_r = img[x - r:x + r + 1, y - r:y + r + 1, 0]
                tmp_g = img[x - r:x + r + 1, y - r:y + r + 1, 1]
                tmp_b = img[x - r:x + r + 1, y - r:y + r + 1, 2]

                # calculating direction & gradient of image and applying Gaussian to get w2(x,y)
                grad = gradient(img[x - r:x + r + 1, y - r:y + r + 1],
                                diameter, x, y)
                logger.info(
                    "Calculated the dot product of p_direction and gradient vector"
                )
                kernel_r = gaussian(grad, sigma_intensity)
                logger.info("Calculated Gaussian for w2(x,y) of range")

                # Calculating weight w(x,y) = w1(x,y)*w2(x,y)
                wgt = (kernel_r[:, :, 0]) + (
                    kernel_r[:, :, 1]) + (kernel_r[:, :, 2]) * kernel_s
                logger.info("Calculated weights w(x,y) = w1(x,y)*w2(x,y)")

                # Changing the center pixel of neighbourhood for all channels
                # filtered image = summation of w(x,y)I(x,y) / summation of w(x,y)
                filtered_img[x, y, 0] = np.sum(wgt * tmp_r) / np.sum(wgt)
                filtered_img[x, y, 1] = np.sum(wgt * tmp_g) / np.sum(wgt)
                filtered_img[x, y, 2] = np.sum(wgt * tmp_b) / np.sum(wgt)
                logger.info(
                    "Updated the intensities of center pixel for all channels")

            elif img.ndim == 2:
                logger.debug("Image type is Grayscale")
                # Identifying k*k size neighbourhood for all channels with center pixel location x,y
                tmp_r = img[x - r:x + r + 1, y - r:y + r + 1]

                # calculating direction & gradient of image and applying Gaussian to get w2(x,y)
                grad = gradient(img[x - r:x + r + 1, y - r:y + r + 1],
                                diameter, x, y)
                logger.info(
                    "Calculated the dot product of p_direction and gradient vector"
                )
                kernel_r = gaussian(grad, sigma_intensity)
                logger.info("Calculated Gaussian for w2(x,y) of range")

                # Calculating weight w(x,y) = w1(x,y)*w2(x,y)
                wgt = (kernel_r * kernel_s)
                logger.info("Calculated weights w(x,y) = w1(x,y)*w2(x,y)")

                # Changing the center pixel of neighbourhood
                # filtered image = summation of w(x,y)I(x,y) / summation of w(x,y)
                filtered_img[x, y] = np.sum(wgt * tmp_r) / np.sum(wgt)
                logger.info(
                    "Updated the intensities of center pixel for all channels")

    return filtered_img