|
from turtle import ycor |
|
import numpy as np |
|
import png |
|
import cv2 |
|
|
|
class Image: |
|
def __init__(self, x_pixels=0, y_pixels=0, filename=''): |
|
|
|
self.input_path = 'pyphotoshop-main\input/' |
|
self.output_path = 'pyphotoshop-main\output/' |
|
|
|
self.x_pixels = x_pixels |
|
self.y_pixels = y_pixels |
|
|
|
self.array = np.zeros((x_pixels, y_pixels)) |
|
|
|
|
|
|
|
im=cv2.imread(r"Animate\images\flag (1).png") |
|
|
|
|
|
|
|
canny_edges=cv2.Canny(image=im, threshold1=100, threshold2=200) |
|
|
|
|
|
manys=np.random.randint(255, size=(5,5)) |
|
ones=np.array([[0, 255, 0, 255,0],[ 255, 0, 0, 255, 255],[0, 255, 0, 255, 0],[255, 255, 0, 255, 0],[ 255, 0, 255, 0, 255]]) |
|
|
|
cv2.imwrite("ones.png",ones) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_last_key(dictionary): |
|
for key in dictionary.keys(): |
|
last_key=key |
|
return last_key |
|
|
|
|
|
def get_white_key(dictionary): |
|
for key,value in dictionary.items(): |
|
if value==255: |
|
white_coord=key |
|
return white_coord |
|
|
|
|
|
|
|
def get_neighbours(image, x, y, x_pixels, y_pixels, kernel=0): |
|
|
|
neighbour_coords=[ |
|
[max(0, (x-1)),max(0,(y-1))], |
|
[max(0, (x-1)),y], |
|
[max(0, (x-1)), min((y_pixels-1),(y+1))], |
|
[x,max(0,y-1)], |
|
[x,min((y_pixels-1),(y+1))], |
|
[min((x_pixels-1),(x+1)),max(0,(y-1))], |
|
[min((x_pixels-1),(x+1)),y], |
|
[min((x_pixels-1),(x+1)),y+1] |
|
] |
|
neighbour_coords=np.array(neighbour_coords) |
|
print(f"Image pixel is : at {x,y} ") |
|
return neighbour_coords |
|
|
|
|
|
def value_at_neighbour(new_frame,image,coord=[0,0],pixel_count=0): |
|
pixel_count+=1 |
|
print(f"Pixel count is at {pixel_count}") |
|
x_pixels, y_pixels=np.shape(image) |
|
neighbour_coords=get_neighbours(image, coord[0], coord[1],x_pixels, y_pixels,kernel=0) |
|
neighbour_values=[] |
|
dict={} |
|
|
|
|
|
for coord in neighbour_coords: |
|
neighbour_value = image[min(x_pixels-1,coord[0]),min(y_pixels-1,coord[1])] |
|
neighbour_values.append(neighbour_value) |
|
|
|
|
|
pyneighbour_value=int(neighbour_value) |
|
pyz=tuple(coord) |
|
dict[pyz]=pyneighbour_value |
|
print(f"My dict of neighbour coords:values is {dict} and value is {pyneighbour_value} ") |
|
|
|
|
|
|
|
|
|
if pixel_count <25: |
|
if 255 in neighbour_values: |
|
coord=get_white_key(dict) |
|
print(f"\n \n New coordinate in recursive function is {coord} and pixl count{pixel_count}") |
|
|
|
|
|
for key, value in dict.items(): |
|
x_index=int(key[0]) |
|
y_index=int(key[1]) |
|
new_frame[x_index][y_index]=value |
|
|
|
|
|
|
|
|
|
frames[pixel_count]=new_frame |
|
|
|
|
|
value_at_neighbour(new_frame, image,coord,pixel_count=pixel_count) |
|
|
|
|
|
|
|
elif 255 not in neighbour_values: |
|
coord=get_last_key(dict) |
|
print(f"\n \n Value is 0 so new coord is {coord}") |
|
value_at_neighbour(new_frame, image,coord,pixel_count) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
That is, if neighbour coord is True |
|
If neighbour coord is True, then move to square |
|
Divide square by number of frames |
|
We need it to pick a square |
|
""" |
|
|
|
|
|
|
|
frame_count=0 |
|
|
|
|
|
def create_path_frames(frames=10) : |
|
new_frame=np.zeros(5,5) |
|
for i in range(frames): |
|
frame_count += 1 |
|
cv2.imwrite(f'new{frame_count}.png',new_frame) |
|
|
|
|
|
|
|
|
|
new_frame=[[0]*5]*5 |
|
|
|
|
|
frames={} |
|
|
|
value_at_neighbour(new_frame, ones) |
|
|
|
print(len(frames)) |
|
""" |
|
for key, value in frames.items(): |
|
frame=np.array(value) |
|
cv2.imwrite(f'frame{key}.png',frame) |
|
""" |
|
|
|
|
|
|
|
|