import code a_list =[1,2,3] another_list =["harry", "ron", "hermione"] yanother_list = [1,"harry", 3.4,"blue"] the_sum = code.my_sum(a_list) # print(the_sum) the_prod = code.my_prod(a_list) # print(the_prod) the_count = code.my_count(a_list) # print(the_count) print(code.get_filenames('C:\\Users\\JuliaMB\\Desktop\\hermine\\pythoncode')) #
from PIL import Image import code def rotate_box(an_image): box = (100, 100, 400, 400) region = an_image.crop(box) transposed = region.transpose(Image.ROTATE_180) an_image.paste(transposed, box) return an_image # to avoid repeting the codes above for every image, we can use lists --> see loops.py new_rotational_game = code.get_filenames( "C:\\Users\\vale\\Desktop\\pictures\\") for pic_name in new_rotational_game: im = Image.open(pic_name) #you have to first open the image! im = rotate_box(im) #you have to torate the im, not everylist im.show() #now i want to change the color of the image to black and white def to_grayscale(an_image): grayscale_im = an_image.convert( "L" ) #iit creates another image, so you have to reassign a new name to it and return that one return grayscale_im # now I want to create a copy of all the images, make it in grey scale and save it in the folder grayscale
from PIL import Image import code import os def rotate_box(an_image): box = (100, 100, 400, 400) region_im = an_image.crop(box) transposed_im = region_im.transpose(Image.ROTATE_180) an_image.paste(transposed_im, box) return an_image def to_grayscale(an_image): grayscale_im = an_image.convert('L') return grayscale_im pic_list = code.get_filenames("C:\\Users\\GiDo1994\\Desktop\\pictures") num = 0 for pic_name in pic_list: im = Image.open(pic_name) im = to_grayscale(im) newfilename = "pic_gray_" + str(num) + ".jpg" num = num + 1 newfullpath = os.path.join( "C:\\Users\\GiDo1994\\Desktop\\pictures\\grayscale", newfilename) im.save(newfullpath)
# im = Image.open("C:\\Users\\Counter\\Pictures\\picture1.jpg") # print(im.size) # print(im.format) # box = (100,100,400,400) # region = im.crop(box) # transposed = region.transpose(Image.ROTATE_180) # im.paste(transposed,box) # im2 = Image.open("C:\\Users\\Counter\\Pictures\\picture2.jpg") # im2 = rotate_box(im2) # im.show() # im2.show() pic_list = code.get_filenames("C:\\Users\\Counter\\Pictures\\pics") print(pic_list) # for pic_name in pic_list: # im = Image.open(pic_name) # im = rotate_box(im) def to_grayscale(an_image): grayscale_im = an_image.convert("L") return grayscale_im # im = Image.open("C:\\Users\\Counter\\Pictures\\pics\\picture1.jpg") # im = to_grayscale(im) # im.show()
import code a_list = [1, 2, 3] another_list = ["harry", "ron", "hermione"] yanother_list = [1, "harry", 3.4, "blue"] the_sum = code.my_sum(a_list) print(the_sum) the_prod = code.my_prod(a_list) print(the_prod) print(code.get_filenames('C:\\Users\\sback\\Desktop\\pythoncode'))
import code a_list = [1,2,3] b_list = [1,4,2,6,12,3,1] list_b = ["ron","hermione","harry"] list_c = [1,"harry",3,4,"blue"] the_sum = code.my_sum(a_list) print(the_sum) the_prod = code.my_prod(a_list) print(the_prod) list_length = code.length(a_list) print(list_length) the_count_1 = code.my_count_1(b_list) print(the_count_1) the_max = code.my_max(b_list) print(the_max) the_get_filenames = code.get_filenames("C:\\Users\\Counter\\Desktop\\pythoncode") print(the_get_filenames)
def rotate_box(an_image): box = (100, 100, 400, 400) region = an_image.crop(box) transposed = region.transpose(Image.ROTATE_180) an_image.paste(transposed, box) return an_image def to_grayscale(an_image): #convert to grey color grayscale_im = an_image.convert("L") return grayscale_im rotate_all_images = code.get_filenames("C:\\Users\\kadira\\Desktop\\Pictures") for pic_name in rotate_all_images: im = Image.open(pic_name) im = rotate_box(im) im.show() im = Image.open("C:\\Users\\kadira\\Desktop\\Pictures\\picture1.jpg") print(im.size) format(im.size) im = rotate_box(im) im2 = Image.open("C:\\Users\\kadira\\Desktop\\Pictures\\picture2.jpg" ) #give source for each picture im2 = rotate_box(im2)
from PIL import Image import code import os def rotate_box(an_image): box = (100, 100, 200, 200) region = an_image.crop(box) transposed = region.transpose(Image.ROTATE_180) an_image.paste(transposed, box) return an_image def to_grayscale(an_image): garyscale_im = an_image.convert('LA') return garyscale_im pic_list = code.get_filenames("C:\\Users\\Josefine\\Desktop\\pictures") num = 0 for pic_name in pic_list: im = Image.open(pic_name) im = to_grayscale(im) new_filename = "pic_gray_" + str(num) + ".jpg" num = num + 1 newfullpath = os.path.join("C:\\Users\\Josefine\\Desktop\\pictures", new_filename) im.save(newfullpath)
from PIL import Image import code import os def rotate_box(an_image): box = (100, 100, 400, 400) region_im = an_image.crop(box) transposed_im = region_im.transpose(Image.ROTATE_180) an_image.paste(transposed_im, box) return an_image def to_grayscale(an_image): grayscale_im = an_image.convert('L') return grayscale_im pic_list = code.get_filenames("C:\\Users\\sback\\Desktop\\pictures") num = 0 for pic_name in pic_list: im = Image.open(pic_name) im = to_grayscale(im) newfilename = "pic_gray_" + str(num) + ".jpg" num = num + 1 newfullpath = os.path.join( "C:\\Users\\sback\\Desktop\\pictures\\grayscale", newfilename) im.save(newfullpath)
print(the_count) #exercise 7: write a function that counts the number of items smaller than 5 the_count_less_than_5 = code.my_count_less_than_5(a) print(the_count_less_than_5) #exercise 8: write a function that counts the number of ones in a list the_count_ones = code.my_count_ones(a) print(the_count_ones) #exercise 9: write a function that gives you the max number in a list the_max = code.my_max(a) print(the_max) #exercise 10: write a function that gives the directory & names of the files in a directory the_get_filenames = code.get_filenames("C:\\Users\\vale\\Desktop\\") print(the_get_filenames) #exercise 11: concept of shallow copy: if you copy a list that has an element which is a list, then the copy you make is actually referring to the list in the list as well. # example: past it in pythontutor and see the visualization a=[1,2,["ciao", "hi"]] a[2][1]= "hola" #to change an element of the list which is a list of the list def play_with_list(a_list): print(a_list) a_list[0]: "good morning" return a_list def get_list_copy(a_list):
a = 23 b = 23 if a < b: print("You know what? It was true!") else: print("It was acutally false!") print("done") import code import os from PIL import Image pics = code.get_filenames(("C:\\Users\\IOnwusonye\\Desktop\\pictures")) num = 1 for picname in pics: im = Image.open(picname) im = code.to_grayscale(im) newfilename = "pic_gray_" + str(num) + ".jpg" num = num + 1 newfullpath = os.path.join( "C:\\Users\\IOnwusonye\\Desktop\\pictures\\grayscale", newfilename) im.save(newfullpath) #damit kann man (in diesem fall 10, kann aber auch eine beliebige andere zahl sein) 10x * auf derselben zeile anzeigen lassen for n in range(10): print("*", end="")
print(im.format) im = rotate_box(im) im2 = Image.open("C:\\Users\\Maxime Zehnder\\Desktop\\Pictures\\picture1.jpg") im2 = rotate_box(im2) im.show() im2.show() #exercise -> opem all 4 images, rotete them or make them gray import code def to_grayscale(an_image): grayscale_im = an_image.convert("L") return grayscale_im pic_list = code.get_filenames("C:\\Users\\Maxime Zehnder\\Desktop\\pictures") for pic_name in pic_list: im = Image.open(pic_name) im = rotate_box(im) #or im = to_grayscale(im) -> to make the picture gray im = to_grayscale(im) # function that turns the image gray im.show() #opening an image, turn it gray and safe it somewhere else im = Image.open("C:\\Users\\Maxime Zehnder\\Desktop\\pictures\\picture1.jpg") im = to_grayscale(im) im.show