Z max projection
Closed this issue · 3 comments
I am trying to create a max projected tiff file. Not able to get it work. Any suggestion appreciated
import numpy as np
import tifffile as tf
import multipagetiff as mtif
File_name = "r01c05f20p0"
file_extension = "sk1fk1fl1.tiff"
image_path = "/mayday/Imaged_03102022/31022_HPC/"
#### get three stacks from each channel: Here its is channel 4
stack_1 = image_path+File_name+"1-"+"ch4"+file_extension
stack_2 = image_path+File_name+"2-"+"ch4"+file_extension
stack_3 = image_path+File_name+"3-"+"ch4"+file_extension
###### Read each images
img = tf.imread(stack_1)
img = np.expand_dims(img, axis=0)
img2 = tf.imread(stack_2)
img2 = np.expand_dims(img2, axis=0)
img3 = tf.imread(stack_3)
img3 = np.expand_dims(img3, axis=0)
### create stacked image
img_merged = np.concatenate([img, img2,img3], axis=0)
##################
# Normalization
s1 = mtif.Stack(img_merged)
s1.normalize = True # normalize the pages
s2 = mtif.flatten(s1)
tf.imwrite('temp_stack.tif', s2, photometric='minisblack')
The file created is truncated
Hello kvshams,
I am not sure to understand what you want to precisely here.
As far as I understand here, s2 should be a 2D RGB array (shape=(MxNx3)).
Could you check this, please? In this case, I think you need something else to save it, for example matplotlib.image.imsave
as in here.
As remark, you could use mtif.load_stack
and mtif.read_stack
to load and save multi-page grayscale tiff files.
Hope this helps, otherwise paste the full error output please.
Marco
@mathildelpx Thanks for the reply. I have three stacks of image (separate tif for each plane) for the same object. I wanted to get a max projection of these three images for downstream image quantification.
Here is the image dimentions
>>> img.shape
(1080, 1080)
>>> img = np.expand_dims(img, axis=0)
>>> img.shape
(1, 1080, 1080)
>>> img2 = tf.imread(stack_2)
>>> img2.shape
(1080, 1080)
>>> img2 = np.expand_dims(img2, axis=0)
>>> img2.shape
(1, 1080, 1080)
>>> img3 = tf.imread(stack_3)
>>> img3.shape
(1080, 1080)
>>> img3 = tf.imread(stack_3)
>>> img3 = np.expand_dims(img3, axis=0)
>>> img3.shape
(1, 1080, 1080)
The error I am getting is while loading the saved tiff file to fiji
/ImageJ
that loading error
image is truncated
Thanks,
Shams
Hello Shams,
I think the problem is that s1 is color coded in rgb.
try mtif.flatten_grayscale(s1) instead of just mtif.flatten(s1)