コード例 #1
0
ファイル: scripts.py プロジェクト: vsoch/brainart
def main():
    parser = argparse.ArgumentParser(description="make images out of brain imaging data")
    parser.add_argument("--input", dest="image", help="full path to jpg image", type=str, default=None, required=True)
    parser.add_argument("--db", dest="db", help="path to folder for png images for database", type=str, default=None)
    parser.add_argument("--sample", dest="sample", help="sample every SAMPLEth pixel", type=int, default=10)
    parser.add_argument(
        "--N",
        dest="N",
        help="Number of top N brains to sample from when seleting image. Larger N means more variation in brains and color.",
        type=float,
        default=20,
    )
    parser.add_argument("--update", dest="update", help="regenerate png database", default=False, action="store_true")
    parser.add_argument("--background-color", dest="bgcolor", help="background color", type=str, default="black")
    parser.add_argument(
        "--color-lookup",
        dest="lookup",
        help="color lookup (white, black) which currently determined background color.",
        type=str,
        default="white",
    )
    parser.add_argument("--output-folder", dest="output", help="output folder for html file", type=str, default=None)

    try:
        args = parser.parse_args()
    except:
        parser.print_help()
        sys.exit(0)

    # Regenerate database of png images
    if args.update == True:
        if args.db is not None:
            get_data(args.folder)
        else:
            print "Please specify location for png images for database with --db argument"
    else:
        if args.image == None:
            print "Please specify input jpg image with --input argument."

        # Check background color
        if args.lookup not in ["black", "white"]:
            print "Unrecognized lookup table! Setting to white."
            args.lookup = "white"

        generate(
            template=args.image,
            output_folder=args.output,
            color_lookup=args.lookup,
            bgcolor=args.bgcolor,
            top=args.N,
            sample=args.sample,
        )
コード例 #2
0
ファイル: scripts.py プロジェクト: erramuzpe/brainart
def main():
    parser = argparse.ArgumentParser(
        description="make images out of brain imaging data")
    parser.add_argument("--input",
                        dest='image',
                        help="full path to jpg image",
                        type=str,
                        default=None,
                        required=True)
    parser.add_argument("--db",
                        dest='db',
                        help="path to folder for png images for database",
                        type=str,
                        default=None)
    parser.add_argument("--sample",
                        dest='sample',
                        help="sample every SAMPLEth pixel",
                        type=int,
                        default=10)
    parser.add_argument(
        "--N",
        dest='N',
        help=
        "Number of top N brains to sample from when seleting image. Larger N means more variation in brains and color.",
        type=float,
        default=20)
    parser.add_argument('--update',
                        dest='update',
                        help="regenerate png database",
                        default=False,
                        action='store_true')
    parser.add_argument("--background-color",
                        dest='bgcolor',
                        help="background color",
                        type=str,
                        default="black")
    parser.add_argument(
        "--color-lookup",
        dest='lookup',
        help=
        "color lookup (white, black) which currently determined background color.",
        type=str,
        default="white")
    parser.add_argument("--output-folder",
                        dest='output',
                        help="output folder for html file",
                        type=str,
                        default=None)

    try:
        args = parser.parse_args()
    except:
        parser.print_help()
        sys.exit(0)

    # Regenerate database of png images
    if args.update == True:
        if args.db is not None:
            get_data(args.folder)
        else:
            print "Please specify location for png images for database with --db argument"
    else:
        if args.image == None:
            print "Please specify input jpg image with --input argument."

        # Check background color
        if args.lookup not in ["black", "white"]:
            print "Unrecognized lookup table! Setting to white."
            args.lookup = "white"

        generate(template=args.image,
                 output_folder=args.output,
                 color_lookup=args.lookup,
                 bgcolor=args.bgcolor,
                 top=args.N,
                 sample=args.sample)
コード例 #3
0
lookup_table_hex = make_hexcolor_brains(brainmaps, png_folder)

# Split into black and white
lookups = dict()
exp = re.compile("white")
white_index = [x for x in lookup_table_hex.index.tolist() if exp.search(x)]
black_index = [x for x in lookup_table_hex.index.tolist() if not exp.search(x)]
lookups["white"] = lookup_table_hex.loc[white_index]
lookups["black"] = lookup_table_hex.loc[black_index]

# For each, we will save a color lookup table to package
output_folder = "/home/vanessa/Documents/Dropbox/Code/Python/mosaic"
for bgcolor, lookup_table in lookups.iteritems():

    # We already have single colors, just need to add colormap versions
    png_images = [x for x in png_colormaps if re.search(bgcolor, x)]
    lookup_table_spectrum = get_color_lookup(png_images)

    # Add the tables
    merged_lookup = lookup_table_spectrum.append(lookup_table)
    output_file = "%s/brainart/data/%s_lookup.pkl" % (output_folder, bgcolor)
    save_lookup(merged_lookup, output_file)

# Finally, we want to include these images in the package, so copy them to package
png_folder = "%s/png" % output_folder
shutil.copytree("%s/png" % download_folder, png_folder)

# Make an image from template
template = "/home/vanessa/Desktop/roman.jpg"
generate(template, color_lookup="black")
コード例 #4
0
ファイル: make_mosaic.py プロジェクト: vsoch/brainart
lookup_table_hex = make_hexcolor_brains(brainmaps, png_folder)

# Split into black and white
lookups = dict()
exp = re.compile("white")
white_index = [x for x in lookup_table_hex.index.tolist() if exp.search(x)]
black_index = [x for x in lookup_table_hex.index.tolist() if not exp.search(x)]
lookups["white"] = lookup_table_hex.loc[white_index]
lookups["black"] = lookup_table_hex.loc[black_index]

# For each, we will save a color lookup table to package
output_folder = "/home/vanessa/Documents/Dropbox/Code/Python/mosaic"
for bgcolor, lookup_table in lookups.iteritems():

    # We already have single colors, just need to add colormap versions
    png_images = [x for x in png_colormaps if re.search(bgcolor, x)]
    lookup_table_spectrum = get_color_lookup(png_images)

    # Add the tables
    merged_lookup = lookup_table_spectrum.append(lookup_table)
    output_file = "%s/brainart/data/%s_lookup.pkl" % (output_folder, bgcolor)
    save_lookup(merged_lookup, output_file)

# Finally, we want to include these images in the package, so copy them to package
png_folder = "%s/png" % output_folder
shutil.copytree("%s/png" % download_folder, png_folder)

# Make an image from template
template = "/home/vanessa/Desktop/roman.jpg"
generate(template, color_lookup="black")