(from_dir, verbose=True)
return ids, study_to_images
Load images in the form study x slices x width x height.
    Each image contains 30 time series frames so that it is ready for the convolutional network.

    :param from_dir: directory with images (train or validate)
    :param verbose: if true then print data
Load images in the form study x slices x width x height.
    Each image contains 30 time series frames so that it is ready for the convolutional network.
Load images in the form study x slices x width x height . Each image contains 30 time series frames so that it is ready for the convolutional network .
def load_images(from_dir, verbose=True):
    """
    Load images in the form study x slices x width x height.
    Each image contains 30 time series frames so that it is ready for the convolutional network.

    :param from_dir: directory with images (train or validate)
    :param verbose: if true then print data
    """
    print('-'*50)
    print('Loading all DICOM images from {0}...'.format(from_dir))
    print('-'*50)

    current_study_sub = ''  # saves the current study sub_folder
    current_study = ''  # saves the current study folder
    current_study_images = []  # holds current study images
    ids = []  # keeps the ids of the studies
    study_to_images = dict()  # dictionary for studies to images
    total = 0
    images = []  # saves 30-frame-images
    from_dir = from_dir if from_dir.endswith('/') else from_dir + '/'
    for subdir, _, files in os.walk(from_dir):
        subdir = subdir.replace('\\', '/')  # windows path fix
        subdir_split = subdir.split('/')
        study_id = subdir_split[-3]
        if "sax" in subdir:
            for f in files:
                image_path = os.path.join(subdir, f)
                if not image_path.endswith('.dcm'):
                    continue

                image = dicom.read_file(image_path)
                image = image.pixel_array.astype(float)
                image /= np.max(image)  # scale to [0,1]
                if img_resize:
                    image = crop_resize(image)

                if current_study_sub != subdir:
                    x = 0
                    try:
                        while len(images) < 30:
                            images.append(images[x])
                            x += 1
                        if len(images) > 30:
                            images = images[0:30]

                    except IndexError:
                        pass
                    current_study_sub = subdir
                    current_study_images.append(images)
                    images = []

                if current_study != study_id:
                    study_to_images[current_study] = np.array(current_study_images)
                    if current_study != "":
                        ids.append(current_study)
                    current_study = study_id
                    current_study_images = []
                images.append(image)
                if verbose:
                    if total % 1000 == 0:
                        print('Images processed {0}'.format(total))
                total += 1
    x = 0
    try:
        while len(images) < 30:
            images.append(images[x])
            x += 1
        if len(images) > 30:
            images = images[0:30]
    except IndexError:
        pass

    print('-'*50)
    print('All DICOM in {0} images loaded.'.format(from_dir))
    print('-'*50)

    current_study_images.append(images)
    study_to_images[current_study] = np.array(current_study_images)
    if current_study != "":
        ids.append(current_study)

    return ids, study_to_images
def load_images ( from_dir , verbose = True ) : print ( '-' * 50 ) print ( 'Loading all DICOM images from {0}...' . format ( from_dir ) ) print ( '-' * 50 ) current_study_sub = '' # saves the current study sub_folder current_study = '' # saves the current study folder current_study_images = [ ] # holds current study images ids = [ ] # keeps the ids of the studies study_to_images = dict ( ) # dictionary for studies to images total = 0 images = [ ] # saves 30-frame-images from_dir = from_dir if from_dir . endswith ( '/' ) else from_dir + '/' for subdir , _ , files in os . walk ( from_dir ) : subdir = subdir . replace ( '\\' , '/' ) # windows path fix subdir_split = subdir . split ( '/' ) study_id = subdir_split [ - 3 ] if "sax" in subdir : for f in files : image_path = os . path . join ( subdir , f ) if not image_path . endswith ( '.dcm' ) : continue image = dicom . read_file ( image_path ) image = image . pixel_array . astype ( float ) image /= np . max ( image ) # scale to [0,1] if img_resize : image = crop_resize ( image ) if current_study_sub != subdir : x = 0 try : while len ( images ) < 30 : images . append ( images [ x ] ) x += 1 if len ( images ) > 30 : images = images [ 0 : 30 ] except IndexError : pass current_study_sub = subdir current_study_images . append ( images ) images = [ ] if current_study != study_id : study_to_images [ current_study ] = np . array ( current_study_images ) if current_study != "" : ids . append ( current_study ) current_study = study_id current_study_images = [ ] images . append ( image ) if verbose : if total % 1000 == 0 : print ( 'Images processed {0}' . format ( total ) ) total += 1 x = 0 try : while len ( images ) < 30 : images . append ( images [ x ] ) x += 1 if len ( images ) > 30 : images = images [ 0 : 30 ] except IndexError : pass print ( '-' * 50 ) print ( 'All DICOM in {0} images loaded.' . format ( from_dir ) ) print ( '-' * 50 ) current_study_images . append ( images ) study_to_images [ current_study ] = np . array ( current_study_images ) if current_study != "" : ids . append ( current_study ) return ids , study_to_images