Skip to content

Commit

Permalink
RF: Add get_frame_size method to use for DataHandler.rois2masks
Browse files Browse the repository at this point in the history
  • Loading branch information
scottclowe committed Jun 18, 2021
1 parent e129045 commit 68d9cc1
Showing 1 changed file with 40 additions and 43 deletions.
83 changes: 40 additions & 43 deletions fissa/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,24 @@ def getmean(data):
raise NotImplementedError()

@staticmethod
def rois2masks(rois, data):
def get_frame_size(data):
"""
Determine the shape of each frame within the recording.
Parameters
----------
data : data_type
The same object as returned by :meth:`image2array`.
Returns
-------
shape : tuple of ints
The 2D, y-by-x, shape of each frame in the movie.
"""
raise NotImplementedError()

@classmethod
def rois2masks(cls, rois, data):
"""
Convert ROIs into a collection of binary masks.
Expand All @@ -97,7 +114,7 @@ def rois2masks(rois, data):
--------
fissa.roitools.getmasks, fissa.roitools.readrois
"""
raise NotImplementedError()
return roitools.rois2masks(rois, cls.get_frame_size(data))

@staticmethod
def extracttraces(data, masks):
Expand Down Expand Up @@ -203,28 +220,21 @@ def getmean(data):
return data.mean(axis=0, dtype=np.float64)

@staticmethod
def rois2masks(rois, data):
"""Take the object `rois` and returns it as a list of binary masks.
def get_frame_size(data):
"""
Determine the shape of each frame within the recording.
Parameters
----------
rois : str or :term:`list` of :term:`array_like`
Either a string containing a path to an ImageJ roi zip file,
or a list of arrays encoding polygons, or list of binary arrays
representing masks.
data : :term:`array_like`
Data array as made by :meth:`image2array`. Must be shaped
``(frames, y, x)``.
data : data_type
The same object as returned by :meth:`image2array`.
Returns
-------
masks : :term:`list` of :class:`numpy.ndarray`
List of binary arrays.
shape : tuple of ints
The 2D, y-by-x, shape of each frame in the movie.
"""
# get the image shape
shape = data.shape[1:]

return roitools.rois2masks(rois, shape)
return data.shape[-2:]

@staticmethod
def extracttraces(data, masks):
Expand Down Expand Up @@ -339,27 +349,21 @@ def getmean(data):
return memory / n_frames

@staticmethod
def rois2masks(rois, data):
"""Take the object `rois` and returns it as a list of binary masks.
def get_frame_size(data):
"""
Determine the shape of each frame within the recording.
Parameters
----------
rois : str or list of array_like
Either a string containing a path to an ImageJ roi zip file,
or a list of arrays encoding polygons, or list of binary arrays
representing masks.
data : tifffile.TiffFile
Open tifffile.TiffFile object.
data : data_type
The same object as returned by :meth:`image2array`.
Returns
-------
masks : list of numpy.ndarray
List of binary arrays.
shape : tuple of ints
The 2D, y-by-x, shape of each frame in the movie.
"""
# Get the image shape
shape = data.pages[0].shape[-2:]

return roitools.rois2masks(rois, shape)
return data.pages[0].shape[-2:]

@staticmethod
def extracttraces(data, masks):
Expand Down Expand Up @@ -463,28 +467,21 @@ def getmean(data):
return avg

@staticmethod
def rois2masks(rois, data):
def get_frame_size(data):
"""
Take the object `rois` and returns it as a list of binary masks.
Determine the shape of each frame within the recording.
Parameters
----------
rois : str or :term:`list` of :term:`array_like`
Either a string containing a path to an ImageJ roi zip file,
or a list of arrays encoding polygons, or list of binary arrays
representing masks.
data : PIL.Image
An open :class:`PIL.Image` handle to a multi-frame TIFF image.
Returns
-------
masks : list of numpy.ndarray
List of binary arrays.
shape : tuple of ints
The 2D, y-by-x, shape of each frame in the movie.
"""
# get the image shape
shape = data.size[::-1]

return roitools.rois2masks(rois, shape)
return data.size[::-1]

@staticmethod
def extracttraces(data, masks):
Expand Down

0 comments on commit 68d9cc1

Please sign in to comment.