Ejemplo n.º 1
0
    def test_translation(self):
        transform = Transform('origin', 'local', translation=[3, 4])

        point1 = Point2D([0, 0], 'origin', transform)
        point2 = Point2D([0, 0], 'local', transform)

        np.testing.assert_almost_equal(point1.get_coord('origin'), [0, 0])
        np.testing.assert_almost_equal(point1.get_coord('local'), [-3, -4])

        np.testing.assert_almost_equal(point2.get_coord('origin'), [3, 4])
        np.testing.assert_almost_equal(point2.get_coord('local'), [0, 0])

        np.testing.assert_almost_equal(point1.dist(point2), 5)
Ejemplo n.º 2
0
    def test_90deg_rotation(self):

        shape = [20, 10]  # [width, height]
        angle = np.pi / 2
        transform = Transform('origin', 'local', dim=shape, angle=angle)

        point1 = Point2D([10, 5], 'origin', transform)
        point2 = Point2D([5, 10], 'local', transform)

        np.testing.assert_almost_equal(point1.get_coord('origin'), [10, 5])
        np.testing.assert_almost_equal(point1.get_coord('local'), [5, 10])

        np.testing.assert_almost_equal(point2.get_coord('origin'), [10, 5])
        np.testing.assert_almost_equal(point2.get_coord('local'), [5, 10])

        np.testing.assert_almost_equal(point1.dist(point2), 0)
Ejemplo n.º 3
0
 def test_missing_transform(self):
     """
     get coordinate returns a MissingTransformError when requested a coordinate in a frame for which the transform is unknown
     """
     transform = Transform('origin', 'local', translation=[0, 0])
     point1 = Point2D([400, 100], 'origin', transform)
     self.assertRaises(MissingTransformError, point1.get_coord, 'space')
Ejemplo n.º 4
0
    def detect_tomatoes(self):
        """detect tomatoes based on the truss segment"""
        pwd = os.path.join(self.pwd, '05_tomatoes')

        if self.truss_crop.sum() == 0:
            warnings.warn("Detect tomato: no pixel has been classified as truss!")
            return False

        if self.save:
            img_bg = self.img_rgb_crop
        else:
            img_bg = self.img_rgb_crop

        centers, radii, com = detect_tomato(self.truss_crop,
                                            self.settings['detect_tomato'],
                                            px_per_mm=self.px_per_mm,
                                            img_rgb=img_bg,
                                            save=self.save,
                                            pwd=pwd,
                                            name=self.name)

        # convert obtained coordinated to two-dimensional points linked to a coordinate frame
        self.radii = radii
        self.centers = points_from_coords(centers, self.LOCAL_FRAME_ID, self.transform)
        self.com = Point2D(com, self.LOCAL_FRAME_ID, self.transform)

        if self.com is None:
            return False
        else:
            return True
Ejemplo n.º 5
0
    def test_transform_forwards_backwards(self):
        """
        get coordinate return the original coordinate after translating forwards and backwards
        """
        shape = [1000, 400]  # [width, height]
        translation = [50, -10]
        for angle_rad in np.arange(-np.pi, np.pi, 10):

            transform = Transform('origin', 'local', shape, angle_rad,
                                  translation)
            point1 = Point2D([400, 100], 'origin', transform)

            coord1 = point1.get_coord('local')
            point2 = Point2D(coord1, 'local', transform)

            np.testing.assert_almost_equal(point1.get_coord('origin'),
                                           point2.get_coord('origin'))
Ejemplo n.º 6
0
    def test_345_rotation(self):

        shape = [8, 6]  # [width, height]
        angle = -np.arctan2(3, 4)
        transform = Transform('origin', 'local', dim=shape, angle=angle)

        point1 = Point2D([4, 3], 'origin', transform)
        point2 = Point2D([5, 3.0 / 5.0 * 8], 'local', transform)

        np.testing.assert_almost_equal(point1.get_coord('origin'), [4, 3])
        np.testing.assert_almost_equal(point1.get_coord('local'),
                                       [5, 3.0 / 5.0 * 8])

        np.testing.assert_almost_equal(point2.get_coord('origin'), [4, 3])
        np.testing.assert_almost_equal(point2.get_coord('local'),
                                       [5, 3.0 / 5.0 * 8])

        np.testing.assert_almost_equal(point1.dist(point2), 0)
Ejemplo n.º 7
0
    def detect_peduncle(self):
        """Detect the peduncle and junctions"""
        pwd = os.path.join(self.pwd, '06_peduncle')
        success = True

        if self.save:
            img_bg = change_brightness(self.get_segmented_image(local=True), 0.85)
        else:
            img_bg = self.img_rgb_crop

        mask, branch_data, junc_coords, end_coords = detect_peduncle(self.peduncle_crop,
                                                                     self.settings['detect_peduncle'],
                                                                     px_per_mm=self.px_per_mm,
                                                                     save=self.save,
                                                                     bg_img=img_bg,
                                                                     name=self.name,
                                                                     pwd=pwd)
        # convert to 2D points
        peduncle_points = points_from_coords(np.argwhere(mask)[:, (1, 0)], self.LOCAL_FRAME_ID, self.transform)
        junction_points = points_from_coords(junc_coords, self.LOCAL_FRAME_ID, self.transform)
        end_points = points_from_coords(end_coords, self.LOCAL_FRAME_ID, self.transform)

        for branch_type in branch_data:
            for i, branch in enumerate(branch_data[branch_type]):
                for lbl in ['coords', 'src_node_coord', 'dst_node_coord', 'center_node_coord']:

                    if lbl == 'coords':
                        branch_data[branch_type][i][lbl] = points_from_coords(branch[lbl], self.LOCAL_FRAME_ID,
                                                                              self.transform)
                    else:
                        branch_data[branch_type][i][lbl] = Point2D(branch[lbl], self.LOCAL_FRAME_ID, self.transform)

        self.junction_points = junction_points
        self.end_points = end_points
        self.peduncle_points = peduncle_points
        self.branch_data = branch_data
        return success
Ejemplo n.º 8
0
 def test_missing_transform(self):
     """
     get coordinate returns a MissingTransformError when requested a coordinate when no transform was given
     """
     point1 = Point2D([400, 100], 'origin')
     self.assertRaises(MissingTransformError, point1.get_coord, 'local')