将图片中的曲线映射到xy平面

时间:2017-02-08 12:20:47

标签: python matlab

有没有人能让我知道MATLAB / Python / Java中的任何库/函数,它带有带曲线的黑白图片并返回描述x和y成分的两个数组?

我最初的想法是将这样的图片映射到其逻辑矩阵并从那里获取位置。缺点是我只使用整数值,重新缩放到浮点数只是不可能。

此类图片的一个例子是

enter image description here

1 个答案:

答案 0 :(得分:0)

我知道这很粗糙,但似乎有效。

from PIL import Image
#
print "\nStarting script"
#
# Load the image
im = Image.open('Pixels_Test_Image.png')
px = im.load()
#
# Determine the image size
width, height = im.size
print "width, height = " + str(width) + ", " + str(height)
#
# Loop over each pixel and test rgb values to find black pixels
non_white_i_pixel = []
non_white_j_pixel = []
i_pixel = 0
set_limit = 100
while i_pixel < width:
    j_pixel = 0
    while j_pixel < height:
        r, g, b, xx = (px[i_pixel, j_pixel])
        #print i_pixel, j_pixel, a, b, c, d
        if(r < set_limit and g < set_limit and b < set_limit):
            non_white_i_pixel.append(i_pixel)
            non_white_j_pixel.append(j_pixel)
        j_pixel += 1
    i_pixel += 1
#
print "len(non_white_i_pixel) = " + str(len(non_white_i_pixel))
print "len(non_white_j_pixel) = " + str(len(non_white_j_pixel))
print non_white_i_pixel
print non_white_j_pixel
#
print "\nFinished script"