I have a related issue and was hoping to piggyback off this answer.
I’ve written some microscope control software in LabVIEW, and i’m trying to construct a 5d image stack of confocal images in ‘RZCYX’ order, but saving the images as they’re acquired rather than buffering the whole capture.
I havent done this before but thought this is a better way to do it vs trying to buffer the whole thing and save at the end, in case something catastrophic happens with the microscope while scanning (power outage, software crash, hardware failure etc.). Also seems prudent for memory management. If there’s a better approach please let me know.
The built-in LabVIEW tiff functions are pretty threadbare, so instead i’m using Tifffile to save each incoming z-stack.Test code to do this is as follows:
from pathlib import Path
import numpy as np
import tifffile as tf
def write_tiff(filepath, image, append):
# incoming image is a list if called from LabVIEW. Convert to numpy array first
if isinstance(image, list):
np_image = np.array(image, dtype='uint16')
np_image = image
with tf.TiffWriter(filepath, append=append) as tif:
if __name__ == '__main__':
# create a random z-stack image similar to the Zeiss LSM 510 12 bit tiff
# One region, consisting of 25 z-slices, 2 channels, x*y of 512*512 pixels
data = np.random.randint(0, 2**12, (1, 25, 2, 512, 512), dtype='uint16')
fpath = Path("test_images/multi_stack_img.ome.tiff")
# create a new file and write data to it
write_tiff(fpath, data, append=False)
# append identically shaped region data to existing file
regions = range(10)
for region in regions:
new_series = np.random.randint(0, 2**8, (1, 25, 2, 512, 512), dtype='uint16')
write_tiff(fpath, new_series, append=True)
The images seem to save (file size is as expected) but the image is only recognised as having a single timepoint (T=1). I tried using ‘R’ instead of ‘T’ in the axes metadata but this doesn’t seem to make a difference.
How do I append regions (or even timepoints) to an existing file. Do i need to reshape the file as I go to achieve this, if that’s even possible?
Any help would be greatly appreciated