我正在寻找一种库/工具/图像处理技术,它可以从图像中生成向量(类似于文本向量化,比如TFIDF之类的)。有谁能分享一些如何进行的想法吗?
发布于 2015-02-24 05:06:53
我不知道你用的是什么编程语言。下面是我在R中使用的示例
这是如何使用Pixmap库以矩阵的形式读取图像。
图书馆(像素图) 下一个命令只能在Linux上运行。 系统(“foo.tiff foo.ppm") img <- read.pnm("foo.ppm")
要获得关于新对象的信息:
str(img)
虽然在前面的输出中包含了图像大小,但是可以通过以下方法提取图像的大小:
img@size
然后从图像中提取前十行的红色通道:
我的提取物<- img@red1:10,
或者将整个红色通道提取到实际的矩阵:
-矩阵(NA,img@size2 1,img@size2 2) red.mat<-img@red
参考如下: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)是我的图像
https://stackoverflow.com/questions/28688414
复制相似问题