Example #1
0
def test_write_read():

    for compression in [None, 'lzw']:
        for itype in [uint8, uint16, uint32, uint64, 
                      int8, int16, int32, int64,
                      float32, float64,
                      complex64, complex128]:
            image = array([[1,2,3], [4,5,6]], itype)
            fn = mktemp('.tif')

            if 0:
                tif = TIFF.open(fn,'w')
                tif.write_image(image, compression=compression)
                tif.close()
            else:
                tif = TIFFimage(image)
                tif.write_file(fn, compression=compression)
                del tif

            tif = TIFFfile(fn)
            data, names = tif.get_samples()
            assert names==['sample0'],`names`
            assert len(data)==1, `len(data)`
            assert image.dtype==data[0].dtype, `image.dtype, data[0].dtype`
            assert (image==data[0]).all()
            
            #os.remove(fn)
            atexit.register(os.remove, fn)
Example #2
0
def test_write_read():

    for compression in [None, 'lzw']:
        for itype in [
                uint8, uint16, uint32, uint64, int8, int16, int32, int64,
                float32, float64, complex64, complex128
        ]:
            image = array([[1, 2, 3], [4, 5, 6]], itype)
            fn = mktemp('.tif')

            if 0:
                tif = TIFF.open(fn, 'w')
                tif.write_image(image, compression=compression)
                tif.close()
            else:
                tif = TIFFimage(image)
                tif.write_file(fn, compression=compression)
                del tif

            tif = TIFFfile(fn)
            data, names = tif.get_samples()
            assert names == ['sample0'], repr(names)
            assert len(data) == 1, repr(len(data))
            assert image.dtype == data[0].dtype, repr(
                (image.dtype, data[0].dtype))
            assert (image == data[0]).all()

            #os.remove(fn)
            atexit.register(os.remove, fn)
Example #3
0
def test_rw_rgb():
    itype = uint8
    dt = dtype(dict(names=list('rgb'), formats=[itype] * 3))

    image = zeros((2, 3), dtype=dt)
    image['r'][:, 0] = 250
    image['g'][:, 1] = 251
    image['b'][:, 2] = 252

    fn = mktemp('.tif')
    tif = TIFFimage(image)
    tif.write_file(fn, compression='lzw')  #, samples='rgb')
    del tif

    tif = TIFFfile(fn)
    data, names = tif.get_samples()
    #os.remove(fn)
    atexit.register(os.remove, fn)
    print image
    print data

    assert itype == data[0].dtype, ` itype, data[0].dtype `
    assert (image['r'] == data[0]).all()
    assert (image['g'] == data[1]).all()
    assert (image['b'] == data[2]).all()
Example #4
0
def test_rw_rgb():
    itype = uint8
    dt = dtype(dict(names = list('rgb'), formats = [itype]*3))
    
    image = zeros((2,3), dtype=dt)
    image['r'][:,0] = 250
    image['g'][:,1] = 251
    image['b'][:,2] = 252

    fn = mktemp('.tif')
    tif = TIFFimage(image)
    tif.write_file(fn,compression='lzw')#, samples='rgb')
    del tif

    tif = TIFFfile(fn)
    data, names = tif.get_samples()
    #os.remove(fn)
    atexit.register(os.remove, fn)
    print image
    print data

    assert itype == data[0].dtype, `itype, data[0].dtype`
    assert (image['r']==data[0]).all()
    assert (image['g']==data[1]).all()
    assert (image['b']==data[2]).all()
Example #5
0
def test_write_read():
    for compression in ['none', 'lzw']:
        for itype in [
                uint8, uint16, uint32, uint64, int8, int16, int32, int64,
                float32, float64, complex64, complex128
        ]:
            image = array([[1, 2, 3], [4, 5, 6]], itype)
            fn = mktemp('.tif')
            tif = TIFFimage(image)
            tif.write_file(fn, compression=compression)
            del tif

            tif = TIFFfile(fn)
            data, names = tif.get_samples()
            #os.remove(fn)
            atexit.register(os.remove, fn)
            assert names == ['sample0'], ` names `
            assert len(data) == 1, ` len(data) `
            assert image.dtype == data[0].dtype, ` image.dtype, data[0].dtype `
            assert (image == data[0]).all()
Example #6
0
def test_write_read():
    for compression in ['none', 'lzw']:
        for itype in [uint8, uint16, uint32, uint64, 
                      int8, int16, int32, int64,
                      float32, float64,
                      complex64, complex128]:
            image = array([[1,2,3], [4,5,6]], itype)
            fn = mktemp('.tif')
            tif = TIFFimage(image)
            tif.write_file(fn, compression=compression)
            del tif
            
            tif = TIFFfile(fn)
            data, names = tif.get_samples()
            #os.remove(fn)
            atexit.register(os.remove, fn)
            assert names==['sample0'],repr(names)
            assert len(data)==1, repr(len(data))
            assert image.dtype==data[0].dtype, repr((image.dtype,data[0].dtype))
            assert (image==data[0]).all()