Ejemplo n.º 1
0
    def setIteration(self, iteration_size: BoundingBox, stride: Vector):
        """
        Sets the parameters for iterating through the dataset

        :param iteration_size: The size of each data sample in the volume
        :param stride: The displacement of each iteration
        """
        if not isinstance(iteration_size, BoundingBox):
            error_string = ("iteration_size must have type BoundingBox" +
                            " instead it has type {}")
            error_string = error_string.format(type(iteration_size))
            raise ValueError(error_string)

        if not isinstance(stride, Vector):
            raise ValueError("stride must have type Vector")

        if not iteration_size.isSubset(
                BoundingBox(Vector(0, 0, 0),
                            self.getBoundingBox().getSize())):
            raise ValueError("iteration_size must be smaller than volume size")

        self.setIterationSize(iteration_size)
        self.setStride(stride)

        def ceil(x):
            return int(round(x))

        self.element_vec = Vector(
            *map(lambda L, l, s: ceil((L - l) / s + 1),
                 self.getBoundingBox().getSize().getComponents(),
                 self.iteration_size.getSize().getComponents(),
                 self.stride.getComponents()))

        self.index = 0
Ejemplo n.º 2
0
    def setIteration(self, iteration_size: BoundingBox, stride: Vector):
        if not isinstance(iteration_size, BoundingBox):
            error_string = ("iteration_size must have type BoundingBox" +
                            " instead it has type {}")
            error_string = error_string.format(type(iteration_size))
            raise ValueError(error_string)

        if not isinstance(stride, Vector):
            raise ValueError("stride must have type Vector")

        if not iteration_size.isSubset(
                BoundingBox(Vector(0, 0, 0),
                            self.getBoundingBox().getSize())):
            raise ValueError(
                "iteration_size must be smaller than volume size " +
                "instead the iteration size is {} ".format(
                    iteration_size.getSize()) +
                "and the volume size is {}".format(
                    self.getBoundingBox().getSize()))

        self.setIterationSize(iteration_size)
        self.setStride(stride)

        def ceil(x):
            return int(round(x))

        self.element_vec = Vector(
            *map(lambda L, l, s: ceil((L - l) / s + 1),
                 self.getBoundingBox().getSize().getComponents(),
                 self.iteration_size.getSize().getComponents(),
                 self.stride.getComponents()))

        self.index = 0
Ejemplo n.º 3
0
    def getArray(self, bounding_box: BoundingBox = None) -> np.ndarray:
        """
        Retrieves the array contents of the volume. If a bounding box is
provided, the subsection is returned.

        :param bounding_box: The bounding box of a subsection of the volume.
If the bounding box is outside of the volume, a ValueError is raised.
        """
        if bounding_box is None:
            return self.array

        else:
            if not bounding_box.isSubset(self.getBoundingBox()):
                raise ValueError("The bounding box must be a subset" +
                                 " of the volume")

            centered_bounding_box = bounding_box - self.getBoundingBox(
            ).getEdges()[0]
            edge1, edge2 = centered_bounding_box.getEdges()
            x1, y1, z1 = edge1.getComponents()
            x2, y2, z2 = edge2.getComponents()

            return self.array[z1:z2, y1:y2, x1:x2]