2017-02-08 36 views
0

任何人都可以讓我知道MATLAB/Python/Java中的任何庫/函數,它使用帶曲線的黑色&白色圖片並返回描述x和y組件的兩個數組?映射從圖片到xy平面的曲線

我最初的想法是將這樣的圖片映射到它的邏輯矩陣,並從那裏採取立場。缺點是我只能使用整數值,重新縮放到浮點數是不可能的。

這樣的畫面的一個例子是

enter image description here

+0

你可以使用numpy庫嗎? – ZdaR

+0

對於我而言,「兩個數組描述x和y分量」的意思有點不清楚。所有黑色像素的座標?但是灰色像素是什麼?如果我正確地理解了你,你想要一個用於繪製圖片的實際路徑的表示?也許你應該嘗試矢量化位圖,例如使用inkscape。 – Fritz

+0

你當然可以用蟒蛇和numpy做蟒蛇。 – Jannick

回答

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"