
    9i                         S SK Jr   S SKJr  S SKJr  Sr " S S	5      r	S
 r
S rg! \ a    Sr " S S\5      r N&f = f)    )multiscale_basic_features)NotFittedError)RandomForestClassifierTFc                       \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r       e/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/future/trainable_segmentation.pyr   r      s    r   r   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
TrainableSegmenter   aX  Estimator for classifying pixels.

Parameters
----------
clf : classifier object, optional
    classifier object, exposing a ``fit`` and a ``predict`` method as in
    scikit-learn's API, for example an instance of
    ``RandomForestClassifier`` or ``LogisticRegression`` classifier.
features_func : function, optional
    function computing features on all pixels of the image, to be passed
    to the classifier. The output should be of shape
    ``(m_features, *labels.shape)``. If None,
    :func:`skimage.feature.multiscale_basic_features` is used.

Methods
-------
compute_features
fit
predict
Nc                 n    Uc&  [         (       a  [        SSS9U l        O[        S5      eXl        X l        g )Nd   )n_estimatorsn_jobszOPlease install scikit-learn or pass a classifier instanceto TrainableSegmenter.)has_sklearnr   clfImportErrorfeatures_func)selfr   r   s      r   __init__TrainableSegmenter.__init__%   s9    ;{1s2N!- 
 H*r   c                 `    U R                   c  [        U l         U R                  U5      U l        g )N)r   r   features)r   images     r   compute_features#TrainableSegmenter.compute_features2   s(    %!:D**51r   c                 f    U R                  U5        [        X R                  U R                  5        g)a  Train classifier using partially labeled (annotated) image.

Parameters
----------
image : ndarray
    Input image, which can be grayscale or multichannel, and must have a
    number of dimensions compatible with ``self.features_func``.
labels : ndarray of ints
    Labeled array of shape compatible with ``image`` (same shape for a
    single-channel image). Labels >= 1 correspond to the training set and
    label 0 to unlabeled pixels to be segmented.
N)r"   fit_segmenterr    r   )r   r!   labelss      r   fitTrainableSegmenter.fit7   s$     	e$fmmTXX6r   c                 ~    U R                   c  [        U l         U R                  U5      n[        X R                  5      $ )a@  Segment new image using trained internal classifier.

Parameters
----------
image : ndarray
    Input image, which can be grayscale or multichannel, and must have a
    number of dimensions compatible with ``self.features_func``.

Raises
------
NotFittedError if ``self.clf`` has not been fitted yet (use ``self.fit``).
)r   r   predict_segmenterr   )r   r!   r    s      r   predictTrainableSegmenter.predictG   s7     %!:D%%e, 8844r   )r   r    r   )NN)
r	   r
   r   r   __doc__r   r"   r'   r+   r   r   r   r   r   r      s    *+2
7 5r   r   c                 ^    U S:  nX   nX   R                  5       nUR                  XE5        U$ )a  Segmentation using labeled parts of the image and a classifier.

Parameters
----------
labels : ndarray of ints
    Image of labels. Labels >= 1 correspond to the training set and
    label 0 to unlabeled pixels to be segmented.
features : ndarray
    Array of features, with the first dimension corresponding to the number
    of features, and the other dimensions correspond to ``labels.shape``.
clf : classifier object
    classifier object, exposing a ``fit`` and a ``predict`` method as in
    scikit-learn's API, for example an instance of
    ``RandomForestClassifier`` or ``LogisticRegression`` classifier.

Returns
-------
clf : classifier object
    classifier trained on ``labels``

Raises
------
NotFittedError if ``self.clf`` has not been fitted yet (use ``self.fit``).
r   )ravelr'   )r&   r    r   masktraining_datatraining_labelss         r   r%   r%   Z   s5    2 A:DNMl((*OGGM+Jr   c                    U R                   nU R                  S:  a  U R                  SUS   45      n  UR                  U 5      nUR                  USS 5      nU$ ! [         a    [	        S5      e[
         aI  nUR                  (       a1  SUR                  S   ;   a  [        UR                  S   S-   S-   5      eUeSnAff = f)	a  Segmentation of images using a pretrained classifier.

Parameters
----------
features : ndarray
    Array of features, with the last dimension corresponding to the number
    of features, and the other dimensions are compatible with the shape of
    the image to segment, or a flattened image.
clf : classifier object
    trained classifier object, exposing a ``predict`` method as in
    scikit-learn's API, for example an instance of
    ``RandomForestClassifier`` or ``LogisticRegression`` classifier. The
    classifier must be already trained, for example with
    :func:`skimage.future.fit_segmenter`.

Returns
-------
output : ndarray
    Labeled array, built from the prediction of the classifier.
   r   zWYou must train the classifier `clf` firstfor example with the `fit_segmenter` function.z#x must consist of vectors of lengthr   
zLMaybe you did not use the same type of features for training the classifier.N)shapendimreshaper+   r   
ValueErrorargs)r    r   shpredicted_labelserroutputs         r   r*   r*   z   s    * 
B}}q##RBL1;;x0 %%b"g.FM  
=
 	
  88=!L`a  Is   A C9AB==CN)skimage.featurer   sklearn.exceptionsr   sklearn.ensembler   r   r   	Exceptionr   r%   r*   r   r   r   <module>rC      sS    5	17KH5 H5V@*e  K s   ' ==