Skip to content

Commit

Permalink
read dv videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Henley13 committed Jan 16, 2020
1 parent 873fab0 commit ab94c2b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
5 changes: 4 additions & 1 deletion bigfish/stack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"""

from .utils import (check_array, check_df, check_recipe, check_parameter,
check_range_value, get_offset_value, get_eps_float32)
check_range_value,
get_offset_value, get_eps_float32)
from .io import (read_image, read_pickle, read_cell_json, read_rna_json,
read_dv,
save_image)
from .preprocess import (build_simulated_dataset, build_stacks, build_stack,
build_stack_no_recipe, rescale,
Expand Down Expand Up @@ -43,6 +45,7 @@
"check_range_value", "get_offset_value", "get_eps_float32"]

_io = ["read_image", "read_pickle", "read_cell_json", "read_rna_json",
"read_dv",
"save_image"]

_preprocess = ["build_simulated_dataset", "build_stacks", "build_stack",
Expand Down
34 changes: 32 additions & 2 deletions bigfish/stack/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import pickle
import mrc
import warnings

import numpy as np
Expand All @@ -21,7 +22,7 @@ def read_image(path):
"""Read an image with the .png, .tif or .tiff extension.
The input image should be in 2-d or 3-d, with unsigned integer 8 or 16
bits, integer
bits.
Parameters
----------
Expand Down Expand Up @@ -118,7 +119,7 @@ def read_pickle(path):
Returns
-------
data = pandas.DataFrame or np.ndarray
data : pandas.DataFrame or np.ndarray
Data store in the pickle file (an image or coordinates with labels and
metadata).
Expand All @@ -130,6 +131,35 @@ def read_pickle(path):
return data


def read_dv(path):
"""Read a video file with the .dv extension.
The input image should be in 2-d or 3-d, with unsigned integer 8 or 16
bits.
Parameters
----------
path : str
Path of the file to read.
Returns
-------
tensor : ndarray, np.uint or np.int
A 2-d or 3-d tensor with spatial dimensions.
"""
# TODO allow more input dtype
# read video file
tensor = mrc.imread(path)

# check the image is in unsigned integer 16 bits with 2 or 3 dimensions
check_array(tensor,
dtype=[np.uint8, np.uint16, np.int64],
ndim=[2, 3],
allow_nan=False)

return tensor


# ### Write ###

def save_image(image, path):
Expand Down

0 comments on commit ab94c2b

Please sign in to comment.