【问题标题】:why does an image of size 9 MB on disk occupy 125 MB in RAM when loaded into numpy?为什么加载到 numpy 时磁盘上大小为 9 MB 的图像在 RAM 中占用 125 MB?
【发布时间】:2019-01-29 16:40:44
【问题描述】:

Link to the image in question

让我重现我面临的问题。

from skimage import io
image = io.imread("https://github.com/thalishsajeed/PythonLearn/raw/master/Houston_Chronicle__May_19_2018_51.jpg")
print((image.nbytes/(1024*1024)))

结果:125.87553691864014

那么,当使用 skimage 加载到 numpy 数组中时,9.45 MB 文件会爆炸到 125 MB 是怎么回事? (我也可以使用 openCV 的 cv2.imread 函数复制相同的结果)

我猜这与 JPEG 压缩有关,但如果有人能提供更详细的解释,我将不胜感激。

【问题讨论】:

标签: python image numpy opencv scikit-image


【解决方案1】:

因为那是一个JPG图片文件,是一种压缩图片格式。您的图像分辨率为 6633x6633,它是彩色图像。意思是:
像素数 = 6633 * 6633
总字节大小 = 6633 * 6633 * 3(RGB,每个颜色像素为 1 字节)
~125 mb

【讨论】:

  • @Mad Physicist 图像中有很多纯色区域,所以高压缩并不奇怪。在这些区域中,64 个 DCT 系数中的 63 个将为零。
猜你喜欢
  • 2014-05-29
  • 1970-01-01
  • 2014-02-08
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多