I am trying to save an altered z-stack .tif file in Python3. Here's my code where I checked that the the functions worked as intended.
#libraries
import imageio as ii
#import initial image
fname='101_nuc1syg1.tif'
adata = ii.volread(fname)
#check to make sure volread works
ii.volsave('temp.tif', adata)
Which results in this:
And now when I try to do a simple threshold, using the following code:
#now doing very simple thresholding
bdata = adata < adata[0].mean()
bdata = bdata +0
ii.volsave('temp.tif', bdata)
I get this:
Any idea how to save a tif file properly after performing image operators on it?
EDIT: Note that I am able to extract each stack and save them as separate .png files, but I would prefer to have them as a single .tif file.
Data from: https://www.nature.com/articles/s41467-020-15987-2


It looks like you need to convert
bdatatype tonp.uint8and multiply the result by 255.The type of the expression (adata < adata[0].mean()) is
np.bool.The common image type is
np.uint8.Convert
(adata < adata[0].mean())to typenp.uint8:When converting the result to
np.uint8, allTrueelements are converted to1and False elements are converted to0.Multiply by
255for converting theTrueelements to255(white color):Complete code:
Note:
I could not test my answer - the link you have posted doesn't contain a link to an image.