python數(shù)字圖像處理之基本圖形的繪制
引言
圖形包括線條、圓形、橢圓形、多邊形等。
在skimage包中,繪制圖形用的是draw模塊,不要和繪制圖像搞混了。
1、畫線條
函數(shù)調(diào)用格式為:
skimage.draw.line(r1,c1,r2,c2)
r1,r2: 開始點(diǎn)的行數(shù)和結(jié)束點(diǎn)的行數(shù)
c1,c2: 開始點(diǎn)的列數(shù)和結(jié)束點(diǎn)的列數(shù)
返回當(dāng)前繪制圖形上所有點(diǎn)的坐標(biāo),如:
rr, cc =draw.line(1, 5, 8, 2)
表示從(1,5)到(8,2)連一條線,返回線上所有的像素點(diǎn)坐標(biāo)[rr,cc]
from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc =draw.line(1, 150, 470, 450) img[rr, cc] =255 plt.imshow(img,plt.cm.gray)

如果想畫其它顏色的線條,則可以使用set_color()函數(shù),格式為:
skimage.draw.set_color(img, coords, color)
例:
draw.set_color(img,[rr,cc],[255,0,0])
則繪制紅色線條。
from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc =draw.line(1, 150, 270, 250) draw.set_color(img,[rr,cc],[0,0,255]) plt.imshow(img,plt.cm.gray)

2、畫圓
函數(shù)格式:skimage.draw.circle(cy, cx, radius)
cy和cx表示圓心點(diǎn),radius表示半徑
from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.circle(150,150,50) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray)

3、多邊形
函數(shù)格式:skimage.draw.polygon(Y,X)
Y為多邊形頂點(diǎn)的行集合,X為各頂點(diǎn)的列值集合。
from skimage import draw,data import matplotlib.pyplot as plt import numpy as np img=data.chelsea() Y=np.array([10,10,60,60]) X=np.array([200,400,400,200]) rr, cc=draw.polygon(Y,X) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray)

我在此處只設(shè)置了四個頂點(diǎn),因此是個四邊形。
4、橢圓
格式:skimage.draw.ellipse(cy, cx, yradius, xradius)
cy和cx為中心點(diǎn)坐標(biāo),yradius和xradius代表長短軸。
from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.ellipse(150, 150, 30, 80) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray)

5、貝塞兒曲線
格式:skimage.draw.bezier_curve(y1,x1,y2,x2,y3,x3,weight)
y1,x1表示第一個控制點(diǎn)坐標(biāo)
y2,x2表示第二個控制點(diǎn)坐標(biāo)
y3,x3表示第三個控制點(diǎn)坐標(biāo)
weight表示中間控制點(diǎn)的權(quán)重,用于控制曲線的彎曲度。
from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.bezier_curve(150,50,50,280,260,400,2) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray)

6、畫空心圓
和前面的畫圓是一樣的,只是前面是實(shí)心圓,而此處畫空心圓,只有邊框線。
格式:skimage.draw.circle_perimeter(yx,yc,radius)
yx,yc是圓心坐標(biāo),radius是半徑
from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.circle_perimeter(150,150,50) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray)

7、空心橢圓
格式:skimage.draw.ellipse_perimeter(cy, cx, yradius, xradius)
cy,cx表示圓心
yradius,xradius表示長短軸
from skimage import draw,data import matplotlib.pyplot as plt img=data.chelsea() rr, cc=draw.ellipse_perimeter(150, 150, 30, 80) draw.set_color(img,[rr,cc],[255,0,0]) plt.imshow(img,plt.cm.gray)

以上就是python數(shù)字圖像處理之基本圖形的繪制的詳細(xì)內(nèi)容,更多關(guān)于python數(shù)字圖像處理基本圖形的繪制的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python Pingouin數(shù)據(jù)統(tǒng)計分析技術(shù)探索
Pingouin庫基于pandas、scipy和statsmodels,為用戶提供了執(zhí)行常見統(tǒng)計分析的功能,它支持各種統(tǒng)計方法和假設(shè)檢驗(yàn),例如 t-tests、ANOVA、correlation analysis 等,本文通過一些示例代碼,以更全面地了解如何使用Pingouin庫進(jìn)行統(tǒng)計分析,2024-01-01
一個基于flask的web應(yīng)用誕生 flask和mysql相連(4)
一個基于flask的web應(yīng)用誕生第四篇,這篇文章主要介紹了如何讓flask和mysql進(jìn)行互聯(lián),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04
pytorch中LN(LayerNorm)及Relu和其變相的輸出操作
這篇文章主要介紹了pytorch中LN(LayerNorm)及Relu和其變相的輸出操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05
詳解Python實(shí)現(xiàn)圖像分割增強(qiáng)的兩種方法
圖像分割就是把圖像分成若干個特定的、具有獨(dú)特性質(zhì)的區(qū)域并提出感興趣目標(biāo)的技術(shù)和過程。本文將為大家分享兩個用Python實(shí)現(xiàn)像分割增強(qiáng)的方法,需要的可以參考一下2022-03-03
Python利用fastapi實(shí)現(xiàn)上傳文件
FastAPI是一個現(xiàn)代的,快速(高性能)python?web框架。本文將利用fastapi實(shí)現(xiàn)上傳文件功能,文中的示例代碼講解詳細(xì),需要的可以參考一下2022-06-06

