本文主要介绍了python图片转为矢量图,分享给大家,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import numpy as np
import matplotlib.pyplot as plt
import cv2
fig, ax = plt.subplots()
plt.figure( 1 )
image = cv2.imread( "2.jpg" )
# you can specify the marker size two ways directly:
# 这样一个一个像素太慢了故而要将同样颜色的坐标进行分类处理
color_class = []
x_y = dict ()
for x,w in enumerate (image):
for y,colors in enumerate (w):
if colors.tolist() not in color_class:
s = image[:, :, : 1 ] = = colors[ 0 ]
s1 = image[:, :, 1 : 2 ] = = colors[ 1 ]
s2 = image[:, :, 2 : 3 ] = = colors[ 2 ]
ss = s * s1 * s2
color_class.append(colors.tolist())
x_y[ len (color_class)] = np.where(ss.reshape((ss.shape[ 0 ],ss.shape[ 1 ])))
print (x,y)
for i ,colors in enumerate (color_class):
a, b = x_y[i + 1 ]
plt.plot(a,b, "." ,color = [colors[ 2 ] / 255 ,colors[ 1 ] / 255 ,colors[ 0 ] / 255 ], markersize = 1 , label = 'a' ) # blue circle with size 20
fig.savefig( 'scatter.svg' , dpi = 200 , format = 'svg' )
if __name__ = = '__main__' :
pass
|
到此这篇关于python将图片转为矢量图的方法步骤的文章就介绍到这了,更多相关python图片转为矢量图内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/weixin_32759777/article/details/115261010