Пример #1
0
    def get_scaled_cutout_wdht(self,
                               x1,
                               y1,
                               x2,
                               y2,
                               new_wd,
                               new_ht,
                               method='basic'):
        """Extract a region of the image defined by corners (x1, y1) and
        (x2, y2) and resample it to fit dimensions (new_wd, new_ht).

        `method` describes the method of interpolation used, where the
        default "basic" is nearest neighbor.
        """

        if method in ('basic', 'view'):
            shp = self.shape

            (view, (scale_x, scale_y)) = \
                trcalc.get_scaled_cutout_wdht_view(shp, x1, y1, x2, y2,
                                                   new_wd, new_ht)
            newdata = self._slice(view)

        else:
            data_np = self._get_data()
            (newdata, (scale_x, scale_y)) = \
                trcalc.get_scaled_cutout_wdht(data_np, x1, y1, x2, y2,
                                              new_wd, new_ht,
                                              interpolation=method,
                                              logger=self.logger)

        res = Bunch.Bunch(data=newdata, scale_x=scale_x, scale_y=scale_y)
        return res
Пример #2
0
    def get_scaled_cutout_wdht(self, x1, y1, x2, y2, new_wd, new_ht,
                               method='basic'):
        """Extract a region of the image defined by corners (x1, y1) and
        (x2, y2) and resample it to fit dimensions (new_wd, new_ht).

        `method` describes the method of interpolation used, where the
        default "basic" is nearest neighbor.
        """

        if method in ('basic', 'view'):
            shp = self.shape

            (view, (scale_x, scale_y)) = \
                trcalc.get_scaled_cutout_wdht_view(shp, x1, y1, x2, y2,
                                                   new_wd, new_ht)
            newdata = self._slice(view)

        else:
            data_np = self._get_data()
            (newdata, (scale_x, scale_y)) = \
                trcalc.get_scaled_cutout_wdht(data_np, x1, y1, x2, y2,
                                              new_wd, new_ht,
                                              interpolation=method,
                                              logger=self.logger)

        res = Bunch.Bunch(data=newdata, scale_x=scale_x, scale_y=scale_y)
        return res
Пример #3
0
    def get_scaled_cutout_wdht(self, x1, y1, x2, y2, new_wd, new_ht):
        shp = self.shape

        (view, (scale_x, scale_y)) = \
            trcalc.get_scaled_cutout_wdht_view(shp, x1, y1, x2, y2,
                                               new_wd, new_ht)
        newdata = self._slice(view)

        res = Bunch.Bunch(data=newdata, scale_x=scale_x, scale_y=scale_y)
        return res
Пример #4
0
    def get_scaled_cutout_wdht(self, x1, y1, x2, y2, new_wd, new_ht):

        shp = self.shape

        (view, (scale_x, scale_y)) = \
            trcalc.get_scaled_cutout_wdht_view(shp, x1, y1, x2, y2,
                                               new_wd, new_ht)
        newdata = self._slice(view)

        res = Bunch.Bunch(data=newdata, scale_x=scale_x, scale_y=scale_y)
        return res
Пример #5
0
    def test_get_scaled_cutout_wdht_view(self):

        data = self._2ddata()
        p1 = (2, 2)
        p2 = (4, 4)
        nd = (8, 10)

        res = np.asarray([[2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2],
                          [2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2],
                          [2, 2, 2, 3, 3, 3, 3, 3], [2, 2, 2, 3, 3, 3, 3, 3],
                          [2, 2, 2, 3, 3, 3, 3, 3], [2, 2, 2, 3, 3, 3, 4, 4],
                          [2, 2, 2, 3, 3, 3, 4, 4], [2, 2, 2, 3, 3, 3, 4, 4]])

        view, scales = trcalc.get_scaled_cutout_wdht_view(
            data.shape, p1[0], p1[1], p2[0], p2[1], nd[0], nd[1])
        new_data = data[view]
        assert new_data.shape == (10, 8)
        assert np.allclose(new_data, res)