As an artist, being able to understand how rules of perspectival space are applied to real world spaces is useful for me to train my own perspective skills. Written using skills learned in my Digital Image Processing class, this is a prototype for a Matlab script that passes in an image of an urban scene and detects the vanishing points and horizon line of the image.

The most common perspectival images artists will render are 1-point perspective and 2-point perspective images, describing the respective number of horizontal vanishing points present in the image. As such, the tool is designed to detect vertical and horizontal perspective lines in an input image using a Hough Transform. The detected horizon lines are then projected onto a Gaussian sphere as proposed by S. Barnard and a primary horizontal vanishing point is determined based on where the lines intersect. Then, a horizon line is extracted from a vertical vanishing point calculated from the vertical perspective lines detected. This horizon line is used to then detect if there is a second prominent horizontal vanishing point in the image.

*Spring 2020*

Blue lines are the measured horizon lines. Red dots are the primary vanishing point and blue dots are the secondary vanishing point.

- Image is converted to greyscale and a 5x5 median filter is passed over the image to smooth edges while suppressing unnecessary details.
- An edge map of the image is formed with the Canny method
- As per R. Duda and P. Hart's spec, a custom Hough transform is performed, returning the equations of the the 2D lines that most directly coincide with the edges mapped in the image

Extracting Perspective Lines:

- The lines returned from the Hough transform that are between 0 and 70 degrees from the x-axis of the image (and thus non-vertical) are projected onto a Gaussian sphere
- Since a sphere is a closed surface, lines that are ostensibly parallel in the image will necessarily intersect when projected onto the Gaussian sphere
- Each projected line is extended into a great circle that circumnavigates the great sphere and the points with the most intersections between great circles are extracted
- The four most prominent points are then pojected back onto the image plane, and if any of the points are within 100 pixels of each other, the two points are geometrically averaged to account for error
- The point with the greatest weight based on number of intersections between perspective lines is thus determined to be the primary horizontal vanishing point

Finding the First Horizontal Vanishing Point

- The lines returned from the Hough transform that are between 70 and 90 degrees from the x-axis of the image (and thus vertical) are projected onto a Gaussian sphere
- Using the same process as before, a primary vertical vanishing point is extracted
- This vanishing point is necessarily a pole for another great circle on the Gaussian sphere. This great circle is the horizon line
- The great circle of the Horizon Line is extracted and projected back onto the image
- Due to errors that results from minute differences in the vertical perspective lines extracted from the Hough transform, the extracted horizon line's angle tends to be off by 2-5% of a degree

Finding the Horizon Line

- The great circle of the horizon line is projected onto the same Gaussian Sphere as the great circles of the horizontal perspective lines used to find the first vanishing point
- Points with the most intersections between perspective lines that are within 50 pixels of the Horizon Line and at least 200 pixels away from the first vanishing point are then extracted and projected back onto the image
- Extracted points near each other are geometrically averaged and the point with the highest number of intersections occurring is assumed to be the second vanishing point. If no points were extracted, the image is assumed to have 1-point perspective
- There was considerable error with the second vanishing points because the algorithm often had fewer clean lines in the image it could use to find the second vanishing point

Finding the Second Horizontal Vanishing Point

© 2020 all rights reserved Mohar Kalra.