[英]How to convert grey scale image to respective pixel values (0-1) in the form of matrix or data frame?
[英]how to convert image to numerical (0-1) pixel matrix in R
我找到了转换图像的代码,并得到480 * 288的数据,因为图像的像素就是那个。 但是,我想要的矩阵要少得多:19 * 12之类的数字。 那我该如何在R中做到这一点呢? 非常感谢!。
library("EBImage")
img <- readImage("sample.jpg")
img <- channel(img, "grey")
write.csv(t(img), "sample.csv", row.names=FALSE)
为了减小所得矩阵的大小,您需要先使用resize
来缩放图像,然后再将其保存到.csv文件中,请参阅我对R中调整图像大小的回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.