0

I though it would be as simple as picking 1 color and keeping the rest of the axis the same.

from tkinter import filedialog
import tifffile as tif
import os

def SplitChannel(ImName):
    TifIm = tif.imread(ImName)
    return TifIm[:,1,:,:] #for some reason this makes the tiff read cyx vs zyx

    
if __name__ == "__main__":
    Folder = filedialog.askdirectory(title = "Select the directory containing Tif files")
    ImageNames = os.listdir(Folder)
    SaveFolder = Folder + " Split Red Channel2" 
    os.mkdir(SaveFolder)
    os.chdir(Folder)
    for Image in ImageNames:
        if Image.split(".")[-1] == "tif":
            print("here")
            SplitRed = SplitChannel(Image)
            os.chdir("...")
            os.chdir(SaveFolder)
            tif.imwrite(Image + "_Red.ome.tif",SplitRed,imagej= True)
            os.chdir("...")
            os.chdir(Folder)

But this gives me a tif in cyx vs zyx. How can I make sure the resulting tif knows I removed a color channel, and not z

1 Answers1

1

Update: Thank you to cgohlke. Specifying the axes in the metadata has done the trick.

tif.imwrite(Image + "_Red.ome.tif",SplitRed,imagej= True,metadata= {'axes': 'ZYX'})

Thank you everyone and sorry for being vague

Born2Smile
  • 2,918
  • 1
  • 18
  • 20