Exemple #1
0
    def update_section_based_data(self, mask, shape, axis, delta,
                                  islice, coor, obj):
        """
        Estimate volume and surface of object classes from their sections.
        WARNING: Surface estimation is very crude!

        Parameters
        ----------

        mask : bool array
            Slice mask, True where the object inside is.
        shape : tuple
            Real 2D shape of the mask.
        axis : 'x', 'y' or 'z'
            Axis perpendicular to the slices.
        delta : float
            Slice distance.
        islice : int
            Index of the section.
        coor : float
            Coordinate of the section along the axis.
        obj : str
            Geometrical object.
        """
        obj_class = obj.obj_class
        pixel_area = self.box.get_pixel_area(axis)

        volumes = self.section_volumes[axis]
        volumes[obj_class] += pixel_area * np.sum(mask) * delta

        mask.shape = shape
        pixel_sizes = self.box.get_pixel_sizes(axis)
        grad0, grad1 = np.gradient(mask)
        val0 = len(grad0[np.where(grad0)]) * pixel_sizes[0]
        val1 = len(grad1[np.where(grad1)]) * pixel_sizes[1]
        circumference = 0.5 * (val0 + val1)

        self.section_circumferences[obj.name].append((axis, islice, coor,
                                                      circumference))

        surfaces = self.section_surfaces[axis]
        surfaces[obj_class] += circumference * delta
Exemple #2
0
    def contains(self, points):
        """
        Point x in ellipsoid A <=> x^T A x <= 1.
        Works for array of points.

        Parameters:
            points : (n_point, 3) array
        """
        points = np.array(points, ndmin=2, dtype=np.float64)
        x = points.T - self.centre[:, np.newaxis]
        aux = np.sum(x * np.dot(self.mtx, x), axis=0)
        mask = np.where(aux <= 1.0, True, False)
        ##         x2 = np.r_[points.T, np.ones((1,points.shape[0]))]
        ##         aux2 = np.sum(x2 * np.dot(self.mtx_hc, x2), axis = 0)
        ##         mask2 = np.where(aux2 <= 0.0, True, False)
        ##         print np.alltrue(mask == mask2)

        return mask
Exemple #3
0
    def contains(self, points):
        """
        Point x in ellipsoid A <=> x^T A x <= 1.
        Works for array of points.

        Parameters:
            points : (n_point, 3) array
        """
        points = np.array(points, ndmin=2, dtype=np.float64)
        x = points.T - self.centre[:,np.newaxis]
        aux = np.sum(x * np.dot(self.mtx, x), axis = 0)
        mask = np.where(aux <= 1.0, True, False)
##         x2 = np.r_[points.T, np.ones((1,points.shape[0]))]
##         aux2 = np.sum(x2 * np.dot(self.mtx_hc, x2), axis = 0)
##         mask2 = np.where(aux2 <= 0.0, True, False)
##         print np.alltrue(mask == mask2)
        
        return mask