【问题标题】:Image Vectorizer [closed]图像矢量化器[关闭]
【发布时间】:2015-02-24 04:55:22
【问题描述】:

我正在寻找一种库/工具/图像处理技术,它可以从图像中创建矢量(类似于 TFIDF 等文本矢量化)。有人可以分享一些想法如何进行吗?

【问题讨论】:

  • 请指定您的编程语言。有像 Python 这样的语言,R 有很多库。请在下面查看我的答案

标签: image-processing vectorization object-recognition


【解决方案1】:

我不确定您使用的是哪种编程语言。下面是我在 R

中使用的示例

这是使用 Pixmap 库将图像作为矩阵读取的方法。

库(像素图)

下一个命令可能只适用于 Linux

system("转换 foo.tiff foo.ppm") img

要获取有关您的新对象的信息:

str(img)

虽然包含在前面的输出中,但可以通过以下方式提取图像的大小:

img@size

然后从图像中提取前十行的红色通道:

myextract

或者将整个红色通道提取为一个实际的矩阵:

red.mat

请参考:how to convert a JPEG to an image matrix in R

你也可以使用 Python-numpy

>>> arr = np.array(im)
>>> arr = np.arange(150).reshape(5, 10, 3)
>>> x, y, z = arr.shape
>>> indices = np.vstack(np.unravel_index(np.arange(x*y), (y, x))).T
#or indices = np.hstack((np.repeat(np.arange(y), x)[:,np.newaxis], np.tile(np.arange(x), y)[:,np.newaxis]))
>>> np.hstack((arr.reshape(x*y, z), indices))
array([[  0,   1,   2,   0,   0],
       [  3,   4,   5,   0,   1],
       [  6,   7,   8,   0,   2],
       [  9,  10,  11,   0,   3],
       [ 12,  13,  14,   0,   4],
       [ 15,  16,  17,   1,   0],
       [ 18,  19,  20,   1,   1],
       [ 21,  22,  23,   1,   2],
       [ 24,  25,  26,   1,   3],
       [ 27,  28,  29,   1,   4],
       [ 30,  31,  32,   2,   0],
       [ 33,  34,  35,   2,   1],
       [ 36,  37,  38,   2,   2],
       ...
       [129, 130, 131,   8,   3],
       [132, 133, 134,   8,   4],
       [135, 136, 137,   9,   0],
       [138, 139, 140,   9,   1],
       [141, 142, 143,   9,   2],
       [144, 145, 146,   9,   3],
       [147, 148, 149,   9,   4]])

其中 arr = np.array(im) 是我的图像

【讨论】:

  • 谢谢它对我有用
猜你喜欢
  • 2010-10-05
  • 2021-03-04
  • 2012-12-23
  • 2021-03-01
  • 2010-09-29
  • 2020-01-09
  • 2018-05-25
  • 2012-04-11
相关资源
最近更新 更多