Dave'o-Telephone
Dave'o-Telephone

Reputation: 113

tifffile in Python not writing 16bit tiff

I had a look for duplicates but I'm not sure similar questions had the answer...

I'm using tifffile in Python to read a multipage tiff (16 bit), take the first channel page/channel, blur it and save it as a 16 bit tiff.

import os
import matplotlib.pyplot as plt
import tifffile as tiff
from scipy import misc

tiff_list = []

for i in files_list[0]:
    tiff_list.append(tiff.imread('/filepath_to_tiff_folder/'+i))

blurred_list = []

for i in tiff_list:
    blurred_list.append(ndimage.gaussian_filter(i[0], sigma=3))

for i,v in enumerate(blurred_list):
    misc.imsave('/filepath/testblur2/'+str(files_list[0][i])+'_Brightfield_Blur.tif', v)

Here, files_list is just a list of the file names of the tiffs.

The above code works absolutely fine for blurring and saving the tiff, but it saves it as 8 bit instead.

Is there something in the above I can add to keep it 16 bit or do I have to use another method?

Upvotes: 2

Views: 1923

Answers (1)

cgohlke
cgohlke

Reputation: 9437

You are using scipy, not tifffile, to save the images.

Use tifffile.imsave to save 16-bit images, e.g.:

from glob import glob
from scipy import ndimage
from tifffile import imread, imsave

for filename in glob('*.tif'):
    i = imread(filename)
    i = ndimage.gaussian_filter(i[0], sigma=3)
    imsave('blurred_' + filename, i)

Upvotes: 3

Related Questions