 # Passing Hough's coordinates to the space domain

I have an assignment where i need to detect the edges of a simple rectangle in this image. I am a little bit lost in the last part where my teacher ask us to extract the spatial coordinates from the Hough coordinates using 𝜌=𝑥cos(𝜃)+𝑦sin(𝜃). He said :

"Find the intersection of these lines which corresponds to the four
corners of the plate. Obtain these coordinates and apply a binary mask
on the original image in order to obtain only the plate. When you get
the pixel coordinates of the corners of the license plate, you can use
the function provided with this assignment.

For the calculation of the intersection points, we can use the normal
form: xcos (theta) + ysin (theta) - rho. If we create a matrix with
this equation, replacing x and y by the position of the pixels and
theta, rho by the parameters of the detected line, we will obtain a
matrix for which the intensities will take a value of 0 when we are on
the line. We can thus identify the pixels in the image belonging to
the line. We can repeat for all the detected lines and use this
result to find the place where the lines intersect."

I am blocked here i tried something but its far from the good way i think … i dont really get how to properly use 𝜃 and 𝜌 to do the job.

``````from skimage.feature import peak_local_max
import math

Local_Max= peak_local_max(out, num_peaks=6,min_distance=15 ,exclude_border=False)

# cadrage is the input of hough_line...its the rectangle
array = np.arange(x*y).reshape(y,x)

# filling the matrix with the equation
for i in range(y):
for j in range(x):
array[i,j] = (i * math.cos(angles)) + (j * math.sin(angles)) - d

``````

Hi @Lynns! Please tag your questions with #scikit-image so that scikit-image maintainers can get notified of your questions :-). So I will try to help you while leaving room for personal work since it’s an assignment you got. Did you already take a look at the gallery example https://scikit-image.org/docs/stable/auto_examples/edges/plot_line_hough_transform.html#sphx-glr-auto-examples-edges-plot-line-hough-transform-py ? From the example you can see that there is a `hough_line_peaks` function which is more suited to the problem than `peak_local_max`. After detecting the peaks, you can create an array of coordinates and apply the different equations of lines to the array of coordinate. This will result in an array which is negative on one side of the line and positive on the other. I think you can multiply all these different arrays and look for minimal to detect the intersection points (haven’t tried it myself but this is the idea outline by your professor). The code below uses the notations of the gallery example

``````hspace, angles, dists = hough_line_peaks(h, theta, d)
rows, cols = np.ogrid[:image.shape, :image.shape]
mask1 = rows * np.cos(angles) + cols * np.sin(angles) - dists

`````` 1 Like

I just added the #scikit-image tag to this topic.

@emmanuelle I increased your user trust level, so you should now be able to edit posts and add tags yourself as well. 1 Like

thank you @imagejan!

Hey ^^

Thanks for the link, it helped me come up with this. The only thing i don’t fully understand is the part inside the for loops. Is it the part where we construct the red lines representing the “votes” of the contours of my image? It’s a sort of conversion from the parameters domain to the space domain right?

I also tried something like

``````rows, cols = np.ogrid[:image.shape, :image.shape]

for (row,col) in [(row,col) for row in rows for col in cols]:
mask[row,col] = row * np.cos(angles[?]) + col * np.sin(angles[?]) - dists[?]
``````

But i really dont understand what i’m doing here… I dont get how is this going to tell me where are the intersections in my image.

1 Like