Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- # PIL accesses images in Cartesian co-ordinates, so it is Image[columns, rows]
- # img = Image.new( 'RGB', (1280, 720), "black") # create a new black image
- #img = Image.open("rsz_2lemibrat.jpg")
- img = Image.open("lena.jpg")
- pixels = img.load() # create the pixel map
- # https://stackoverflow.com/questions/6667201/how-to-define-a-two-dimensional-array-in-python
- # Creates a list containing 32 lists, each of 32 items, all set to 0
- k_w, k_h = 40, 40
- x_pos, y_pos = 200, 250
- k_i, k_j = 0, 0
- kernel = {}
- # kernel = [[0 for x in range(w)] for y in range(h)]
- print(img.size) # Prints (250, 250)
- #for i in range(img.size[0]): # for every col:
- #for j in range(img.size[1]): # For every row
- #pixels[i,j] = (i, j, 100) # set the colour accordingly
- # print(pixels[i,j][0])
- for i in range(x_pos, x_pos + k_w):
- for j in range (y_pos, y_pos + k_h):
- kernel[k_i, k_j] = pixels[i, j]
- k_j += 1
- print('k_j = ' + str(k_j) + ' a vrednost RGB = ' + str(pixels[i, j]))
- if k_j == k_h:
- k_j = 0
- k_i += 1
- print('k_i = ' + str(k_i) + ' a vrednost RGB = ' + str(pixels[i, j]))
- if k_i == k_w:
- k_i = 0
- #print('Trenutno ispisujem: ' + str(kernel[22,23]))
- k_R, k_G, k_B = 0, 0, 0
- for i in range(0, k_w):
- for j in range (0, k_h):
- k_R += kernel[i, j][0]
- k_G += kernel[i, j][1]
- k_B += kernel[i, j][2]
- #print(kernel[i, j])
- # Hehe, nisi dovoljno mocan ako ne mozes ovo ha ha ha
- # k_R, k_G, k_B /= 32, 32, 32
- k_R /= k_w * k_h
- k_G /= k_w * k_h
- k_B /= k_w * k_h
- print('Srednja vrijednost: R = ' + str(k_R) + ' G = ' + str(k_G) + ' B = ' + str(k_B))
- for i in range(x_pos, x_pos + k_w):
- for j in range (y_pos, y_pos + k_h):
- pixels[i, j] = (k_R, k_G, k_B)
- img.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement