代码之家  ›  专栏  ›  技术社区  ›  Baron Yugovich

Scipy imsave和imread更改格式

  •  0
  • Baron Yugovich  · 技术社区  · 6 年前

    当我保存图像时,它的格式是 numpy.uint16 numpy.uint8 ,它把整个管道都搞砸了。我如何防止这种情况发生?

    我在打电话

    from scipy.misc import imread, imsave
    image = imread(path)
    imread(image_path)
    
    2 回复  |  直到 6 年前
        1
  •  3
  •   Lakshay Sharma    6 年前

    这个 imsave imread 方法已弃用,并将在以后的SciPy版本中删除。使用 imageio.imsave imageio.imread

    >>> import imageio
    >>> img = imageio.imread('img.jpg')
    >>> img.dtype
    dtype('uint8')
    >>> imageio.imwrite('img_saved.jpg', img)
    >>> img_read = imageio.imread('img_saved.jpg')
    >>> img_read.dtype
    dtype('uint8')
    
        2
  •  0
  •   Mark Setchell    6 年前

    我会在这样的TIFF中读写16位灰度数据:

    #!/usr/local/bin/python3
    
    import numpy as np
    from PIL import Image
    
    # Make a greyscale image of random 16-bit ints in range 0..65535
    arr = np.random.randint(0,65535,(320,240), dtype=np.uint16)
    
    # Make PIL image from numpy array and save
    im=Image.fromarray(arr).save("result.tif")
    
    # Re-read from file
    reloadedim  = Image.open("result.tif")
    reloadedarr = np.array(reloadedim)
    
    # Calculate difference
    diff = arr - reloadedarr
    print("Number of different pixels: {}".format(sum(diff.ravel())))
    

    它印出来了 .

    推荐文章