Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.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
Python 为什么枕头和scikit图像以不同方式打开8位RGB图像?_Python_Python Imaging Library_Scikit Image - Fatal编程技术网

Python 为什么枕头和scikit图像以不同方式打开8位RGB图像?

Python 为什么枕头和scikit图像以不同方式打开8位RGB图像?,python,python-imaging-library,scikit-image,Python,Python Imaging Library,Scikit Image,我正在打开一个8位图像,包括枕头和Scikit图像。Scikit图像给出了每像素三个字节,而枕头给出了每像素一个字节 我已使用以下代码打开此图像: im1=skimage.io.imread(img\u地址) im2=Image.open(img\U地址) 结果: >im1[0,0] 数组([153153153],dtype=uint8) im2.getpixel((0,0)) 13 我想知道数组([153153153],dtype=uint8)是如何转换为13您的PNG文件似乎是一个P

我正在打开一个8位图像,包括枕头和Scikit图像。Scikit图像给出了每像素三个字节,而枕头给出了每像素一个字节

我已使用以下代码打开此图像:

im1=skimage.io.imread(img\u地址)
im2=Image.open(img\U地址)
结果:

>im1[0,0]
数组([153153153],dtype=uint8)
im2.getpixel((0,0)) 13
我想知道数组([153153153],dtype=uint8)是如何转换为13您的PNG文件似乎是一个Pallete编码的PNG文件。此类文件中的像素由PNG类型调色板中的整数值描述,从而减小文件大小。要在RGB中查看文件,您需要使用
im=im.convert('RGB')
将图像转换为RGB

如果您随后使用
im.getpixel((0,0))
请求像素值,您将获得期望得到的
(153153153)

总之,scikit image package会自动进行PNG转换,而pillow会返回原始数据并将其留给您将图像转换为RGB

更多关于PNG调色板的信息,请访问[libpng.org][1]

8.5.1. Palette-Based
Palette-based images, also known as colormapped or index-color images, use the PLTE chunk and are supported in four pixel depths: 1, 2, 4, and 8 bits, corresponding to a maximum of 2, 4, 16, or 256 palette entries. Unlike GIF images, however, fewer than the maximum number of entries may be present. On the other hand, GIF does support pixel depths of 3, 5, 6, and 7 bits; 6-bit (64-color) images, in particular, are common on the World Wide Web.

TIFF also supports palette images, but baseline TIFF allows only 4- and 8-bit pixel depths. Perhaps a more useful comparison is with the superset of baseline TIFF that is supported by Sam Leffler's free libtiff, which has become the software industry's unofficial standard for TIFF decoding. libtiff supports palette bit depths of 1, 2, 4, 8, and 16 bits. Unlike PNG and GIF, however, the TIFF palette always uses 16-bit integers for each red, green, and blue value, and as with GIF, all 2bit depth entries must be present in the file. Nor is there any provision for compression of the palette data--so a 16-bit TIFF palette would require 384 KB all by itself.


  [1]: http://www.libpng.org/pub/png/book/chapter08.html

您的PNG文件似乎是Pallete编码的PNG文件。此类文件中的像素由PNG类型调色板中的整数值描述,从而减小文件大小。要在RGB中查看文件,您需要使用
im=im.convert('RGB')
将图像转换为RGB

如果您随后使用
im.getpixel((0,0))
请求像素值,您将获得期望得到的
(153153153)

总之,scikit image package会自动进行PNG转换,而pillow会返回原始数据并将其留给您将图像转换为RGB

更多关于PNG调色板的信息,请访问[libpng.org][1]

8.5.1. Palette-Based
Palette-based images, also known as colormapped or index-color images, use the PLTE chunk and are supported in four pixel depths: 1, 2, 4, and 8 bits, corresponding to a maximum of 2, 4, 16, or 256 palette entries. Unlike GIF images, however, fewer than the maximum number of entries may be present. On the other hand, GIF does support pixel depths of 3, 5, 6, and 7 bits; 6-bit (64-color) images, in particular, are common on the World Wide Web.

TIFF also supports palette images, but baseline TIFF allows only 4- and 8-bit pixel depths. Perhaps a more useful comparison is with the superset of baseline TIFF that is supported by Sam Leffler's free libtiff, which has become the software industry's unofficial standard for TIFF decoding. libtiff supports palette bit depths of 1, 2, 4, 8, and 16 bits. Unlike PNG and GIF, however, the TIFF palette always uses 16-bit integers for each red, green, and blue value, and as with GIF, all 2bit depth entries must be present in the file. Nor is there any provision for compression of the palette data--so a 16-bit TIFF palette would require 384 KB all by itself.


  [1]: http://www.libpng.org/pub/png/book/chapter08.html

不太清楚这里发生了什么,但是如果你只是对一个解决方案感兴趣,你应该能够解决它,如果你这么做:
pix=im2.load()
然后
pix[0,0]
,或者
pix[x,y]
它给出的数字与
im2.getpixel((0,0))相同
:13.文件类型是什么?它是png文件您的png文件似乎是Pallete编码的png文件。我已经用推理更新了我下面的答案,并链接到了完整的解释。我不太确定这里发生了什么,但是如果你只是对一个解决方案感兴趣,你应该能够解决它,如果你这么做:
pix=im2.load()
然后
pix[0,0]
,或者
pix[x,y]
它给出的数字与
im2.getpixel((0,0))相同
:13.文件类型是什么?它是png文件您的png文件似乎是Pallete编码的png文件。我已经用推理更新了我下面的答案,并链接到完整的解释。没错,在转换后,
converted\u im2=im2.convert('RGB')
converted\u im2.getpixel((0,0))
等于
(153153153)
。我发现
im2.mode
'P'
,而
converted\u im2
'RGB'
,这证实了你所说的。(但我认为scikit image提供了原始数据,而pillow提供了转换后的数据(可能是
raw\u im.convert('P')
))谢谢。要确认/否认这一点,我们必须研究源映像是如何创建的。我希望这已经给了你足够的提示来开始这项工作problem@That右边,在转换后,
converted\u im2=im2.convert('RGB')
converted\u im2.getpixel((0,0))
等于
(153153153)
。我发现
im2.mode
'P'
,而
converted\u im2
'RGB'
,这证实了你所说的。(但我认为scikit image提供了原始数据,而pillow提供了转换后的数据(可能是
raw\u im.convert('P')
))谢谢。要确认/否认这一点,我们必须研究源映像是如何创建的。我希望这已经给了你足够的提示来开始这个问题@