zudi-lin / pytorch_connectomics

PyTorch Connectomics: segmentation toolbox for EM connectomics
http://connectomics.readthedocs.io/
MIT License
169 stars 77 forks source link

Dataset analysis functions #117

Closed Lauenburg closed 2 years ago

Lauenburg commented 2 years ago

Added three functions for dataset analysis:

def voxel_instance_size(target: np.ndarray, ds_name: str) -> pd.DataFrame:
    ''' Calculate the voxel based size of each instance in an instance segmentation map.

        Args:
            target: The target data as numpy ndarray
            ds_name: Name of the dataset, saved in pd column

        Return
            A single column Panda data frame that contains the voxel-based instance sizes.
    '''
def distance_nn(target: np.ndarray, ds_name: str, iso=[1, 1, 1]) -> pd.DataFrame:
    ''' Caculate the distance to the NN for each instance in the target matrix. 

        Args:
            target: The target data as numpy ndarray
            iso: Axis scaling factor in case of anisotropy
            ds_name: Name of the dataset, saved in pd column

        Return
            A single column Panda data frame that contains the distance of each instance to its NN
    '''
def pixel_intensity(source: np.ndarray, target: np.ndarray, bOrF: str, ds_name: str) -> pd.DataFrame:
    ''' Retrives the intesity of each pixel. Writes them to a Pandas data frame.
        Can handle background for foreground.
        Args:
            source: Source numpy ndarray
            target: Target numpy ndarray
            bOrF: Either 'Foreground' or 'Background', indicates which intensities to estimate
            ds_name: Name of the dataset, saved in pd column

        Return
            A pandas frame with the intensity of each pixel, if the pixel belongs to the background
            or foreground, and the dataset it belongs to.
    '''