SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PIL import Image
  2. import numpy as np
  3. import math
  4.  
  5. image = Image.open('picture_scene.png')
  6. width, height = image.size
  7.  
  8. img = image.rotate(30)
  9. img.save( "array_to_image_cmp.png")
  10. image_array = np.array(image)
  11. new_array = np.zeros((width, height, 4), dtype = np.uint8) #dtype=np.uint8
  12.  
  13. for i in range(width):
  14.     for j in range(height):
  15.         flag1 = (i - width/2) * math.cos(-30 * math.pi/180) - (j - height/2) * math.sin(-30 * math.pi/180) + width/2
  16.         flag2 = (i - width/2) * math.sin(-30 * math.pi/180) + (j - height/2) * math.cos(-30 * math.pi/180) + height/2
  17.         if flag1 < 0 or flag2 < 0 or flag1 > width or flag2 > height:
  18.                 new_array[i, j] = [0, 0, 0, 255]
  19.         else:
  20.                 if (int)(flag1) - flag1 <= (int)(flag1) + 1 - flag1:
  21.                         new_flag1 = (int)(flag1)
  22.                 else:
  23.                         new_flag1 = (int)(flag1) + 1
  24.                 if (int)(flag2) - flag2 <= (int)(flag2) + 1 - flag2:
  25.                         new_flag2 = (int)(flag2)
  26.                 else:
  27.                         new_flag2 = (int)(flag2) + 1
  28.                 new_array[i, j] = image_array[new_flag1, new_flag2]
  29.         #new_array[i, j] = [0, 0, 0, 0]
  30. array_to_image = Image.fromarray(new_array, 'RGBA')
  31. print(width,  height, array_to_image)
  32. array_to_image.save("array_to_image.png")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top