Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R中的magick软件包从16位tiff图像中获取像素值_R_Imagemagick_Wolfram Mathematica_Tiff - Fatal编程技术网

使用R中的magick软件包从16位tiff图像中获取像素值

使用R中的magick软件包从16位tiff图像中获取像素值,r,imagemagick,wolfram-mathematica,tiff,R,Imagemagick,Wolfram Mathematica,Tiff,有人知道如何使用R中的magick软件包从16位tiff图像中获取每个通道(RGB)的像素值吗?目前我正在使用Mathematica来执行此操作,因为我找不到在Mathematica中执行此操作的等效方法 我尝试从image magick软件包中读取像素值,结果是原始类型(例如“ff”)。我使用函数rawToNum(package“pack”)将原始类型转换为数字,结果与我在Mathematica中使用ImageDate函数获得的结果非常接近,但并不完全相同。我对R知之甚少,但我想您可以使用sy

有人知道如何使用R中的magick软件包从16位tiff图像中获取每个通道(RGB)的像素值吗?目前我正在使用Mathematica来执行此操作,因为我找不到在Mathematica中执行此操作的等效方法


我尝试从image magick软件包中读取像素值,结果是原始类型(例如“ff”)。我使用函数rawToNum(package“pack”)将原始类型转换为数字,结果与我在Mathematica中使用ImageDate函数获得的结果非常接近,但并不完全相同。

我对
R
知之甚少,但我想您可以使用
system()来“壳出”并执行外部命令
之类的

如果,那么,也许你可以用这个。首先,让我们制作一个16位TIFF文件,它是一个从红蓝到宽10像素、高1像素的渐变:

convert -size 10x1 gradient:red-blue image.tiff

现在我们可以使用ImageMagick将像素转储到文件中:

convert image.tiff rgb:image.rgb

# Now check its length - yes, 60 bytes = 10 pixels with 2 bytes each for RG &B
ls -l image.rgb
-rw-r--r--  1 mark  staff  60 11 Jul 10:32 image.rgb
我们也可以这样将数据写入
stdout

convert image.tiff rgb:- 
convert image.tiff rgb: | od -An -tuS | awk '{for(i=1;i<=NF;i++){print $i}}'
65535
0
0
58253
0
7282
50972
0
14563
43690
0
21845
36408
0
29127
29127
0
36408
21845
0
43690
14563
0
50972
7282
0
58253
0
0
65535
还可以用每行1个像素(6字节)来查看它

我希望您可以在
R
中执行类似操作,包括:

system("convert image.tif rgb:-")

另一种转储像素的方法可能是使用
Perl
对整个文件进行压缩,然后解压包含的未签名短片,并每行打印一条:

convert image.tiff rgb: | perl -e 'my $str=do{local $/; <STDIN>}; print join("\n",unpack("v*",$str)),"\n";'

查看数据的另一种方式可能是使用
od
awk
如下:

convert image.tiff rgb:- 
convert image.tiff rgb: | od -An -tuS | awk '{for(i=1;i<=NF;i++){print $i}}'
65535
0
0
58253
0
7282
50972
0
14563
43690
0
21845
36408
0
29127
29127
0
36408
21845
0
43690
14563
0
50972
7282
0
58253
0
0
65535

convert image.tiff rgb:| od-An-tuS | awk'{for(i=1;i我对
R
知之甚少,但我想您可以使用
system()
或类似的方法“退出”并执行外部命令

如果,那么,也许你可以使用这个。首先,让我们制作一个16位TIFF文件,它是一个从红到蓝的渐变,只有10像素宽,1像素高:

convert -size 10x1 gradient:red-blue image.tiff

现在我们可以使用ImageMagick将像素转储到文件中:

convert image.tiff rgb:image.rgb

# Now check its length - yes, 60 bytes = 10 pixels with 2 bytes each for RG &B
ls -l image.rgb
-rw-r--r--  1 mark  staff  60 11 Jul 10:32 image.rgb
我们也可以这样将数据写入
stdout

convert image.tiff rgb:- 
convert image.tiff rgb: | od -An -tuS | awk '{for(i=1;i<=NF;i++){print $i}}'
65535
0
0
58253
0
7282
50972
0
14563
43690
0
21845
36408
0
29127
29127
0
36408
21845
0
43690
14563
0
50972
7282
0
58253
0
0
65535
还可以用每行1个像素(6字节)来查看它

我希望您可以在
R
中执行类似操作,包括:

system("convert image.tif rgb:-")

另一种转储像素的方法可能是使用
Perl
对整个文件进行压缩,然后解压包含的未签名短片,并每行打印一条:

convert image.tiff rgb: | perl -e 'my $str=do{local $/; <STDIN>}; print join("\n",unpack("v*",$str)),"\n";'

查看数据的另一种方式可能是使用
od
awk
如下:

convert image.tiff rgb:- 
convert image.tiff rgb: | od -An -tuS | awk '{for(i=1;i<=NF;i++){print $i}}'
65535
0
0
58253
0
7282
50972
0
14563
43690
0
21845
36408
0
29127
29127
0
36408
21845
0
43690
14563
0
50972
7282
0
58253
0
0
65535

convert image.tiff rgb:| od-An-tuS | awk'{for(i=1;i在ImageMagick中,可能更简单的方法是使用txt:output格式

使用Mark Setchell的图像:

convert -size 10x1 gradient:red-blue image.tiff
使用TXT:as

convert image.tiff txt: | sed -n 's/^.*[(]\(.*\)[)].*[#].*$/\1/p'
产生:

65535,0,0
58253,0,7282
50972,0,14563
43690,0,21845
36408,0,29127
29127,0,36408
21845,0,43690
14563,0,50972
7282,0,58253
0,0,65535
0,0: (65535,0,0)
1,0: (58253,0,7282)
2,0: (50972,0,14563)
3,0: (43690,0,21845)
4,0: (36408,0,29127)
5,0: (29127,0,36408)
6,0: (21845,0,43690)
7,0: (14563,0,50972)
8,0: (7282,0,58253)
9,0: (0,0,65535)
或者使用TXT:包含像素坐标

convert image.tiff txt: | sed -n 's/^\(.*[)]\).*[#].*$/\1/p'
产生:

65535,0,0
58253,0,7282
50972,0,14563
43690,0,21845
36408,0,29127
29127,0,36408
21845,0,43690
14563,0,50972
7282,0,58253
0,0,65535
0,0: (65535,0,0)
1,0: (58253,0,7282)
2,0: (50972,0,14563)
3,0: (43690,0,21845)
4,0: (36408,0,29127)
5,0: (29127,0,36408)
6,0: (21845,0,43690)
7,0: (14563,0,50972)
8,0: (7282,0,58253)
9,0: (0,0,65535)

在ImageMagick中,一种稍微简单的方法可能是使用txt:output格式

使用Mark Setchell的图像:

convert -size 10x1 gradient:red-blue image.tiff
使用TXT:as

convert image.tiff txt: | sed -n 's/^.*[(]\(.*\)[)].*[#].*$/\1/p'
产生:

65535,0,0
58253,0,7282
50972,0,14563
43690,0,21845
36408,0,29127
29127,0,36408
21845,0,43690
14563,0,50972
7282,0,58253
0,0,65535
0,0: (65535,0,0)
1,0: (58253,0,7282)
2,0: (50972,0,14563)
3,0: (43690,0,21845)
4,0: (36408,0,29127)
5,0: (29127,0,36408)
6,0: (21845,0,43690)
7,0: (14563,0,50972)
8,0: (7282,0,58253)
9,0: (0,0,65535)
或者使用TXT:包含像素坐标

convert image.tiff txt: | sed -n 's/^\(.*[)]\).*[#].*$/\1/p'
产生:

65535,0,0
58253,0,7282
50972,0,14563
43690,0,21845
36408,0,29127
29127,0,36408
21845,0,43690
14563,0,50972
7282,0,58253
0,0,65535
0,0: (65535,0,0)
1,0: (58253,0,7282)
2,0: (50972,0,14563)
3,0: (43690,0,21845)
4,0: (36408,0,29127)
5,0: (29127,0,36408)
6,0: (21845,0,43690)
7,0: (14563,0,50972)
8,0: (7282,0,58253)
9,0: (0,0,65535)

谢谢大家。我找到的最好答案是我的一个学生用光栅包给出的:

library(raster)
img <- stack(filename)
x <- as.matrix(raster(img, 1)) # here we specify the layer 1, 2 or 3
库(光栅)

img谢谢大家。我找到的最好答案是我的一个学生用光栅包给出的:

library(raster)
img <- stack(filename)
x <- as.matrix(raster(img, 1)) # here we specify the layer 1, 2 or 3
库(光栅)

img您还可以使用
magick
软件包以数字数组的形式访问像素

library(magick)

tiger <- image_read('http://jeroen.github.io/images/tiger.svg')
tiger_tiff <- image_convert(tiger, "tiff")

# Access data in raw format and convert to integer
tiger_array <- as.integer(tiger_tiff[[1]])

您还可以使用
magick
软件包以数字数组的形式访问像素

library(magick)

tiger <- image_read('http://jeroen.github.io/images/tiger.svg')
tiger_tiff <- image_convert(tiger, "tiff")

# Access data in raw format and convert to integer
tiger_array <- as.integer(tiger_tiff[[1]])

您尝试过R中的
tiff
包中的
readTIFF
吗?我用它来获取tiff图像的RGB值。您尝试过R中的
tiff
包中的
readTIFF
吗?我用它来获取tiff图像的RGB值。