如何检测明亮区域

时间:2015-06-07 11:09:14

标签: python

我想找到图像中最大明亮区域中心的(x,y)坐标。 这是示例图像 http://postimg.org/image/id3k558bx/

1 个答案:

答案 0 :(得分:-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()