def check_labels(self, labels):
        """
        Check that the input label(s) are valid label numbers within the
        segmentation image.

        Parameters
        ----------
        labels : int, 1D array-like (int)
            The label(s) to check.

        Raises
        ------
        ValueError
            If any input ``labels`` are invalid.
        """

        labels = np.atleast_1d(labels)
        bad_labels = set()

        # check for positive label numbers
        idx = np.where(labels <= 0)[0]
        if len(idx) > 0:
            bad_labels.update(labels[idx])

        # check if label is in the segmentation image
        bad_labels.update(np.setdiff1d(labels, self.labels))

        if len(bad_labels) > 0:
            if len(bad_labels) == 1:
                raise ValueError('label {} is invalid'.format(bad_labels))
            else:
                raise ValueError('labels {} are invalid'.format(bad_labels))
def check_labels ( self , labels ) : labels = np . atleast_1d ( labels ) bad_labels = set ( ) idx = np . where ( labels <= 0 ) [ 0 ] if len ( idx ) > 0 : bad_labels . update ( labels [ idx ] ) bad_labels . update ( np . setdiff1d ( labels , self . labels ) ) if len ( bad_labels ) > 0 : if len ( bad_labels ) == 1 : raise ValueError ( 'label {} is invalid' . format ( bad_labels ) ) else : raise ValueError ( 'labels {} are invalid' . format ( bad_labels ) )
Check that the input label(s) are valid label numbers within the
        segmentation image.

        Parameters
        ----------
        labels : int, 1D array-like (int)
            The label(s) to check.

        Raises
        ------
        ValueError
            If any input ``labels`` are invalid.