def thin_test(): x = np.arange(11 * 12).reshape(11, 12) print("X:") print(x) sp = ScrapBooker() a = sp.thin(x, 3, 1) print("a") print(a)
def juxtapose_test(): x = np.arange(3 * 4).reshape(3, 4) print("x:") print(x) sp = ScrapBooker() b = sp.juxtapose(x, 1, 1) c = sp.juxtapose(x, 1, 0) print("b:") print(b) print("c:") print(c)
def make_kernel(self, kernel, array, size, position): y_ = position[1] - 1 x_ = position[0] - 1 to_kernel = ScrapBooker.crop(self, array, size, position=(y_, x_)) value = kernel * to_kernel value = np.sum(value) value = value / (size[0] * size[1]) return value
def mean_blur(array, level=1): blurred = array.copy() array_red = clf.to_red(array) array_blue = clf.to_blue(array) array_green = clf.to_green(array) if (level < 1): return array.copy() size = level * 2 + 1 div = (size) * (size) for row in range(level, array.shape[0] - level): for col in range(level, array.shape[1] - level): pos = (row - level, col - level) zone = sbk.crop(array_red, (size, size), pos) blurred[row][col][0] = zone.sum() / div zone = sbk.crop(array_green, (size, size), pos) blurred[row][col][1] = zone.sum() / div zone = sbk.crop(array_blue, (size, size), pos) blurred[row][col][2] = zone.sum() / div return blurred
#!/usr/bin/python import numpy as np from ScrapBooker import ScrapBooker tst = ScrapBooker() array = np.array([list(range(6)),list(range(6, 12))]) # print(array) print(tst.mosaic(array, (2, 2)))
from ImageProcessor import ImageProcessor from ScrapBooker import ScrapBooker import numpy as np img = ImageProcessor() sb = ScrapBooker() arr = img.load("../resources/mario.jpeg") img.display(arr) cropped = sb.crop(arr, (50, 50), (100, 100)) img.display(cropped) tothin = np.array(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']) tothin = np.tile(tothin, (7, 1)) print(tothin) print("") print(sb.thin(tothin, 3, 0)) print("") tothin2 = np.transpose(tothin) print(tothin2) print("") print(sb.thin(tothin2, 4, 1)) juxta = sb.juxtapose(arr, 3, 0) img.display(juxta) juxta2 = sb.juxtapose(arr, 4, 1) img.display(juxta2) mos = sb.mosaic(arr, (2, 3)) img.display(mos)
from ImageProcessor import ImageProcessor from ScrapBooker import ScrapBooker if __name__ == "__main__": ip = ImageProcessor() sp = ScrapBooker() img = ip.load('42AI.png') # img = sp.crop(img, (100, 100), (0,0)) # ip.display(sp.crop(img, (500, 500))) # ip.display(sp.crop(img, (50, 50), (50, 50))) # ip.display(sp.crop(img, (1, 1), (199, 199))) # ip.display(sp.thin(img, 2, 0)) # ip.display(sp.thin(img, 2, 1)) # ip.display(sp.juxtapose(img, 4, 0)) # ip.display(sp.juxtapose(img, 2, 1)) # ip.display(sp.juxtapose(img, 1, 1)) # ip.display(sp.juxtapose(img, 0, 1)) ip.display(sp.mosaic(img, (4, 4)))
import numpy as np from ScrapBooker import ScrapBooker notrand_array = np.array(range(25)).reshape((5, 5)) print(notrand_array) print(notrand_array.shape) #print(rand_array) sb = ScrapBooker() new_array = sb.crop(notrand_array, (3, 3), (1, 2)) print(new_array) print(new_array.shape) print(sb.juxtapose(notrand_array, 2, 1)) print(sb.mosaic(notrand_array, (2, 3)))
from ScrapBooker import ScrapBooker import matplotlib.pyplot as plt r = ScrapBooker() #img = open("../resources/42AI.png", "") imgn = plt.imread("../resources/small_img_1.png") #plt.imshow(imgn) #plt.show() imgn = r.mosaic(imgn, (8, 8)) plt.imshow(imgn) plt.show()
from ScrapBooker import ScrapBooker import numpy as np import matplotlib #from PIL import Image img = ScrapBooker() data_img = img.load("42AI.png") ###################### #img.display(img.crop(data_img, 100, (250, 250))) ####################### arr = np.array([['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '1'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '2'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '3'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '4'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '5'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '6'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '7'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '8'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '9'], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', '10']]) #arr = img.thin(arr, 3, 1) #print(arr) ###################### #juxtaposed_v = ScrapBooker.juxtapose(data_img, 3, 0) #juxtaposed_h = ScrapBooker.juxtapose(data_img, 3, 1) #img.display(juxtaposed_v) #img.display(juxtaposed_h) ##################### mosaic = ScrapBooker.mosaic(data_img, (6, 6)) img.display(mosaic)
#!/usr/bin/env python3 from ImageProcessor import ImageProcessor from ScrapBooker import ScrapBooker imp = ImageProcessor() sb = ScrapBooker() arr = imp.load("../resources/42AI.png") print('size before:', arr.shape) # arr = sb.thin(arr, 3, 1) # arr = sb.crop(arr, (80, 80), (50, 50)) # arr = sb.crop(arr, (800, 80), (50, 50)) # arr = sb.juxtapose(arr, 3, 1) arr = sb.mosaic(arr, (2, 4)) print('size after: ', arr.shape) imp.display(arr)
from ScrapBooker import ScrapBooker from cv2 import cv2 path = r'C:\Users\Gabriel\Desktop\Mes documents - Google Drive\DATA\19\day03\ex01\42AI.png' im = cv2.imread(path) dimensions = (2, 4) abc = ScrapBooker() a = abc.juxtapose(im, dimensions[0], 1) b = abc.juxtapose(a, dimensions[1], 0) cv2.imwrite( r'C:\Users\Gabriel\Desktop\Mes documents - Google Drive\DATA\19\day03\ex01\new_image.png', b) cv2.imshow('image name of the window', b) cv2.waitKey(0)
from ScrapBooker import ScrapBooker from ImageProcessor import ImageProcessor img = ImageProcessor() scrap = ScrapBooker() data = img.load("image/screen.png") # data = scrap.crop(data, (800, 1200), (200,200)) # data = scrap.thin(data, 2, 0) # data = scrap.juxtapose(data, 2, 1) data = scrap.mosaic(data, (3, 2)) print(len(data[0]), len(data)) img.display(data)
import numpy as np from ScrapBooker import ScrapBooker ma = [["A", "B", "C", "D", "E"], ["0", "B", "C", "D", "E"], ["1", "B", "C", "D", "E"], ["2", "B", "C", "D", "E"], ["3", "B", "C", "D", "E"], ["4", "B", "C", "D", "E"]] na = np.asarray(ma) nb = np.transpose(na) #print(na) print("------------------------------------------------------------") print(ScrapBooker.juxtapose(na, 2, 1)) print("------------------------------------------------------------") print("------------------------------------------------------------") print(ScrapBooker.juxtapose(nb, 2, 0)) print("------------------------------------------------------------")
import numpy from ScrapBooker import ScrapBooker scbook = ScrapBooker() array = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'B', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'C', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'D', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'E', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'F', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'G', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'H', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'I', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'J', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L', 'Q', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'Q', 'L'] array = numpy.reshape(array, (11, 12)) array = numpy.array(array) print("Array") print(array) x = scbook.crop(array, (5, 3), (0, 2)) print("\nCroped array(dimensions(5,3), position(0,2))") print(x) x = scbook.thin(array, 3, 0) print("\nThined array(n=3, axis=0)") print(x) x = scbook.juxtapose(array, 1, 1) print("\nJuxtaposed array(n=1, axis=1)") print(x) x = scbook.mosaic(array, (1, 1)) print("\nMosaic array(1x1)")
import numpy as np class ImageProcessor: def load(self, path): array = mpimg.imread(path) return (array) def display(self, array): img_plt = plt.imshow(array) plt.show() return (img_plt) ip = ImageProcessor() sb = ScrapBooker() ### test crop #arr = ip.load("../resources/42AI.png") #arr1 = sb.crop(arr, (100,100), (0,100)) #ip.display(arr1) ### test thin # arr = np.array([[0,0,0,0,0],[0,1,1,1,1],[0,1,2,2,2], [0,1,2,3,3],[0,1,2,3,4]]) # print("Base array :\n", arr) # arr1 = sb.thin(arr, 2, 0) # print("vertical :\n", arr1)
res[y][x][z] = tmp[0][0] elif abs(res[y][x][z] - tmp[0][1]) < abs(res[y][x][z] - tmp[0][2]): res[y][x][z] = tmp[0][1] elif abs(res[y][x][z] - tmp[0][2]) < abs(res[y][x][z] - tmp[0][3]): res[y][x][z] = tmp[0][2] else: res[y][x][z] = tmp[0][3] return res if __name__ == "__main__": imp = ImageProcessor() cf = ColorFilter() sb = ScrapBooker() arr = imp.load("./elonmusk.png") #invert = cf.invert(arr) celluloid = cf.celluloid(arr) #blue_arr = cf.to_blue(arr) #green_arr = cf.to_green(arr) #red_arr = cf.to_red(arr) resa = np.concatenate((arr, celluloid), 1) #resb = np.concatenate((invert, blue_arr), 1) #resc = np.concatenate((green_arr, red_arr), 1) #res = np.concatenate((resa, resb, resc), 0) imp.display(resa)
from ScrapBooker import ScrapBooker import sys sys.path.append('../ex01') from ImageProcessor import ImageProcessor try: img = ImageProcessor() arr = img.load('../ex01/42AI.png') #newImage = ScrapBooker.crop(arr, (100,100)) #newImage = ScrapBooker.thin(arr, 100, 0) newImage = ScrapBooker.juxtapose(arr, 3, 0) #newImage = ScrapBooker. img.display(newImage) except ValueError as err: print(err)
from ScrapBooker import ScrapBooker from ImageProcessor import ImageProcessor import numpy as np imp = ImageProcessor() arr = imp.load("../resources/42AI.png") print(arr) # imp.display(arr) print("---------Crop-------") sb = ScrapBooker() slice_arr = sb.crop(arr, (3, 3)) print(slice_arr) print("---------Thin-------") arr = np.arange(49).reshape(7, 7) print(arr) thin_arr = sb.thin(arr, 3, 1) print(thin_arr) print("---------Juxtapose-------") juxt_arr = sb.juxtapose(arr, 3, axis=1) imp.display(juxt_arr) print("---------Mosaic-------") mos_arr = sb.mosaic(arr, (2, 3)) imp.display(mos_arr)
from ImageProcessor import ImageProcessor from ScrapBooker import ScrapBooker from ColorFilter import ColorFilter imp = ImageProcessor() arr = imp.load("./42AI.png") scrap = ScrapBooker() filter = ColorFilter() # arr = scrap.juxtapose(arr, 10, 0) # arr = scrap.thin(arr, 2, 1) arr = filter.invert(arr) imp.display(arr)
def load(self, path): img = mpimg.imread(path) print('Loading image of dimensions', len(img[0]), 'x', len(img)) return np.asarray(img) def display(slef, array): imgplot = plt.imshow(array) plt.show() imp = ImageProcessor() arr = imp.load("../ex01/resources/42AI.png") #ligne colonne obj = ScrapBooker() #thin #array = obj.thin(arr, 2, 1) #mosaic #array = obj.mosaic(arr, (5,9)) #juxtapose #array = obj.juxtapose(arr, 2, 1) #crop #array = obj.crop(arr, (100, 100), (50, 50)) imp.display(array) #print (array)
["9", "B", "C", "D", "E", "F", "G", "H", "I", "J", "Q", "L"]] nbase = np.asarray(base) sbase = nbase[:2, :] #print(nbase) ibase = [["A", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A"], ["B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B"], ["C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C"], ["D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D"], ["E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E"], ["F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F"], ["G", "G", "G", "G", "G", "G", "G", "G", "G", "G", "G", "G"], ["H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"], ["I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I", "I"], ["J", "J", "J", "J", "J", "J", "J", "J", "J", "J", "J", "J"], ["K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K", "K"], ["L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L"]] nibase = np.asarray(ibase) sibase = nibase[:, :2] print("------------------------------------------------------------") print(ScrapBooker.thin(nbase, 3, 0)) print("------------------------------------------------------------") print(ScrapBooker.thin(sbase, 3, 0)) print("------------------------------------------------------------") print("------------------------------------------------------------") print(ScrapBooker.thin(nibase, 4, 1)) print("------------------------------------------------------------") print(ScrapBooker.thin(sibase, 4, 1)) print("------------------------------------------------------------")
from ScrapBooker import ScrapBooker as sb from ImageProcessor import ImageProcessor as ip import numpy as np from PIL import Image #array1 = np.random.randint(10, size=(10, 10)) array1 = ip.load(path='../ex01/koala.jpg') print(array1) crop1 = sb.crop(array1, (300, 450), (100, 200)) print("\nCropped!") print(crop1) ip.display(crop1) print("\nThined1") thin1 = sb.thin(array1, 2, 0) print(thin1) ip.display(thin1) print("\nThined2") thin2 = sb.thin(array1, 2, 1) print(thin2) ip.display(thin2) print("\nJuxtaposed1") j1 = sb.juxtapose(array1, 2, 0) print(j1) ip.display(j1) print("\nJuxtaposed2") j2 = sb.juxtapose(array1, 2, 1) print(j2) ip.display(j2)
from ImageProcessor import ImageProcessor from ScrapBooker import ScrapBooker imp = ImageProcessor() arr = imp.load("./42AI.png") scrap = ScrapBooker() #arr = scrap.crop(arr, [100, 100], [100, 100]) # arr = scrap.thin(arr, 2, 0) arr = scrap.mosaic(arr, [2, 3]) imp.display(arr)
import numpy as np from ScrapBooker import ScrapBooker ############################################################################### # TESTS FROM SUBJECT # # Test 1 spb = ScrapBooker() arr1 = np.arange(0, 25).reshape(5, 5) print(spb.crop(arr1, (3, 1), (1, 0))) # #Output # # array([[ 5], # # [10], # # [15]]) # # # # Test 2 (from 42AI slack example (the second example from subject is false)) arr2 = np.array("A B C D E F G H I J Q L".split() * 6).reshape(-1, 12) tp_np_array = np.array("A B C D E F G H I J K L".split()) arr3 = np.transpose([tp_np_array] * 12) print(spb.thin(arr2, 3, 0)) # Output : # # perform thin with n=3 and axis=0: # # ABCDEFGHIJQL ABDEGHJQ # # ABCDEFGHIJQL ABDEGHJQ # # ABCDEFGHIJQL ABDEGHJQ # # ABCDEFGHIJQL ABDEGHJQ # # ABCDEFGHIJQL ABDEGHJQ # # ABCDEFGHIJQL ==> ABDEGHJQ # # ABCDEFGHIJQL ABDEGHJQ # # ABCDEFGHIJQL ABDEGHJQ