examples.loading_scan_images
1#!/usr/bin/env python 2 3import os 4from csi_images.csi_scans import Scan 5from csi_images.csi_tiles import Tile 6from csi_images.csi_frames import Frame 7 8 9# Create a basic DatabaseHandler 10def load_in_images(): 11 repository_path = os.path.dirname(os.path.dirname(__file__)) 12 test_data_path = os.path.join(repository_path, "tests", "data") 13 14 # First, let's load in a scan's metadata 15 scan = Scan.load_yaml(test_data_path) 16 17 # Using that metadata, we can load in a tile or a ton of tiles 18 tile = Tile(scan, 0) 19 tiles = Tile.get_tiles(scan) 20 21 # By default, these will load in a single list 22 assert len(tiles) == scan.roi[0].tile_rows * scan.roi[0].tile_cols 23 24 # But we can also load them in as a grid 25 tiles = Tile.get_tiles(scan, as_flat=False) 26 assert len(tiles) == scan.roi[0].tile_rows 27 assert len(tiles[0]) == scan.roi[0].tile_cols 28 29 # We can also load in frames for a tile or a ton of tiles 30 frames = Frame.get_frames(tile) 31 all_frames = Frame.get_all_frames(scan) 32 assert len(all_frames) == scan.roi[0].tile_rows * scan.roi[0].tile_cols 33 assert len(all_frames[0]) == 4 34 all_frames = Frame.get_all_frames(scan, as_flat=False) 35 assert len(all_frames) == scan.roi[0].tile_rows 36 assert len(all_frames[0]) == scan.roi[0].tile_cols 37 assert len(all_frames[0][0]) == 4 38 39 # And for each frame, we can load the actual image 40 # First element is the image array, second element is the file path it came from 41 image = frames[0].get_image() 42 assert image.shape == scan.get_image_size() 43 44 45if __name__ == "__main__": 46 load_in_images()
def
load_in_images():
11def load_in_images(): 12 repository_path = os.path.dirname(os.path.dirname(__file__)) 13 test_data_path = os.path.join(repository_path, "tests", "data") 14 15 # First, let's load in a scan's metadata 16 scan = Scan.load_yaml(test_data_path) 17 18 # Using that metadata, we can load in a tile or a ton of tiles 19 tile = Tile(scan, 0) 20 tiles = Tile.get_tiles(scan) 21 22 # By default, these will load in a single list 23 assert len(tiles) == scan.roi[0].tile_rows * scan.roi[0].tile_cols 24 25 # But we can also load them in as a grid 26 tiles = Tile.get_tiles(scan, as_flat=False) 27 assert len(tiles) == scan.roi[0].tile_rows 28 assert len(tiles[0]) == scan.roi[0].tile_cols 29 30 # We can also load in frames for a tile or a ton of tiles 31 frames = Frame.get_frames(tile) 32 all_frames = Frame.get_all_frames(scan) 33 assert len(all_frames) == scan.roi[0].tile_rows * scan.roi[0].tile_cols 34 assert len(all_frames[0]) == 4 35 all_frames = Frame.get_all_frames(scan, as_flat=False) 36 assert len(all_frames) == scan.roi[0].tile_rows 37 assert len(all_frames[0]) == scan.roi[0].tile_cols 38 assert len(all_frames[0][0]) == 4 39 40 # And for each frame, we can load the actual image 41 # First element is the image array, second element is the file path it came from 42 image = frames[0].get_image() 43 assert image.shape == scan.get_image_size()