silx-kit / fabio

I/O library for images produced by 2D X-ray detector
Other
57 stars 52 forks source link

[TIFF] Management of multi-frame tiff #543

Closed kif closed 1 year ago

kif commented 1 year ago

Apparently, this is not foreseen ... reported by Tra.

kif commented 1 year ago

@vasole do you have an idea in this issue ?

vasole commented 1 year ago

Multi-frames TIFF is handled by TiffIO since its very first version.

You can save and load a complete stack of images as a single TIFF if you want.

Tiled Tiff images are not handled.

vasole commented 1 year ago

The test code inside TiffIO.py shows clearly how to do it

if __name__ == "__main__":
    filename = sys.argv[1]
    dtype = numpy.uint16
    if not os.path.exists(filename):
        print("Testing file creation")
        tif = TiffIO(filename, mode='wb+')
        data = numpy.arange(10000).astype(dtype)
        data.shape = 100, 100
        tif.writeImage(data, info={'Title': '1st'})
        tif = None
        if os.path.exists(filename):
            print("Testing image appending")
            tif = TiffIO(filename, mode='rb+')
            tif.writeImage((data * 2).astype(dtype), info={'Title': '2nd'})
            tif = None
    tif = TiffIO(filename)
    print("Number of images = %d" % tif.getNumberOfImages())
    for i in range(tif.getNumberOfImages()):
        info = tif.getInfo(i)
        for key in info:
            if key not in ["colormap"]:
                print("%s = %s" % (key, info[key]))
            elif info['colormap'] is not None:
                print("RED   %s = %s" % (key, info[key][0:10, 0]))
                print("GREEN %s = %s" % (key, info[key][0:10, 1]))
                print("BLUE  %s = %s" % (key, info[key][0:10, 2]))
        data = tif.getImage(i)[0, 0:10]
        print("data [0, 0:10] = ", data)