Esempio n. 1
0
    def for_subimage(self, bbox: Box2I) -> ImageSectionTransform:
        """Return the transform that maps a subimage to the same coordinate
        system.

        Parameters
        ----------
        bbox : `Box2I`
            Bounding box of the subimage that the new transform will operate
            on.  Must satisfy ``self.input_bbox.contains(bbox)``.

        Returns
        -------
        subimage_transform : `ImageSectionTransform`
            A transform whose ``input_bbox`` is the given ``bbox`` that maps it
            to the appropriate location within ``self.output_bbox`` and applies
            the same flips.
        """
        # Distances (defined to be positive) between minimum points of both
        # boxes and maximum points of both boxes.
        lower_dist_x, lower_dist_y = bbox.getMin() - self.input_bbox.getMin()
        upper_dist_x, upper_dist_y = self.input_bbox.getMax() - bbox.getMax()
        if self.flip_x:
            lower_dist_x, upper_dist_x = upper_dist_x, lower_dist_x
        if self.flip_y:
            lower_dist_y, upper_dist_y = upper_dist_y, lower_dist_y
        output_bbox = Box2I(
            minimum=self.output_bbox.getMin() + ExtentI(lower_dist_x, lower_dist_y),
            maximum=self.output_bbox.getMax() - ExtentI(upper_dist_x, upper_dist_y),
        )
        return ImageSectionTransform(
            input_bbox=bbox,
            output_bbox=output_bbox,
            flip_x=self.flip_x,
            flip_y=self.flip_y,
        )
Esempio n. 2
0
 def subimage(self, bbox: Box2I) -> NumPyImageSection:
     # Docstring inherited.
     start = bbox.getMin() - self._bbox_min
     stop = start + bbox.getSize()
     return NumPyImageSection(
         self._array[start.getY():stop.getY(),
                     start.getX():stop.getX(), ...],  # noqa:E203
         bbox,
     )