2017-06-05 17 views
-1

在添加曲線我有一個圖像,如下所示:的Python:如何將圖像

enter image description here

的圖像被在Python生成。我想進一步繪製一個包含白色區域的圖像頂部的曲線。我已經獲得了區域邊界的像素索引。我知道在Matlab,例如,它可以簡單地完成由:

hold on 
plot(x,y,'r-') %x and y are the indices of boundary pixels. 

得到的圖像應該是這樣的:

enter image description here

我怎樣才能做到這圖像中的頂部輪廓Python,而不是cv2.drawContours?任何人都可以幫助我解決這個問題?

+0

Matplotlib的重複幾乎相同的語法Matlab的 –

+0

@ cricket_007:但繪製在頂部曲線時如何「待定」的形象? – jingweimo

+0

我明白了。只需在繪圖代碼的末尾添加plt.show() – jingweimo

回答

-1

您可以使用它的枕頭庫。沒有進入整個解決方案,在他們的教程中有一個很好的例子,如何閱讀一個圖像和做一些後記繪圖:https://pillow.readthedocs.io/en/4.1.x/handbook/tutorial.html#drawing-postscript

你幾乎只需要將矩形改爲圓形。

的削減的例子是:

from PIL import Image 
from PIL import PSDraw 

im = Image.open("lena.ppm") 
box = (1*72, 2*72, 7*72, 10*72) # in points 

ps = PSDraw.PSDraw() # default is sys.stdout 
ps.begin_document(title) 

# draw the image (75 dpi) 
ps.image(box, im, 75) 
ps.rectangle(box) 

ps.end_document() 

PS。我假設「我有一張圖像如下:」你的意思是,你有一個圖像文件,並希望處理,而不是你已經在python中生成該圖。如果您首先使用類似matplotlib的東西生成它,則可以將其添加到那裏。

如果你已經在做了在matplotlib,那麼問題很可能matplotlib: add circle to plot

+0

感謝您的回覆!圖像顯示由matplot.pyplot.imshow生成。我想要做的就是在imshow命令後面添加一條邊界曲線,類似於在Matlab中使用「hold on」。我會嘗試你的代碼。 – jingweimo

相關問題