
    0-Ph                         d dl mZ d dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZ  G d d          Zd Zd	 Zd
 Zd ZdS )    )partialN)spatial)fit_segmenterpredict_segmenterTrainableSegmenter)multiscale_basic_featuresc                       e Zd Zd Zd ZdS )DummyNNClassifierc                 ^    || _         || _        t          j        | j                   | _        d S )N)Xlabelsr   cKDTreetree)selfr   r   s      p/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/future/tests/test_trainable_segmentation.pyfitzDummyNNClassifier.fit   s'    ODF++			    c                     |j         d         | j        j         d         k    r1t          d| j        j         d          d|j         d          d          | j                            |          d         }| j        |         S )N   z	Expected z features but got .)shaper   
ValueErrorr   queryr   )r   r   nearest_neighborss      r   predictzDummyNNClassifier.predict   sz    71:a((LDFLOLLqwqzLLL   !IOOA..q1{,--r   N)__name__
__module____qualname__r   r    r   r   r
   r
      s2        , , ,
. . . . .r   r
   c                     t          j        d          } d| d d<   | dt          j        j        | j         z  z  } t          j        | t           j                  }d|d d<   d|dd <   t                      }t          t          ddd	d
          } ||           }t          |||          }t          ||          }t          j        |d d         dk              sJ t          j        |dd          dk              sJ d S )N   r"   r   
   皙?dtype   F      ?edgestexture	sigma_min	sigma_max)npzerosrandomrandnr   
zeros_likeuint8r
   r   r   r   r   all)imgr   clffeatures_funcfeaturesouts         r   )test_trainable_segmentation_singlechannelr;      s   
(8

CCH4")/39---C]3bh///FF2A2JF233K


C!  M }S!!H
#
.
.C
Hc
*
*C6#crc(a-     6#bcc(a-       r   c                     t          j        d          } d| d d<   | dt          j        j        | j         z  z  } t          j        | d         t           j                  }d|d d<   d|dd <   t                      }t          | d	d	d
dd          }t          |||          }t          ||          }t          j        |d d         dk              sJ t          j        |dd          dk              sJ d S )N)r"   r"      r   r#   r$   ).r   r%   r'   r(   Fr)   )r+   r,   r-   r.   channel_axis)r/   r0   r1   r2   r   r3   r4   r
   r   r   r   r5   )r6   r   r7   r9   r:   s        r   (test_trainable_segmentation_multichannelr@   1   s	   
(;

CCH4")/39---C]3v;bh777FF2A2JF233K


C(  H #
.
.C
Hc
*
*C6#crc(a-     6#bcc(a-       r   c                  N   t          j        d          } d| d d<   | dt          j        j        | j         z  z  } t          j        | t           j                  }d|d d<   d|dd <   t                      }t          t          ddd	d
          } ||           }t          |||          }t           j                            d          }t          j        t                    5 }t          ||          }dt          |j                  v sJ 	 d d d            d S # 1 swxY w Y   d S )Nr!   r   r#   r$   r%   r'   r(   Fr)   r*   )   r"   r"   ztype of features)r/   r0   r1   r2   r   r3   r4   r
   r   r   r   pytestraisesr   r   strvalue)r6   r   r7   r8   r9   test_featureserr_s           r   #test_trainable_segmentation_predictrJ   G   si   
(8

CCH4")/39---C]3bh///FF2A2JF233K


C!  M }S!!H
#
.
.CI$$[11M	z	"	" 4cmS11!S^^333334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s   #)DD!Dc                     t          j        d          } d| dd<   | dt          j        j        | j         z  z  } t          j        | t           j                  }d|dd<   d|dd<   t                      }t          t          d	d	d
d          }t          ||          }|                    | |           t           j                            |j        ||dk                        |                    |           }t          j        |dd         dk              sJ t          j        |dd         dk              sJ t          j        | | j        fd          }t          t          d          }t          ||          }|                    ||           t           j                            |j        ||dk                        |                    |          }t          j        |dd         dk              sJ t          j        |dd         dk              sJ t'          j        t*                    5  |                    t          j        |d                     ddd           n# 1 swxY w Y   t'          j        t*                    5  |                    t          j        |gdz  d                     ddd           dS # 1 swxY w Y   dS )zFTest the object-oriented interface using the TrainableSegmenter class.r!   r   Nr#   r$   r%   r'   r(   Fr)   r*   )r7   r8   r   r>   )axis)r?   )r/   r0   r1   r2   r   r3   r4   r
   r   r   r   r   testingassert_array_almost_equalr   r   r5   stackTrC   rD   r   expand_dimsconcatenate)r6   r   r7   r8   	segmenterr:   img_with_channelss          r   test_trainable_segmentation_oorU   _   sk    (8

CCH4")/39---C]3bh///FF2A2JF233K


C!  M #s-HHHIMM#v J((VFQJ5GHHH


C
 
 C6#crc(a-     6#bcc(a-      #suB777!  M #s-HHHIMM#V,,, J((VFQJ5GHHH


-
.
.C6#crc(a-     6#bcc(a-      
z	"	" F F".):DDDEEEF F F F F F F F F F F F F F F 
z	"	" L L".*;)<q)@rJJJKKKL L L L L L L L L L L L L L L L L Ls$   9*I//I36I3.KKK)	functoolsr   numpyr/   rC   scipyr   skimage.futurer   r   r   skimage.featurer   r
   r;   r@   rJ   rU   r   r   r   <module>r[      s                     O O O O O O O O O O 5 5 5 5 5 5. . . . . . . . ! ! !,! ! !,4 4 401L 1L 1L 1L 1Lr   