dim(y) [1] 77 101 -6ren">
gpt4 book ai didi

r - 如何提取像素数据 使用R的pixmap包?

转载 作者:行者123 更新时间:2023-12-04 19:19:14 25 4
gpt4 key购买 nike

如何提取像素数据 使用R的pixmap包?

所以我使用以下方法读取图像文件:

picture <- read.pnm("picture.pgm") picture Pixmap image Type : pixmapGrey Size : 749x745 Resolution : 1x1 Bounding box : 0 0 745 749



如何将像素数据提取到某个矩阵中?

最佳答案

您可以通过 getChannels 将数据作为灰度图像的 2-D 矩阵或彩色图像的 3-D 阵列获取。 .

>  x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
> y <- getChannels(x)
> class(y)
[1] "array"
> dim(y)
[1] 77 101 3
>
> x <- read.pnm(system.file("pictures/logo.pgm", package="pixmap")[1])
> y <- getChannels(x)
> class(y)
[1] "matrix"
> dim(y)
[1] 77 101

如果您想更直接地访问数据,请使用 S4 访问器( @ ),例如:
>  x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
> str(x)
Formal class 'pixmapRGB' [package "pixmap"] with 8 slots
..@ red : num [1:77, 1:101] 1 1 1 1 1 1 1 1 1 1 ...
..@ green : num [1:77, 1:101] 1 1 1 1 1 1 1 1 1 1 ...
..@ blue : num [1:77, 1:101] 1 1 0.992 0.992 1 ...
..@ channels: chr [1:3] "red" "green" "blue"
..@ size : int [1:2] 77 101
..@ cellres : num [1:2] 1 1
..@ bbox : num [1:4] 0 0 101 77
..@ bbcent : logi FALSE
> x@size
[1] 77 101

关于r - 如何提取像素数据 使用R的pixmap包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6085090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com