def read_images(fpath):
    lines = utils.read_image_list(fpath)

    logger.info('loading data: {}'.format(fpath))
    X_data, y_data = [], []
    for inst_path, truth_path in lines:
        inst, truth = [cv2.imread(p, cv2.IMREAD_GRAYSCALE)
                for p in (inst_path, truth_path)]
        assert inst is not None and truth is not None, (inst_path, truth_path)

        pad_h, pad_w = [x / 2 for x in MODEL_INPUT_SHAPE]
        padded = cv2.copyMakeBorder(inst, pad_h, pad_h, pad_w, pad_w,
                               cv2.BORDER_REFLECT)

        m7  = cv2.medianBlur(padded, 7)
        m15 = cv2.medianBlur(padded, 15)

        c7 = 255 - cv2.subtract(m7, padded)
        c15 = 255 - cv2.subtract(m15, padded)

        # (c, h, w) layout
        input = np.array((padded, m7, m15, c7, c15))
        truth = truth.reshape((1,) + truth.shape)

        # pad input image
        X_data.append(input)
        y_data.append(truth)

    return X_data, y_data
def read_images(fpath):
    lines = utils.read_image_list(fpath)

    is_train = os.path.basename(fpath) == 'train.list'

    logger.info('loading data: {}'.format(fpath))
    X_data, y_data = [], []
    for inst_path, truth_path in lines:
        inst, truth = [cv2.imread(p, cv2.IMREAD_GRAYSCALE)
                for p in (inst_path, truth_path)]
        assert inst is not None and truth is not None, (inst_path, truth_path)

        pad_h, pad_w = [x / 2 for x in MODEL_INPUT_SHAPE]
        # pad input image
        inst = cv2.copyMakeBorder(inst, pad_h, pad_h, pad_w, pad_w,
                               cv2.BORDER_REFLECT)
        truth_padded = cv2.copyMakeBorder(truth, pad_h, pad_h, pad_w, pad_w,
                               cv2.BORDER_REFLECT)

        X_data.append(inst)
        y_data.append(truth)

        if is_train:
            insts = generate_data(truth_padded)

            for i in insts:
#                 cv2.imshow('', i)
#                 cv2.waitKey(0)
                X_data.append(i)
                y_data.append(truth)

    return X_data, y_data
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--image_list', required=True)
    parser.add_argument('--config', required=True)
    parser.add_argument('--dump_prefix', required=True)
    parser.add_argument('--output_dir', required=True)
    args = parser.parse_args()

    conf_mod = imp.load_source('config', args.config)
    config = conf_mod.get()

    model = config['model']
    utils.load_model(model, args.dump_prefix)

    X, _ = conf_mod.get_data(args.image_list)

    utils.mkdir_p(args.output_dir)
    image_list = utils.read_image_list(args.image_list)

    logger.info('compiling model ...')
    model.compile(loss='mean_squared_error', optimizer=Adam())

    for x, (input_path, _) in ProgressBar()(zip(X, image_list)):
        y = model.predict(np.array([x], dtype='float32'),
                               batch_size=1, verbose=False)
        img = np.round(y.reshape(y.shape[2:]) * 255.0).astype('uint8')

        # FIXME: we assume that basenames of images are distinct
        fname = os.path.basename(input_path)
        output_path = os.path.join(args.output_dir, fname)
        cv2.imwrite(output_path, img)
Beispiel #4
0
def GetImage(image_path):

    #Get the images from the path of image
    list_file = read_image_list(image_path)
    list_file.sort(compare)

    image_array = getShapeForData(list_file)

    return image_array
def get_bgimg_pool():
    global _bgimgs
    if _bgimgs is None:
        list_path = os.path.join(DATA_DIR, 'background.list')
        paths = sum(utils.read_image_list(list_path), [])
        _bgimgs = [cv2.imread(p, cv2.IMREAD_GRAYSCALE) for p in paths]
        _bgimgs = filter(lambda x: x is not None, _bgimgs)
        logger.info('{} background images'.format(len(_bgimgs)))

    return _bgimgs
def read_images(fpath):
    lines = utils.read_image_list(fpath)

    logger.info("loading data: {}".format(fpath))
    X_data, y_data = [], []
    for inst_path, truth_path in lines:
        inst, truth = [cv2.imread(p, cv2.IMREAD_GRAYSCALE) for p in (inst_path, truth_path)]
        assert inst is not None and truth is not None, (inst_path, truth_path)

        pad_h, pad_w = [x / 2 for x in MODEL_INPUT_SHAPE]
        inst = cv2.copyMakeBorder(inst, pad_h, pad_h, pad_w, pad_w, cv2.BORDER_REFLECT)
        # pad input image
        X_data.append(inst)
        y_data.append(truth)

    return X_data, y_data
def read_images(fpath):
    lines = utils.read_image_list(fpath)

    logger.info('loading data: {}'.format(fpath))
    X_data, y_data = [], []
    for inst_path, truth_path in lines:
        inst, truth = [cv2.imread(p, cv2.IMREAD_GRAYSCALE)
                for p in (inst_path, truth_path)]
        assert inst is not None and truth is not None, (inst_path, truth_path)

        pad_h, pad_w = [x / 2 for x in MODEL_INPUT_SHAPE]
        padded = cv2.copyMakeBorder(inst, pad_h, pad_h, pad_w, pad_w,
                               cv2.BORDER_REFLECT)
        truth = truth.reshape((1,) + truth.shape)

        for img in [padded] + [augment(padded) for _ in range(10)]:
            input = gen_multi_channel(img)

            X_data.append(input)
            y_data.append(truth)

    return X_data, y_data
def read_images(fpath):
    lines = utils.read_image_list(fpath)

    is_train = os.path.basename(fpath) == 'train.list'

    logger.info('loading data: {}'.format(fpath))
    X_data, y_data = [], []
    for inst_path, truth_path in lines:
        inst, truth = [cv2.imread(p, cv2.IMREAD_GRAYSCALE)
                for p in (inst_path, truth_path)]
        assert inst is not None and truth is not None, (inst_path, truth_path)

        pad_h, pad_w = [x / 2 for x in MODEL_INPUT_SHAPE]
        # pad input image
        padded = cv2.copyMakeBorder(inst, pad_h, pad_h, pad_w, pad_w,
                               cv2.BORDER_REFLECT)
        truth_padded = cv2.copyMakeBorder(truth, pad_h, pad_h, pad_w, pad_w,
                               cv2.BORDER_REFLECT)

        truth = truth.reshape((1,) + truth.shape)

        input = gen_multi_channel(augment(padded))

        X_data.append(input)
        y_data.append(truth)

        if is_train:
            insts = generate_data(truth_padded)

            for i in insts:
                input = gen_multi_channel(augment(i))
#                 for c in range(5):
#                     cv2.imshow(str(c), input[c])
#                 cv2.waitKey(0)
                X_data.append(input)
                y_data.append(truth)

    return X_data, y_data