def test_graphcut(self):
        if _has_graphcut:
            data = self.data

            # Core labels don't matter in this graphcut test
            # core_binary = (data == 5)
            core_labels = np.empty_like(data, dtype=np.uint32)
            # core_labels[0,...,0] = vigra.analysis.labelMultiArrayWithBackground(core_binary[0,...,0].astype(np.uint8))

            op = OpLabeledThreshold(graph=Graph())
            op.Method.setValue(ThresholdMethod.GRAPHCUT)
            op.FinalThreshold.setValue(0.5)
            op.Input.setValue(data.copy())
            op.CoreLabels.setValue(core_labels)
            op.GraphcutBeta.setValue(
                0.5)  # High enough to fill the hole in the third segment

            result = op.Output[:].wait()
            result_yx = result[0, :, :, 0, 0]
            # print result_yx

            label_values = np.unique(result)[1:]
            assert len(label_values) == 3
            assert len(np.unique(result_yx[1:12,
                                           1:5])) == 1  # Same as 'simple'
            assert len(
                np.unique(result_yx[7:10, 6:9])
            ) == 1  # Almost same as simple, but with the hole filled in.
 def test_simple(self):
     data = self.data
     core_labels = np.zeros_like(data) # core_labels aren't used by 'simple' method
     
     op = OpLabeledThreshold(graph=Graph())
     op.Method.setValue(ThresholdMethod.SIMPLE)
     op.FinalThreshold.setValue(0.5)
     op.Input.setValue(data.copy())
     op.CoreLabels.setValue(core_labels)
     
     result = op.Output[:].wait()
     assert result.max() == 3
     assert (result.astype(bool) == data.astype(bool)).all()
    def test_ipht(self):
        data = self.data
        core_binary = (data == 5)
        core_labels = np.empty_like(data, dtype=np.uint32)
        core_labels[0,...,0] = vigra.analysis.labelMultiArrayWithBackground(core_binary[0,...,0].astype(np.uint8))

        op = OpLabeledThreshold(graph=Graph())
        op.Method.setValue(ThresholdMethod.IPHT)
        op.FinalThreshold.setValue(0.5)
        op.Input.setValue(data.copy())
        op.CoreLabels.setValue(core_labels)
        
        result = op.Output[:].wait()
        result_yx = result[0,:,:,0,0]
        #print result_yx
        
        label_values = np.unique(result)[1:]
        assert len(label_values) == 2
        assert len(np.unique(result_yx[1:6, 1:5])) == 1
        assert len(np.unique(result_yx[7:12, 1:5])) == 1
    def test_hysteresis(self):
        data = self.data
        core_binary = (data == 5)
        core_labels = np.empty_like(data, dtype=np.uint32)
        core_labels[0,...,0] = vigra.analysis.labelMultiArrayWithBackground(core_binary[0,...,0].astype(np.uint8))

        op = OpLabeledThreshold(graph=Graph())
        op.Method.setValue(ThresholdMethod.HYSTERESIS)
        op.FinalThreshold.setValue(0.5)
        op.Input.setValue(data.copy())
        op.CoreLabels.setValue(core_labels)
        
        result = op.Output[:].wait()
        
        label_values = np.unique(result)[1:]
        assert len(label_values) == 1

        expected_result = np.where(data, label_values[0], 0)
        expected_result[0,:,5:,0,0] = 0 # Right half won't survive
        
        #print expected_result[0,:,:,0,0]
        #print result[0,:,:,0,0]
        assert (result == expected_result).all()