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