<commit_before>"""Feature computations and other functions for the Marcelle myoblast
fusion screen.
"""
from __future__ import absolute_import
from __future__ import print_function

import os
import collections as coll

import numpy as np
from scipy import ndimage as nd
from skimage.filters import threshold_otsu, threshold_adaptive

from .. import features
from six.moves import map
from six.moves import zip


def feature_vector_from_rgb(image, sample_size=None, random_seed=None):
    """Compute a feature vector from the composite images.

    The channels are assumed to be in the following order:
     - Red: MCF-7
     - Green: cytoplasm GFP
     - Blue: DAPI/Hoechst

    Parameters
    ----------
    im : array, shape (M, N, 3)
        The input image.
    sample_size : int, optional
        For features based on quantiles, sample this many objects
        rather than computing full distribution. This can considerably
        speed up computation with little cost to feature accuracy.
    random_seed : int or numpy.RandomState, optional
        A random seed to fix the sampling.

    Returns
    -------
    fs : 1D array of float
        The features of the image.
    names : list of string
        The feature names.
    """
    all_fs, all_names = [], []
    ims = np.rollaxis(image[..., :3], -1, 0) # toss out alpha chan if present
    mcf, cells, nuclei = ims
    prefixes = ['mcf', 'cells', 'nuclei']
    for im, prefix in zip(ims, prefixes):
        fs, names = features.intensity_object_features(im,
                                                       sample_size=sample_size,
                                                       random_seed=random_seed)
        names = [prefix + '-' + name for name in names]
        all_fs.append(fs)
        all_names.extend(names)
    nuclei_mean = nd.label(nuclei > np.mean(nuclei))[0]
    fs, names = features.nearest_neighbors(nuclei_mean)
    all_fs.append(fs)
    all_names.extend(['nuclei-' + name for name in names])
    mcf_mean = nd.label(mcf)[0]<commit_msg>Allow arbitrary parameters to specific feature maps<commit_after>"""Feature computations and other functions for the Marcelle myoblast
fusion screen.
"""
from __future__ import absolute_import
from __future__ import print_function

import os
import collections as coll

import numpy as np
from scipy import ndimage as nd
from skimage.filters import threshold_otsu, threshold_adaptive

from .. import features
from six.moves import map
from six.moves import zip


def feature_vector_from_rgb(image, sample_size=None, random_seed=None,
                            **kwargs):
    """Compute a feature vector from the composite images.

    The channels are assumed to be in the following order:
     - Red: MCF-7
     - Green: cytoplasm GFP
     - Blue: DAPI/Hoechst

    Parameters
    ----------
    im : array, shape (M, N, 3)
        The input image.
    sample_size : int, optional
        For features based on quantiles, sample this many objects
        rather than computing full distribution. This can considerably
        speed up computation with little cost to feature accuracy.
    random_seed : int or numpy.RandomState, optional
        A random seed to fix the sampling.

    Other parameters
    ----------------
    (``**kwargs`` to accept parameters meant for other feature maps.)

    Returns
    -------
    fs : 1D array of float
        The features of the image.
    names : list of string
        The feature names.
    """
    all_fs, all_names = [], []
    ims = np.rollaxis(image[..., :3], -1, 0) # toss out alpha chan if present
    mcf, cells, nuclei = ims
    prefixes = ['mcf', 'cells', 'nuclei']
    for im, prefix in zip(ims, prefixes):
        fs, names = features.intensity_object_features(im,
                                                       sample_size=sample_size,
                                                       random_seed=random_seed)
        names = [prefix + '-' + name for name in names]
        all_fs.append(fs)
        all_names.extend(names)
    nuclei_mean = nd.label(nuclei > np.mean(nuclei))[0]
    fs, names = features.nearest_neighbors(nuclei_mean)
    all_fs.append(fs)
    all_names.extend(['nuclei-' + name for name in names])
    mcf_mean = nd.label(mcf)[0]
{'fraction_non_alphanumeric': 0.08777282328091997, 'fraction_numerical': 0.0037549870922318706, 'mean_word_length': 2.361198738170347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4798792', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1146, 'n_words': 427}