Load a tiff stack in a numpy array with python

后端 未结 2 1850
一个人的身影
一个人的身影 2021-02-05 19:59

I am having a little issue with .tif files. I am sure it is only a minor problem that I can´t get around (keep in mind, I am a relatively new programmer).

Basically: I h

2条回答
  •  不要未来只要你来
    2021-02-05 20:23

    PIL has a function seek to move to different slices of a tiff stack.

    from PIL import Image
    
    file_path=(D:\luca\test\test.tif)
    print("The selected stack is a .tif")
    dataset = Image.open(file_path)
    h,w = np.shape(dataset)
    tiffarray = np.zeros((h,w,dataset.n_frames))
    for i in range(dataset.n_frames):
       dataset.seek(i)
       tiffarray[:,:,i] = np.array(dataset)
    expim = tiffarray.astype(np.double);
    print(expim.shape)
    

提交回复
热议问题