2015-06-07 54 views

回答

-1

現在你改變了你的問題,並增加了一個示例圖像:

import scipy.ndimage as img 
import matplotlib.pylab as plt 
image = img.imread('threshold_Image.jpg', flatten=True) 

image_thresh= image 
threshold = 127 # half of the maximum - might want to vary it if your image is noisy etc. 
image_thresh[image < threshold] = 0 

labeled, num_objects = img.label(image_thresh) 
slices = img.find_objects(labeled) 
xcomlist, ycomlist = [], [] 
for peakslice in slices: 
    y, x = peakslice 
    xcom, ycom= img.measurements.center_of_mass(image[peakslice]) 
    xcom += x.start 
    ycom += y.start 
    xcomlist.append(xcom) 
    ycomlist.append(ycom) 

plt.imshow(image_thresh) 
plt.plot(xcomlist, ycomlist, 'gx') 
plt.show() 
+0

我可以問爲什麼downvoting? – mmensing

+0

非常感謝,如何用python中的opencv處理這個圖像,我沒有足夠的聲望來投票,對不起 – Petter

+0

這幾乎是一樣的。你只需要在opencv模塊中找到等價的函數。例如。 Com是通過當前操作計算的。看看http://answers.opencv.org/question/460/finding-centroid-of-a-mask/和http://stackoverflow.com/questions/968332/calculate-the-center-of-a - 地區。 – mmensing