示例#1
0
def make_thin(im):
    loaded = utils.load_image(im)
    utils.apply_to_each_pixel(loaded, lambda x: 0.0 if x > 10 else 1.0)
    print "loading phase done"

    t1 = [[1, 1, 1], [0, 1, 0], [0.1, 0.1, 0.1]]
    t2 = utils.transpose(t1)
    t3 = reverse(t1)
    t4 = utils.transpose(t3)
    t5 = [[0, 1, 0], [0.1, 1, 1], [0.1, 0.1, 0]]
    t7 = utils.transpose(t5)
    t6 = reverse(t7)
    t8 = reverse(t5)

    thinners = [t1, t2, t3, t4, t5, t6, t7]

    usage = True
    while(usage):
        usage = apply_all_structures(loaded, thinners)
        print "single thining phase done"

    print "thining done"

    utils.apply_to_each_pixel(loaded, lambda x: 255.0 * (1 - x))
    utils.load_pixels(im, loaded)
    im.show()
示例#2
0
def make_thin(im):
    loaded = utils.load_image(im)
    utils.apply_to_each_pixel(loaded, lambda x: 0.0 if x > 10 else 1.0)
    print("loading phase done")

    t1 = [[1, 1, 1], [0, 1, 0], [0.1, 0.1, 0.1]]
    t2 = utils.transpose(t1)
    t3 = reverse(t1)
    t4 = utils.transpose(t3)
    t5 = [[0, 1, 0], [0.1, 1, 1], [0.1, 0.1, 0]]
    t7 = utils.transpose(t5)
    t6 = reverse(t7)
    t8 = reverse(t5)

    thinners = [t1, t2, t3, t4, t5, t6, t7]

    usage = True
    while (usage):
        usage = apply_all_structures(loaded, thinners)
        print("single thining phase done")

    print("thining done")

    utils.apply_to_each_pixel(loaded, lambda x: 255.0 * (1 - x))
    utils.load_pixels(im, loaded)
    im.show()
示例#3
0
    out_arr = np.rot90(out_arr, k=3)
    out_arr = np.fliplr(out_arr)
    save_pixels(path_to_outfile, out_arr.astype(np.int8))


parser = argparse.ArgumentParser()
parser.add_argument("--target_image", type=str, action="store", help="Path to the image file we'll be trying to learn", required = True)
parser.add_argument("--model_output_root", type=str, action="store", help="root of name for various save files", default = "facepaint_out_")
parser.add_argument("--pixels", type=int, action="store", default=256, help="Input image will be resampled to this size.  Easy way to control training time.")
parser.add_argument("--batch_size", type=int, action="store", default=32, help="Size of batch of samples used to update weights at each step")
parser.add_argument("--epochs", type=int, action="store", default=1000, help="Number of passes to take through the training data")
parser.add_argument("--mask", type=str, action="store", help="A greyscale image that tells us which parts of the target are more important.", required=False)
args = parser.parse_args()

image_matrix = load_pixels(args.target_image, args.pixels, args.pixels)
mask_matrix = None
if args.mask == None:
    # Give all pixels equal weight if no mask specified
    mask_matrix = np.ones(shape=image_matrix.shape)
else:
    mask_matrix = load_pixels(args.mask, args.pixels, args.pixels)

X,Y = map_imagematrix_to_tuples(image_matrix)

model = Sequential()

# Inputs: x and y => 2 dimensions
model.add(Dense(20, input_dim=2, activation="relu"))

# Adding more layers will give better results. Don't be shy - try doubling!
示例#4
0
    help="Size of batch of samples used to update weights at each step")
parser.add_argument("--epochs",
                    type=int,
                    action="store",
                    default=1000,
                    help="Number of passes to take through the training data")
parser.add_argument(
    "--mask",
    type=str,
    action="store",
    help=
    "A greyscale image that tells us which parts of the target are more important.",
    required=False)
args = parser.parse_args()

image_matrix = load_pixels(args.target_image, args.pixels, args.pixels)
mask_matrix = None
if args.mask == None:
    # Give all pixels equal weight if no mask specified
    mask_matrix = np.ones(shape=image_matrix.shape)
else:
    mask_matrix = load_pixels(args.mask, args.pixels, args.pixels)

X, Y = map_imagematrix_to_tuples(image_matrix)

model = Sequential()

# Inputs: x and y => 2 dimensions
model.add(Dense(20, input_dim=2, activation="relu"))

# Adding more layers will give better results. Don't be shy - try doubling!