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
bdata
type tonp.uint8
and 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
, allTrue
elements are converted to1
and False elements are converted to0
.Multiply by
255
for converting theTrue
elements 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.