【问题标题】:How to create an image with height as pixel values如何创建高度为像素值的图像
【发布时间】:2021-05-22 06:28:42
【问题描述】:

我想创建一个大小为 343 x 389(高度 x 宽度)的 jpg 图像,高度为像素值。例如,对于整个最上面的像素,我需要将其设为值 1,下一行像素的值应为 2。最后,最后一个像素的值为 343。然后以 jpg 格式导出该图像。这该怎么做?在 python 中还是在 Matlab 中?

【问题讨论】:

    标签: python matlab matrix


    【解决方案1】:

    在 MATLAB 中

    在 MATLAB 中使用 meshgrid() 函数的解决方案可能有效。一个重要的部分是将double 类型的数组Image 转换为一个无符号的8 位整数数组uint8,然后使用imwrite() 函数将其导出为.jpg



    [~,Image] = meshgrid((1:389),(1:343));
    imwrite(uint8(Image),"Depth.jpg");
    

    【讨论】:

      【解决方案2】:

      做到了

      from PIL import Image
      import numpy as np
      a = np.empty(shape=(343, 389), dtype=int)
      
      for i in range(343):
          for j in range(389):
              a[i,j]=i
      im = Image.fromarray(a,'L')
      
      im.save('depth.jpg')
      

      【讨论】:

        猜你喜欢
        • 2012-02-24
        • 2015-05-30
        • 1970-01-01
        • 1970-01-01
        • 2012-09-14
        • 1970-01-01
        • 1970-01-01
        • 2020-02-21
        • 1970-01-01
        相关资源
        最近更新 更多