【问题标题】:Converting TIFF images to NumPy format将 TIFF 图像转换为 NumPy 格式
【发布时间】:2022-12-05 01:30:44
【问题描述】:

我需要帮助来创建将我的 tiff 图像转换为 .npy 格式的代码,以便我可以将其保存为 .npy 文件。 我在这个平台上的任何地方都没有找到好的解决方案。先感谢您!

【问题讨论】:

    标签: python numpy tiff


    【解决方案1】:

    这是一个代码 sn-p,您可以使用它在 Python 中将 TIFF 图像转换为 .npy 格式:

    import numpy as np
    from PIL import Image
    
    # Load the TIFF image
    im = Image.open('my_image.tiff')
    
    # Convert the image to a numpy array
    im_array = np.array(im)
    
    # Save the array to a .npy file
    np.save('my_image.npy', im_array)
    

    然后,您可以使用 np.load 函数加载 .npy 文件,并使用该数组进行进一步的操作。

    # Load the .npy file
    im_array = np.load('my_image.npy')
    #Use the array for your operations
    

    ... 我希望这有帮助!如果您还有其他问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多