ufo-kit / ufo-filters

Common plugin suite for the ufo-core processing framework
GNU Lesser General Public License v3.0
10 stars 14 forks source link

Enable append to bigtiffs #222

Closed sgasilov closed 1 year ago

sgasilov commented 1 year ago

Hello,

there is "append" flag in "write" sink which is presently not doing much. Could you program it in such a way that when True, one can add pages to an existing bigtiff file? For instance: for i in *; do ufo-launch read path=$i/sli-nlmdn/ start=4 number=216 ! write filename=../head-neck.tif append=True; done will take certain slices from a bunch of directories and pack them together in one container.

Cheers, Sergei.

tfarago commented 1 year ago

Could you please git checkout -t origin/append-to-files, install it and check if it's doing what you need?

tfarago commented 1 year ago

Example usage: ufo-launch -q read path=foobar.tif number=10 ! write filename=appended-rewritten.tif tiff-bigtiff=True append-file=True

sgasilov commented 1 year ago

Tomas, hello

It does put all images into one file, however, for whatever reason not always to the end? That is, if I open results of: for i in ; do ufo-launch read path=$i/sli-nlmdn/ start=4 number=216 ! write filename=../head-neck.tif append=True; done and scroll, I see z02 - z00 - z01, not z00 - z01 - z02. Is it my bash or something in libtif? If I run that: (ufoenv) head>for i in ; do echo $i; done I get the correct sequence: z00 z01 z02

tfarago commented 1 year ago

I don't see this behavior, could you try in python:

ones = np.ones((n, n), dtype=np.float32)
fmt = '{}/image-{:>04}.tif'

for i in range(8):
     for j in range(256):
         out_dir = f'{i:>02}'  # you need to make sure this dir exists
         tifffile.imwrite(fmt.format(out_dir, j), ones * (256 * i + j))

then in bash:

for i in */; do ufo-launch -q read path=$i ! write filename=appended.tif tiff-bigtiff=True append-file=True; done

and then again in python:

reader = TiffSequenceReader('appended.tif')
x = [reader.read(i)[0, 0] for i in range(reader.num_images)]
assert np.all(np.gradient(x) == 1)
sgasilov commented 1 year ago

Did that and have no assertion errors

tfarago commented 1 year ago

OK, so I leave this open and when you check it on real data write me please and we will merge this.

sgasilov commented 1 year ago

Everything works correctly, thank you very much!