コード例 #1
0
ファイル: pygco.py プロジェクト: jgera/Segmentation-Code
    def setAllNeighbors(self, s1, s2, w):
        """Setup the whole neighbor system in the graph.
        s1, s2, w are 1d numpy ndarrays of the same length.

        Each element in s1 should be smaller than the corresponding element in s2.
        """
        if s1.min() < 0 or s1.max() >= self.numSites or s2.min() < 0 or s2.max() >= self.numSites:
            raise IndexOutOfBoundError()

        # These attributes are just used to keep a reference to corresponding 
        # arrays, otherwise the temporarily used arrays will be destroyed by
        # python's garbage collection system, and the C++ library won't have
        # access to them any more, which may cause trouble.
        self._edgeS1 = s1.astype(np.intc)
        self._edgeS2 = s2.astype(np.intc)
        self._edgeW = self._convertPairwiseArray(w)

        _cgco.gcoSetAllNeighbors(
                self.handle, self._edgeS1, self._edgeS2, self._edgeW, np.intc(self._edgeS1.size))
コード例 #2
0
    def set_all_neighbors(self, s1, s2, w):
        """Setup the whole neighbor system in the graph.
        s1, s2, w are 1d numpy ndarrays of the same length.

        Each element in s1 should be smaller than the corresponding element in s2.
        """
        if s1.min() < 0 or s1.max() >= self.nb_sites or s2.min() < 0 \
                or s2.max() >= self.nb_sites:
            raise IndexOutOfBoundError()

        # These attributes are just used to keep a reference to corresponding
        # arrays, otherwise the temporarily used arrays will be destroyed by
        # python's garbage collection system, and the C++ library won't have
        # access to them any more, which may cause trouble.
        self._edge_s1 = s1.astype(np.intc)
        self._edge_s2 = s2.astype(np.intc)
        self._edge_w = self._convert_pairwise_array(w)

        _cgco.gcoSetAllNeighbors(self.handle, self._edge_s1, self._edge_s2,
                                 self._edge_w, np.intc(self._edge_s1.size))