Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python image processing : Help needed for corner detection in preferably PIL or any relevant module

I'm new to image processing and got to do corner detection for this image: enter image description here

In this image, I need to extract the starting and end points of each line segment or the coordinates of the corners. This is just a small part in my project and I'm stuck on this because I've no experience in image processing.

like image 458
VoodooChild92 Avatar asked Dec 31 '11 07:12

VoodooChild92


2 Answers

Here's a solution, using scikit-image:

from skimage import io, color, morphology
from scipy.signal import convolve2d
import numpy as np
import matplotlib.pyplot as plt

img = color.rgb2gray(io.imread('6EnOn.png'))

# Reduce all lines to one pixel thickness
snakes = morphology.skeletonize(img < 1)

# Find pixels with only one neighbor
corners = convolve2d(snakes, [[1, 1, 1],
                              [1, 0, 1],
                              [1, 1, 1]], mode='same') == 1
corners = corners & snakes

# Those are the start and end positions of the segments
y, x = np.where(corners)

plt.imshow(img, cmap=plt.cm.gray, interpolation='nearest')
plt.scatter(x, y)
plt.axis('off')
plt.show()

corners of line segments

like image 174
Stefan van der Walt Avatar answered Sep 25 '22 23:09

Stefan van der Walt


I would recommend using OpenCV, which comes with both the Harris corner detector and the Shi-Tomasi corner detector.

like image 30
jminardi Avatar answered Sep 22 '22 23:09

jminardi