Exemple #1
0
def execute_command(command: str, new_image: Image, threshold=True) -> Image:
    """ __author__ = "Trong Nguyen"
    
    Return a new image given a valid command, an image and if required, 
    a threshold value.
    
    >>> execute_command("E", new_image, 10)    
    """
    functions = {
        "L": load,
        "S": save_as,
        "2": two_tone,
        "3": three_tone,
        "X": extreme_contrast,
        "T": sepia,
        "P": posterize,
        "E": detect_edges,
        "I": detect_edges_better,
        "V": flip_vertical,
        "H": flip_horizontal
    }

    if command == "S":
        save_as(new_image, input("Enter new filename: "))
    elif command == "2":
        tone1 = "yellow"
        tone2 = "cyan"
        new_image = two_tone(new_image, tone1, tone2)
    elif command == "3":
        tone1 = "yellow"
        tone2 = "magenta"
        tone3 = "cyan"
        new_image = three_tone(new_image, tone1, tone2, tone3)
    elif command == "E":
        if threshold:
            threshold = int(input("Enter threshold value: "))
        else:
            threshold = 10
        new_image = detect_edges(new_image, threshold)
    elif command == "I":
        if threshold:
            threshold = int(input("Enter threshold value: "))
        else:
            threshold = 10
        new_image = detect_edges_better(new_image, threshold)
    elif functions[command]:
        new_image = functions[command](new_image)
    else:
        print("\t=> No such command\n")
    return new_image
Exemple #2
0
    filterinput = input(
        "L)oad image  S)ave-as\n2)-tone  3)-tone  X)treme contrast" +
        " T)int sepia  P)osterize\nE)edge detect  I)mproved edge detect" +
        " V)ertical flip  H)orizontal flip\nQ)uit\n\n: ")

    if filterinput == "L" or filterinput == "l":
        image = copy(load_image(choose_file()))
        show(image)

    elif filterinput == "S" or filterinput == "s":
        if image is None:
            print("Please load an image")
        else:
            filename = input("Please enter a filename with the type of file" +
                             "(example: mypicture.jpg)\n: ")
            save_as(image, filename)

    elif filterinput == '2':
        if image is None:
            print("Please load an image")
        else:
            image = two_tone(image, "yellow", "cyan")
            show(image)

    elif filterinput == '3':
        if image is None:
            print("Please load an image")
        else:
            image = three_tone(image, "yellow", "magenta", "cyan")
            show(image)
COLOUR3 = "cyan"

# A list of all the possible commands
ACCEPTED_INPUTS = ["L","S","2","3","X","T","P","E","I","V","H","Q"]

# A list of all the filters.
FILTERS = [two_tone, three_tone, extreme_contrast, sepia, posterize, 
           detect_edges, detect_edges_better, flip_vertical,flip_horizontal]


while command != "Q": # Stops the program when the user enters 'Q'
    command = get_command()
    
    if command != "Q":
        if command == "L":
            original_image = open_image ()
            
        # Makes sure there is an image already selected before letting the user
        # Choose any filters
        elif original_image == None:
            print ("No image loaded")
            
        # If the user the wants to save the image it prompts them for the name    
        elif command == "S":
            save_as (original_image)
            
        else:
            original_image = apply_filter (original_image, command)
            show(original_image)

    elif filterinput == 'E' or filterinput == "e":
        image = detect_edges(image, 10)

    elif filterinput == 'I' or filterinput == "i":
        image = detect_edges_better(image, 10)

    elif filterinput == 'V' or filterinput == "v":
        image = flip_vertical(image)

    elif filterinput == 'H' or filterinput == "h":
        image = flip_horizontal(image)

    return image


file = open("batch_sample.txt", "r")
lines = file.readlines()
for line in lines:  #Goes through each line element in the lines list in the file
    commands = line.split(
        " ")  #Splits each line into a list based on the space
    image = copy(load_image(
        commands[0]))  #Define the name of the image(constant)
    filename = commands[1]  #Define the filename (constant)
    del commands[0:2]
    for filterinput in commands:  #Goes through each command in the commands list
        image = inputanalysis(filterinput, image)
    save_as(image,
            filename)  #Saves the image after every command is looked at.

file.close()
Exemple #5
0
# Main Code
# Assumptions: Cimpl.py, T64_image_filters.py, and simple_Cimpl_filters.py are
# In the same folder as this program
commands = read_file()

# Constants
THRESHOLD = 10
COLOUR1 = "yellow"
COLOUR2 = "magenta"
COLOUR3 = "cyan"

# A list of all the possible commands
ACCEPTED_INPUTS = ["L", "S", "2", "3", "X", "T", "P", "E", "I", "V", "H", "Q"]

# A list of all the filters.
FILTERS = [
    two_tone, three_tone, extreme_contrast, sepia, posterize, detect_edges,
    detect_edges_better, flip_vertical, flip_horizontal
]

for l in commands:
    # Loads the original image (first element of the line)
    original_image = load_image(l[0])

    for i in range(2, len(l)):
        # Goes through the commands and applies them to the image
        original_image = apply_filter(original_image, l[i])

    # Saves the final image (second element of the line)
    save_as(original_image, l[1])
Team identifier: 10
Contributing member(s):
    Trong Nguyen, 100848232
    Ahmed Abdellah, 101163588
    Karandev Andotra, 101141882
    Hussein Rashid, 101141962

Carleton University
ECOR 1051 Module 2 Project - Milestone 3
RELEASE = "April 2, 2020"
"""

from Cimpl import copy, load_image, save_as
from T10_user_interface import execute_command

#-----------------------------------------------------------------
# Batch User Interface Main Script

if __name__ == "__main__":

    batch_file = open(input("Enter batch filename: "))
    
    for line in batch_file:
        items = line.strip().split()
        new_image = copy(load_image(items[0]))
        for i in range(len(items)-2):
            new_image = execute_command((items[i+2]), new_image, False)
            save_as(new_image, str(items[1]))
        
    batch_file.close()
    
Exemple #7
0
def save_img() -> Tuple[bool, bool, Image]:
    """
    Prompts the user to save the image. Returns the dont_quit variable as True, image_loaded as True, and the same image that was saved.
    """
    save_as(image)
    return True, True, image