from edge import hough_transform
from edge import canny
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from time import time
from skimage import io
import PIL.Image

# Load image
img = io.imread('road.jpg', as_gray=True)

# Run Canny edge detector
edges = canny(img, kernel_size=5, sigma=1.4, high=0.03, low=0.02)
H, W = img.shape

# Generate mask for ROI (Region of Interest)
mask = np.zeros((H, W))
for i in range(H):
    for j in range(W):
        if i > (H / W) * j and i > -(H / W) * j + H:
            mask[i, j] = 1

# Extract edges in ROI
roi = edges * mask
acc, rhos, thetas = hough_transform(roi)

I8 = (((acc - acc.min()) / (acc.max() - acc.min())) * 255.9).astype(np.uint8)

img = PIL.Image.fromarray(I8)
img.save("file.png")
a=1