Errno 22: Invalid argument while using tiff.imread() in python

50 views Asked by At

I have a folder with ~800 tiff images. i wrote the following code to save these as multiple tiff stacks of 220 images each. In a later section of this code, i try to open the tiff stacks that I've saved using tiff.imread() but I get the Error[22] Invalid Argument.

My import functions:

import numpy as np
import scipy as sp
import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd
import sys
import tifffile as tiff
from skimage import io
import cv2
import tifftools
from tifffile import imread, imsave
from tifffile import TiffWriter, memmap
image_stack =[]

tiff_files = math.ceil(len(list_of_images)/220)  ## each tiff file to be 220 images long
print(tiff_files)

if tiff_files >1:
    for i in range(tiff_files-1):
        print(i)
        
        image_stack =[]
        for j in range(220):
            print(j)
            image_r = imread(wrk_dir + list_of_images[j+i*220])
            image_stack.append(image_r)
        tiff.imwrite(output_dir + str(i)+'.tif', image_stack)
        print(i,'done')
    
    image_stack =[]
    for j in range(len(list_of_images)-220*(tiff_files-1)):
        print(j)
        image_r = imread(wrk_dir + list_of_images[j+(tiff_files-1)*220])
        image_stack.append(image_r)
    tiff.imwrite(output_dir + str(tiff_files-1)+'.tif', image_stack)
    print(tiff_files-1,'done')
    
else:
    image_stack =[]
    for j in range(len(list_of_images)):
        print(j)
        image_r = imread(wrk_dir+ list_of_images[j])
        image_stack.append(image_r)
    tiff.imwrite(output_dir + str(tiff_files-1)+'.tif', image_stack)
    print(tiff_files-1,'done')

the code snippet where i try to read the tiff stack but then i get the error:


for i in range(tiff_files):
    print(i)
    # read all images matching the pattern
    image_stack = tiff.imread(output_dir+str(i)+'.tif')

I tried to open the tiff stacks but i got the invalid argument error. What can i do to solve this? Sometimes the same code works and sometimes it doesnt :/

0

There are 0 answers