承接国内外服务器租用托管、定制开发、网站代运营、网站seo优化托管接单、网站代更新,新老站点皆可!!咨询QQ:3787320601
当前位置:首页  >  软件开发  >  python 画油画利用

python 画油画利用

管理员 2023-06-26 08:31:39 软件开发 5 ℃ 0 评论 1348字 收藏

python 画油画利用

Python是一种非常强大的编程语言,有很多优秀的利用程序被开发出来。其中,画油画利用程序也能够用Python来实现。以下是一些使用Python实现油画利用程序的代码。

# 导入绘图库,如matplotlib
import matplotlib.pyplot as plt
# 加载图片
img = plt.imread("image.jpg")
# 将图片转为灰度图
gray = img.mean(axis=2)
# 定义油画效果的函数
def oil_painting(img, radius):
# 创建画布
target = np.zeros_like(img)
# 遍历每一个像素
for y in range(radius, img.shape[0] - radius):
for x in range(radius, img.shape[1] - radius):
# 找到最多见的色彩
color = np.bincount(img[y - radius:y + radius, x - radius:x + radius].flatten())
most_common_color = np.argmax(color)
# 将该像素用最多见的色彩替换
target[y - radius:y + radius, x - radius:x + radius][img[y - radius:y + radius, x - radius:x + radius] != most_common_color] = 0
target[y - radius:y + radius, x - radius:x + radius][img[y - radius:y + radius, x - radius:x + radius] == most_common_color] = most_common_color
return target
# 履行油画效果函数并显示结果
result = oil_painting(img, 5)
plt.imshow(result)
plt.show()

以上就是一些使用Python实现油画利用程序的代码。有了这些代码,我们就能够使用Python来绘制出优美的油画了。

文章来源:丸子建站

文章标题:python 画油画利用

https://www.wanzijz.com/view/59443.html

TAG: css 油画python

相关文章

Related articles

X

截屏,微信识别二维码

微信号:weimawl

(点击微信号复制,添加好友)

打开微信