![](/img/trans.png)
[英]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.