abria / TeraStitcher

A tool for fast automatic 3D-stitching of teravoxel-sized microscopy images
http://abria.github.io/TeraStitcher/
Other
78 stars 32 forks source link

Stack to channels: Is there a way to convert an "Unstitched 3D" with three color channels to an RGB image? #54

Closed ilykos closed 4 years ago

ilykos commented 4 years ago

My data consists of RGB images represented by 1 intensity image per channel.

So there are:

I have successfully aligned these images with the command line tool.

My goal is to merge these into a single BigTiff file with RGB channels. Not a TIFF stack, but a single image where each pixel is interpreted as having an RGB value.

When I try to do that I get a stacked TIFF.

So far, I have been using the following command suggested by one of the maintainers:

teraconverter --sfmt="TIFF (unstitched, 3D)" --dfmt="TIFF (tiled, 3D)" -s="C:\Users\Imisystem\Desktop\P60-020-color-8bit-split-channels\xml_merging.xml" -d="C:\Users\Imisystem\Desktop\st" --V0=0 --V1=10000 --H0=0 --H1=10000 --libtiff_bigtiff

If I understand this correctly, TeraStitcher cannot stitch RGB images (they need to be split into separate grayscales per channel). Please correct me if I am wrong here!

If so, can you suggest a way of converting a stacked TIFF into a RGB channel TIFF? My challenge is that I cannot open the file in ImageJ, it is way too big.

iannellog commented 4 years ago

Try to read section 1.8 of the TeraTools Guide (link at Wiki page, panel on the right). That seems your case.

ilykos commented 4 years ago

@iannellog Thank you, I did not notice the guide originally and it was a surprisingly informative read.

For those who struggle with the instructions in the guide, I can suggest an alternative way involving python library imageio:

  1. Export your image as 3D TIFF, make sure BigTiff checkbox in advanced options is enabled. This will export a single TIFF file with 3 pages.
  2. Install imageio library from pip.
  3. Open your file in python and create a numpy dstack out the channels in your file (see code below). This will turn pages into channels for red green and blue.
  4. Save the file as tiff with BigTiff flag enabled (see code below).
import imageio
import numpy as np

image_in = r"test.tif" # bigtiff export from TeraStitcher
image_out = r"test_rgb_merged.tif"

image = imageio.mimread(image_in, memtest=False)
rgb = np.dstack(image)
imageio.imsave(image_out, rgb, bigtiff=True)

This successfully produced 75000 x 75000 pixel image in three channels on a computer with 32 GB RAM.