图像矢量器
Image Vectorizer
我正在寻找一种 library/tool/image 处理技术,它可以从图像中创建矢量(类似于 TFIDF 等文本矢量化)。谁能分享一些如何进行的想法?
我不确定您使用的是什么编程语言。下面是我在 R
中使用的示例
这是使用 Pixmap 库将图像作为矩阵读入的方法。
library(pixmap)
the next command may only work on Linux
system("convert foo.tiff foo.ppm")
img <- read.pnm("foo.ppm")
要获取有关您的新对象的信息:
str(img)
虽然包含在之前的输出中,但可以通过以下方式提取图像的大小:
img@size
然后从图像中提取前十行的红色通道:
myextract <- img@red[1:10,]
或者将整个红色通道提取到实际矩阵中:
red.mat<-matrix(NA,img@size[1],img@size[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) 是我的图像
我正在寻找一种 library/tool/image 处理技术,它可以从图像中创建矢量(类似于 TFIDF 等文本矢量化)。谁能分享一些如何进行的想法?
我不确定您使用的是什么编程语言。下面是我在 R
中使用的示例这是使用 Pixmap 库将图像作为矩阵读入的方法。
library(pixmap)
the next command may only work on Linux
system("convert foo.tiff foo.ppm") img <- read.pnm("foo.ppm")
要获取有关您的新对象的信息:
str(img)
虽然包含在之前的输出中,但可以通过以下方式提取图像的大小:
img@size
然后从图像中提取前十行的红色通道:
myextract <- img@red[1:10,]
或者将整个红色通道提取到实际矩阵中:
red.mat<-matrix(NA,img@size[1],img@size[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) 是我的图像