예제 #1
0
파일: mosaic.py 프로젝트: enricapq/picLab
def create_dataset(dataset_folder, thumbs_folder, ext, num_clusters, thumb_size):
    for pathfile in glob.iglob(dataset_folder + '/**/*', recursive=True):
        filename = basename(pathfile)
        if filename.endswith(tuple(ext)):
            image = image_utils.open_image(pathfile, "RGB")
            color, image = dominant_color.find_dominant_color_and_generate_thumb(image, filename, thumbs_folder,
                                                                                 num_clusters, thumb_size, True)
            dataset_thumbs.write_pic(color.red, color.green, color.blue, filename)
    return True
예제 #2
0
파일: core.py 프로젝트: enricapq/picLab
def get_candidate_image(candidate_images, thumbs_folder):
    """
    :param candidate_images: array of filename
    :param thumbs_folder: folder containing thumbnails
    """
    output = None
    while not output and candidate_images:
        filename_candidate = candidate_images.pop(random.randrange(len(candidate_images)))
        output = image_utils.open_image(thumbs_folder + filename_candidate, "RGB")
    return output
예제 #3
0
def to_gray_and_save_pic(uri, elaborated_folder):
    image = image_utils.open_image(uri, "RGB")
    if not image:
        return False
    else:
        if image.format == "PNG":
            image = image.convert('LA')
        else:
            image = image.convert('L')
        image_utils.save_image(image, basename(uri), elaborated_folder)
        return True
예제 #4
0
def create_dataset(dataset_folder, thumbs_folder, ext, num_clusters,
                   thumb_size):
    for pathfile in glob.iglob(dataset_folder + '/**/*', recursive=True):
        filename = basename(pathfile)
        if filename.endswith(tuple(ext)):
            image = image_utils.open_image(pathfile, "RGB")
            color, image = dominant_color.find_dominant_color_and_generate_thumb(
                image, filename, thumbs_folder, num_clusters, thumb_size, True)
            dataset_thumbs.write_pic(color.red, color.green, color.blue,
                                     filename)
    return True
예제 #5
0
    def __init__(self, path2data, path2Individual, path2postures, number_sequences, size, use_memory, number_data, transforms_target_label=None, transforms_individual=None):
        self.sequence_number = number_sequences
        self.size = size
        self.transforms_target_label = transforms_target_label
        self.transforms_individual = transforms_individual
        self.use_memory = use_memory
        self.target_path, self.label_path = self.get_target_label_path(path2data, path2Individual, path2postures, number_data)
        self.path2Image_map = {}

        if use_memory:
            path2Individual = os.path.join(path2data, path2Individual)
            path2postures = os.path.join(path2data, path2postures)

            iu.folder_to_map(path2Individual, self.path2Image_map, lambda image_path: iu.open_image(image_path, self.size), depth=2)
            iu.folder_to_map(path2postures, self.path2Image_map, lambda image_path: iu.open_image(image_path, self.size), depth=2)
예제 #6
0
def to_sepia_and_save_pic(uri, elaborated_folder):
    """
    Convert before in grayscale and then in sepia
    """
    img = image_utils.open_image(uri, "RGB")
    if img:
        orig_mode = img.mode
        if orig_mode != "L":
            img = img.convert("L")
        sepia = make_linear_ramp()
        img.putpalette(sepia)
        img = img.convert(orig_mode)
        image_utils.save_image(img, basename(uri), elaborated_folder)
        return True
    else:
        return False
예제 #7
0
def resize_and_save_pic(uri, width, height, elaborated_folder):
    image = image_utils.open_image(uri, "RGB")
    image = image_utils.resize_image(image, (width,height))
    image_utils.save_image(image, basename(uri), elaborated_folder)
    return True