numpy

2012-12-18 10 views
9

के साथ 2 डी अंशांकन पैटर्न बिंदु क्रमबद्ध करें मेरे पास एक आयताकार अंशांकन पैटर्न में बिंदुओं से मिले बिंदुओं (x, y) के साथ एक n: 2 मैट्रिक्स है। मुझे पंक्ति से इन बिंदु पंक्ति को सॉर्ट करना पसंद है। मैंने इन बिंदुओं को लेक्सॉर्ट के साथ क्रमबद्ध किया है लेकिन कैमरे से विरूपण बहुत बड़ा है ताकि y-coordinates ओवरलैप हो जाएंगे।numpy

imageloading... 
blobs=imageprocessing.... 
coordinates=np.array([blob.centroid() for blob in blobs]) 
nd=np.lexsort((coordinates[:,0],coordinates[:,1])) 
coordinates=coordinates[ind] 

enter image description here

वहाँ एक डेलॉनाय पैटर्न एक लंबी कतारें जा रहा की मदद से इस सुलझाने के लिए कोई तरीका है?

import matplotlib.tri as tri 
x=coordinates[:,0] y=coordinates[:,1] 
triang = tri.Triangulation(x, y) 

enter image description here

+0

क्या आप एक्स-निर्देशांक पर भरोसा नहीं कर सकते हैं ओवरलैपिंग? आप अपने सॉर्टिंग ऑर्डर को उलटा कर सकते हैं और फिर परिणामी मैट्रिक्स को ट्रांसफर कर सकते हैं। इससे जीवन बहुत आसान हो जाएगा। Delaunay त्रिकोण छोटे ओवरलैप के लिए और अधिक मजबूत हो सकता है, लेकिन अगर विरूपण बहुत बड़ा है, तो यह आयताकार पैटर्न भी तोड़ देगा। – Jaime

+0

आप उन्हें क्यों सॉर्ट करना चाहते हैं? कैलिब्रेटिंग का बिंदु यह है कि आप एल्गोरिदम में बड़ी संख्या में बिंदु डाल सकते हैं। कैलिब्रेट करने के बाद, आप छवि को पुनर्स्थापित कर सकते हैं और अंक बिल्कुल लाइनों पर होंगे। – RobAu

उत्तर

2

ट्राईऐन्ग्युलेशंस का उपयोग वास्तव में दिलचस्प है, और आप आवेदन के लिए इस्तेमाल किया जा सकता:

import numpy as np 
import matplotlib.tri as tri 
import matplotlib.pyplot as plt 
import random 

# create fake data 
x,y = np.meshgrid(np.arange(10), np.arange(10)) 
x = x.flatten() 
y = y.flatten() 
coordinates = np.column_stack([x,y])+0.04 * np.random.rand(len(x), 2) 
np.random.shuffle(coordinates) 
x=coordinates[:,0] 
y=coordinates[:,1] 

# perform triangulation 
triang=tri.Triangulation(x,y) 
f = plt.figure(0) 
ax = plt.axes() 
tri.triplot(ax,triang) 

# find horizontal edges 
f = plt.figure(1) 
e_start = coordinates[triang.edges[:,0]] 
e_end = coordinates[triang.edges[:,1]] 
e_diff = e_end - e_start 
e_x = e_diff[:,0] 
e_y = e_diff[:,1] 

e_len = np.sqrt(e_x**2+e_y**2) 
alpha = 180*np.arcsin(e_y/e_len)/np.pi 

hist, bins, patches = plt.hist(alpha, bins=20) 

# in the histogram, we find that the 'horizontal' lines 
# have an alpha < 10. 

ind_horizontal = (-10<alpha) & (alpha < 10) 
edges_horizontal = triang.edges[ind_horizontal] 
plt.show() 

नतीजतन, आप क्षैतिज किनारों edges_horizontal में जो एक 2 डी सरणी है मिलता है, [[p_{0},p_{1}], ..., [p_{n}, p_{n+1}]], जिसमें p_i coordinates सरणी में सूचकांक हैं।