ct_segnet/data_utils/data_io.py
def write_tiffseq(S, SaveDir = "", increment_flag = False,\
                  suffix_len = None):
    """Write a sequence of tiff images to a directory.
    S              : numpy array (3D), sequence will be created along axis 0
    SaveDir        : str, path to folder, will create directory if doesn't exist
    increment_flag : bool, True to write append images to existing ones in folder
    suffix_len     : int, e.g. 4 for 1000 images, 5 for 10,000
    """
    if not suffix_len:
        if increment_flag:
            raise ValueError("suffix_len required if increment_flag is True.")
        else:
            suffix_len = len(str(S.shape[0]))
    
    last_num = 0
    if not os.path.exists(SaveDir):
        os.makedirs(SaveDir)
    else:
        if not increment_flag:
            shutil.rmtree(SaveDir)
            os.makedirs(SaveDir)
        else:
            ImgFileList = sorted(glob.glob(SaveDir+'/*.tif'))
            if not ImgFileList: ImgFileList = sorted(glob.glob(SaveDir+'/*.tiff'))
            if not ImgFileList:
                last_num = 0
            else:
                last_num = int(ImgFileList[-1].split('.')[0][-suffix_len:])    
    
    BaseDirName = os.path.basename(os.path.normpath(SaveDir))
    
    for iS in range(S.shape[0]):
        img_num = str(iS+1+last_num).zfill(suffix_len)
        imsave(os.path.join(SaveDir, BaseDirName + img_num + '.tif'), S[iS])
    
    return
Write a sequence of tiff images to a directory.
    S              : numpy array (3D), sequence will be created along axis 0
    SaveDir        : str, path to folder, will create directory if doesn't exist
    increment_flag : bool, True to write append images to existing ones in folder
    suffix_len     : int, e.g. 4 for 1000 images, 5 for 10,000
    
Write a sequence of tiff images to a directory.
S              : numpy array (3D), sequence will be created along axis 0
SaveDir        : str, path to folder, will create directory if doesn't exist
increment_flag : bool, True to write append images to existing ones in folder
suffix_len     : int, e.g.
Write a sequence of tiff images to a directory . S : numpy array ( 3D ) sequence will be created along axis 0 SaveDir : str path to folder will create directory if doesn ' t exist increment_flag : bool True to write append images to existing ones in folder suffix_len : int e . g .
def write_tiffseq(S, SaveDir = "", increment_flag = False,\
                  suffix_len = None):
    if not suffix_len:
        if increment_flag:
            raise ValueError("suffix_len required if increment_flag is True.")
        else:
            suffix_len = len(str(S.shape[0]))
    last_num = 0
    if not os.path.exists(SaveDir):
        os.makedirs(SaveDir)
    else:
        if not increment_flag:
            shutil.rmtree(SaveDir)
            os.makedirs(SaveDir)
        else:
            ImgFileList = sorted(glob.glob(SaveDir+'/*.tif'))
            if not ImgFileList: ImgFileList = sorted(glob.glob(SaveDir+'/*.tiff'))
            if not ImgFileList:
                last_num = 0
            else:
                last_num = int(ImgFileList[-1].split('.')[0][-suffix_len:])    
    BaseDirName = os.path.basename(os.path.normpath(SaveDir))
    for iS in range(S.shape[0]):
        img_num = str(iS+1+last_num).zfill(suffix_len)
        imsave(os.path.join(SaveDir, BaseDirName + img_num + '.tif'), S[iS])
    return
def write_tiffseq ( S , SaveDir = "" , increment_flag = False , suffix_len = None ) : if not suffix_len : if increment_flag : raise ValueError ( "suffix_len required if increment_flag is True." ) else : suffix_len = len ( str ( S . shape [ 0 ] ) ) last_num = 0 if not os . path . exists ( SaveDir ) : os . makedirs ( SaveDir ) else : if not increment_flag : shutil . rmtree ( SaveDir ) os . makedirs ( SaveDir ) else : ImgFileList = sorted ( glob . glob ( SaveDir + '/*.tif' ) ) if not ImgFileList : ImgFileList = sorted ( glob . glob ( SaveDir + '/*.tiff' ) ) if not ImgFileList : last_num = 0 else : last_num = int ( ImgFileList [ - 1 ] . split ( '.' ) [ 0 ] [ - suffix_len : ] ) BaseDirName = os . path . basename ( os . path . normpath ( SaveDir ) ) for iS in range ( S . shape [ 0 ] ) : img_num = str ( iS + 1 + last_num ) . zfill ( suffix_len ) imsave ( os . path . join ( SaveDir , BaseDirName + img_num + '.tif' ) , S [ iS ] ) return
Write a sequence of tiff images to a directory.
Write a sequence of tiff images to a directory .
"""Write a sequence of tiff images to a directory.
    S              : numpy array (3D), sequence will be created along axis 0
    SaveDir        : str, path to folder, will create directory if doesn't exist
    increment_flag : bool, True to write append images to existing ones in folder
    suffix_len     : int, e.g. 4 for 1000 images, 5 for 10,000
    """
S
SaveDir
increment_flag
suffix_len