Exemplo n.º 1
0
def test_euler():
    f = np.zeros((16,16), np.bool)
    f[4:8,4:8] = 1
    assert euler(f) == 1

    f[6:7,5:7] = 0

    assert euler(f) == 0
Exemplo n.º 2
0
def test_euler():
    f = np.zeros((16,16), np.bool)
    f[4:8,4:8] = 1
    assert euler(f) == 1
    assert euler(f, 4) == 1

    f[6:7,5:7] = 0

    assert euler(f) == 0
    assert euler(f, 4) == 0
Exemplo n.º 3
0
def test_euler7():
    f = np.arange(100)
    f = (f % 5) == 1
    f = f.reshape((10,10))
    with pytest.raises(ValueError):
        euler(f, 7)
Exemplo n.º 4
0
def test_euler7():
    f = np.arange(100)
    f = (f % 5) == 1
    f = f.reshape((10, 10))
    euler(f, 7)
Exemplo n.º 5
0
def test_euler7():
    f = np.arange(100)
    f = (f % 5) == 1
    f = f.reshape((10,10))
    euler(f, 7)
Exemplo n.º 6
0
def imgfeaturesdna(imageproc, dnaproc, isfield=False):
    """
    values = imgfeaturesdna(imageproc, dnaproc, isfield=False)

    calculates object features for imageproc
    where imageproc contains the pre-processed fluorescence image,
    and dnaproc the pre-processed dna fluorescence image.
    Pre-processed means that the image has been cropped and had
    pixels of interest selected (via a threshold, for instance).
    use dnaproc=None to exclude features based on the dna image.

    Parameters
    ----------
        * imageproc: pre-processed image
        * dnaproc: pre-processed DNA image
        * isfield: whether to calculate only field level features
                (default: False)

    Features calculated include:
      - Number of objects
      - Euler number of the image (# of objects - # of holes)
      - Average of the object sizes
      - Variance of the object sizes
      - Ratio of the largest object to the smallest
      - Average of the object distances from the COF [unless isfield]
      - Variance of the object distances from the COF [unless isfield]
      - Ratio of the largest object distance to the smallest
      - DNA: average of the object distances to the DNA COF [unless isfield]
      - DNA: variance of the object distances to the DNA COF [unless isfield]
      - DNA: ratio of the largest object distance to the smallest
      - DNA/Image: distance of the DNA COF to the image COF [unless isfield]
      - DNA/Image: ratio of the DNA image area to the image area
      - DNA/Image: fraction of image that overlaps with DNA
    """
    bwimage = (imageproc > 0)
    imagelabeled,nr_objs = ndimage.label(bwimage)
    if not nr_objs:
        nfeatures = 5
        if not isfield:
            nfeatures += 3
        if dnaproc is not None:
            nfeatures += 2
        if (not isfield and (dnaproc is not None)):
            nfeatures  += 1
        return np.zeros(nfeatures)

    values = [nr_objs]
    dnacof = None
    euler_nr = euler(bwimage)
    values.append(euler_nr)

    cof = None
    if not isfield:
        cof = center_of_mass(imageproc.astype(np.uint32))

    obj_sizes = fullhistogram(imagelabeled.view(np.uint32))[1:]

    obj_size_avg = obj_sizes.mean()
    obj_size_var = obj_sizes.var()
    obj_size_ratio = obj_sizes.max()/obj_sizes.min()

    values.append(obj_size_avg)
    values.append(obj_size_var)
    values.append(obj_size_ratio)


    if not isfield:
        obj_cms = center_of_mass(imageproc.astype(np.uint32), imagelabeled)
        obj_cms = obj_cms[1:]
        obj_distances = []
        obj_dnadistances = []
        if dnaproc is not None:
            dnacof = center_of_mass(dnaproc.astype(np.uint32))
        for obj_center in obj_cms:
            obj_distance = _norm2(obj_center - cof)
            obj_distances.append(obj_distance)

            if dnaproc is not None:
                obj_dnadistance = _norm2(obj_center - dnacof)
                obj_dnadistances.append(obj_dnadistance)
        obj_distances = np.array(obj_distances)
        obj_dist_avg = obj_distances.mean()
        obj_dist_var = obj_distances.var()
        mindist = obj_distances.min()
        if mindist != 0:
            obj_dist_ratio = obj_distances.max()/mindist
        else:
            obj_dist_ratio = 0

        values.append(obj_dist_avg)
        values.append(obj_dist_var)
        values.append(obj_dist_ratio)

        if dnaproc is not None:
            obj_dnadistances = np.array(obj_dnadistances)
            obj_dnadist_avg = obj_dnadistances.mean()
            obj_dnadist_var = obj_dnadistances.var()
            obj_dnamindist=obj_dnadistances.min()
            if obj_dnamindist != 0:
                obj_dnadist_ratio = obj_dnadistances.max()/obj_dnamindist
            else:
                obj_dnadist_ratio = 0 ;
            values.append(obj_dnadist_avg)
            values.append(obj_dnadist_var)
            values.append(obj_dnadist_ratio)



    if dnaproc is not None:
        dna_area = (dnaproc > 0).sum()
        image_area = (imageproc > 0).sum()

        # what fraction of the image fluorescence area overlaps the dna image?
        image_overlap = ( (imageproc > 0) & (dnaproc > 0) ).sum()

        if image_area == 0:
            dna_image_area_ratio = 0
            image_dna_overlap = 0
        else:
            dna_image_area_ratio = dna_area/image_area
            image_dna_overlap = image_overlap/image_area

        if dnacof is not None:
            dna_image_distance = _norm2(cof-dnacof)
            values.append(dna_image_distance)
        values.append(dna_image_area_ratio)
        values.append(image_dna_overlap)
    return values