tests.test_frames API documentation

# tests.test_frames

View Source

     1import os
     2
     3import cv2
     4
     5from csi_images import csi_frames, csi_tiles, csi_scans
     6
     7if os.environ.get("DEBIAN_FRONTEND") == "noninteractive":
     8    SHOW_PLOTS = False
     9else:
    10    # Change this to your preference for local testing, but commit as True
    11    SHOW_PLOTS = True
    12
    13
    14def test_getting_frames():
    15    scan = csi_scans.Scan.load_yaml("tests/data")
    16    tile = csi_tiles.Tile(scan, 100)
    17    frames = csi_frames.Frame.get_frames(tile)
    18    assert len(frames) == 4
    19    frames = csi_frames.Frame.get_all_frames(scan)
    20    assert len(frames) == scan.roi[0].tile_rows * scan.roi[0].tile_cols
    21    assert len(frames[0]) == 4
    22    frames = csi_frames.Frame.get_all_frames(scan, as_flat=False)
    23    assert len(frames) == scan.roi[0].tile_rows
    24    assert len(frames[0]) == scan.roi[0].tile_cols
    25    assert len(frames[0][0]) == 4
    26
    27
    28def test_make_rgb():
    29    scan = csi_scans.Scan.load_txt("tests/data")
    30    tile = csi_tiles.Tile(scan, 1000)
    31    frames = csi_frames.Frame.get_frames(tile)
    32
    33    if SHOW_PLOTS:
    34        for frame in frames:
    35            cv2.imshow("Frames from a tile", frame.get_image())
    36            cv2.waitKey(0)
    37        cv2.destroyAllWindows()
    38
    39    channel_indices = scan.get_channel_indices(["TRITC", "CY5", "DAPI"])
    40    channels = {
    41        channel_indices[0]: (1.0, 0.0, 0.0),
    42        channel_indices[1]: (0.0, 1.0, 0.0),
    43        channel_indices[2]: (0.0, 0.0, 1.0),
    44    }
    45    image = csi_frames.Frame.make_rgb_image(tile, channels)
    46    assert image.shape == (scan.tile_height_px, scan.tile_width_px, 3)
    47
    48    if SHOW_PLOTS:
    49        cv2.imshow("RGB tile", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
    50        cv2.waitKey(0)
    51        cv2.destroyAllWindows()
    52
    53    # Test with a white channel
    54    channel_indices = scan.get_channel_indices(["TRITC", "CY5", "DAPI", "AF488"])
    55    channels = {
    56        channel_indices[0]: (1.0, 0.0, 0.0),
    57        channel_indices[1]: (0.0, 1.0, 0.0),
    58        channel_indices[2]: (0.0, 0.0, 1.0),
    59        channel_indices[3]: (1.0, 1.0, 1.0),
    60    }
    61    image = csi_frames.Frame.make_rgb_image(tile, channels)
    62    assert image.shape == (scan.tile_height_px, scan.tile_width_px, 3)
    63
    64    if SHOW_PLOTS:
    65        cv2.imshow("RGBW tile", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
    66        cv2.waitKey(0)
    67        cv2.destroyAllWindows()

def test_getting_frames(): View Source

    15def test_getting_frames():
    16    scan = csi_scans.Scan.load_yaml("tests/data")
    17    tile = csi_tiles.Tile(scan, 100)
    18    frames = csi_frames.Frame.get_frames(tile)
    19    assert len(frames) == 4
    20    frames = csi_frames.Frame.get_all_frames(scan)
    21    assert len(frames) == scan.roi[0].tile_rows * scan.roi[0].tile_cols
    22    assert len(frames[0]) == 4
    23    frames = csi_frames.Frame.get_all_frames(scan, as_flat=False)
    24    assert len(frames) == scan.roi[0].tile_rows
    25    assert len(frames[0]) == scan.roi[0].tile_cols
    26    assert len(frames[0][0]) == 4

def test_make_rgb(): View Source

    29def test_make_rgb():
    30    scan = csi_scans.Scan.load_txt("tests/data")
    31    tile = csi_tiles.Tile(scan, 1000)
    32    frames = csi_frames.Frame.get_frames(tile)
    33
    34    if SHOW_PLOTS:
    35        for frame in frames:
    36            cv2.imshow("Frames from a tile", frame.get_image())
    37            cv2.waitKey(0)
    38        cv2.destroyAllWindows()
    39
    40    channel_indices = scan.get_channel_indices(["TRITC", "CY5", "DAPI"])
    41    channels = {
    42        channel_indices[0]: (1.0, 0.0, 0.0),
    43        channel_indices[1]: (0.0, 1.0, 0.0),
    44        channel_indices[2]: (0.0, 0.0, 1.0),
    45    }
    46    image = csi_frames.Frame.make_rgb_image(tile, channels)
    47    assert image.shape == (scan.tile_height_px, scan.tile_width_px, 3)
    48
    49    if SHOW_PLOTS:
    50        cv2.imshow("RGB tile", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
    51        cv2.waitKey(0)
    52        cv2.destroyAllWindows()
    53
    54    # Test with a white channel
    55    channel_indices = scan.get_channel_indices(["TRITC", "CY5", "DAPI", "AF488"])
    56    channels = {
    57        channel_indices[0]: (1.0, 0.0, 0.0),
    58        channel_indices[1]: (0.0, 1.0, 0.0),
    59        channel_indices[2]: (0.0, 0.0, 1.0),
    60        channel_indices[3]: (1.0, 1.0, 1.0),
    61    }
    62    image = csi_frames.Frame.make_rgb_image(tile, channels)
    63    assert image.shape == (scan.tile_height_px, scan.tile_width_px, 3)
    64
    65    if SHOW_PLOTS:
    66        cv2.imshow("RGBW tile", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
    67        cv2.waitKey(0)
    68        cv2.destroyAllWindows()