def test_model_transform_single(eng):
    regions = many([[[0, 0], [0, 1]]])
    model = ExtractionModel(regions=regions)
    im0 = [[0, 1], [1, 2]]
    im1 = [[3, 4], [5, 6]]
    im2 = [[7, 8], [9, 10]]
    data = fromarray([im0, im1, im2], engine=eng)
    transformed = model.transform(data)
    assert allclose(transformed.toarray(), [[0.5, 3.5, 7.5]])
Esempio n. 2
0
def filter_shape(model, min_diameter=7, max_diameter=13, min_eccentricity=0.2):
    """
    Filter extraction model regions based on shape criterion.

    Parameters
    ----------
    model : ExtractionModel.

    min_diameter : float, default 7.
        Minimum allowed diameter of regions

    max_diameter : float, default 13.
        Maxium allowed diameter of regions

    min_eccentricity : float, default 0.2.
        Minimum allowed eccentricity of regions
    """

    regions = []
    for region in model.regions:
        mask = region.mask(fill=[1, 1, 1], background=[0, 0, 0])[:, :, 0]
        props = regionprops(mask.astype('int'))[0]
        if (props.eccentricity > min_eccentricity) and (
                props.equivalent_diameter >
                min_diameter) and (props.equivalent_diameter < max_diameter):
            regions.append(region)
    return ExtractionModel(regions)
Esempio n. 3
0
    def fit(self, images):
        # compute local correlation of each pixel after bluring a cell bodies worth
        localcorr = images.localcorr(self.diameter)

        # detect blobs in local correlations corresponding to size of a cell
        centers = findcenters(localcorr[:, self.boundary[0]:-self.boundary[1]],
                              diameter=self.diameter,
                              clip_limit=self.clip_limit,
                              threshold=self.theshold)
        centers = array([[x[0], x[1] + self.boundary[0]] for x in centers])

        # reshape the data into blocks around each center coordinate
        reshaped = images.map(
            lambda x: selectCenters(x, centers, self.diameter))

        # compute cross correlation with central pixels timeseries in each block
        stack = centercorr(reshaped, sigma_blur=self.sigma_blur)

        # detect boundaries of each putative cell and reshift coordinates back to original image
        masks = [
            detect(img,
                   dilationSize=2,
                   radial=True,
                   filterSize=int(5 * self.diameter)) for img in stack
        ]
        regions = [
            mask_to_coords(masks[ii], centers[ii])
            for ii in range(len(centers))
        ]

        return ExtractionModel(regions)
Esempio n. 4
0
def neuropilModel(model, inner=3, outer=8, mask=True, shape=(512, 512)):
    regionsNeuropil = model.regions.outline(inner, outer)
    regionsNeuropil = regionsNeuropil.crop(zeros(len(shape)), shape)
    if mask:
        mask = model.regions.mask(fill=[1, 1, 1], base=zeros(shape))[:, :, 0]
        regionsNeuropil = regionsNeuropil.exclude(mask)
    return ExtractionModel(regionsNeuropil)
def test_load():
    model = ExtractionModel.load('test/resources/regions.json')
    assert allclose(model.regions.coordinates, [[[0, 1], [0, 2]], [[1, 2], [1, 3]]])