Ejemplo n.º 1
0
def main():
    global img_list
    global gmap
    global weight

    img_list = utils.read_images("../../test_data/cafe", N, downsample=3)
    full_img_list = utils.read_images("../../test_data/cafe", N)
    gray_imgs = utils.read_images("../../test_data/cafe", N, gray=True)
    x0 = np.full(N, 1.0/N)

    (gmap, weight) = gradient_map(gray_imgs)

    bnds = []
    for i in range(len(img_list)):
        bnds.append((0, 1))

    lambdas = minimize(edge_light, x0, method='TNC', jac=False,
                       bounds=bnds)

    ret_image = sum_images(lambdas.x, full_img_list)
    print lambdas.message
    print "Choice of lambdas = %s" % (lambdas.x)

    cv2.imwrite('output_edge.png', utils.denormalize_img(ret_image))
    cv2.imshow('image', ret_image)
    cv2.waitKey(0)
def diffuse_light(directory, output, count=-1, downsample=0, verbose=False):
    """
    This function calculates the fill light of the images.

    Arguments:
    directory -- the directory where the images are located
    count     -- the number of imags to use for this calculation
    verbose   -- should we print debug info
    """
    img_list = utils.read_images(directory, count)
    d_img_list = utils.read_images(directory, count, downsample=downsample)
    basis = basis_lights.BasisLights(img_list, verbose=verbose,
                                     downsampled=d_img_list)
    res_image = basis.diffuse_color()
    cv2.imwrite(output, utils.denormalize_img(res_image))
    cv2.imshow('Diffuse color light', res_image)
    cv2.waitKey(0)
def soft_modifier(directory, output, sigma, count=-1, verbose=False):
    """
    This function calculates the soft lightning modifier for an image.

    Arguments:
    directory -- the directory where the images are located
    sigma     -- determines how far the lights get diffused
    count     -- the number of imags to use for this calculation
    verbose   -- should we print debug info
    """
    img_list = utils.read_images(directory, count, normalize=False)
    modifier = modifier_lights.ModifierLights(img_list, verbose=verbose)
    res_image = modifier.soft(sigma)
    cv2.imwrite(output, res_image)
    cv2.imshow('Soft modifier', res_image)
    cv2.waitKey(0)
    #path_patches='../DATA_GHANA/RAW_PATCHES/120_x_120/'
    path_patches = sys.argv[2]
    if not os.path.exists(path_patches):
        os.makedirs(path_patches)

    for i in range(3, len(sys.argv)):
        arg = sys.argv[i]
        if arg.startswith('--width_patch'):
            WIDTH = int(arg[len('--width_patch='):])
            STRIDE = WIDTH

    #patch_test_number=300
    ## Panchromatic
    panchromatic_file = path + NAME_PANCHRO
    panchromatic = read_images(panchromatic_file)
    hr_size = panchromatic.shape
    panchromatic = panchromatic[newaxis, :, :, newaxis]
    print('\n PANCHROMATIC \n\n')
    panchromatic = extract_patches(panchromatic, WIDTH, STRIDE)

    ## Find patches to discard
    keep = np.arange(len(panchromatic))
    discard = []
    print('Original size of the dataset is %d' % len(panchromatic))
    for i in range(len(panchromatic)):
        if (np.sum(panchromatic[i, :, :, :])).astype(int) == 0:
            discard.append(i)

    discard = np.asarray(discard)
    keep = np.delete(keep, discard)
    #path_patches='../DATA_GHANA/RAW_PATCHES/120_x_120/'
    path_patches=sys.argv[2]
    if not os.path.exists(path_patches):
            os.makedirs(path_patches)
    
    
    for i in range(3, len(sys.argv)):
        arg = sys.argv[i]
        if arg.startswith('--width_patch'):
            WIDTH=int(arg[len('--width_patch='):])
            STRIDE=WIDTH
    
    #patch_test_number=300
     ## Panchromatic
    panchromatic_file=path+NAME_PANCHRO
    panchromatic=read_images(panchromatic_file)
    hr_size=panchromatic.shape
    panchromatic=panchromatic[newaxis,:,:,newaxis]
    print('\n PANCHROMATIC \n\n')
    panchromatic=extract_patches(panchromatic,WIDTH,STRIDE)
    
    ## Find patches to discard
    keep=np.arange(len(panchromatic))
    discard=[]
    print('Original size of the dataset is %d'%len(panchromatic))
    for i in range(len(panchromatic)):
        if (np.sum(panchromatic[i,:,:,:])).astype(int)==0:
            discard.append(i)

    discard=np.asarray(discard)
    keep=np.delete(keep,discard)
Ejemplo n.º 6
0
def main():
    # px1 = np.array([0, 126, 255], dtype=float)
    # px2 = np.array([0, 0, 0], dtype=float)
    global img_list
    img_list = utils.read_images("../../test_data/cafe", N, downsample=4)

    full_img_list = utils.read_images("../../test_data/cafe", N)

    # for i in range(0, N):
    #     # img_name = "../../../input_image/cafe/images/%03d.png" % (i)
    #     img_name = "../test_data/cafe/%03d.png" % (i)
    #     img = cv2.imread(img_name)
    #     img_list.append(utils.normalize_img(img))
    #     # img_list.append(img)

    # print alpha(10, 10)
    # print px_avg(400, 500)
    # print px_avg(img_list, 0, 0)
    # px1 = np.ndarray(shape=(3, 1), dtype=float,
    # buffer=np.array([0, 126, 255]))
    # px2 = np.ndarray(shape=(1, 3), dtype=float,
    #                  buffer=np.array([[255], [0], [128]]))
    # diffuse_color(1)

    x0 = np.full(N, 1.0/N)
    # print fprime(x0)
    # print x0
    # print diffuse_color(x0)
    # x0 = np.zeros(N)
    # print diffuse_color(x1)

    # x0 = np.ones(N)
    # print diffuse_color(x2)

    
    # results = pyipopt.fmin_unconstrained(diffuse_color, x0, fprime)

    # print results

    # nlp = pyipopt.create(diffuse_color, N)
    # x, zl, zu, constraint_multipliers, obj, status = nlp.solve(x0)

    # nlp.close()

    # leastsq(diffuse_color, x0)

    bnds = []
    for i in range(len(img_list)):
        bnds.append((0, 1))


    lambdas = minimize(diffuse_color, x0, method='TNC', jac=False,
                       bounds=bnds)

    # lambdas = np.array([ 0.0772488 ,  0.07700344,  0.0769977 ,  0.07699107,  0.07702644,
    #     0.07702589,  0.07702531,  0.07694187,  0.07695671,  0.07701653,
    #     0.07696243,  0.07767547,  0.07693373])

    # lambdas = np.array([ 0.03336186,  0.03335751,  0.03336186,  0.03336186,  0.03335691,
    #     0.03336186,  0.03335623,  0.03335545,  0.03336186,  0.03316012,
    #     0.03336186,  0.03332896,  0.03336186,  0.03336186,  0.03335172,
    #     0.03335502,  0.03336186,  0.03336186,  0.03335585,  0.03333409,
    #     0.03335658,  0.03335828,  0.03335722,  0.03335778,  0.03336186,
    #     0.03335804,  0.03336186,  0.03335251,  0.03332677,  0.0333048 ])
    # print("lambda: %s" % lambdas)
    ret_image = sum_images(lambdas.x, full_img_list)
    print lambdas.message
    print "Choice of lambdas = %s" % (lambdas.x)
    cv2.imwrite('output_diffuse.png', utils.denormalize_img(ret_image))
    cv2.imshow('image', ret_image)
    cv2.waitKey(0)