import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import csv
import numpy as np

img=cv2.imread('cleaned_skeleton_1_robot.pgm',0)
img2=cv2.imread('cleaned_skeleton_ROADS_robot.pgm',0)
#img3=mpimg.imread('map_6cm_updated.pgm')
img4=mpimg.imread('cleaned_skeleton_2_robot.pgm')

for i in range(len(img)):
    for j in range(len(img[i])):
        if(img[i][j]!=0):
            img[i][j]=1

cv2.imwrite('cleaned_skeleton_1_robot.pgm', img)

for i in range(len(img2)):
    for j in range(len(img2[i])):
        if(img2[i][j]!=0):
            img2[i][j]=1

cv2.imwrite('cleaned_skeleton_ROADS_robot.pgm', img2)
#pixely to skeletov poli
Skeleton1=[]
Skeleton2=[]

#imgplot = plt.imshow(img3,cmap='gray')
imgplot = plt.imshow(img4,cmap='gray')
###########zobrazenie
for i in range(len(img)):
    for j in range(len(img[i])):
        if(img[i][j]==1):
            Skeleton1.append([i,j])


for i in range(len(img2)):
    for j in range(len(img2[i])):
        if(img2[i][j]==1):
            Skeleton2.append([i,j])

print(Skeleton1)
print("-----------------------------------------------------------")
print(Skeleton2)
#######################PRIDANE UKLADANIE PIXLOV


# with open("Skeleton1.csv", "w", newline="") as f:
#     writer = csv.writer(f)
#     writer.writerows(Skeleton1)
#
# with open("Skeleton2.csv", "w", newline="") as f:
#     writer = csv.writer(f)
#     writer.writerows(Skeleton2)
# #######################PRIDANE UKLADANIE PIXLOV
#
#
# #nacitanie pixlov zo subora
# Bridges_Edges=[]
# nodes = []
# with open('finded_nodes.csv', 'r') as csvfile:
#     reader = csv.reader(csvfile)
#     for row in reader:
#         nodes.append([int(val) for val in row])
# #nacitanie nodov zo subora\
Skeleton_spolu=[]
for a in Skeleton1:
    for b in Skeleton2:
        if(a==b):
            Skeleton_spolu.append(a)
print("-----------------------------------------------")
print(Skeleton_spolu)

Skeleton1=np.asarray(Skeleton1)
Skeleton2=np.asarray(Skeleton2)
Skeleton_spolu=np.asarray(Skeleton_spolu)

#plt.scatter(Skeleton1[:,[1]],Skeleton1[:,[0]], color='yellow', s=40)
plt.scatter(Skeleton2[:,[1]],Skeleton2[:,[0]], color='blue', s=40)
plt.scatter(Skeleton_spolu[:,[1]],Skeleton_spolu[:,[0]], color='red', s=40)
plt.show()
